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

Function test_pidfile_self

tools/libutil/tests/pidfile_test.c:86–122  ·  view source on GitHub ↗

* Test that pidfile_open() locks against self. */

Source from the content-addressed store, hash-verified

84 * Test that pidfile_open() locks against self.
85 */
86static const char *
87test_pidfile_self(void)
88{
89 const char *fn = "test_pidfile_self";
90 struct pidfh *pf1, *pf2;
91 pid_t other = 0;
92 int serrno;
93
94 unlink(fn);
95 pf1 = pidfile_open(fn, 0600, &other);
96 if (pf1 == NULL && other != 0)
97 return ("pidfile exists and is locked");
98 if (pf1 == NULL)
99 return (strerror(errno));
100 if (pidfile_write(pf1) != 0) {
101 serrno = errno;
102 pidfile_close(pf1);
103 unlink(fn);
104 return (strerror(serrno));
105 }
106 // second open should fail
107 pf2 = pidfile_open(fn, 0600, &other);
108 if (pf2 != NULL) {
109 pidfile_close(pf1);
110 pidfile_close(pf2);
111 unlink(fn);
112 return ("managed to opened pidfile twice");
113 }
114 if (other != getpid()) {
115 pidfile_close(pf1);
116 unlink(fn);
117 return ("pidfile contained wrong PID");
118 }
119 pidfile_close(pf1);
120 unlink(fn);
121 return (NULL);
122}
123
124/*
125 * Common code for test_pidfile_{contested,inherited}.

Callers

nothing calls this directly

Calls 3

pidfile_openFunction · 0.85
pidfile_writeFunction · 0.85
pidfile_closeFunction · 0.85

Tested by

no test coverage detected