* Make sure we handle relative pidfile paths correctly. */
| 267 | * Make sure we handle relative pidfile paths correctly. |
| 268 | */ |
| 269 | static const char * |
| 270 | test_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 | |
| 300 | static struct test { |
| 301 | const char *name; |
nothing calls this directly
no test coverage detected