watchdog: Isolate the watchdog from jobs 19/20819/1
authorJosé Bollo <jose.bollo@iot.bzh>
Wed, 13 Feb 2019 16:09:05 +0000 (17:09 +0100)
committerJose Bollo <jose.bollo@iot.bzh>
Wed, 27 Mar 2019 09:48:40 +0000 (10:48 +0100)
Change-Id: Iaa7f71dc7e5d8d525463619b4da980c827722909
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/CMakeLists.txt
src/jobs.c
src/main-afb-daemon.c
src/main-afs-supervisor.c
src/watchdog.c [new file with mode: 0644]
src/watchdog.h [new file with mode: 0644]

index 4733268..086a2aa 100644 (file)
@@ -75,6 +75,7 @@ SET(AFB_LIB_SOURCES
        sig-monitor.c
        subpath.c
        verbose.c
+       watchdog.c
        websock.c
        wrap-json.c
 )
index abfe699..f30904a 100644 (file)
 
 #define _GNU_SOURCE
 
-#if defined(NO_JOBS_WATCHDOG)
-#   define HAS_WATCHDOG 0
-#else
-#   define HAS_WATCHDOG 1
-#endif
-
 #include <stdlib.h>
 #include <stdint.h>
 #include <unistd.h>
@@ -36,9 +30,6 @@
 #include <sys/eventfd.h>
 
 #include <systemd/sd-event.h>
-#if HAS_WATCHDOG
-#include <systemd/sd-daemon.h>
-#endif
 
 #include "jobs.h"
 #include "sig-monitor.h"
@@ -890,12 +881,6 @@ int jobs_start(int allowed_count, int start_count, int waiter_count, void (*star
        running = 0;
        remains = waiter_count;
 
-#if HAS_WATCHDOG
-       /* set the watchdog */
-       if (sd_watchdog_enabled(0, NULL))
-               sd_event_set_watchdog(get_sd_event_locked(), 1);
-#endif
-
        /* start at least one thread: the current one */
        launched = 1;
        while (launched < start_count) {
index 0a8e018..beb08d3 100644 (file)
@@ -66,6 +66,7 @@
 #include "wrap-json.h"
 #include "jobs.h"
 #include "sig-monitor.h"
+#include "watchdog.h"
 
 #if !defined(DEFAULT_BINDER_INTERFACE)
 #  define DEFAULT_BINDER_INTERFACE NULL
@@ -861,6 +862,13 @@ static void start(int signum, void *arg)
 
        /* ready */
        sd_notify(1, "READY=1");
+
+       /* activate the watchdog */
+#if HAS_WATCHDOG
+       if (watchdog_activate() < 0)
+               ERROR("can't start the watchdog");
+#endif
+
        return;
 error:
        exit(1);
index b425083..6b79c9c 100644 (file)
@@ -39,6 +39,7 @@
 #include "verbose.h"
 #include "jobs.h"
 #include "process-name.h"
+#include "watchdog.h"
 
 #if !defined(DEFAULT_SUPERVISOR_INTERFACE)
 #  define DEFAULT_SUPERVISOR_INTERFACE NULL
@@ -191,6 +192,14 @@ static void start(int signum, void *arg)
 
        /* ready */
        sd_notify(1, "READY=1");
+
+       /* activate the watchdog */
+#if HAS_WATCHDOG
+       if (watchdog_activate() < 0)
+               ERROR("can't start the watchdog");
+#endif
+
+       /* discover binders */
        afs_supervisor_discover();
        return;
 error:
diff --git a/src/watchdog.c b/src/watchdog.c
new file mode 100644 (file)
index 0000000..f9afd64
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2016-2019 "IoT.bzh"
+ * Author José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+
+#include "watchdog.h"
+
+#if HAS_WATCHDOG
+
+#include <stdlib.h>
+
+#include <systemd/sd-event.h>
+#include <systemd/sd-daemon.h>
+
+#include "jobs.h"
+
+int watchdog_activate()
+{
+       /* set the watchdog */
+       if (sd_watchdog_enabled(0, NULL))
+               sd_event_set_watchdog(jobs_get_sd_event(), 1);
+       return 0;
+}
+
+#endif
\ No newline at end of file
diff --git a/src/watchdog.h b/src/watchdog.h
new file mode 100644 (file)
index 0000000..6dc0a05
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2016-2019 "IoT.bzh"
+ * Author José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#if !defined(HAS_WATCHDOG)
+#  if defined(NO_JOBS_WATCHDOG)
+#     define HAS_WATCHDOG 0
+#  else
+#     define HAS_WATCHDOG 1
+#  endif
+#endif
+
+#if HAS_WATCHDOG
+extern int watchdog_activate();
+#endif
+