Initial bootstrap program.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Fri, 20 Jun 2014 19:31:37 +0000 (21:31 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Fri, 20 Jun 2014 19:31:37 +0000 (21:31 +0200)
Makefile.am
src/bootstrap.c [new file with mode: 0644]

index a8c16f597126960b7660faa40a44b55d7125c6bf..bcf541ce9bff17704646a51400e81d221ea39c24 100644 (file)
@@ -4,7 +4,8 @@ ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
 bin_PROGRAMS = \
        bin/process1 \
        bin/process2 \
-       bin/process3
+       bin/process3 \
+       bin/bootstrap
 
 bin_process1_SOURCES = \
        src/process1.c
@@ -14,3 +15,6 @@ bin_process2_SOURCES = \
 
 bin_process3_SOURCES = \
        src/process3.c
+
+bin_bootstrap_SOURCES = \
+       src/bootstrap.c
diff --git a/src/bootstrap.c b/src/bootstrap.c
new file mode 100644 (file)
index 0000000..1df77c1
--- /dev/null
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+/* strerror, and errno family.. */
+#include <errno.h>
+
+/* exec family.. */
+#include <unistd.h>
+
+/** Number of processes to spawn */
+#define PROCESS_NUMBER 3
+
+char * processes[PROCESS_NUMBER] = {
+       "process1",
+       "process2",
+       "process3"
+};
+
+/**
+ * Bootstrap program used for starting all three main processes.
+ */
+int main(void) {
+
+       pid_t pid;
+       int i = 0;
+       int err = 0;
+
+       for (; i < PROCESS_NUMBER; i++) {
+               fprintf(stderr, "[%s] Forking process %d\n", "bootstrap", i);
+               pid = fork();
+
+               /* If it is child fork */
+               if (pid == 0) {
+                       err = execl(processes[i], processes[i], NULL);
+
+                       /*
+                        * According to manual, this will only occur
+                        * if there was an error in execl
+                        */
+                       if (err == -1) {
+                               fprintf(stderr, "[%s] Something went wrong when spawning %s. Error: %s\n",
+                                       "bootstrap", processes[i], strerror(errno));
+                       }
+               }
+       }
+
+       /* All processes should be now spawned. Close bootstrap program. */
+       
+       return 0;
+}
\ No newline at end of file