chiark / gitweb /
load-fragment: properly parse Nice= value
[elogind.git] / src / load-fragment.c
index 424e6c37bb9d8d6e82572d986713a407ae04eec5..fc64ddd5a0f0b5bc49c2d0a4ec959c076fc64adb 100644 (file)
@@ -191,7 +191,6 @@ static int config_parse_listen(
                 void *data,
                 void *userdata) {
 
-        int r;
         SocketPort *p;
         Socket *s;
 
@@ -217,7 +216,7 @@ static int config_parse_listen(
         } else {
                 p->type = SOCKET_SOCKET;
 
-                if ((r = socket_address_parse(&p->address, rvalue)) < 0) {
+                if (socket_address_parse(&p->address, rvalue) < 0) {
                         log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
                         free(p);
                         return 0;
@@ -289,14 +288,14 @@ static int config_parse_nice(
                 void *userdata) {
 
         ExecContext *c = data;
-        int priority, r;
+        int priority;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atoi(rvalue, &priority)) < 0) {
+        if (safe_atoi(rvalue, &priority) < 0) {
                 log_error("[%s:%u] Failed to parse nice priority, ignoring: %s. ", filename, line, rvalue);
                 return 0;
         }
@@ -307,7 +306,7 @@ static int config_parse_nice(
         }
 
         c->nice = priority;
-        c->nice_set = false;
+        c->nice_set = true;
 
         return 0;
 }
@@ -322,14 +321,14 @@ static int config_parse_oom_score_adjust(
                 void *userdata) {
 
         ExecContext *c = data;
-        int oa, r;
+        int oa;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atoi(rvalue, &oa)) < 0) {
+        if (safe_atoi(rvalue, &oa) < 0) {
                 log_error("[%s:%u] Failed to parse the OOM score adjust value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -433,7 +432,7 @@ static int config_parse_exec(
 
                 k = 0;
                 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                        if (strncmp(w, ";", l) == 0)
+                        if (strncmp(w, ";", MAX(l, 1U)) == 0)
                                 break;
 
                         k++;
@@ -444,7 +443,7 @@ static int config_parse_exec(
 
                 k = 0;
                 FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                        if (strncmp(w, ";", l) == 0)
+                        if (strncmp(w, ";", MAX(l, 1U)) == 0)
                                 break;
 
                         if (honour_argv0 && w == rvalue) {
@@ -506,14 +505,13 @@ static int config_parse_usec(
                 void *userdata) {
 
         usec_t *usec = data;
-        int r;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = parse_usec(rvalue, usec)) < 0) {
+        if (parse_usec(rvalue, usec) < 0) {
                 log_error("[%s:%u] Failed to parse time value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -893,14 +891,13 @@ static int config_parse_timer_slack_nsec(
 
         ExecContext *c = data;
         unsigned long u;
-        int r;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atolu(rvalue, &u)) < 0) {
+        if (safe_atolu(rvalue, &u) < 0) {
                 log_error("[%s:%u] Failed to parse time slack value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -928,7 +925,7 @@ static int config_parse_limit(
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atollu(rvalue, &u)) < 0) {
+        if (safe_atollu(rvalue, &u) < 0) {
                 log_error("[%s:%u] Failed to parse resource value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -985,14 +982,14 @@ static int config_parse_sysv_priority(
                 void *userdata) {
 
         int *priority = data;
-        int r, i;
+        int i;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atoi(rvalue, &i)) < 0 || i < 0) {
+        if (safe_atoi(rvalue, &i) < 0 || i < 0) {
                 log_error("[%s:%u] Failed to parse SysV start priority, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -1012,14 +1009,14 @@ static int config_parse_fsck_passno(
                 void *userdata) {
 
         int *passno = data;
-        int r, i;
+        int i;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if ((r = safe_atoi(rvalue, &i)) < 0 || i < 0) {
+        if (safe_atoi(rvalue, &i) || i < 0) {
                 log_error("[%s:%u] Failed to parse fsck pass number, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -1077,11 +1074,11 @@ static int config_parse_mount_flags(
         assert(data);
 
         FOREACH_WORD_QUOTED(w, l, rvalue, state) {
-                if (strncmp(w, "shared", l) == 0)
+                if (strncmp(w, "shared", MAX(l, 6U)) == 0)
                         flags |= MS_SHARED;
-                else if (strncmp(w, "slave", l) == 0)
+                else if (strncmp(w, "slave", MAX(l, 5U)) == 0)
                         flags |= MS_SLAVE;
-                else if (strncmp(w, "private", l) == 0)
+                else if (strncmp(w, "private", MAX(l, 7U)) == 0)
                         flags |= MS_PRIVATE;
                 else {
                         log_error("[%s:%u] Failed to parse mount flags, ignoring: %s", filename, line, rvalue);
@@ -1104,7 +1101,6 @@ static int config_parse_timer(
 
         Timer *t = data;
         usec_t u;
-        int r;
         TimerValue *v;
         TimerBase b;
 
@@ -1118,7 +1114,7 @@ static int config_parse_timer(
                 return 0;
         }
 
-        if ((r = parse_usec(rvalue, &u)) < 0) {
+        if (parse_usec(rvalue, &u) < 0) {
                 log_error("[%s:%u] Failed to parse timer value, ignoring: %s", filename, line, rvalue);
                 return 0;
         }
@@ -1348,26 +1344,37 @@ static int config_parse_env_file(
         FILE *f;
         int r;
         char ***env = data;
+        bool ignore = false;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
+        if (rvalue[0] == '-') {
+                ignore = true;
+                rvalue++;
+        }
+
+        if (!path_is_absolute(rvalue)) {
+                log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename, line, rvalue);
+                return 0;
+        }
+
         if (!(f = fopen(rvalue, "re"))) {
-                log_error("[%s:%u] Failed to open environment file '%s', ignoring: %m", filename, line, rvalue);
+                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;
+                char l[LINE_MAX], *p, *u;
                 char **t;
 
                 if (!fgets(l, sizeof(l), f)) {
                         if (feof(f))
                                 break;
 
-                        r = -errno;
                         log_error("[%s:%u] Failed to read environment file '%s', ignoring: %m", filename, line, rvalue);
                         r = 0;
                         goto finish;
@@ -1381,7 +1388,21 @@ static int config_parse_env_file(
                 if (strchr(COMMENTS, *p))
                         continue;
 
-                t = strv_env_set(*env, p);
+                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;
         }
@@ -1405,7 +1426,6 @@ static int config_parse_ip_tos(
                 void *userdata) {
 
         int *ip_tos = data, x;
-        int r;
 
         assert(filename);
         assert(lvalue);
@@ -1413,7 +1433,7 @@ static int config_parse_ip_tos(
         assert(data);
 
         if ((x = ip_tos_from_string(rvalue)) < 0)
-                if ((r = safe_atoi(rvalue, &x)) < 0) {
+                if (safe_atoi(rvalue, &x) < 0) {
                         log_error("[%s:%u] Failed to parse IP TOS value, ignoring: %s", filename, line, rvalue);
                         return 0;
                 }
@@ -1448,7 +1468,8 @@ static int config_parse_condition_path(
                 return 0;
         }
 
-        if (!(c = condition_new(CONDITION_PATH_EXISTS, rvalue, negate)))
+        if (!(c = condition_new(streq(lvalue, "ConditionPathExists") ? CONDITION_PATH_EXISTS : CONDITION_DIRECTORY_NOT_EMPTY,
+                                rvalue, negate)))
                 return -ENOMEM;
 
         LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
@@ -1793,6 +1814,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "PAMName",                config_parse_string_printf,   &(context).pam_name,                             section   }, \
                 { "KillMode",               config_parse_kill_mode,       &(context).kill_mode,                            section   }, \
                 { "KillSignal",             config_parse_kill_signal,     &(context).kill_signal,                          section   }, \
+                { "SendSIGKILL",            config_parse_bool,            &(context).send_sigkill,                         section   }, \
                 { "UtmpIdentifier",         config_parse_string_printf,   &(context).utmp_id,                              section   }
 
         const ConfigItem items[] = {
@@ -1815,6 +1837,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "DefaultDependencies",    config_parse_bool,            &u->meta.default_dependencies,                   "Unit"    },
                 { "JobTimeoutSec",          config_parse_usec,            &u->meta.job_timeout,                            "Unit"    },
                 { "ConditionPathExists",    config_parse_condition_path,  u,                                               "Unit"    },
+                { "ConditionDirectoryNotEmpty", config_parse_condition_path,  u,                                           "Unit"    },
                 { "ConditionKernelCommandLine", config_parse_condition_kernel, u,                                          "Unit"    },
                 { "ConditionNull",          config_parse_condition_null,  u,                                               "Unit"    },
 
@@ -1886,6 +1909,8 @@ static int load_from_path(Unit *u, const char *path) {
 
                 { "What",                   config_parse_path,            &u->swap.parameters_fragment.what,               "Swap"    },
                 { "Priority",               config_parse_int,             &u->swap.parameters_fragment.priority,           "Swap"    },
+                { "TimeoutSec",             config_parse_usec,            &u->swap.timeout_usec,                           "Swap"    },
+                EXEC_CONTEXT_CONFIG_ITEMS(u->swap.exec_context, "Swap"),
 
                 { "OnActiveSec",            config_parse_timer,           &u->timer,                                       "Timer"   },
                 { "OnBootSec",              config_parse_timer,           &u->timer,                                       "Timer"   },