summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-07-23 21:17:07 +0200
committerGitHub <noreply@github.com>2018-07-23 21:17:07 +0200
commit0dbff467f7fe35861ac8ce967878c5eb48e45ea8 (patch)
tree01bc747ef00cc05c78d23f44b64ba4a8c4cb76b9 /src/core
parentMerge pull request #9701 from yuwata/string-table-cleanups (diff)
parenttest: add a table test for ShowStatus (diff)
downloadsystemd-0dbff467f7fe35861ac8ce967878c5eb48e45ea8.tar.xz
systemd-0dbff467f7fe35861ac8ce967878c5eb48e45ea8.zip
Merge pull request #9685 from yuwata/fix-9663
core: serialize and deserialize current ShowStatus
Diffstat (limited to 'src/core')
-rw-r--r--src/core/dbus-manager.c2
-rw-r--r--src/core/main.c8
-rw-r--r--src/core/manager.c17
-rw-r--r--src/core/show-status.c26
-rw-r--r--src/core/show-status.h13
5 files changed, 43 insertions, 23 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 4ed68af1e0..4c0f79b983 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -232,7 +232,7 @@ static int property_get_show_status(
assert(reply);
assert(m);
- b = m->show_status > 0;
+ b = IN_SET(m->show_status, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES);
return sd_bus_message_append_basic(reply, 'b', &b);
}
diff --git a/src/core/main.c b/src/core/main.c
index 6bffd6f362..b7e98502eb 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -95,7 +95,7 @@ static int arg_crash_chvt = -1;
static bool arg_crash_shell = false;
static bool arg_crash_reboot = false;
static char *arg_confirm_spawn = NULL;
-static ShowStatus arg_show_status = _SHOW_STATUS_UNSET;
+static ShowStatus arg_show_status = _SHOW_STATUS_INVALID;
static bool arg_switched_root = false;
static bool arg_no_pager = false;
static bool arg_service_watchdogs = true;
@@ -470,7 +470,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
} else if (streq(key, "quiet") && !value) {
- if (arg_show_status == _SHOW_STATUS_UNSET)
+ if (arg_show_status == _SHOW_STATUS_INVALID)
arg_show_status = SHOW_STATUS_AUTO;
} else if (streq(key, "debug") && !value) {
@@ -1219,7 +1219,7 @@ static int status_welcome(void) {
_cleanup_free_ char *pretty_name = NULL, *ansi_color = NULL;
int r;
- if (arg_show_status <= 0)
+ if (IN_SET(arg_show_status, SHOW_STATUS_NO, SHOW_STATUS_AUTO))
return 0;
r = parse_os_release(NULL,
@@ -1985,7 +1985,7 @@ static int load_configuration(int argc, char **argv, const char **ret_error_mess
}
/* Initialize the show status setting if it hasn't been set explicitly yet */
- if (arg_show_status == _SHOW_STATUS_UNSET)
+ if (arg_show_status == _SHOW_STATUS_INVALID)
arg_show_status = SHOW_STATUS_YES;
return 0;
diff --git a/src/core/manager.c b/src/core/manager.c
index ada8712fd5..1d177008e5 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -3016,6 +3016,10 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) {
fprintf(f, "taint-logged=%s\n", yes_no(m->taint_logged));
fprintf(f, "service-watchdogs=%s\n", yes_no(m->service_watchdogs));
+ t = show_status_to_string(m->show_status);
+ if (t)
+ fprintf(f, "show-status=%s\n", t);
+
if (m->log_level_overridden)
fprintf(f, "log-level-override=%i\n", log_get_max_level());
if (m->log_target_overridden)
@@ -3205,6 +3209,15 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {
else
m->service_watchdogs = b;
+ } else if ((val = startswith(l, "show-status="))) {
+ ShowStatus s;
+
+ s = show_status_from_string(val);
+ if (s < 0)
+ log_notice("Failed to parse show-status flag %s", val);
+ else
+ manager_set_show_status(m, s);
+
} else if ((val = startswith(l, "log-level-override="))) {
int level;
@@ -3912,7 +3925,7 @@ void manager_set_show_status(Manager *m, ShowStatus mode) {
mode == SHOW_STATUS_NO ? "Disabling" : "Enabling");
m->show_status = mode;
- if (mode > 0)
+ if (IN_SET(mode, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES))
(void) touch("/run/systemd/show-status");
else
(void) unlink("/run/systemd/show-status");
@@ -3934,7 +3947,7 @@ static bool manager_get_show_status(Manager *m, StatusType type) {
if (type != STATUS_TYPE_EMERGENCY && manager_check_ask_password(m) > 0)
return false;
- return m->show_status > 0;
+ return IN_SET(m->show_status, SHOW_STATUS_TEMPORARY, SHOW_STATUS_YES);
}
const char *manager_get_confirm_spawn(Manager *m) {
diff --git a/src/core/show-status.c b/src/core/show-status.c
index fd9aeb9416..d8d2317d38 100644
--- a/src/core/show-status.c
+++ b/src/core/show-status.c
@@ -5,26 +5,30 @@
#include "io-util.h"
#include "parse-util.h"
#include "show-status.h"
+#include "string-table.h"
#include "string-util.h"
#include "terminal-util.h"
#include "util.h"
+static const char* const show_status_table[_SHOW_STATUS_MAX] = {
+ [SHOW_STATUS_NO] = "no",
+ [SHOW_STATUS_AUTO] = "auto",
+ [SHOW_STATUS_TEMPORARY] = "temporary",
+ [SHOW_STATUS_YES] = "yes",
+};
+
+DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(show_status, ShowStatus, SHOW_STATUS_YES);
+
int parse_show_status(const char *v, ShowStatus *ret) {
- int r;
+ ShowStatus s;
- assert(v);
assert(ret);
- if (streq(v, "auto")) {
- *ret = SHOW_STATUS_AUTO;
- return 0;
- }
-
- r = parse_boolean(v);
- if (r < 0)
- return r;
+ s = show_status_from_string(v);
+ if (s < 0 || s == SHOW_STATUS_TEMPORARY)
+ return -EINVAL;
- *ret = r ? SHOW_STATUS_YES : SHOW_STATUS_NO;
+ *ret = s;
return 0;
}
diff --git a/src/core/show-status.h b/src/core/show-status.h
index 1a80de33d9..ac590303c1 100644
--- a/src/core/show-status.h
+++ b/src/core/show-status.h
@@ -8,13 +8,16 @@
/* Manager status */
typedef enum ShowStatus {
- _SHOW_STATUS_UNSET = -2,
- SHOW_STATUS_AUTO = -1,
- SHOW_STATUS_NO = 0,
- SHOW_STATUS_YES = 1,
- SHOW_STATUS_TEMPORARY = 2,
+ SHOW_STATUS_NO,
+ SHOW_STATUS_AUTO,
+ SHOW_STATUS_TEMPORARY,
+ SHOW_STATUS_YES,
+ _SHOW_STATUS_MAX,
+ _SHOW_STATUS_INVALID = -1,
} ShowStatus;
+ShowStatus show_status_from_string(const char *v) _const_;
+const char* show_status_to_string(ShowStatus s) _pure_;
int parse_show_status(const char *v, ShowStatus *ret);
int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0);