| 74 | } |
| 75 | |
| 76 | static int |
| 77 | pidfile_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 | |
| 102 | struct pidfh * |
| 103 | pidfile_open(const char *pathp, mode_t mode, pid_t *pidptr) |
no test coverage detected