From: Rafał Długołęcki Date: Fri, 20 Jun 2014 19:31:37 +0000 (+0200) Subject: Initial bootstrap program. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=8c1fe1f8edbdb17e876546e623bc65e7205c7335;p=wsti_so.git Initial bootstrap program. --- 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