MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_flopen_lock_other

Function test_flopen_lock_other

tools/libutil/tests/flopen_test.c:120–146  ·  view source on GitHub ↗

* Test that flopen() can lock against other processes */

Source from the content-addressed store, hash-verified

118 * Test that flopen() can lock against other processes
119 */
120const char *
121test_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

Callers

nothing calls this directly

Calls 2

flopenFunction · 0.85
closeFunction · 0.50

Tested by

no test coverage detected