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

Function pidfile_read

tools/libutil/pidfile.c:76–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76static int
77pidfile_read(int dirfd, const char *filename, pid_t *pidptr)
78{
79 char buf[16], *endptr;
80 int error, fd, i;
81
82 fd = openat(dirfd, filename, O_RDONLY | O_CLOEXEC);
83 if (fd == -1)
84 return (errno);
85
86 i = read(fd, buf, sizeof(buf) - 1);
87 error = errno; /* Remember errno in case close() wants to change it. */
88 close(fd);
89 if (i == -1)
90 return (error);
91 else if (i == 0)
92 return (EAGAIN);
93 buf[i] = '\0';
94
95 *pidptr = strtol(buf, &endptr, 10);
96 if (endptr != &buf[i])
97 return (EINVAL);
98
99 return (0);
100}
101
102struct pidfh *
103pidfile_open(const char *pathp, mode_t mode, pid_t *pidptr)

Callers 1

pidfile_openFunction · 0.85

Calls 3

strtolFunction · 0.85
readFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected