diff options
author | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2013-02-15 14:16:47 +0900 |
---|---|---|
committer | YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> | 2013-02-15 14:16:47 +0900 |
commit | bd93a0b3f608e5b676bbd0db0b31d1ac77fa8bca (patch) | |
tree | e749e70667edc3a8d74fe9c3e1fa20e0b359d869 /ninfod | |
parent | 7b2b88ac124bd60d495852a81feac33d9c158fa3 (diff) | |
download | iputils-bd93a0b3f608e5b676bbd0db0b31d1ac77fa8bca.tar.gz |
ninfod: Open pidfile exclusively for write.
Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Diffstat (limited to 'ninfod')
-rw-r--r-- | ninfod/ninfod.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/ninfod/ninfod.c b/ninfod/ninfod.c index ac7c21f..5ff6993 100644 --- a/ninfod/ninfod.c +++ b/ninfod/ninfod.c @@ -436,6 +436,23 @@ static void cleanup_pidfile(void) } } +static FILE *fopen_excl(const char *file) +{ +#ifndef __linux__ + int fd; + FILE *fp; + + fd = open(file, O_CREAT | O_RDWR | O_EXCL, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (fd < 0) + return NULL; + + return fdopen(file, "w+"); +#else + return fopen(file, "w+x"); +#endif +} + static void do_daemonize(void) { FILE *fp = NULL; @@ -456,7 +473,7 @@ static void do_daemonize(void) } } - fp = fopen(opt_p, "w+"); + fp = fopen_excl(opt_p); if (!fp) { DEBUG(LOG_ERR, "failed to open file '%s': %s\n", opt_p, strerror(errno)); |