[netfilter-cvslog] r3360 - trunk/nfsim/tools

rusty at netfilter.org rusty at netfilter.org
Tue Dec 14 02:32:14 CET 2004


Author: rusty at netfilter.org
Date: 2004-12-14 02:32:14 +0100 (Tue, 14 Dec 2004)
New Revision: 3360

Modified:
   trunk/nfsim/tools/iptables.c
Log:
Use execvp, with enhanced path.
Report error when exec fails.


Modified: trunk/nfsim/tools/iptables.c
===================================================================
--- trunk/nfsim/tools/iptables.c	2004-12-14 01:04:08 UTC (rev 3359)
+++ trunk/nfsim/tools/iptables.c	2004-12-14 01:32:14 UTC (rev 3360)
@@ -31,18 +31,14 @@
 #include "utils.h"
 #include "message.h"
 
-static char *command_prefix = "/sbin";
-
 static bool run_command(int argc, char **argv)
 {
 	pid_t child;
 	int status;
 	int childfd[2];
- 	char cmd[strlen(command_prefix) + 1 + strlen(argv[0]) + 1];
+	char *prefix;
 	char buf[4096] = { 0 };
 
-	sprintf(cmd, "%s/%s", command_prefix, argv[0]);
-
 	if (pipe(childfd) != 0)
 		barf_perror("%s pipe", cmd);
 
@@ -55,7 +51,17 @@
 		dup2(childfd[1], STDERR_FILENO);
 		if (setenv("LD_PRELOAD", "fakesockopt.so.1.0", 1))
 			barf("putenv failed");
-		execv(cmd, argv);
+		prefix = getenv("NFSIM_IPTABLES_PREFIX");
+		if (prefix) {
+			char *path = talloc_asprintf(NULL, "%s/%s", prefix,
+						     argv[0]);
+			execv(path, argv);
+			fprintf(stderr, "Could not exec %s!\n", path);
+			talloc_free(path);
+		} else {
+			execvp(argv[0], argv);
+			fprintf(stderr, "Could not exec %s!\n", argv[0]);
+		}
 		exit(1);
 	}
 
@@ -91,10 +97,14 @@
 
 static void init(void)
 {
-	char *prefix = getenv("NFSIM_IPTABLES_PREFIX");
-	if (prefix)
-		command_prefix = prefix;
+	char *path = getenv("PATH");
 
+	/* Some people don't have sbin etc. in their path: append. */
+	path = talloc_asprintf(NULL, "%s:/sbin:/usr/sbin:/usr/local/sbin",
+			       getenv("PATH"));
+	setenv("PATH", path, 1);
+	talloc_free(path);
+
 	tui_register_command("iptables", run_command, run_command_help);
 	tui_register_command("iptables-save", run_command, run_command_help);
 	tui_register_command("iptables-restore", run_command,




More information about the netfilter-cvslog mailing list