On Fri, Jan 04, 2019 at 08:37:01AM +0000, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fzig...@redhat.com>
> ---
>  src/vdagent/vdagent.c   | 10 ++++++----
>  src/vdagentd/vdagentd.c | 10 ++++++----
>  2 files changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
> index 87dfa7c..eb741bc 100644
> --- a/src/vdagent/vdagent.c
> +++ b/src/vdagent/vdagent.c
> @@ -283,7 +283,6 @@ static void wait_and_exit(int s)
>  
>  static int daemonize(void)
>  {
> -    int x;
>      int fd[2];
>  
>      if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fd)) {
> @@ -298,9 +297,12 @@ static int daemonize(void)
>          close(STDOUT_FILENO);
>          close(STDERR_FILENO);
>          setsid();
> -        x = open("/dev/null", O_RDWR);
> -        x = dup(x);
> -        x = dup(x);
> +        // coverity[leaked_handle] just opening standard file descriptors
> +        if (open("/dev/null", O_RDWR) != STDIN_FILENO ||
> +            dup(STDIN_FILENO) != STDOUT_FILENO ||
> +            dup(STDOUT_FILENO) != STDERR_FILENO) {
> +            exit(1);
> +        }

Not really a fan of chaining function calls like this in an if()
statement, I'd just handle them one by one even if that means some more
line of codes.

Christophe

>          close(fd[0]);
>          return fd[1];
>      case -1:
> diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
> index ec679fd..8fa1534 100644
> --- a/src/vdagentd/vdagentd.c
> +++ b/src/vdagentd/vdagentd.c
> @@ -943,7 +943,6 @@ static void agent_read_complete(struct udscs_connection 
> **connp,
>  
>  static void daemonize(void)
>  {
> -    int x;
>      FILE *pidfile;
>  
>      /* detach from terminal */
> @@ -953,9 +952,12 @@ static void daemonize(void)
>          close(STDOUT_FILENO);
>          close(STDERR_FILENO);
>          setsid();
> -        x = open("/dev/null", O_RDWR);
> -        x = dup(x);
> -        x = dup(x);
> +        // coverity[leaked_handle] just opening standard file descriptors
> +        if (open("/dev/null", O_RDWR) != STDIN_FILENO ||
> +            dup(STDIN_FILENO) != STDOUT_FILENO ||
> +            dup(STDOUT_FILENO) != STDERR_FILENO) {
> +            exit(1);
> +        }
>          pidfile = fopen(pidfilename, "w");
>          if (pidfile) {
>              fprintf(pidfile, "%d\n", (int)getpid());
> -- 
> 2.20.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel

Attachment: signature.asc
Description: PGP signature

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

Reply via email to