dhcpcd-discuss

Re: compile error dhcpcd 6.3.2

Roy Marples

Thu Apr 17 10:57:30 2014

On 17/04/2014 11:38, Olaf Westrik wrote:
sorry, forgot to mention: gcc=4.4.5, glibc=2.11.3, linux headers=3.4

If you can't update glibc to 2.12, can you test the attached patch pleaase?

Thanks

Roy
Index: dhcpcd.c
==================================================================
--- dhcpcd.c
+++ dhcpcd.c
@@ -36,10 +36,11 @@
 #include <sys/types.h>
 #include <sys/uio.h>
 
 #include <ctype.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <getopt.h>
 #include <limits.h>
 #include <paths.h>
 #include <signal.h>
 #include <stdio.h>
@@ -1369,13 +1370,15 @@
 		if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST)
 			syslog(LOG_ERR, "mkdir `%s': %m", RUNDIR);
 		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 {
 			/* Lock the file so that only one instance of dhcpcd
 			 * runs on an interface */
@@ -1383,10 +1386,20 @@
 				syslog(LOG_ERR, "flock `%s': %m", pidfile);
 				close(ctx.pid_fd);
 				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());
 		}
 	}
 
 


Follow-Ups:
Re: compile error dhcpcd 6.3.2Olaf Westrik
References:
compile error dhcpcd 6.3.2Olaf Westrik
Re: compile error dhcpcd 6.3.2Roy Marples
Re: compile error dhcpcd 6.3.2Olaf Westrik
Archive administrator: postmaster@marples.name