summary refs log tree commit diff
path: root/daemon.h
diff options
context:
space:
mode:
Diffstat (limited to 'daemon.h')
-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;