[systemd-devel] [PATCH] systemctl: add command set-log-level
Vaclav Pavlin
vpavlin at redhat.com
Wed May 29 07:08:11 PDT 2013
From: Václav Pavlín <vpavlin at redhat.com>
Command changes current log level
---
man/systemctl.xml | 8 ++++++++
src/systemctl/systemctl.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/man/systemctl.xml b/man/systemctl.xml
index 9c3a5b0..af72972 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -1016,6 +1016,14 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service
</varlistentry>
<varlistentry>
+ <term><command>set-log-level <replaceable>LEVEL</replaceable></command></term>
+
+ <listitem>
+ <para>Change current log level to LEVEL.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><command>load <replaceable>NAME</replaceable>...</command></term>
<listitem>
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 0955f2c..e6e2f2b 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4462,6 +4462,53 @@ 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);
+
+ if (!(m = dbus_message_new_method_call(
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.DBus.Properties",
+ "Set")))
+ 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;
@@ -5705,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;
--
1.8.1.4
More information about the systemd-devel
mailing list