From ecec2b38bf30b99054761d737909511872b4bb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Wed, 3 Sep 2008 21:15:45 +0000 Subject: [PATCH] Cleanup process spawner --- spawn.c | 26 ++++++++------------------ spawn.h | 4 ++-- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/spawn.c b/spawn.c index 70afafc8..14b05ddb 100644 --- a/spawn.c +++ b/spawn.c @@ -32,8 +32,6 @@ extern char **environ; -static dtimer_t reaper_timer; - pthread_mutex_t spawn_mutex = PTHREAD_MUTEX_INITIALIZER; static LIST_HEAD(, spawn) spawns; @@ -63,16 +61,14 @@ typedef struct spawn_output_buf { /** * The reaper is called once a second to finish of any pending spawns */ -static void -reaper(void *opaque, int64_t now) +void +spawn_reaper(void) { pid_t pid; int status; char txt[100]; spawn_t *s; - dtimer_arm(&reaper_timer, reaper, NULL, 1); - while(1) { pid = waitpid(-1, &status, WNOHANG); if(pid < 1) @@ -85,19 +81,19 @@ reaper(void *opaque, int64_t now) if (WIFEXITED(status)) { snprintf(txt, sizeof(txt), - "exited, status=%d\n", WEXITSTATUS(status)); + "exited, status=%d", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { snprintf(txt, sizeof(txt), - "killed by signal %d\n", WTERMSIG(status)); + "killed by signal %d", WTERMSIG(status)); } else if (WIFSTOPPED(status)) { snprintf(txt, sizeof(txt), - "stopped by signal %d\n", WSTOPSIG(status)); + "stopped by signal %d", WSTOPSIG(status)); } else if (WIFCONTINUED(status)) { snprintf(txt, sizeof(txt), - "continued\n"); + "continued"); } else { snprintf(txt, sizeof(txt), - "unknown status\n"); + "unknown status"); } @@ -113,13 +109,6 @@ reaper(void *opaque, int64_t now) } -void -spawn_init(void) -{ - dtimer_arm(&reaper_timer, reaper, NULL, 1); -} - - /** * Enqueue a spawn on the pending spawn list */ @@ -223,6 +212,7 @@ spawn_and_store_stdout(const char *prog, char *const argv[], char **outp) } assert(r == totalsize); *outp = outbuf; + outbuf[totalsize] = 0; return totalsize; } diff --git a/spawn.h b/spawn.h index 3f77508d..41fb20c8 100644 --- a/spawn.h +++ b/spawn.h @@ -21,8 +21,8 @@ int spawn_and_store_stdout(const char *prog, char *const argv[], char **outp); -void spawn_init(void); - int spawnv(const char *prog, char *const argv[]); +void spawn_reaper(void); + #endif /* SPAWN_H */