From 8c1fe1f8edbdb17e876546e623bc65e7205c7335 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Fri, 20 Jun 2014 21:31:37 +0200 Subject: [PATCH] Initial bootstrap program. --- Makefile.am | 6 +++++- src/bootstrap.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/bootstrap.c diff --git a/Makefile.am b/Makefile.am index a8c16f5..bcf541c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..1df77c1 --- /dev/null +++ b/src/bootstrap.c @@ -0,0 +1,50 @@ +#include +#include + +/* strerror, and errno family.. */ +#include + +/* exec family.. */ +#include + +/** 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 -- 2.30.2