Re: [spice-vdagent PATCH 1/2] vdagentd: daemonize: check fprintf return value

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

 



> 
> Other fprintf calls are checked.
> 
> If fprintf fails write an error message and continue.
> 
> Make covscan happy
> 
> Signed-off-by: Uri Lublin  <uril@xxxxxxxxxx>
> ---
>  src/vdagentd/vdagentd.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
> index 72a3e13..22a62b8 100644
> --- a/src/vdagentd/vdagentd.c
> +++ b/src/vdagentd/vdagentd.c
> @@ -996,7 +996,10 @@ static void daemonize(void)
>          }
>          pidfile = fopen(pidfilename, "w");
>          if (pidfile) {
> -            fprintf(pidfile, "%d\n", (int)getpid());
> +            int r = fprintf(pidfile, "%d\n", (int)getpid());
> +            if (r < 0) {
> +                syslog(LOG_ERR, "Error writing to %s: %m", pidfilename);
> +            }
>              fclose(pidfile);
>          }
>          break;

You can wrap the code (fprintf line in this case) in

#ifndef __clang_analyzer__
... code ...
#endif

As already discussed in a previous proposal is more common that file
creation fails but this is silently ignored.

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]