diff options
author | Václav Pavlín <vpavlin@redhat.com> | 2013-05-29 16:08:11 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-05-30 20:44:41 -0400 |
commit | 76d5a71de99b6fe0ecc9bfd82ec641a5d408e191 (patch) | |
tree | f1ea73e8d0bf951a66e2dd601902dc7fffc9b1e2 | |
parent | 99504dd4c13af7516a976fffc0f68e6f26d3faac (diff) |
systemctl: add command set-log-level
Command changes current log level
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | man/systemctl.xml | 13 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 46 |
3 files changed, 59 insertions, 2 deletions
@@ -91,8 +91,6 @@ Features: * we need dynamic units -* add s.th. like "systemctl set-log-level debug" - * cgtop: make cgtop useful in a container * test/: diff --git a/man/systemctl.xml b/man/systemctl.xml index 430e16c327..54573e8f5f 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -546,6 +546,19 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service </listitem> </varlistentry> + <varlistentry> + <term><command>set-log-level <replaceable>LEVEL</replaceable></command></term> + + <listitem> + <para>Change current log level of the + <command>systemd</command> daemon to + <replaceable>LEVEL</replaceable> (accepts the same values + as <option>--log-level=</option> described in + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>). + </para> + </listitem> + </varlistentry> + <varlistentry> <term><command>start <replaceable>NAME</replaceable>...</command></term> diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 56021a6889..5ccbbbc0c7 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4462,6 +4462,51 @@ finish: return r; } +static int set_log_level(DBusConnection *bus, char **args) { + _cleanup_dbus_error_free_ DBusError error; + _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL; + DBusMessageIter iter, sub; + const char* property = "LogLevel"; + const char* interface = "org.freedesktop.systemd1.Manager"; + const char* value; + + assert(bus); + assert(args); + + value = args[1]; + dbus_error_init(&error); + + m = dbus_message_new_method_call("org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.DBus.Properties", + "Set"); + if (!m) + return log_oom(); + + dbus_message_iter_init_append(m, &iter); + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface) || + !dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property) || + !dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, "s", &sub)) + return log_oom(); + + if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &value)) { + dbus_message_iter_abandon_container(&iter, &sub); + return log_oom(); + } + + if (!dbus_message_iter_close_container(&iter, &sub)) + return log_oom(); + + reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error); + if (!reply) { + log_error("Failed to issue method call: %s", bus_error_message(&error)); + return -EIO; + } + + return 0; +} + static int unit_is_enabled(DBusConnection *bus, char **args) { _cleanup_dbus_error_free_ DBusError error; int r; @@ -5707,6 +5752,7 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError { "list-dependencies", LESS, 2, list_dependencies }, { "set-default", EQUAL, 2, enable_unit }, { "get-default", LESS, 1, get_default }, + { "set-log-level", EQUAL, 2, set_log_level }, }; int left; |