summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-08-14 18:11:14 -0400
committerJune McEnroe <june@causal.agency>2020-08-14 18:11:14 -0400
commite68a29c15e5f1050a19b399f86ff5caf5d1d77f0 (patch)
treedd5b73598f3d4c655e6799980a55a90c5db909d9
parentReset restartInterval and restartDeadline on start (diff)
downloadcatsit-e68a29c15e5f1050a19b399f86ff5caf5d1d77f0.tar.gz
catsit-e68a29c15e5f1050a19b399f86ff5caf5d1d77f0.zip
Implement serviceSignal, serviceStop, serviceRestart
-rw-r--r--daemon.h4
-rw-r--r--service.c29
2 files changed, 32 insertions, 1 deletions
diff --git a/daemon.h b/daemon.h
index 32827aa..5975034 100644
--- a/daemon.h
+++ b/daemon.h
@@ -67,6 +67,7 @@ extern char *serviceEnviron[EnvironLen];
 enum State {
 	Stop,
 	Start,
+	Restart,
 };
 
 enum { LineCap = 512 };
@@ -96,6 +97,9 @@ extern struct Services {
 
 int serviceAdd(const char *name, const char *command);
 void serviceStart(struct Service *service);
+void serviceStop(struct Service *service);
+void serviceRestart(struct Service *service);
+void serviceSignal(struct Service *service, int signal);
 
 extern char configError[];
 int configParse(const char *path);
diff --git a/service.c b/service.c
index ef4834a..290372d 100644
--- a/service.c
+++ b/service.c
@@ -19,6 +19,8 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <paths.h>
+#include <signal.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -108,7 +110,7 @@ err:
 }
 
 void serviceStart(struct Service *service) {
-	if (service->state == Start) return;
+	if (service->state != Stop) return;
 
 	if (service->intent == Start) {
 		struct timespec backoff = service->restartInterval;
@@ -164,3 +166,28 @@ void serviceStart(struct Service *service) {
 	);
 	err(StopExit, "%s", _PATH_BSHELL);
 }
+
+void serviceSignal(struct Service *service, int signal) {
+	if (service->state != Start) return;
+	int error = kill(service->pid, signal);
+	if (error) {
+		syslog(
+			LOG_ERR, "signal %s %s[%ju]: %m",
+			sys_signame[signal], service->name, (uintmax_t)service->pid
+		);
+	}
+}
+
+void serviceStop(struct Service *service) {
+	service->intent = Stop;
+	serviceSignal(service, SIGTERM);
+}
+
+void serviceRestart(struct Service *service) {
+	if (service->state == Start) {
+		service->intent = Restart;
+		serviceSignal(service, SIGTERM);
+	} else {
+		serviceStart(service);
+	}
+}
ight acceptable since base.txz is similarly fetched for FreeBSD. Since this isn't ideal, I'll look into whether these man pages are intended to be in baseXX.tgz or not. If not, I'll see about changing this upstream, and this patch can be reverted. [1] Lines 2876-2931: https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/distrib/sets/lists/base/mi?annotate=1.1065 2022-05-08Update to OpenBSD 7.1 2062.73June McEnroe 2021-10-15Update to OpenBSD 7.0 2062.63June McEnroe 2021-08-29Update to Linux man-pages 5.13 2062.53Štěpán Němec 2021-08-26Update to NetBSD 9.2 2062.52June McEnroe 2021-08-26Support DESTDIR in install/uninstallJune McEnroe 2021-08-26Add version number generatorJune McEnroe 2021-08-22Add ISC license headerJune McEnroe 2021-08-22Update to Linux man-pages 5.12Štěpán Němec 2021-06-21Add manuals for macOS 11.3June McEnroe 2021-05-08Update to OpenBSD 6.9June McEnroe 2021-04-26Update to Linux man-pages 5.11June McEnroe 2021-04-26Update to FreeBSD 13.0June McEnroe 2021-01-27Completely rewrite how manuals are fetched and installedJune McEnroe Also add section 6 manuals from NetBSD and OpenBSD! 2020-12-14Update to man-pages-posix 2017-aJune McEnroe 2020-12-14Update to OpenBSD 6.8June McEnroe 2020-12-14Update to NetBSD 9.1June McEnroe 2020-12-14Update to man-pages 5.09June McEnroe 2020-12-14Update to FreeBSD 12.2June McEnroe 2020-06-08Update to OpenBSD 6.7June McEnroe 2020-05-04Add hack for macOS to search extra man sectionsJune McEnroe 2020-05-04Don't clear MANSECTJune McEnroe