[PATCH] Fix "networkCommand" to use handle $ENVIRONMENT correctly. (#474422)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Because networkCommand was using poptParseArgvString() to parse its
command line, environmental variables weren't being handled, which means
we can't use kernel command line parameters there.  Instead, build and
argz using getArg(), and pass it to poptGetContext directly.
---
 nash/nash.c    |   38 +++++++++++++++++++++++++-------------
 nash/net.h     |    2 +-
 nash/network.c |    9 +--------
 3 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/nash/nash.c b/nash/nash.c
index 7450504..0fd8cd6 100644
--- a/nash/nash.c
+++ b/nash/nash.c
@@ -56,7 +56,7 @@
 #include <mntent.h>
 #include <execinfo.h>
 #include <sched.h>
-
+#include <argz.h>
 #include <asm/unistd.h>
 #include <linux/fs.h>
 
@@ -2910,24 +2910,36 @@ usage:
 static int
 networkCommand(char *cmd, char *end)
 {
-    char *ncmd = NULL;
-    char c;
+    size_t argz_len = 0;
+    char *argz = NULL;
+
+    int argc;
+    char **argv;
+
+    char *initial_argv[] = { "network", NULL };
+    char *value = NULL;
     int rc;
-    size_t len;
 
     /* popt expects to get network --args here */
     if (!cmd || cmd >= end)
         return 1;
 
-    len = strcspn(cmd, "\n");
-    c = cmd[len];
-    cmd[len] = '\0';
-    rc = asprintf(&ncmd, "network %s", cmd);
-    cmd[len] = c;
-    if (rc < 0)
-        return rc;
-    rc = nashNetworkCommand(ncmd);
-    free(ncmd);
+    argz_create(initial_argv, &argz, &argz_len);
+
+    while ((cmd = getArg(cmd, end, &value)))
+        argz_add(&argz, &argz_len, value);
+
+    argc = argz_count(argz, argz_len);
+    argv = calloc(argc + 1, sizeof (char *));
+
+    argz_extract(argz, argz_len, argv);
+
+    rc = nashNetworkCommand(argc, argv);
+
+    free(argv);
+    while (argz)
+        argz_delete(&argz, &argz_len, argz);
+
     return rc;
 }
 
diff --git a/nash/net.h b/nash/net.h
index 9cd0164..1c70450 100644
--- a/nash/net.h
+++ b/nash/net.h
@@ -38,7 +38,7 @@ typedef uint32_t u32;
 typedef uint16_t u16;
 typedef uint8_t u8;
 
-int nashNetworkCommand(char * cmd);
+int nashNetworkCommand(int argc, char *argv[]);
 int renameNetworkInterface(char *hwaddr, char *ifname);
 
 #endif
diff --git a/nash/network.c b/nash/network.c
index 84398df..218e89a 100644
--- a/nash/network.c
+++ b/nash/network.c
@@ -377,9 +377,7 @@ static char *nashSetupInterface(char *dev, char *ip, char *netmask, char *broadc
     return NULL;
 }
 
-int nashNetworkCommand(char * cmd) {
-    int argc;
-    char ** argv;
+int nashNetworkCommand(int argc, char *argv[]) {
     char * bootProto = NULL, * dev = NULL, * dhcpclass = NULL, * ethtool = NULL, * hostname = NULL;
     char * gateway = NULL, * ip = NULL, * nameserver = NULL, * netmask = NULL, * dns = NULL, * domain = NULL;
     char * broadcast = NULL;
@@ -408,11 +406,6 @@ int nashNetworkCommand(char * cmd) {
         { NULL, 0, 0, NULL, 0, NULL, NULL }
     };
 
-    if (poptParseArgvString(cmd, &argc, (const char ***) &argv) || !argc) {
-        eprintf("ERROR: Invalid options to network command\n");
-        return 1;
-    }
-
     optCon = poptGetContext(NULL, argc, (const char **) argv,
                             netOptions, 0);
 
-- 
1.6.1.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux