chiark / gitweb /
main: add link to wiki page with longer explanation of the /usr madness
[elogind.git] / src / load-fragment.c
index eaeaadaea48b3e273c464c0b28912e6b875bbfb0..bd7529ff950461f59e184c02b822437a4e3cce38 100644 (file)
@@ -1340,79 +1340,25 @@ static int config_parse_env_file(
                 void *data,
                 void *userdata) {
 
-        FILE *f;
-        int r;
-        char ***env = data;
-        bool ignore = false;
+        char ***env = data, **k;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if (rvalue[0] == '-') {
-                ignore = true;
-                rvalue++;
-        }
-
-        if (!path_is_absolute(rvalue)) {
+        if (!path_is_absolute(rvalue[0] == '-' ? rvalue + 1 : rvalue)) {
                 log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename, line, rvalue);
                 return 0;
         }
 
-        if (!(f = fopen(rvalue, "re"))) {
-                if (!ignore)
-                        log_error("[%s:%u] Failed to open environment file '%s', ignoring: %m", filename, line, rvalue);
-                return 0;
-        }
-
-        while (!feof(f)) {
-                char l[LINE_MAX], *p, *u;
-                char **t;
-
-                if (!fgets(l, sizeof(l), f)) {
-                        if (feof(f))
-                                break;
-
-                        log_error("[%s:%u] Failed to read environment file '%s', ignoring: %m", filename, line, rvalue);
-                        r = 0;
-                        goto finish;
-                }
-
-                p = strstrip(l);
-
-                if (!*p)
-                        continue;
-
-                if (strchr(COMMENTS, *p))
-                        continue;
-
-                if (!(u = normalize_env_assignment(p))) {
-                        log_error("Out of memory");
-                        r = -ENOMEM;
-                        goto finish;
-                }
-
-                t = strv_append(*env, u);
-                free(u);
-
-                if (!t) {
-                        log_error("Out of memory");
-                        r = -ENOMEM;
-                        goto finish;
-                }
-
-                strv_free(*env);
-                *env = t;
-        }
-
-        r = 0;
+        if (!(k = strv_append(*env, rvalue)))
+                return -ENOMEM;
 
-finish:
-        if (f)
-                fclose(f);
+        strv_free(*env);
+        *env = k;
 
-        return r;
+        return 0;
 }
 
 static int config_parse_ip_tos(
@@ -1503,6 +1449,34 @@ static int config_parse_condition_kernel(
         return 0;
 }
 
+static int config_parse_condition_virt(
+                const char *filename,
+                unsigned line,
+                const char *section,
+                const char *lvalue,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        Unit *u = data;
+        bool negate;
+        Condition *c;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        if ((negate = rvalue[0] == '!'))
+                rvalue++;
+
+        if (!(c = condition_new(CONDITION_VIRTUALIZATION, rvalue, negate)))
+                return -ENOMEM;
+
+        LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
+        return 0;
+}
+
 static int config_parse_condition_null(
                 const char *filename,
                 unsigned line,
@@ -1714,6 +1688,7 @@ static void dump_items(FILE *f, const ConfigItem *items) {
                 { config_parse_condition_path,   "CONDITION" },
                 { config_parse_condition_kernel, "CONDITION" },
                 { config_parse_condition_null,   "CONDITION" },
+                { config_parse_condition_virt,   "CONDITION" },
         };
 
         assert(f);
@@ -1774,7 +1749,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "CPUAffinity",            config_parse_cpu_affinity,    &(context),                                      section   }, \
                 { "UMask",                  config_parse_mode,            &(context).umask,                                section   }, \
                 { "Environment",            config_parse_strv,            &(context).environment,                          section   }, \
-                { "EnvironmentFile",        config_parse_env_file,        &(context).environment,                          section   }, \
+                { "EnvironmentFile",        config_parse_env_file,        &(context).environment_files,                    section   }, \
                 { "StandardInput",          config_parse_input,           &(context).std_input,                            section   }, \
                 { "StandardOutput",         config_parse_output,          &(context).std_output,                           section   }, \
                 { "StandardError",          config_parse_output,          &(context).std_error,                            section   }, \
@@ -1838,6 +1813,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "ConditionPathExists",    config_parse_condition_path,  u,                                               "Unit"    },
                 { "ConditionDirectoryNotEmpty", config_parse_condition_path,  u,                                           "Unit"    },
                 { "ConditionKernelCommandLine", config_parse_condition_kernel, u,                                          "Unit"    },
+                { "ConditionVirtualization",config_parse_condition_virt,  u,                                               "Unit"    },
                 { "ConditionNull",          config_parse_condition_null,  u,                                               "Unit"    },
 
                 { "PIDFile",                config_parse_path,            &u->service.pid_file,                            "Service" },