summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-08-17 15:13:58 -0400
committerJune McEnroe <june@causal.agency>2020-08-17 15:49:19 -0400
commit00e35a1031d58133f6de38573bf1b532c7c79641 (patch)
tree040605a22bf534946b5d07a0285f36c3f9cf7c10
parentProperly handle command line truncation (diff)
downloadcatsit-00e35a1031d58133f6de38573bf1b532c7c79641.tar.gz
catsit-00e35a1031d58133f6de38573bf1b532c7c79641.zip
Simplify parseConfig error handling
Diffstat (limited to '')
-rw-r--r--daemon.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/daemon.c b/daemon.c
index 969675f..99b9fb9 100644
--- a/daemon.c
+++ b/daemon.c
@@ -22,7 +22,6 @@
 #include <poll.h>
 #include <pwd.h>
 #include <signal.h>
-#include <stdarg.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -57,24 +56,14 @@ static void signalHandler(int signal) {
 	signals[signal]++;
 }
 
-static void configerr(bool exit, const char *format, ...) {
-	va_list ap;
-	va_start(ap, format);
-	if (exit) {
-		verrx(EX_DATAERR, format, ap);
-	} else {
-		vsyslog(LOG_WARNING, format, ap);
-	}
-	va_end(ap);
-}
-
-static void parseConfig(bool exit, const char *path) {
+static int parseConfig(const char *path) {
+	int ret = -1;
 	size_t cap = 0;
 	char *buf = NULL;
 
 	FILE *file = fopen(path, "r");
 	if (!file) {
-		configerr(exit, "%s: %s", path, strerror(errno));
+		syslog(LOG_WARNING, "%s: %m", path);
 		goto err;
 	}
 
@@ -90,32 +79,35 @@ static void parseConfig(bool exit, const char *path) {
 		} else if (ptr[0] == '%') {
 			int error = prependAdd(&ptr[1]);
 			if (error) {
-				configerr(
-					exit, "cannot add prepend command: %s", strerror(errno)
-				);
+				syslog(LOG_WARNING, "cannot add prepend command: %m");
 				goto err;
 			}
 		} else {
 			char *name = strsep(&ptr, WS);
 			if (!ptr) {
-				configerr(
-					exit, "%s:%d: no command line for service %s",
+				syslog(
+					LOG_WARNING, "%s:%d: no command line for service %s",
 					path, line, name
 				);
 				goto err;
 			}
 			int error = serviceAdd(name, ptr);
 			if (error) {
-				configerr(exit, "cannot add service: %s", strerror(errno));
+				syslog(LOG_WARNING, "cannot add service: %m");
 				goto err;
 			}
 		}
 	}
-	if (ferror(file)) configerr(exit, "%s: %s", path, strerror(errno));
+	if (ferror(file)) {
+		syslog(LOG_WARNING, "%s: %m", path);
+		goto err;
+	}
+	ret = 0;
 
 err:
 	free(buf);
-	fclose(file);
+	if (file) fclose(file);
+	return ret;
 }
 
 typedef void Action(struct Service *service);
@@ -276,7 +268,8 @@ int main(int argc, char *argv[]) {
 
 	openlog(getprogname(), LOG_NDELAY | LOG_PID | LOG_PERROR, LOG_DAEMON);
 
-	parseConfig(true, configPath);
+	error = parseConfig(configPath);
+	if (error) return EX_DATAERR;
 
 	if (daemonize) {
 		error = daemon(0, 0);
@@ -392,7 +385,7 @@ int main(int argc, char *argv[]) {
 			break;
 		}
 		if (signals[SIGHUP]) {
-			parseConfig(false, configPath);
+			parseConfig(configPath);
 			setTitle();
 			signals[SIGHUP] = 0;
 		}
ass='nohover-highlight'> Unbearably straight. Eyerolls and sighs per page off the charts. Shout out to Joanna, I guess. I kinda like the lack of quotation marks though to be honest. After half of the Ruth Ozeki novel and now this, I need to get back to some genre fiction. 2022-07-26Rewrite glitch from new pngoJune McEnroe 2022-07-26Update Care with time-to-ID and piercingsJune McEnroe 2022-07-26Add -w to upJune McEnroe 2022-07-13Set push.autoSetupRemoteJune McEnroe 2022-07-08Remove TOURJune McEnroe There is not that much distinct stuff here anymore. 2022-07-03Add The Bone Shard EmperorJune McEnroe Suffers a little bit from middle book but I really enjoyed it. Read it faster than the first one too, despite its length. 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe Mixed bag like most collections of short stories. Some of them are pretty good. The author of the worst written story also has the worst written bio. 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe Absolutely indiscriminately. 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe For some reason I haven't been able to figure out, trying to poll /dev/tty returns POLLNVAL (and this was using 100% CPU looping), but using stderr instead works fine. 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe