From 90657286fcc2e76a6c76b2c7df6f20f222051c1f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 27 Jan 2018 21:51:32 +0900 Subject: [PATCH] analyze: merge {get,set}-log-{level,target} to log-{level,target} (#8020) Also, service-watchdogs now shows current watchdog state when no optional argument is provided. --- man/systemd-analyze.xml | 47 +++++++++++-------------------- shell-completion/bash/systemd-analyze | 6 ++-- shell-completion/zsh/_systemd-analyze | 10 +++---- src/analyze/analyze.c | 53 +++++++++++++++++++++++++++-------- 4 files changed, 64 insertions(+), 52 deletions(-) diff --git a/man/systemd-analyze.xml b/man/systemd-analyze.xml index 7e54531..4f7248c 100644 --- a/man/systemd-analyze.xml +++ b/man/systemd-analyze.xml @@ -94,24 +94,14 @@ systemd-analyze OPTIONS - set-log-level - LEVEL + log-level + LEVEL systemd-analyze OPTIONS - set-log-target - TARGET - - - systemd-analyze - OPTIONS - get-log-level - - - systemd-analyze - OPTIONS - get-log-target + log-target + TARGET systemd-analyze @@ -135,7 +125,7 @@ systemd-analyze OPTIONS service-watchdogs - STATE + BOOL @@ -198,26 +188,20 @@ state. Its format is subject to change without notice and should not be parsed by applications. - systemd-analyze set-log-level - LEVEL changes the current log - level of the systemd daemon to - LEVEL (accepts the same values as + systemd-analyze log-level + prints the current log level of the systemd daemon. + If an optional argument LEVEL is provided, then the command changes the current log + level of the systemd daemon to LEVEL (accepts the same values as described in systemd1). - systemd-analyze set-log-target - TARGET changes the current log - target of the systemd daemon to - TARGET (accepts the same values as + systemd-analyze log-target + prints the current log target of the systemd daemon. + If an optional argument TARGET is provided, then the command changes the current log + target of the systemd daemon to TARGET (accepts the same values as , described in systemd1). - systemd-analyze get-log-level - prints the current log level of the systemd daemon. - - systemd-analyze get-log-target - prints the current log target of the systemd daemon. - systemd-analyze syscall-filter SET… will list system calls contained in the specified system call set SET, or all known sets if no sets are specified. Argument SET must include @@ -239,8 +223,9 @@ syntax described in systemd.time7. - systemd-analyze service-watchdogs - STATE globally enables or disables the service + systemd-analyze service-watchdogs + prints the current state of service runtime watchdogs of the systemd daemon. + If an optional boolean argument is provided, then globally enables or disables the service runtime watchdogs () and emergency actions (e.g. or ); see systemd.service5. diff --git a/shell-completion/bash/systemd-analyze b/shell-completion/bash/systemd-analyze index 171802e..fb30487 100644 --- a/shell-completion/bash/systemd-analyze +++ b/shell-completion/bash/systemd-analyze @@ -42,11 +42,11 @@ _systemd_analyze() { ) local -A VERBS=( - [STANDALONE]='time blame plot dump get-log-level get-log-target calendar' + [STANDALONE]='time blame plot dump calendar' [CRITICAL_CHAIN]='critical-chain' [DOT]='dot' - [LOG_LEVEL]='set-log-level' - [LOG_TARGET]='set-log-target' + [LOG_LEVEL]='log-level' + [LOG_TARGET]='log-target' [VERIFY]='verify' [SECCOMP_FILTER]='syscall-filter' [SERVICE_WATCHDOGS]='service-watchdogs' diff --git a/shell-completion/zsh/_systemd-analyze b/shell-completion/zsh/_systemd-analyze index 85e46dc..ae13f4b 100644 --- a/shell-completion/zsh/_systemd-analyze +++ b/shell-completion/zsh/_systemd-analyze @@ -1,13 +1,13 @@ #compdef systemd-analyze # SPDX-License-Identifier: LGPL-2.1+ -_systemd_analyze_set-log-level() { +_systemd_analyze_log-level() { local -a _levels _levels=(debug info notice warning err crit alert emerg) _describe -t level 'logging level' _levels || compadd "$@" } -_systemd_analyze_set-log-target() { +_systemd_analyze_log-target() { local -a _targets _targets=(console journal kmsg journal-or-kmsg null) _describe -t target 'logging target' _targets || compadd "$@" @@ -33,10 +33,8 @@ _systemd_analyze_command(){ 'plot:Output SVG graphic showing service initialization' 'dot:Dump dependency graph (in dot(1) format)' 'dump:Dump server status' - 'set-log-level:Set systemd log threshold' - 'set-log-target:Set systemd log target' - 'get-log-level:Get systemd log threshold' - 'get-log-target:Get systemd log target' + 'log-level:Get/set systemd log threshold' + 'log-target:Get/set systemd log target' 'service-watchdogs:Get/set service watchdog status' 'syscall-filter:List syscalls in seccomp filter' 'verify:Check unit files for correctness' diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 4611044..834620a 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -1353,6 +1353,10 @@ static int get_log_level(int argc, char *argv[], void *userdata) { return 0; } +static int get_or_set_log_level(int argc, char *argv[], void *userdata) { + return (argc == 1) ? get_log_level(argc, argv, userdata) : set_log_level(argc, argv, userdata); +} + static int set_log_target(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; @@ -1405,6 +1409,10 @@ static int get_log_target(int argc, char *argv[], void *userdata) { return 0; } +static int get_or_set_log_target(int argc, char *argv[], void *userdata) { + return (argc == 1) ? get_log_target(argc, argv, userdata) : set_log_target(argc, argv, userdata); +} + #if HAVE_SECCOMP static void dump_syscall_filter(const SyscallFilterSet *set) { const char *syscall; @@ -1526,19 +1534,39 @@ static int service_watchdogs(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int b, r; - assert(argc == 2); + assert(IN_SET(argc, 1, 2)); assert(argv); + r = acquire_bus(false, &bus); + if (r < 0) + return log_error_errno(r, "Failed to create bus connection: %m"); + + /* get ServiceWatchdogs */ + if (argc == 1) { + r = sd_bus_get_property_trivial( + bus, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "ServiceWatchdogs", + &error, + 'b', + &b); + if (r < 0) + return log_error_errno(r, "Failed to get service-watchdog state: %s", bus_error_message(&error, r)); + + printf("%s\n", yes_no(!!b)); + + return 0; + } + + /* set ServiceWatchdogs */ b = parse_boolean(argv[1]); if (b < 0) { log_error("Failed to parse service-watchdogs argument."); return -EINVAL; } - r = acquire_bus(false, &bus); - if (r < 0) - return log_error_errno(r, "Failed to create bus connection: %m"); - r = sd_bus_set_property( bus, "org.freedesktop.systemd1", @@ -1549,7 +1577,7 @@ static int service_watchdogs(int argc, char *argv[], void *userdata) { "b", b); if (r < 0) - return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r)); + return log_error_errno(r, "Failed to set service-watchdog state: %s", bus_error_message(&error, r)); return 0; } @@ -1588,15 +1616,13 @@ static int help(int argc, char *argv[], void *userdata) { " critical-chain [UNIT...] Print a tree of the time critical chain of units\n" " plot Output SVG graphic showing service initialization\n" " dot [UNIT...] Output dependency graph in man:dot(1) format\n" - " set-log-level LEVEL Set logging threshold for manager\n" - " set-log-target TARGET Set logging target for manager\n" - " get-log-level Get logging threshold for manager\n" - " get-log-target Get logging target for manager\n" + " log-level [LEVEL] Get/set logging threshold for manager\n" + " log-target [TARGET] Get/set logging target for manager\n" " dump Output state serialization of service manager\n" " syscall-filter [NAME...] Print list of syscalls in seccomp filter\n" " verify FILE... Check unit files for correctness\n" " calendar SPEC... Validate repetitive calendar time events\n" - " service-watchdogs on/off Enable/disable service watchdogs\n" + " service-watchdogs [BOOL] Get/set service watchdog state\n" , program_invocation_short_name); /* When updating this list, including descriptions, apply @@ -1748,6 +1774,9 @@ int main(int argc, char *argv[]) { { "critical-chain", VERB_ANY, VERB_ANY, 0, analyze_critical_chain }, { "plot", VERB_ANY, 1, 0, analyze_plot }, { "dot", VERB_ANY, VERB_ANY, 0, dot }, + { "log-level", VERB_ANY, 2, 0, get_or_set_log_level }, + { "log-target", VERB_ANY, 2, 0, get_or_set_log_target }, + /* The following four verbs are deprecated aliases */ { "set-log-level", 2, 2, 0, set_log_level }, { "get-log-level", VERB_ANY, 1, 0, get_log_level }, { "set-log-target", 2, 2, 0, set_log_target }, @@ -1756,7 +1785,7 @@ int main(int argc, char *argv[]) { { "syscall-filter", VERB_ANY, VERB_ANY, 0, dump_syscall_filters }, { "verify", 2, VERB_ANY, 0, do_verify }, { "calendar", 2, VERB_ANY, 0, test_calendar }, - { "service-watchdogs", 2, 2, 0, service_watchdogs }, + { "service-watchdogs", VERB_ANY, 2, 0, service_watchdogs }, {} }; -- 2.7.4