radvd/radvd-1.1-stale_pid.patch
2008-04-11 09:25:01 +00:00

45 lines
1.3 KiB
Diff

diff -up radvd-1.1/radvd.c.stale_pid radvd-1.1/radvd.c
--- radvd-1.1/radvd.c.stale_pid 2008-01-24 11:03:17.000000000 +0100
+++ radvd-1.1/radvd.c 2008-04-04 15:10:52.000000000 +0200
@@ -70,6 +70,7 @@ main(int argc, char *argv[])
{
unsigned char msg[MSG_SIZE];
char pidstr[16];
+ int ret;
int c, log_method;
char *logfile, *pidfile;
sigset_t oset, nset;
@@ -230,10 +231,29 @@ main(int argc, char *argv[])
exit(1);
}
- /* FIXME: not atomic if pidfile is on an NFS mounted volume */
- if ((fd = open(pidfile, O_CREAT|O_EXCL|O_WRONLY, 0644)) < 0)
+ if ((fd = open(pidfile, O_RDONLY, 0)) > 0)
{
- flog(LOG_ERR, "radvd pid file already exists or cannot be created, terminating: %s", strerror(errno));
+ ret = read(fd, pidstr, sizeof(pidstr) - 1);
+ if (ret < 0)
+ {
+ flog(LOG_ERR, "cannot read radvd pid file, terminating: %s", strerror(errno));
+ exit(1);
+ }
+ pidstr[ret] = '\0';
+ if (!kill(atol(pidstr), 0))
+ {
+ flog(LOG_ERR, "radvd already running, terminating.");
+ exit(1);
+ }
+ close(fd);
+ fd = open(pidfile, O_CREAT|O_TRUNC|O_WRONLY, 0644);
+ }
+ else /* FIXME: not atomic if pidfile is on an NFS mounted volume */
+ fd = open(pidfile, O_CREAT|O_EXCL|O_WRONLY, 0644);
+
+ if (fd < 0)
+ {
+ flog(LOG_ERR, "cannot create radvd pid file, terminating: %s", strerror(errno));
exit(1);
}