changeset 2498:a08798c4143c draft

-4 and -6 are now mutually exclusive and when running on a single interface per protocol pidfiles are created. This means that other control options suchs as -x and -n will require the -4 or -6 option as well.
author Roy Marples <roy@marples.name>
date Thu, 29 May 2014 12:52:27 +0000
parents 61ce8921b6cd
children 0554844cb8a4
files defs.h dhcpcd.8.in dhcpcd.c
diffstat 3 files changed, 38 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/defs.h	Thu May 29 11:12:09 2014 +0000
+++ b/defs.h	Thu May 29 12:52:27 2014 +0000
@@ -49,7 +49,7 @@
 # define LEASEFILE6		DBDIR "/" PACKAGE "-%s.lease6"
 #endif
 #ifndef PIDFILE
-# define PIDFILE		RUNDIR "/" PACKAGE "%s%s.pid"
+# define PIDFILE		RUNDIR "/" PACKAGE "%s%s%s.pid"
 #endif
 #ifndef CONTROLSOCKET
 # define CONTROLSOCKET		RUNDIR "/" PACKAGE "%s%s.sock"
--- a/dhcpcd.8.in	Thu May 29 11:12:09 2014 +0000
+++ b/dhcpcd.8.in	Thu May 29 12:52:27 2014 +0000
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd March 7, 2014
+.Dd May 29, 2014
 .Dt DHCPCD 8
 .Os
 .Sh NAME
@@ -613,6 +613,16 @@
 requires a Berkley Packet Filter, or BPF device on BSD based systems and a
 Linux Socket Filter, or LPF device on Linux based systems for all IPv4
 configuration.
+.Pp
+If restricting
+.Nm
+to a single interface and optionally address family via the command-line
+then all futher calls to
+.Nm
+to rebind, reconfigure or exit need to include the same restrictive flags
+so that
+.Nm
+knows which process to signal.
 .Sh FILES
 .Bl -ohang
 .It Pa @SYSCONFDIR@/dhcpcd.conf
--- a/dhcpcd.c	Thu May 29 11:12:09 2014 +0000
+++ b/dhcpcd.c	Thu May 29 12:52:27 2014 +0000
@@ -1116,7 +1116,7 @@
 main(int argc, char **argv)
 {
 	struct dhcpcd_ctx ctx;
-	char pidfile[sizeof(PIDFILE) + IF_NAMESIZE];
+	char pidfile[sizeof(PIDFILE) + IF_NAMESIZE + 1];
 	struct if_options *ifo;
 	struct interface *ifp;
 	uint16_t family = 0;
@@ -1174,9 +1174,19 @@
 	{
 		switch (opt) {
 		case '4':
+			if (family) {
+				syslog(LOG_ERR, "cannot specify more than one"
+				    " address family");
+				goto exit_failure;
+			}
 			family = AF_INET;
 			break;
 		case '6':
+			if (family) {
+				syslog(LOG_ERR, "cannot specify more than one"
+				    " address family");
+				goto exit_failure;
+			}
 			family = AF_INET6;
 			break;
 		case 'f':
@@ -1278,16 +1288,29 @@
 		/* If we have any other args, we should run as a single dhcpcd
 		 *  instance for that interface. */
 		if (optind == argc - 1 && !(ctx.options & DHCPCD_MASTER)) {
+			const char *per;
+
 			if (strlen(argv[optind]) > IF_NAMESIZE) {
 				syslog(LOG_ERR, "%s: interface name too long",
 				    argv[optind]);
 				goto exit_failure;
 			}
+			/* Allow a dhcpcd interface per address family */
+			switch(family) {
+			case AF_INET:
+				per = "-4";
+				break;
+			case AF_INET6:
+				per = "-6";
+				break;
+			default:
+				per = "";
+			}
 			snprintf(pidfile, sizeof(pidfile),
-			    PIDFILE, "-", argv[optind]);
+			    PIDFILE, "-", argv[optind], per);
 		}
 		else {
-			snprintf(pidfile, sizeof(pidfile), PIDFILE, "", "");
+			snprintf(pidfile, sizeof(pidfile), PIDFILE, "", "", "");
 			ctx.options |= DHCPCD_MASTER;
 		}
 	}