From 729dfb7d89c30431d23e8bda21013f7469e0bf07 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 26 Apr 2015 08:31:28 +0200 Subject: fix bugs in examples/daemon-depedencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- doc/examples/daemon-depedencies/await-ready.c | 7 ++++--- doc/examples/daemon-depedencies/await-started.c | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'doc/examples/daemon-depedencies') diff --git a/doc/examples/daemon-depedencies/await-ready.c b/doc/examples/daemon-depedencies/await-ready.c index 03df950..5dfd9a7 100644 --- a/doc/examples/daemon-depedencies/await-ready.c +++ b/doc/examples/daemon-depedencies/await-ready.c @@ -48,7 +48,8 @@ static int callback(const char *message, void *user_data) ppid = getppid(); pid = fork(); if (pid == 0) { - announce_wait(ppid); + if (fork() == 0) + announce_wait(ppid); exit(0); } else { (void) waitpid(pid, NULL, 0); /* Let's pretend everything will go swimmingly. */ @@ -59,7 +60,7 @@ static int callback(const char *message, void *user_data) strncpy(msg, message, BUS_MEMORY_SIZE - 1); msg[BUS_MEMORY_SIZE - 1] = 0; - arg2 = strchr(message, ' '); + arg2 = strchr(msg, ' '); if (!arg2) return 1; arg3 = strchr(++arg2, ' '); @@ -90,7 +91,7 @@ int main(int argc_, char *argv_[]) if (argc < 2) return fprintf(stderr, "USAGE: %s daemon...", *argv), 2; t(bus_open(&bus, getenv("BUS_INIT"), BUS_RDONLY)); - started = calloc(argc - 1, sizeof(char)); + started = calloc(argc, sizeof(char)); t(started == NULL); started[0] = 1; diff --git a/doc/examples/daemon-depedencies/await-started.c b/doc/examples/daemon-depedencies/await-started.c index 152f02c..1b75fc6 100644 --- a/doc/examples/daemon-depedencies/await-started.c +++ b/doc/examples/daemon-depedencies/await-started.c @@ -48,7 +48,8 @@ static int callback(const char *message, void *user_data) ppid = getppid(); pid = fork(); if (pid == 0) { - announce_wait(ppid); + if (fork() == 0) + announce_wait(ppid); exit(0); } else { (void) waitpid(pid, NULL, 0); /* Let's pretend everything will go swimmingly. */ @@ -59,7 +60,7 @@ static int callback(const char *message, void *user_data) strncpy(msg, message, BUS_MEMORY_SIZE - 1); msg[BUS_MEMORY_SIZE - 1] = 0; - arg2 = strchr(message, ' '); + arg2 = strchr(msg, ' '); if (!arg2) return 1; arg3 = strchr(++arg2, ' '); @@ -89,8 +90,8 @@ int main(int argc_, char *argv_[]) if (argc < 2) return fprintf(stderr, "USAGE: %s daemon...", *argv), 2; - t(bus_open(&bus, getenv("BUS_INIT"), BUS_WRONLY)); - started = calloc(argc - 1, sizeof(char)); + t(bus_open(&bus, getenv("BUS_INIT"), BUS_RDONLY)); + started = calloc(argc, sizeof(char)); t(started == NULL); started[0] = 1; -- cgit v1.2.3-70-g09d2