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

Function test_pidfile_relative

tools/libutil/tests/pidfile_test.c:269–298  ·  view source on GitHub ↗

* Make sure we handle relative pidfile paths correctly. */

Source from the content-addressed store, hash-verified

267 * Make sure we handle relative pidfile paths correctly.
268 */
269static const char *
270test_pidfile_relative(void)
271{
272 char path[PATH_MAX], pid[32], tmpdir[PATH_MAX];
273 struct pidfh *pfh;
274 int fd;
275
276 (void)snprintf(tmpdir, sizeof(tmpdir), "%s.XXXXXX", __func__);
277 if (mkdtemp(tmpdir) == NULL)
278 return (strerror(errno));
279 (void)snprintf(path, sizeof(path), "%s/pidfile", tmpdir);
280
281 pfh = pidfile_open(path, 0600, NULL);
282 if (pfh == NULL)
283 return (strerror(errno));
284 if (pidfile_write(pfh) != 0)
285 return (strerror(errno));
286 fd = open(path, O_RDONLY);
287 if (fd < 0)
288 return (strerror(errno));
289 if (read(fd, pid, sizeof(pid)) < 0)
290 return (strerror(errno));
291 if (atoi(pid) != getpid())
292 return ("pid mismatch");
293 if (close(fd) != 0)
294 return (strerror(errno));
295 if (pidfile_close(pfh) != 0)
296 return (strerror(errno));
297 return (NULL);
298}
299
300static struct test {
301 const char *name;

Callers

nothing calls this directly

Calls 6

snprintfFunction · 0.85
pidfile_openFunction · 0.85
pidfile_writeFunction · 0.85
pidfile_closeFunction · 0.85
readFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected