aboutsummaryrefslogtreecommitdiff
path: root/modutils/modutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'modutils/modutils.c')
-rw-r--r--modutils/modutils.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/modutils/modutils.c b/modutils/modutils.c
index 415dbbe44..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,13 +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 /* Spaces handled by "" pairs, but no way of escaping quotes */ 74 const char *var;
75//TODO: module-init-tools version 3.11.1 quotes only value: 75 const char *val;
76//it generates var="val with spaces", not "var=val with spaces" 76
77//(and it won't quote var *name* even if it has spaces) 77 var = *argv;
78 optlen += sprintf(options + optlen, (strchr(*argv, ' ') ? "\"%s\" " : "%s "), *argv); 78 options = xrealloc(options, optlen + 2 + strlen(var) + 2);
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);
79 } 95 }
96 /* Remove trailing space. Disabled */
97 /* if (optlen != 0) options[optlen-1] = '\0'; */
80 return options; 98 return options;
81} 99}
82 100