chiark / gitweb /
when determining unit file list, include invalid unit names in an "invalid" state
authorLennart Poettering <lennart@poettering.net>
Mon, 10 Sep 2012 23:11:32 +0000 (01:11 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 10 Sep 2012 23:14:25 +0000 (01:14 +0200)
.gitignore
Makefile.am
TODO
src/shared/install.c
src/shared/install.h
src/systemctl/systemctl.c
src/test/test-unit-file.c [new file with mode: 0644]

index ca95d7afba597f679d94bb40102f6fd556bafa3f..cc904f19ed5fda308612c2f960fd7c8a56b1f697 100644 (file)
@@ -1,3 +1,4 @@
+/test-unit-file
 /test-log
 /test-journal-verify
 /test-journal-match
index df3d3cad9d1570ee723c3aef00072ceb08ba5743..135d9f8ab19b8ca9f7740f221255f0250fa3b6f0 100644 (file)
@@ -1120,13 +1120,15 @@ noinst_PROGRAMS += \
        test-install \
        test-watchdog \
        test-unit-name \
-       test-log
+       test-log \
+       test-unit-file
 
 TESTS += \
        test-job-type \
        test-env-replace \
        test-strv \
-       test-unit-name
+       test-unit-name \
+       test-unit-file
 
 test_engine_SOURCES = \
        src/test/test-engine.c
@@ -1176,6 +1178,12 @@ test_unit_name_SOURCES = \
 test_unit_name_LDADD = \
        libsystemd-core.la
 
+test_unit_file_SOURCES = \
+       src/test/test-unit-file.c
+
+test_unit_file_LDADD = \
+       libsystemd-core.la
+
 test_log_SOURCES = \
        src/test/test-log.c
 
diff --git a/TODO b/TODO
index ec6d5ea8e85d15adedea56f2b561e57fe375aa65..10de80f91b1b504142eacae8391a3b92fe14f85e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -49,6 +49,8 @@ Bugfixes:
 
 Features:
 
+* Document word splitting syntax for ExecStart= and friends
+
 * merge: github.com/systemd/python-systemd
 
 * when writing journal entries order field items by their address to improve speed on rotating media
index ef1c3f584d3a4d28c9c76eb4326d37070a31cdc8..1a69337f5aef8c1d338a6c7a616b295e4434ca8b 100644 (file)
@@ -2003,25 +2003,24 @@ int unit_file_get_list(
                                 free(f->path);
                                 free(f);
                                 goto finish;
-                        } else if (r > 0)
+                        } else if (r > 0) {
+                                f->state = UNIT_FILE_ENABLED;
                                 goto found;
+                        }
 
                         r = unit_file_can_install(&paths, root_dir, f->path, true);
-                        if (r < 0) {
+                        if (r == -EINVAL ||  /* Invalid setting? */
+                            r == -EBADMSG || /* Invalid format? */
+                            r == -ENOENT     /* Included file not found? */)
+                                f->state = UNIT_FILE_INVALID;
+                        else if (r < 0) {
                                 free(f->path);
                                 free(f);
                                 goto finish;
-                        } else if (r > 0) {
+                        } else if (r > 0)
                                 f->state = UNIT_FILE_DISABLED;
-                                goto found;
-                        } else {
+                        else
                                 f->state = UNIT_FILE_STATIC;
-                                goto found;
-                        }
-
-                        free(f->path);
-                        free(f);
-                        continue;
 
                 found:
                         r = hashmap_put(h, path_get_file_name(f->path), f);
@@ -2051,7 +2050,8 @@ static const char* const unit_file_state_table[_UNIT_FILE_STATE_MAX] = {
         [UNIT_FILE_MASKED] = "masked",
         [UNIT_FILE_MASKED_RUNTIME] = "masked-runtime",
         [UNIT_FILE_STATIC] = "static",
-        [UNIT_FILE_DISABLED] = "disabled"
+        [UNIT_FILE_DISABLED] = "disabled",
+        [UNIT_FILE_INVALID] = "invalid",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState);
index f02fa3efbdaf0ce1b48547ff76ec9b0e4a22fa45..55249914b13bc8aa240039eaadbc28e8cf5a3306 100644 (file)
@@ -40,6 +40,7 @@ typedef enum UnitFileState {
         UNIT_FILE_MASKED_RUNTIME,
         UNIT_FILE_STATIC,
         UNIT_FILE_DISABLED,
+        UNIT_FILE_INVALID,
         _UNIT_FILE_STATE_MAX,
         _UNIT_FILE_STATE_INVALID = -1
 } UnitFileState;
index 98d0fcb39ea212ad71c6deb0d1fe821863a42823..5102c8ee58562cda88c322afc48083e73e346d13 100644 (file)
@@ -585,7 +585,8 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) {
 
                 if (u->state == UNIT_FILE_MASKED ||
                     u->state == UNIT_FILE_MASKED_RUNTIME ||
-                    u->state == UNIT_FILE_DISABLED) {
+                    u->state == UNIT_FILE_DISABLED ||
+                    u->state == UNIT_FILE_INVALID) {
                         on  = ansi_highlight_red(true);
                         off = ansi_highlight_red(false);
                 } else if (u->state == UNIT_FILE_ENABLED) {
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
new file mode 100644 (file)
index 0000000..b390c44
--- /dev/null
@@ -0,0 +1,52 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2012 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <assert.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+
+#include "install.h"
+#include "util.h"
+#include "macro.h"
+#include "hashmap.h"
+
+int main(int argc, char *argv[]) {
+
+        int r;
+        Hashmap *h;
+        Iterator i;
+        UnitFileList *p;
+
+        h = hashmap_new(string_hash_func, string_compare_func);
+        assert(h);
+
+        r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h);
+        log_info("%s", strerror(-r));
+        assert(r >= 0);
+
+        HASHMAP_FOREACH(p, h, i)
+                printf("%s = %s\n", p->path, unit_file_state_to_string(p->state));
+
+        unit_file_list_free(h);
+
+        return 0;
+}