summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-02-01 11:36:31 -0500
committerJune McEnroe <june@causal.agency>2021-02-01 11:36:31 -0500
commitda4ccb18f4c6900c6e5ad39e226cab9699837412 (patch)
treeabb08465d5b6c1e811e6a99c7de0e5d29d14cd99
parentLog a message when stopping a service waiting to restart (diff)
downloadcatsit-da4ccb18f4c6900c6e5ad39e226cab9699837412.tar.gz
catsit-da4ccb18f4c6900c6e5ad39e226cab9699837412.zip
Check signals first in the loop
Signals need to be checked first in the loop to catch any that were
delivered between setting up the signals handlers and entering the
loop, i.e. in the time it takes to initially start each of the
services.
-rw-r--r--daemon.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/daemon.c b/daemon.c
index cf7f805..59215f6 100644
--- a/daemon.c
+++ b/daemon.c
@@ -321,6 +321,31 @@ int main(int argc, char *argv[]) {
 	sigset_t mask;
 	sigemptyset(&mask);
 	for (;;) {
+		if (signals[SIGCHLD]) {
+			int status;
+			pid_t pid;
+			while (0 < (pid = waitpid(-1, &status, WNOHANG))) {
+				serviceReap(pid, status);
+			}
+			if (pid < 0 && errno != ECHILD) syslog(LOG_WARNING, "waitpid: %m");
+			setTitle();
+			signals[SIGCHLD] = 0;
+		}
+
+		if (signals[SIGINT] || signals[SIGTERM]) {
+			break;
+		}
+		if (signals[SIGHUP]) {
+			parseConfig(configPath);
+			setTitle();
+			signals[SIGHUP] = 0;
+		}
+		if (signals[SIGINFO]) {
+			char command[] = "status *";
+			parseControl(command);
+			signals[SIGINFO] = 0;
+		}
+
 		struct pollfd fds[1 + 2 * services.len];
 		fds[0].fd = fifo;
 		fds[0].events = POLLIN;
@@ -393,31 +418,6 @@ int main(int argc, char *argv[]) {
 			}
 			setTitle();
 		}
-
-		if (signals[SIGCHLD]) {
-			int status;
-			pid_t pid;
-			while (0 < (pid = waitpid(-1, &status, WNOHANG))) {
-				serviceReap(pid, status);
-			}
-			if (pid < 0 && errno != ECHILD) syslog(LOG_WARNING, "waitpid: %m");
-			setTitle();
-			signals[SIGCHLD] = 0;
-		}
-
-		if (signals[SIGINT] || signals[SIGTERM]) {
-			break;
-		}
-		if (signals[SIGHUP]) {
-			parseConfig(configPath);
-			setTitle();
-			signals[SIGHUP] = 0;
-		}
-		if (signals[SIGINFO]) {
-			char command[] = "status *";
-			parseControl(command);
-			signals[SIGINFO] = 0;
-		}
 	}
 
 	close(fifo);
' class='logmsg'> 2020-08-27Sandbox pounce with pledge(2)June McEnroe unveil(2) is a bit complicated to apply to this, I'll have to think about it more. 2020-08-27Sandbox calico with pledge(2) and unveil(2)June McEnroe 2020-08-27Add support for OpenBSDJune McEnroe 2020-08-27Remove rc scriptsJune McEnroe 2020-08-27contrib/palaver: Fix documented database pathJune McEnroe 2020-08-27contrib/palaver: Remove rc scriptJune McEnroe 2020-08-27contrib/palaver: Fix database search and creationJune McEnroe 2020-08-27contrib/palaver: Use pounce's XDG directoryJune McEnroe 2020-08-27contrib/palaver: Only allow HTTPSJune McEnroe 2020-08-25Support the pounce_env rc variableJune McEnroe 2020-08-25Remove deprecated option namesJune McEnroe The next release will be 2.0 so these can be removed now. 2020-08-25Document configuration and data file searchJune McEnroe 2020-08-24Use dataOpen for save fileJune McEnroe 2020-08-24Use configOpen to load localCAJune McEnroe 2020-08-24Use configPath to load client cert/privJune McEnroe 2020-08-24Use configOpen in getopt_configJune McEnroe 2020-08-24Import xdg.c from catgirlJune McEnroe 2020-08-23Replace “RAND_bytes” by “getentropy”Issam E. Maghni This removes the dependency on libcrypto. Signed-off-by: Issam E. Maghni <issam.e.maghni@mailbox.org> 2020-08-16contrib/palaver: Add no message preview flagsJune McEnroe 2020-08-13contrib/palaver: Don't set channel for PMsJune McEnroe 2020-08-13Fix unintended interception of NICK after registrationJune McEnroe Another bug caused by trying to support broken clients. I'm annoyed. 2020-08-12Add Additional Components section to READMEJune McEnroe 2020-08-12Document -L / palaver optionJune McEnroe 2020-08-11contrib/palaver: Document service configurationJune McEnroe 2020-08-11contrib/palaver: Add install target and rc scriptJune McEnroe 2020-08-11contrib/palaver: Implement command and notificationsJune McEnroe