Re: [linux-agent v1 3/5] After fork, use one expression per line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> From: Victor Toso <me@xxxxxxxxxxxxxx>
> 
> And use well defined macros for standard file descriptors.
> 
> Signed-off-by: Victor Toso <victortoso@xxxxxxxxxx>
> ---
>  src/vdagent/vdagent.c   | 8 ++++++--
>  src/vdagentd/vdagentd.c | 8 ++++++--
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
> index f7c8b72..87dfa7c 100644
> --- a/src/vdagent/vdagent.c
> +++ b/src/vdagent/vdagent.c
> @@ -294,9 +294,13 @@ static int daemonize(void)
>      /* detach from terminal */
>      switch (fork()) {
>      case 0:
> -        close(0); close(1); close(2);
> +        close(STDIN_FILENO);
> +        close(STDOUT_FILENO);
> +        close(STDERR_FILENO);
>          setsid();
> -        x = open("/dev/null", O_RDWR); x = dup(x); x = dup(x);
> +        x = open("/dev/null", O_RDWR);
> +        x = dup(x);
> +        x = dup(x);
>          close(fd[0]);
>          return fd[1];
>      case -1:
> diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
> index 99683da..a2f0946 100644
> --- a/src/vdagentd/vdagentd.c
> +++ b/src/vdagentd/vdagentd.c
> @@ -949,9 +949,13 @@ static void daemonize(void)
>      /* detach from terminal */
>      switch (fork()) {
>      case 0:
> -        close(0); close(1); close(2);
> +        close(STDIN_FILENO);
> +        close(STDOUT_FILENO);
> +        close(STDERR_FILENO);
>          setsid();
> -        x = open("/dev/null", O_RDWR); x = dup(x); x = dup(x);
> +        x = open("/dev/null", O_RDWR);
> +        x = dup(x);
> +        x = dup(x);
>          pidfile = fopen(pidfilename, "w");
>          if (pidfile) {
>              fprintf(pidfile, "%d\n", (int)getpid());

Sure,
Acked-by: Frediano Ziglio <fziglio@xxxxxxxxxx>

Maybe would be also good to rename "x" to some more sensible name ?
OT: Looks like the 2 hunks are pretty similar, maybe factoring out a common
function?

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]