diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-04-26 08:31:28 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-04-26 08:31:28 +0200 |
commit | 729dfb7d89c30431d23e8bda21013f7469e0bf07 (patch) | |
tree | c0010838a60dfb2636c0f5db43bea48f91f63346 /doc | |
parent | start on a more complex example (diff) | |
download | bus-729dfb7d89c30431d23e8bda21013f7469e0bf07.tar.gz bus-729dfb7d89c30431d23e8bda21013f7469e0bf07.tar.bz2 bus-729dfb7d89c30431d23e8bda21013f7469e0bf07.tar.xz |
fix bugs in examples/daemon-depedencies
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | doc/examples/daemon-depedencies/await-ready.c | 7 | ||||
-rw-r--r-- | doc/examples/daemon-depedencies/await-started.c | 9 |
2 files changed, 9 insertions, 7 deletions
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; |