[Spice-devel] [spice-vdagent PATCH 1/2] vdagentd: daemonize: check fprintf return value
Frediano Ziglio
fziglio at redhat.com
Wed Aug 28 16:09:18 UTC 2019
>
> Other fprintf calls are checked.
>
> If fprintf fails write an error message and continue.
>
> Make covscan happy
>
> Signed-off-by: Uri Lublin <uril at redhat.com>
> ---
> 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
More information about the Spice-devel
mailing list