diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-09-11 01:11:32 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-09-11 01:14:25 +0200 |
commit | b5b46d599524341ddd7407e5dff1021af8ff5089 (patch) | |
tree | 05e2bb1a8800ab7800f1c7c3455d7c07cb7a1af5 /src | |
parent | 802840582c71e9679637a4631866ce2d179f03c5 (diff) |
when determining unit file list, include invalid unit names in an "invalid" state
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/install.c | 24 | ||||
-rw-r--r-- | src/shared/install.h | 1 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 3 | ||||
-rw-r--r-- | src/test/test-unit-file.c | 52 |
4 files changed, 67 insertions, 13 deletions
diff --git a/src/shared/install.c b/src/shared/install.c index ef1c3f584d..1a69337f5a 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -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); diff --git a/src/shared/install.h b/src/shared/install.h index f02fa3efbd..55249914b1 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -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; diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 98d0fcb39e..5102c8ee58 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -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 index 0000000000..b390c44b05 --- /dev/null +++ b/src/test/test-unit-file.c @@ -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; +} |