]> err.no Git - systemd/commitdiff
watchdog: make watchdog dbus properties writable
authorLennart Poettering <lennart@poettering.net>
Fri, 13 Apr 2012 19:33:28 +0000 (21:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 13 Apr 2012 19:37:59 +0000 (21:37 +0200)
src/core/dbus-manager.c
src/core/manager.c
src/shared/dbus-common.c
src/shared/dbus-common.h

index 88945b5c64c214b0a778678033569c7f0534b29d..e81e6afb046d2fa2eeb76ab2c03878574063404c 100644 (file)
@@ -30,6 +30,7 @@
 #include "build.h"
 #include "dbus-common.h"
 #include "install.h"
+#include "watchdog.h"
 
 #define BUS_MANAGER_INTERFACE_BEGIN                                     \
         " <interface name=\"org.freedesktop.systemd1.Manager\">\n"
         "  <property name=\"DefaultControllers\" type=\"as\" access=\"read\"/>\n" \
         "  <property name=\"DefaultStandardOutput\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"DefaultStandardError\" type=\"s\" access=\"read\"/>\n" \
-        "  <property name=\"RuntimeWatchdogUSec\" type=\"s\" access=\"read\"/>\n" \
-        "  <property name=\"ShutdownWatchdogUSec\" type=\"s\" access=\"read\"/>\n" \
+        "  <property name=\"RuntimeWatchdogUSec\" type=\"s\" access=\"readwrite\"/>\n" \
+        "  <property name=\"ShutdownWatchdogUSec\" type=\"s\" access=\"readwrite\"/>\n" \
         "  <property name=\"HaveWatchdog\" type=\"b\" access=\"read\"/>\n"
 
 #ifdef HAVE_SYSV_COMPAT
@@ -508,6 +509,17 @@ static int bus_manager_append_have_watchdog(DBusMessageIter *i, const char *prop
         return 0;
 }
 
+static int bus_manager_set_runtime_watchdog_usec(DBusMessageIter *i, const char *property, void *data) {
+        uint64_t *t = data;
+
+        assert(i);
+        assert(property);
+
+        dbus_message_iter_get_basic(i, t);
+
+        return watchdog_set_timeout(t);
+}
+
 static const char systemd_property_string[] =
         PACKAGE_STRING "\0"
         DISTRIBUTION "\0"
@@ -529,8 +541,8 @@ static const BusProperty bus_manager_properties[] = {
         { "StartupTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, startup_timestamp.monotonic) },
         { "FinishTimestamp", bus_property_append_uint64,           "t", offsetof(Manager, finish_timestamp.realtime)   },
         { "FinishTimestampMonotonic", bus_property_append_uint64,  "t", offsetof(Manager, finish_timestamp.monotonic)  },
-        { "LogLevel",      bus_manager_append_log_level,           "s", 0,                                             0, bus_manager_set_log_level },
-        { "LogTarget",     bus_manager_append_log_target,          "s", 0,                                             0, bus_manager_set_log_target },
+        { "LogLevel",      bus_manager_append_log_level,           "s", 0,                                             false, bus_manager_set_log_level },
+        { "LogTarget",     bus_manager_append_log_target,          "s", 0,                                             false, bus_manager_set_log_target },
         { "NNames",        bus_manager_append_n_names,             "u", 0                                              },
         { "NJobs",         bus_manager_append_n_jobs,              "u", 0                                              },
         { "NInstalledJobs",bus_property_append_uint32,             "u", offsetof(Manager, n_installed_jobs)            },
@@ -547,8 +559,8 @@ static const BusProperty bus_manager_properties[] = {
         { "DefaultControllers", bus_property_append_strv,         "as", offsetof(Manager, default_controllers),        true },
         { "DefaultStandardOutput", bus_manager_append_exec_output, "s", offsetof(Manager, default_std_output)          },
         { "DefaultStandardError",  bus_manager_append_exec_output, "s", offsetof(Manager, default_std_error)           },
-        { "RuntimeWatchdogUSec", bus_property_append_usec,         "t", offsetof(Manager, runtime_watchdog),           },
-        { "ShutdownWatchdogUSec", bus_property_append_usec,        "t", offsetof(Manager, shutdown_watchdog),          },
+        { "RuntimeWatchdogUSec", bus_property_append_usec,         "t", offsetof(Manager, runtime_watchdog),           false, bus_manager_set_runtime_watchdog_usec },
+        { "ShutdownWatchdogUSec", bus_property_append_usec,        "t", offsetof(Manager, shutdown_watchdog),          false, bus_property_set_usec },
         { "HaveWatchdog",  bus_manager_append_have_watchdog,       "b", 0                                              },
 #ifdef HAVE_SYSV_COMPAT
         { "SysVConsole",   bus_property_append_bool,               "b", offsetof(Manager, sysv_console)                },
index 1d32adff6d6882f5e81e88386535bbbcefc2a2a6..c8ac29be5b00e24cc49cf878c240d13b6c1bb432 100644 (file)
@@ -2457,7 +2457,6 @@ static int process_event(Manager *m, struct epoll_event *ev) {
 
 int manager_loop(Manager *m) {
         int r;
-        int wait_msec = -1;
 
         RATELIMIT_DEFINE(rl, 1*USEC_PER_SEC, 50000);
 
@@ -2476,18 +2475,12 @@ int manager_loop(Manager *m) {
         if (r < 0)
                 return r;
 
-        /* Sleep for half the watchdog time */
-        if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM)  {
-                wait_msec = (int) (m->runtime_watchdog / 2 / USEC_PER_MSEC);
-                if (wait_msec <= 0)
-                        wait_msec = 1;
-        }
-
         while (m->exit_code == MANAGER_RUNNING) {
                 struct epoll_event event;
                 int n;
+                int wait_msec = -1;
 
-                if (wait_msec >= 0)
+                if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM)
                         watchdog_ping();
 
                 if (!ratelimit_test(&rl)) {
@@ -2518,6 +2511,14 @@ int manager_loop(Manager *m) {
                 if (swap_dispatch_reload(m) > 0)
                         continue;
 
+                /* Sleep for half the watchdog time */
+                if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM) {
+                        wait_msec = (int) (m->runtime_watchdog / 2 / USEC_PER_MSEC);
+                        if (wait_msec <= 0)
+                                wait_msec = 1;
+                } else
+                        wait_msec = -1;
+
                 n = epoll_wait(m->epoll_fd, &event, 1, wait_msec);
                 if (n < 0) {
 
index badd037db1dd45f3747e76f3752fc3d5e8a32c68..6d000e11622f204fbea272fa17088eafa7561e1a 100644 (file)
@@ -660,6 +660,16 @@ int bus_property_append_long(DBusMessageIter *i, const char *property, void *dat
         return 0;
 }
 
+int bus_property_set_uint64(DBusMessageIter *i, const char *property, void *data) {
+        uint64_t *t = data;
+
+        assert(i);
+        assert(property);
+
+        dbus_message_iter_get_basic(i, t);
+        return 0;
+}
+
 const char *bus_errno_to_dbus(int error) {
 
         switch(error) {
index ca398fc3f5444f41802e8fbb2ce860f37188745f..2bfcdfa5d412f6ee0eaef0acaf69fc070e75eafc 100644 (file)
@@ -144,6 +144,9 @@ int bus_property_append_long(DBusMessageIter *i, const char *property, void *dat
 #define bus_property_append_unsigned bus_property_append_uint32
 #define bus_property_append_usec bus_property_append_uint64
 
+int bus_property_set_uint64(DBusMessageIter *i, const char *property, void *data);
+#define bus_property_set_usec bus_property_set_uint64
+
 #define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type)             \
         int function(DBusMessageIter *i, const char *property, void *data) { \
                 const char *value;                                      \