1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

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.
This commit is contained in:
Yu Watanabe 2018-01-27 21:51:32 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent 4c0d481095
commit 90657286fc
4 changed files with 64 additions and 52 deletions

View File

@ -94,24 +94,14 @@
<cmdsynopsis> <cmdsynopsis>
<command>systemd-analyze</command> <command>systemd-analyze</command>
<arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">OPTIONS</arg>
<arg choice="plain">set-log-level</arg> <arg choice="plain">log-level</arg>
<arg choice="plain"><replaceable>LEVEL</replaceable></arg> <arg choice="opt"><replaceable>LEVEL</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
<cmdsynopsis> <cmdsynopsis>
<command>systemd-analyze</command> <command>systemd-analyze</command>
<arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">OPTIONS</arg>
<arg choice="plain">set-log-target</arg> <arg choice="plain">log-target</arg>
<arg choice="plain"><replaceable>TARGET</replaceable></arg> <arg choice="opt"><replaceable>TARGET</replaceable></arg>
</cmdsynopsis>
<cmdsynopsis>
<command>systemd-analyze</command>
<arg choice="opt" rep="repeat">OPTIONS</arg>
<arg choice="plain">get-log-level</arg>
</cmdsynopsis>
<cmdsynopsis>
<command>systemd-analyze</command>
<arg choice="opt" rep="repeat">OPTIONS</arg>
<arg choice="plain">get-log-target</arg>
</cmdsynopsis> </cmdsynopsis>
<cmdsynopsis> <cmdsynopsis>
<command>systemd-analyze</command> <command>systemd-analyze</command>
@ -135,7 +125,7 @@
<command>systemd-analyze</command> <command>systemd-analyze</command>
<arg choice="opt" rep="repeat">OPTIONS</arg> <arg choice="opt" rep="repeat">OPTIONS</arg>
<arg choice="plain">service-watchdogs</arg> <arg choice="plain">service-watchdogs</arg>
<arg choice="plain"><replaceable>STATE</replaceable></arg> <arg choice="opt"><replaceable>BOOL</replaceable></arg>
</cmdsynopsis> </cmdsynopsis>
</refsynopsisdiv> </refsynopsisdiv>
@ -198,26 +188,20 @@
state. Its format is subject to change without notice and should state. Its format is subject to change without notice and should
not be parsed by applications.</para> not be parsed by applications.</para>
<para><command>systemd-analyze set-log-level <para><command>systemd-analyze log-level</command>
<replaceable>LEVEL</replaceable></command> changes the current log prints the current log level of the <command>systemd</command> daemon.
level of the <command>systemd</command> daemon to If an optional argument <replaceable>LEVEL</replaceable> is provided, then the command changes the current log
<replaceable>LEVEL</replaceable> (accepts the same values as level of the <command>systemd</command> daemon to <replaceable>LEVEL</replaceable> (accepts the same values as
<option>--log-level=</option> described in <option>--log-level=</option> described in
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>).</para> <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>).</para>
<para><command>systemd-analyze set-log-target <para><command>systemd-analyze log-target</command>
<replaceable>TARGET</replaceable></command> changes the current log prints the current log target of the <command>systemd</command> daemon.
target of the <command>systemd</command> daemon to If an optional argument <replaceable>TARGET</replaceable> is provided, then the command changes the current log
<replaceable>TARGET</replaceable> (accepts the same values as target of the <command>systemd</command> daemon to <replaceable>TARGET</replaceable> (accepts the same values as
<option>--log-target=</option>, described in <option>--log-target=</option>, described in
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>).</para> <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>).</para>
<para><command>systemd-analyze get-log-level</command>
prints the current log level of the <command>systemd</command> daemon.</para>
<para><command>systemd-analyze get-log-target</command>
prints the current log target of the <command>systemd</command> daemon.</para>
<para><command>systemd-analyze syscall-filter <optional><replaceable>SET</replaceable></optional></command> <para><command>systemd-analyze syscall-filter <optional><replaceable>SET</replaceable></optional></command>
will list system calls contained in the specified system call set <replaceable>SET</replaceable>, will list system calls contained in the specified system call set <replaceable>SET</replaceable>,
or all known sets if no sets are specified. Argument <replaceable>SET</replaceable> must include or all known sets if no sets are specified. Argument <replaceable>SET</replaceable> must include
@ -239,8 +223,9 @@
syntax described in syntax described in
<citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para> <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
<para><command>systemd-analyze service-watchdogs <para><command>systemd-analyze service-watchdogs</command>
<replaceable>STATE</replaceable></command> globally enables or disables the service prints the current state of service runtime watchdogs of the <command>systemd</command> daemon.
If an optional boolean argument is provided, then globally enables or disables the service
runtime watchdogs (<option>WatchdogSec=</option>) and emergency actions (e.g. runtime watchdogs (<option>WatchdogSec=</option>) and emergency actions (e.g.
<option>OnFailure=</option> or <option>StartLimitAction=</option>); see <option>OnFailure=</option> or <option>StartLimitAction=</option>); see
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>.

View File

