summaryrefslogtreecommitdiff
path: root/src/task.c
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2011-11-15 13:06:28 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2011-11-15 13:41:45 +0100
commita0464661f2aee397e6f6d48dbb7e7bb84a0c5610 (patch)
treee003fd96d5454290618f64612c75e3f8d85e1b35 /src/task.c
parenta8b48dd50550941138a4600f8b79d09f50d8a81a (diff)
downloadconnman-a0464661f2aee397e6f6d48dbb7e7bb84a0c5610.tar.gz
connman-a0464661f2aee397e6f6d48dbb7e7bb84a0c5610.tar.bz2
connman-a0464661f2aee397e6f6d48dbb7e7bb84a0c5610.zip
task: Make sure the process is eventually killed
If a task refuses to kill itself, then wait two secs before trying again and if that does not help then forcefully kill it.
Diffstat (limited to 'src/task.c')
-rw-r--r--src/task.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/task.c b/src/task.c
index d26d6170..8be3b252 100644
--- a/src/task.c
+++ b/src/task.c
@@ -350,6 +350,44 @@ int connman_task_run(struct connman_task *task,
return 0;
}
+static gboolean force_kill_timeout(gpointer user_data)
+{
+ pid_t pid = GPOINTER_TO_INT(user_data);
+ if (pid > 0) {
+ if (kill(pid, SIGKILL) == 0)
+ connman_warn("killing pid %d by force", pid);
+ }
+
+ return FALSE;
+}
+
+static gboolean kill_timeout(gpointer user_data)
+{
+ pid_t pid = GPOINTER_TO_INT(user_data);
+ if (pid > 0) {
+ if (kill(pid, SIGINT) == 0)
+ g_timeout_add_seconds(1, force_kill_timeout,
+ GINT_TO_POINTER(pid));
+ }
+
+ return FALSE;
+}
+
+static gboolean check_kill(gpointer user_data)
+{
+ pid_t pid = GPOINTER_TO_INT(user_data);
+ if (pid > 0) {
+ if (kill(pid, 0) == 0) {
+ connman_info("pid %d was not killed, "
+ "retrying after 2 sec", pid);
+ g_timeout_add_seconds(2, kill_timeout,
+ GINT_TO_POINTER(pid));
+ }
+ }
+
+ return FALSE;
+}
+
/**
* connman_task_stop:
* @task: task structure
@@ -360,9 +398,13 @@ int connman_task_stop(struct connman_task *task)
{
DBG("task %p", task);
- if (task->pid > 0)
+ if (task->pid > 0) {
kill(task->pid, SIGTERM);
+ g_timeout_add_seconds(0, check_kill,
+ GINT_TO_POINTER(task->pid));
+ }
+
return 0;
}