Commit 79d906b7 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Track FreeBSD's pidfile.c as close as possible.

parent b264be7b
......@@ -76,7 +76,7 @@ vpf_read(const char *path, pid_t *pidptr)
char buf[16], *endptr;
int error, fd, i;
fd = open(path, O_RDONLY);
fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd == -1)
return (errno);
......@@ -85,6 +85,8 @@ vpf_read(const char *path, pid_t *pidptr)
(void)close(fd);
if (i == -1)
return (error);
else if (i == 0)
return (EAGAIN);
buf[i] = '\0';
*pidptr = strtol(buf, &endptr, 10);
......@@ -105,17 +107,10 @@ VPF_Open(const char *path, mode_t mode, pid_t *pidptr)
if (pfh == NULL)
return (NULL);
#if 0
if (path == NULL)
len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
"/var/run/%s.pid", getprogname());
else
#endif
{
assert(path != NULL);
len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
"%s", path);
}
assert(path != NULL);
len = snprintf(pfh->pf_path, sizeof(pfh->pf_path),
"%s", path);
if (len >= (int)sizeof(pfh->pf_path)) {
free(pfh);
errno = ENAMETOOLONG;
......@@ -124,12 +119,12 @@ VPF_Open(const char *path, mode_t mode, pid_t *pidptr)
/*
* Open the PID file and obtain exclusive lock.
* We truncate PID file here only to remove old PID immediatelly,
* We truncate PID file here only to remove old PID immediately,
* PID file will be truncated again in VPF_Write(), so
* VPF_Write() can be called multiple times.
*/
fd = VFL_Open(pfh->pf_path,
O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode);
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NONBLOCK, mode);
if (fd == -1) {
if (errno == EWOULDBLOCK && pidptr != NULL) {
errno = vpf_read(pfh->pf_path, pidptr);
......@@ -139,6 +134,7 @@ VPF_Open(const char *path, mode_t mode, pid_t *pidptr)
free(pfh);
return (NULL);
}
/*
* Remember file information, so in VPF_Write() we are sure we write
* to the proper descriptor.
......
#!/bin/sh
#
# Script to compare vpf.c with FreeBSD's pidfile.c
#
# Run this on a up-to-date FreeBSD source tree
sed '
s/vpf_/pidfile_/g
s/VPF_/pidfile_/g
s/pidfile_fh/pidfh/g
s/pidfile_Write/pidfile_write/g
s/pidfile_Close/pidfile_close/g
s/pidfile_Remove/pidfile_remove/g
s/pidfile_Open/pidfile_open/g
s/ (void)/ /g
' lib/libvarnish/vpf.c |
diff -ub /usr/src/lib/libutil/pidfile.c -
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment