summary refs log tree commit diff
path: root/daemon.h
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-08-14 15:56:10 -0400
committerJune McEnroe <june@causal.agency>2020-08-14 16:00:35 -0400
commite0dab12078fa6dc9903c8a73616a84347a6b93b2 (patch)
tree04b63da065d8e5cb6d495259e807761c3e52355c /daemon.h
parentOpen syslog, daemonize, write PID (diff)
downloadcatsit-e0dab12078fa6dc9903c8a73616a84347a6b93b2.tar.gz
catsit-e0dab12078fa6dc9903c8a73616a84347a6b93b2.zip
Implement spawntab parsing
Diffstat (limited to '')
-rw-r--r--daemon.h51
1 files changed, 47 insertions, 4 deletions
diff --git a/daemon.h b/daemon.h
index 3a141ba..d7efb28 100644
--- a/daemon.h
+++ b/daemon.h
@@ -17,9 +17,56 @@
 #include <grp.h>
 #include <pwd.h>
 #include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
 
 typedef unsigned char byte;
 
+extern struct Prepend {
+	size_t cap, len;
+	char **commands;
+} prepend;
+
+static inline void prependClear(void) {
+	for (size_t i = 0; i < prepend.len; ++i) {
+		free(prepend.commands[i]);
+	}
+	prepend.len = 0;
+}
+static inline int prependAdd(const char *command) {
+	if (prepend.len == prepend.cap) {
+		size_t cap = (prepend.cap ? prepend.cap * 2 : 8);
+		void *ptr = realloc(prepend.commands, sizeof(*prepend.commands) * cap);
+		if (!ptr) return -1;
+		prepend.cap = cap;
+		prepend.commands = ptr;
+	}
+	prepend.commands[prepend.len] = strdup(command);
+	if (!prepend.commands[prepend.len]) return -1;
+	prepend.len++;
+	return 0;
+}
+
+extern const char *serviceDir;
+extern struct passwd *serviceUser;
+extern struct group *serviceGroup;
+
+struct Service {
+	char *name;
+	char *command;
+	// TODO: And many other things...
+};
+
+extern struct Services {
+	size_t cap, len;
+	struct Service *ptr;
+} services;
+
+int serviceAdd(const char *name, const char *command);
+
+extern char configError[];
+int configParse(const char *path);
+
 struct Set256 {
 	uint32_t bits[8];
 };
@@ -35,7 +82,3 @@ static inline uint32_t setTest(const struct Set256 *set, byte x) {
 
 extern int restartInterval;
 extern struct Set256 stopExits;
-
-extern const char *serviceDir;
-extern struct passwd *serviceUser;
-extern struct group *serviceGroup;