*
* Connection Manager
*
- * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
struct connman_task {
char *path;
pid_t pid;
+ guint child_watch;
GPtrArray *argv;
GPtrArray *envp;
connman_task_exit_t exit_func;
if (task->pid > 0)
kill(task->pid, SIGTERM);
+ if (task->child_watch > 0)
+ g_source_remove(task->child_watch);
+
g_ptr_array_foreach(task->envp, free_pointer, NULL);
g_ptr_array_free(task->envp, TRUE);
static void task_died(GPid pid, gint status, gpointer user_data)
{
struct connman_task *task = user_data;
+ int exit_code;
- if (WIFEXITED(status))
- DBG("task %p exit status %d", task, WEXITSTATUS(status));
- else
+ if (WIFEXITED(status)) {
+ exit_code = WEXITSTATUS(status);
+ DBG("task %p exit status %d", task, exit_code);
+ } else {
+ exit_code = 0;
DBG("task %p signal %d", task, WTERMSIG(status));
+ }
g_spawn_close_pid(pid);
task->pid = -1;
+ task->child_watch = 0;
+
if (task->exit_func)
- task->exit_func(task, task->exit_data);
+ task->exit_func(task, exit_code, task->exit_data);
}
static void task_setup(gpointer user_data)
return -EIO;
}
- g_child_watch_add(task->pid, task_died, task);
+ task->child_watch = g_child_watch_add(task->pid, task_died, task);
return 0;
}