Cleanup process spawner

This commit is contained in:
Andreas Öman 2008-09-03 21:15:45 +00:00
parent d759a3a419
commit ecec2b38bf
2 changed files with 10 additions and 20 deletions

26
spawn.c
View file

@ -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;
}

View file

@ -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 */