aboutsummaryrefslogtreecommitdiff
path: root/modutils/modutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'modutils/modutils.c')
-rw-r--r--modutils/modutils.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/modutils/modutils.c b/modutils/modutils.c
index 565d0d22f..6187ca72f 100644
--- a/modutils/modutils.c
+++ b/modutils/modutils.c
@@ -62,7 +62,7 @@ char* FAST_FUNC filename2modname(const char *filename, char *modname)
62 return modname; 62 return modname;
63} 63}
64 64
65char* FAST_FUNC parse_cmdline_module_options(char **argv) 65char* FAST_FUNC parse_cmdline_module_options(char **argv, int quote_spaces)
66{ 66{
67 char *options; 67 char *options;
68 int optlen; 68 int optlen;
@@ -70,14 +70,31 @@ char* FAST_FUNC parse_cmdline_module_options(char **argv)
70 options = xzalloc(1); 70 options = xzalloc(1);
71 optlen = 0; 71 optlen = 0;
72 while (*++argv) { 72 while (*++argv) {
73 options = xrealloc(options, optlen + 2 + strlen(*argv) + 2); 73 const char *fmt;
74 /* Older versions were enclosing space-containing *argv in "", 74 const char *var;
75 * but both modprobe and insmod from module-init-tools 3.11.1 75 const char *val;
76 * don't do this anymore. (As to extra trailing space, 76
77 * insmod adds it but modprobe does not. We do in both cases) 77 var = *argv;
78 */ 78 options = xrealloc(options, optlen + 2 + strlen(var) + 2);
79 optlen += sprintf(options + optlen, "%s ", *argv); 79 fmt = "%.*s%s ";
80 val = strchrnul(var, '=');
81 if (quote_spaces) {
82 /*
83 * modprobe (module-init-tools version 3.11.1) compat:
84 * quote only value:
85 * var="val with spaces", not "var=val with spaces"
86 * (note: var *name* is not checked for spaces!)
87 */
88 if (*val) { /* has var=val format. skip '=' */
89 val++;
90 if (strchr(val, ' '))
91 fmt = "%.*s\"%s\" ";
92 }
93 }
94 optlen += sprintf(options + optlen, fmt, (int)(val - var), var, val);
80 } 95 }
96 /* Remove trailing space. Disabled */
97 /* if (optlen != 0) options[optlen-1] = '\0'; */
81 return options; 98 return options;
82} 99}
83 100