Mercurial > hg > dhcpcd
changeset 2421:8ef3c579ef9f draft
Work with older libc's without O_CLOEXEC.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Fri, 18 Apr 2014 13:17:42 +0000 |
| parents | 56c36e50a079 |
| children | 531eb96614d9 |
| files | dhcpcd.c |
| diffstat | 1 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/dhcpcd.c Sun Apr 06 17:50:53 2014 +0000 +++ b/dhcpcd.c Fri Apr 18 13:17:42 2014 +0000 @@ -38,6 +38,7 @@ #include <ctype.h> #include <errno.h> +#include <fcntl.h> #include <getopt.h> #include <limits.h> #include <paths.h> @@ -1371,9 +1372,11 @@ 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 @@ 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()); } }
