Added support to get country-code.
[platform/upstream/connman.git] / src / task.c
old mode 100644 (file)
new mode 100755 (executable)
index 8b9e1d9..280b5e4
@@ -45,8 +45,10 @@ struct connman_task {
        GPtrArray *argv;
        GPtrArray *envp;
        connman_task_exit_t exit_func;
+       connman_task_setup_t setup_func;
        void *exit_data;
        GHashTable *notify;
+       void *setup_data;
 };
 
 static GHashTable *task_hash = NULL;
@@ -93,7 +95,9 @@ static void free_task(gpointer data)
  *
  * Returns: a newly-allocated #connman_task structure
  */
-struct connman_task *connman_task_create(const char *program)
+struct connman_task *connman_task_create(const char *program,
+                                       connman_task_setup_t custom_task_setup,
+                                       void *setup_data)
 {
        struct connman_task *task;
        gint counter;
@@ -116,9 +120,13 @@ struct connman_task *connman_task_create(const char *program)
        str = g_strdup(program);
        g_ptr_array_add(task->argv, str);
 
+       task->setup_func = custom_task_setup;
+
        task->notify = g_hash_table_new_full(g_str_hash, g_str_equal,
                                                        g_free, g_free);
 
+       task->setup_data = setup_data;
+
        DBG("task %p", task);
 
        g_hash_table_insert(task_hash, task->path, task);
@@ -130,7 +138,7 @@ struct connman_task *connman_task_create(const char *program)
  * connman_task_destory:
  * @task: task structure
  *
- * Remove and destory #task
+ * Remove and destroy #task
  */
 void connman_task_destroy(struct connman_task *task)
 {
@@ -220,7 +228,7 @@ int connman_task_add_variable(struct connman_task *task,
 /**
  * connman_task_set_notify:
  * @task: task structure
- * @member: notifcation method name
+ * @member: notification method name
  * @function: notification callback
  * @user_data: optional notification user data
  *
@@ -277,6 +285,9 @@ static void task_setup(gpointer user_data)
        sigemptyset(&mask);
        if (sigprocmask(SIG_SETMASK, &mask, NULL) < 0)
                connman_error("Failed to clean signal mask");
+
+       if (task->setup_func)
+               task->setup_func(task->setup_data);
 }
 
 /**
@@ -401,8 +412,7 @@ int connman_task_stop(struct connman_task *task)
        if (task->pid > 0) {
                kill(task->pid, SIGTERM);
 
-               g_timeout_add_seconds(0, check_kill,
-                               GINT_TO_POINTER(task->pid));
+               g_idle_add(check_kill, GINT_TO_POINTER(task->pid));
        }
 
        return 0;