@ -42,11 +42,11 @@ _systemd_analyze() {
) )
local -A VERBS=( 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' [CRITICAL_CHAIN]='critical-chain'
[DOT]='dot' [DOT]='dot'
[LOG_LEVEL]='set-log-level' [LOG_LEVEL]='log-level'
[LOG_TARGET]='set-log-target' [LOG_TARGET]='log-target'
[VERIFY]='verify' [VERIFY]='verify'
[SECCOMP_FILTER]='syscall-filter' [SECCOMP_FILTER]='syscall-filter'
[SERVICE_WATCHDOGS]='service-watchdogs' [SERVICE_WATCHDOGS]='service-watchdogs'

View File

@ -1,13 +1,13 @@
#compdef systemd-analyze #compdef systemd-analyze
# SPDX-License-Identifier: LGPL-2.1+ # SPDX-License-Identifier: LGPL-2.1+
_systemd_analyze_set-log-level() { _systemd_analyze_log-level() {
local -a _levels local -a _levels
_levels=(debug info notice warning err crit alert emerg) _levels=(debug info notice warning err crit alert emerg)
_describe -t level 'logging level' _levels || compadd "$@" _describe -t level 'logging level' _levels || compadd "$@"
} }
_systemd_analyze_set-log-target() { _systemd_analyze_log-target() {
local -a _targets local -a _targets
_targets=(console journal kmsg journal-or-kmsg null) _targets=(console journal kmsg journal-or-kmsg null)
_describe -t target 'logging target' _targets || compadd "$@" _describe -t target 'logging target' _targets || compadd "$@"
@ -33,10 +33,8 @@ _systemd_analyze_command(){
'plot:Output SVG graphic showing service initialization' 'plot:Output SVG graphic showing service initialization'
'dot:Dump dependency graph (in dot(1) format)' 'dot:Dump dependency graph (in dot(1) format)'
'dump:Dump server status' 'dump:Dump server status'
'set-log-level:Set systemd log threshold' 'log-level:Get/set systemd log threshold'
'set-log-target:Set systemd log target' 'log-target:Get/set systemd log target'
'get-log-level:Get systemd log threshold'
'get-log-target:Get systemd log target'
'service-watchdogs:Get/set service watchdog status' 'service-watchdogs:Get/set service watchdog status'
'syscall-filter:List syscalls in seccomp filter' 'syscall-filter:List syscalls in seccomp filter'
'verify:Check unit files for correctness' 'verify:Check unit files for correctness'

View File

@ -1353,6 +1353,10 @@ static int get_log_level(int argc, char *argv[], void *userdata) {
return 0; 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) { 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_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = 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; 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 #if HAVE_SECCOMP
static void dump_syscall_filter(const SyscallFilterSet *set) { static void dump_syscall_filter(const SyscallFilterSet *set) {
const char *syscall; 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; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int b, r; int b, r;
assert(argc == 2); assert(IN_SET(argc, 1, 2));
assert(argv); 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]); b = parse_boolean(argv[1]);
if (b < 0) { if (b < 0) {
log_error("Failed to parse service-watchdogs argument."); log_error("Failed to parse service-watchdogs argument.");
return -EINVAL; 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( r = sd_bus_set_property(
bus, bus,
"org.freedesktop.systemd1", "org.freedesktop.systemd1",
@ -1549,7 +1577,7 @@ static int service_watchdogs(int argc, char *argv[], void *userdata) {
"b", "b",
b); b);
if (r < 0) 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; 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" " critical-chain [UNIT...] Print a tree of the time critical chain of units\n"
" plot Output SVG graphic showing service initialization\n" " plot Output SVG graphic showing service initialization\n"
" dot [UNIT...] Output dependency graph in man:dot(1) format\n" " dot [UNIT...] Output dependency graph in man:dot(1) format\n"
" set-log-level LEVEL Set logging threshold for manager\n" " log-level [LEVEL] Get/set logging threshold for manager\n"
" set-log-target TARGET Set logging target for manager\n" " log-target [TARGET] Get/set logging target for manager\n"
" get-log-level Get logging threshold for manager\n"
" get-log-target Get logging target for manager\n"
" dump Output state serialization of service manager\n" " dump Output state serialization of service manager\n"
" syscall-filter [NAME...] Print list of syscalls in seccomp filter\n" " syscall-filter [NAME...] Print list of syscalls in seccomp filter\n"
" verify FILE... Check unit files for correctness\n" " verify FILE... Check unit files for correctness\n"
" calendar SPEC... Validate repetitive calendar time events\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); , program_invocation_short_name);
/* When updating this list, including descriptions, apply /* 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 }, { "critical-chain", VERB_ANY, VERB_ANY, 0, analyze_critical_chain },
{ "plot", VERB_ANY, 1, 0, analyze_plot }, { "plot", VERB_ANY, 1, 0, analyze_plot },
{ "dot", VERB_ANY, VERB_ANY, 0, dot }, { "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 }, { "set-log-level", 2, 2, 0, set_log_level },
{ "get-log-level", VERB_ANY, 1, 0, get_log_level }, { "get-log-level", VERB_ANY, 1, 0, get_log_level },
{ "set-log-target", 2, 2, 0, set_log_target }, { "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 }, { "syscall-filter", VERB_ANY, VERB_ANY, 0, dump_syscall_filters },
{ "verify", 2, VERB_ANY, 0, do_verify }, { "verify", 2, VERB_ANY, 0, do_verify },
{ "calendar", 2, VERB_ANY, 0, test_calendar }, { "calendar", 2, VERB_ANY, 0, test_calendar },
{ "service-watchdogs", 2, 2, 0, service_watchdogs }, { "service-watchdogs", VERB_ANY, 2, 0, service_watchdogs },
{} {}
}; };