watchdog: Support changing watchdog_usec during runtime
authorKunhoon Baik <knhoon.baik@samsung.com>
Fri, 26 Aug 2016 04:22:20 +0000 (13:22 +0900)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Fri, 26 Jan 2024 16:49:49 +0000 (17:49 +0100)
 (#3492)

Add sd_notify() parameter to change watchdog_usec during runtime.

Application can change watchdog_usec value by
sd_notify like this. Example. sd_notify(0, "WATCHDOG_USEC=20000000").

To reset watchdog_usec as configured value in service file,
restart service.

Notice.
sd_event is not currently supported. If application uses
sd_event_set_watchdog, or sd_watchdog_enabled, do not use
"WATCHDOG_USEC" option through sd_notify.

Origin: https://github.com/systemd/systemd/commit/2787d83c2
Note: There are two additional patches for clean backport patch
      1)rework unit timeout patch - https://github.com/systemd/systemd/commit/36c16a7cd
      2)rework per-object logging - https://github.com/systemd/systemd/commit/f2341e0a8
      However, we will not apply the patch for minimal backport

Change-Id: Ic1a91dc4e611f3e92fdc734fb1eb70e27244aa37

src/core/service.c

index 458d74a..298239d 100644 (file)
@@ -2160,6 +2160,9 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
         if (s->watchdog_override_enable)
                unit_serialize_item_format(u, f, "watchdog-override-usec", USEC_FMT, s->watchdog_override_usec);
 
+        if (s->watchdog_override_enable)
+               unit_serialize_item_format(u, f, "watchdog-override-usec", USEC_FMT, s->watchdog_override_usec);
+
         return 0;
 }
 
@@ -3094,6 +3097,15 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags, FDSet *fds)
                         service_reset_watchdog_timeout(s, watchdog_override_usec);
         }
 
+        e = strv_find_startswith(tags, "WATCHDOG_USEC=");
+        if (e) {
+                usec_t watchdog_override_usec;
+                if (safe_atou64(e, &watchdog_override_usec) < 0)
+                        log_unit_warning(u->id, "Failed to parse WATCHDOG_USEC=%s", e);
+                else
+                        service_reset_watchdog_timeout(s, watchdog_override_usec);
+        }
+
         /* Notify clients about changed status or main pid */
         if (notify_dbus)
                 unit_add_to_dbus_queue(u);