]> git.mdlowis.com Git - proto/labwc.git/commitdiff
session: resolve variables in environment file
authorJohan Malm <jgm323@gmail.com>
Mon, 11 Oct 2021 21:15:44 +0000 (22:15 +0100)
committerJohan Malm <jgm323@gmail.com>
Mon, 11 Oct 2021 21:15:44 +0000 (22:15 +0100)
When parsing <key>=<value> pairs to set enrivonment variables,
resolve variables in <value>.

For example, resolve $bar in

    foo=$bar

Fix issue #70

src/config/session.c

index 4372c7ebf37a0da67ac4e57fff37d1cef2d46677..880eaeae774db5543655a21c9cabfdd0cb255e7f 100644 (file)
@@ -7,6 +7,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <wlr/util/log.h>
+#include "common/buf.h"
 #include "common/dir.h"
 #include "common/spawn.h"
 #include "common/string-helpers.h"
@@ -30,18 +31,24 @@ process_line(char *line)
        if (string_empty(line) || line[0] == '#') {
                return;
        }
-       char *key = NULL, *value = NULL;
+       char *key = NULL;
        char *p = strchr(line, '=');
        if (!p) {
                return;
        }
        *p = '\0';
        key = string_strip(line);
-       value = string_strip(++p);
-       if (string_empty(key) || string_empty(value)) {
-               return;
+
+       struct buf value;
+       buf_init(&value);
+       buf_add(&value, string_strip(++p));
+       buf_expand_shell_variables(&value);
+       if (string_empty(key) || !value.len) {
+               goto error;
        }
-       setenv(key, value, 1);
+       setenv(key, value.buf, 1);
+error:
+       free(value.buf);
 }
 
 void