Hi Mohamed,

> diff --git a/src/task.c b/src/task.c
> index f5495d7..85e8787 100644
> --- a/src/task.c
> +++ b/src/task.c
> @@ -267,12 +267,15 @@ static void task_setup(gpointer user_data)
>   * @task: task structure
>   * @function: exit callback
>   * @user_data: optional exit user data
> + * @fd: optional spawn with pipe
>   *
>   * Execute program specified by #task
>   */
>  int connman_task_run(struct connman_task *task,
> -                     connman_task_exit_t function, void *user_data)
> +                     connman_task_exit_t function, void *user_data,
> +                     int *fd)
>  {
> +     gboolean ret;

call this variable "result" instead of shortcut "ret".

>       GSpawnFlags flags = G_SPAWN_DO_NOT_REAP_CHILD |
>                                               G_SPAWN_STDOUT_TO_DEV_NULL;
>       char **argv, **envp;
> @@ -312,8 +315,16 @@ int connman_task_run(struct connman_task *task,
>       argv = (char **) task->argv->pdata;
>       envp = (char **) task->envp->pdata;
>  
> -     if (g_spawn_async(NULL, argv, envp, flags,
> -                             task_setup, task, &task->pid, NULL) == FALSE) {
> +     if (fd)
> +             ret = g_spawn_async_with_pipes(NULL, argv, envp,
> +                                            G_SPAWN_DO_NOT_REAP_CHILD,
> +                                            task_setup, task, &task->pid,
> +                                            fd, NULL, NULL, NULL);
> +      else
> +             ret = g_spawn_async(NULL, argv, envp, flags,
> +                                 task_setup, task, &task->pid, NULL);
> +     

The split here is actually fully pointless since GLib internally uses
g_spawn_async_with_pipes with NULL pipes when you call g_spawn_async. So
we have no optimization here whatsoever.

While thinking about this a bit more, I prefer if we just turn task_run
into a proper function that also handles stderr and stdout. So please
modify this to add file descriptors for in the order of input, output
and error.

The flags needs to be dynamically adjusted. If stdout is not present
then mark it as TO_DEV_NULL etc.

Regards

Marcel


_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to