* Test that flopen() can lock against other processes */
| 118 | * Test that flopen() can lock against other processes |
| 119 | */ |
| 120 | const char * |
| 121 | test_flopen_lock_other(void) |
| 122 | { |
| 123 | const char *fn = "test_flopen_lock_other"; |
| 124 | const char *result = NULL; |
| 125 | volatile int fd1, fd2; |
| 126 | |
| 127 | unlink(fn); |
| 128 | fd1 = flopen(fn, O_RDWR|O_CREAT, 0640); |
| 129 | if (fd1 < 0) { |
| 130 | result = strerror(errno); |
| 131 | } else { |
| 132 | fd2 = -42; |
| 133 | if (vfork() == 0) { |
| 134 | fd2 = flopen(fn, O_RDWR|O_NONBLOCK); |
| 135 | close(fd2); |
| 136 | _exit(0); |
| 137 | } |
| 138 | if (fd2 == -42) |
| 139 | result = "vfork() doesn't work as expected"; |
| 140 | if (fd2 >= 0) |
| 141 | result = "second open succeeded"; |
| 142 | close(fd1); |
| 143 | } |
| 144 | unlink(fn); |
| 145 | return (result); |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Test that child processes inherit the lock |