Allow the values for environment variables specified with -e to be
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 27 Dec 2008 23:37:09 +0000 (15:37 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sat, 27 Dec 2008 23:37:09 +0000 (15:37 -0800)
quoted.  Note that shells may strip the quotes so using this feature
may also require the use of backslashes.

sys/platform/vkernel/platform/init.c

index 84f2246..7d37aa8 100644 (file)
@@ -144,7 +144,9 @@ main(int ac, char **av)
        int bootOnDisk = -1;    /* set below to vcd (0) or vkd (1) */
        int c;
        int i;
+       int j;
        int n;
+       int isq;
        int real_vkernel_enable;
        int supports_sse;
        size_t vsize;
@@ -179,17 +181,27 @@ main(int ac, char **av)
                case 'e':
                        /*
                         * name=value:name=value:name=value...
+                        * name="value"...
+                        *
+                        * Allow values to be quoted but note that shells
+                        * may remove the quotes, so using this feature
+                        * to embed colons may require a backslash.
                         */
                        n = strlen(optarg);
+                       isq = 0;
                        kern_envp = malloc(n + 2);
-                       for (i = 0; i < n; ++i) {
-                               if (optarg[i] == ':')
-                                       kern_envp[i] = 0;
+                       for (i = j = 0; i < n; ++i) {
+                               if (optarg[i] == '"')
+                                       isq ^= 1;
+                               else if (optarg[i] == '\'')
+                                       isq ^= 2;
+                               else if (isq == 0 && optarg[i] == ':')
+                                       kern_envp[j++] = 0;
                                else
-                                       kern_envp[i] = optarg[i];
+                                       kern_envp[j++] = optarg[i];
                        }
-                       kern_envp[i++] = 0;
-                       kern_envp[i++] = 0;
+                       kern_envp[j++] = 0;
+                       kern_envp[j++] = 0;
                        break;
                case 's':
                        boothowto |= RB_SINGLE;