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

Uri Lublin uril at redhat.com
Wed Aug 28 16:02:33 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;
-- 
2.21.0



More information about the Spice-devel mailing list