]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/main.c
Merge pull request #1216 from poettering/coccinelle-fixes-2
[thirdparty/systemd.git] / src / core / main.c
index 2736b272dcc0f1b030e270e3b411d81f9cedfaa4..48b5057a85d629bd6dc890afc2a5d5db47b1ec42 100644 (file)
@@ -374,7 +374,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value) {
                 /* Note that log_parse_environment() handles 'debug'
                  * too, and sets the log level to LOG_DEBUG. */
 
-                if (detect_container(NULL) > 0)
+                if (detect_container() > 0)
                         log_set_target(LOG_TARGET_CONSOLE);
 
         } else if (!in_initrd() && !value) {
@@ -433,25 +433,28 @@ static int config_parse_cpu_affinity2(
                 void *data,
                 void *userdata) {
 
-        const char *word, *state;
-        size_t l;
-        cpu_set_t *c = NULL;
+        const char *whole_rvalue = rvalue;
+        _cleanup_cpu_free_ cpu_set_t *c = NULL;
         unsigned ncpus = 0;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
 
-        FOREACH_WORD_QUOTED(word, l, rvalue, state) {
-                char *t;
-                int r;
+        for (;;) {
+                _cleanup_free_ char *word = NULL;
                 unsigned cpu;
+                int r;
 
-                if (!(t = strndup(word, l)))
-                        return log_oom();
+                r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
+                if (r < 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, r, "Invalid value for %s: %s", lvalue, whole_rvalue);
+                        return r;
+                }
+                if (r == 0)
+                        break;
 
-                r = safe_atou(t, &cpu);
-                free(t);
+                r = safe_atou(word, &cpu);
 
                 if (!c)
                         if (!(c = cpu_set_malloc(&ncpus)))
@@ -460,23 +463,19 @@ static int config_parse_cpu_affinity2(
                 if (r < 0 || cpu >= ncpus) {
                         log_syntax(unit, LOG_ERR, filename, line, -r,
                                    "Failed to parse CPU affinity '%s'", rvalue);
-                        CPU_FREE(c);
                         return -EBADMSG;
                 }
 
                 CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
         }
-        if (!isempty(state))
+        if (!isempty(rvalue))
                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
                            "Trailing garbage, ignoring.");
 
-        if (c) {
+        if (c)
                 if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0)
                         log_warning("Failed to set CPU affinity: %m");
 
-                CPU_FREE(c);
-        }
-
         return 0;
 }
 
@@ -1119,9 +1118,10 @@ static void test_mtab(void) {
         if (r >= 0 && nulstr_contains(ok, p))
                 return;
 
-        log_warning("/etc/mtab is not a symlink or not pointing to /proc/self/mounts. "
-                    "This is not supported anymore. "
-                    "Please make sure to replace this file by a symlink to avoid incorrect or misleading mount(8) output.");
+        log_error("/etc/mtab is not a symlink or not pointing to /proc/self/mounts. "
+                  "This is not supported anymore. "
+                  "Please make sure to replace this file by a symlink to avoid incorrect or misleading mount(8) output.");
+        freeze();
 }
 
 static void test_usr(void) {
@@ -1205,12 +1205,11 @@ static int status_welcome(void) {
                            "PRETTY_NAME", &pretty_name,
                            "ANSI_COLOR", &ansi_color,
                            NULL);
-        if (r == -ENOENT) {
+        if (r == -ENOENT)
                 r = parse_env_file("/usr/lib/os-release", NEWLINE,
                                    "PRETTY_NAME", &pretty_name,
                                    "ANSI_COLOR", &ansi_color,
                                    NULL);
-        }
 
         if (r < 0 && r != -ENOENT)
                 log_warning_errno(r, "Failed to read os-release file: %m");
@@ -1298,7 +1297,7 @@ int main(int argc, char *argv[]) {
         if (getpid() == 1)
                 umask(0);
 
-        if (getpid() == 1 && detect_container(NULL) <= 0) {
+        if (getpid() == 1 && detect_container() <= 0) {
 
                 /* Running outside of a container as PID 1 */
                 arg_running_as = MANAGER_SYSTEM;
@@ -1552,14 +1551,14 @@ int main(int argc, char *argv[]) {
         }
 
         if (arg_running_as == MANAGER_SYSTEM) {
-                const char *virtualization = NULL;
+                int v;
 
                 log_info(PACKAGE_STRING " running in %ssystem mode. (" SYSTEMD_FEATURES ")",
                          arg_action == ACTION_TEST ? "test " : "" );
 
-                detect_virtualization(&virtualization);
-                if (virtualization)
-                        log_info("Detected virtualization %s.", virtualization);
+                v = detect_virtualization();
+                if (v > 0)
+                        log_info("Detected virtualization %s.", virtualization_to_string(v));
 
                 write_container_id();
 
@@ -1843,10 +1842,8 @@ finish:
                 arg_shutdown_watchdog = m->shutdown_watchdog;
         m = manager_free(m);
 
-        for (j = 0; j < ELEMENTSOF(arg_default_rlimit); j++) {
-                free(arg_default_rlimit[j]);
-                arg_default_rlimit[j] = NULL;
-        }
+        for (j = 0; j < ELEMENTSOF(arg_default_rlimit); j++)
+                arg_default_rlimit[j] = mfree(arg_default_rlimit[j]);
 
         arg_default_unit = mfree(arg_default_unit);
 
@@ -2047,7 +2044,7 @@ finish:
                 /* Avoid the creation of new processes forked by the
                  * kernel; at this point, we will not listen to the
                  * signals anyway */
-                if (detect_container(NULL) <= 0)
+                if (detect_container() <= 0)
                         (void) cg_uninstall_release_agent(SYSTEMD_CGROUP_CONTROLLER);
 
                 execve(SYSTEMD_SHUTDOWN_BINARY_PATH, (char **) command_line, env_block);