ctdlsvc.c: added. This will be used to build init scripts.
authorArt Cancro <ajc@citadel.org>
Mon, 27 Nov 2006 02:58:36 +0000 (02:58 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 27 Nov 2006 02:58:36 +0000 (02:58 +0000)
webcit/ctdlsvc.c [new file with mode: 0644]

diff --git a/webcit/ctdlsvc.c b/webcit/ctdlsvc.c
new file mode 100644 (file)
index 0000000..69c5277
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * $Id: $
+ *
+ * This is just a quick little hack to start a program and automatically
+ * restart it if it exits with a nonzero exit status.
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+
+int main(int argc, char **argv)
+{
+       pid_t child = 0;
+       int status = 0;
+
+       --argc;
+       ++argv;
+
+       do {
+               child = fork();
+       
+               if (child < 0) {
+                       perror("fork");
+                       exit(errno);
+               }
+       
+               else if (child == 0) {
+                       exit(execvp(argv[0], &argv[0]));
+               }
+       
+               else {
+                       printf("%s: started.  pid = %d\n", argv[0], child);
+                       waitpid(child, &status, 0);
+                       printf("Exit code %d\n", status);
+               }
+
+       } while (status != 0);
+
+       exit(0);
+}
+