]> Nishi Git Mirror - mandshurica.git/commitdiff
set environment variable in exec directive
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 11 May 2024 00:46:27 +0000 (00:46 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 11 May 2024 00:46:27 +0000 (00:46 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@72 f982e544-4a7d-3444-ad1a-fde59a2a69f1

Mandshurica/template.c

index 142e8f584ba30b985c879d5025dfbc4d5d6115c3..e57a333c258b144878e5405a15558765a5b4030c 100644 (file)
@@ -42,6 +42,8 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+extern char** params;
+
 char* mandshurica_parse_template(const char* data, struct ms_param param) {
        char* webroot = mandshurica_get_param("HTTPRoot");
        if(webroot == NULL) webroot = WEBROOT_PREFIX;
@@ -127,6 +129,28 @@ char* mandshurica_parse_template(const char* data, struct ms_param param) {
                                                        free(tmp);
                                                }
                                        }
+                               } else if(strcmp(op, "exec") == 0) {
+                                       /* Kinda dangerous directive */
+                                       if(arg != NULL) {
+                                               int j;
+                                               for(j = 0; params[j] != NULL; j += 2) {
+                                                       char* name = mandshurica_strcat("Config_", params[j]);
+                                                       setenv(name, params[j + 1], 1);
+                                                       free(name);
+                                               }
+                                               FILE* proc = popen(arg, "r");
+                                               char buf[513];
+                                               int len;
+                                               while(1) {
+                                                       len = fread(buf, 1, 512, proc);
+                                                       if(len == 0) break;
+                                                       buf[len] = 0;
+                                                       char* tmp = ret;
+                                                       ret = mandshurica_strcat(tmp, buf);
+                                                       free(tmp);
+                                               }
+                                               pclose(proc);
+                                       }
                                } else if(strcmp(op, "version") == 0) {
                                        char* tmp = ret;
                                        ret = mandshurica_strcat(tmp, MANDSHURICA_VERSION);