summaryrefslogtreecommitdiffstats
path: root/dhcpcd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2014-04-18 13:17:42 +0000
committerRoy Marples <roy@marples.name>2014-04-18 13:17:42 +0000
commitfbc3019cc13ffe2debf558fe1a4598b042ca8a29 (patch)
treee2fa2e2901263aed8e422848356632bda35c49bb /dhcpcd.c
parenta3099289692d6d750912cbc9d9104caddb6fece6 (diff)
downloaddhcpcd-fbc3019cc13ffe2debf558fe1a4598b042ca8a29.tar.xz
Work with older libc's without O_CLOEXEC.
Diffstat (limited to 'dhcpcd.c')
-rw-r--r--dhcpcd.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/dhcpcd.c b/dhcpcd.c
index 399b5744..847a3136 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -38,6 +38,7 @@ const char dhcpcd_copyright[] = "Copyright (c) 2006-2014 Roy Marples";
#include <ctype.h>
#include <errno.h>
+#include <fcntl.h>
#include <getopt.h>
#include <limits.h>
#include <paths.h>
@@ -1371,9 +1372,11 @@ main(int argc, char **argv)
if (mkdir(DBDIR, 0755) == -1 && errno != EEXIST)
syslog(LOG_ERR, "mkdir `%s': %m", DBDIR);
- ctx.pid_fd = open(pidfile,
- O_WRONLY | O_CREAT | O_CLOEXEC | O_NONBLOCK,
- 0664);
+ opt = O_WRONLY | O_CREAT | O_NONBLOCK;
+#ifdef O_CLOEXEC
+ opt |= O_CLOEXEC;
+#endif
+ ctx.pid_fd = open(pidfile, opt, 0664);
if (ctx.pid_fd == -1)
syslog(LOG_ERR, "open `%s': %m", pidfile);
else {
@@ -1385,6 +1388,16 @@ main(int argc, char **argv)
ctx.pid_fd = -1;
goto exit_failure;
}
+#ifndef O_CLOEXEC
+ if (fcntl(ctx.pid_fd, F_GETFD, &opt) == -1 ||
+ fcntl(ctx.pid_fd, F_SETFD, opt | FD_CLOEXEC) == -1)
+ {
+ syslog(LOG_ERR, "fcntl: %m");
+ close(ctx.pid_fd);
+ ctx.pid_fd = -1;
+ goto exit_failure;
+ }
+#endif
write_pid(ctx.pid_fd, getpid());
}
}