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

Re: [Libvir] [PATCH] Fix warn_unused_result when compiling with latest glibc



Daniel Veillard wrote:
On Mon, Mar 26, 2007 at 03:39:51PM +0100, Richard W.M. Jones wrote:
I'm not sure if this is the right way to solve this, but it is a way.

we should test the return value to check for an error there, the unfortunate thing is that since we are in a signal handler there isn't
much we can do, I suggest to increment a global variable (which could
for example be checked if we hit that problem by some other code in
the main loop).
  Other ideas ?

How about this patch.  It implements your suggestion.

Rich.
Index: qemud/qemud.c
===================================================================
RCS file: /data/cvs/libvirt/qemud/qemud.c,v
retrieving revision 1.34
diff -u -r1.34 qemud.c
--- qemud/qemud.c	22 Mar 2007 18:30:57 -0000	1.34
+++ qemud/qemud.c	26 Mar 2007 15:21:04 -0000
@@ -57,15 +57,23 @@
 static int verbose = 0;
 static int sigwrite = -1;
 
+static sig_atomic_t sig_errors = 0;
+static int sig_lasterrno = 0;
+
 static void sig_handler(int sig) {
     unsigned char sigc = sig;
     int origerrno;
+    int r;
 
     if (sig == SIGCHLD) /* We explicitly waitpid the child later */
         return;
 
     origerrno = errno;
-    write(sigwrite, &sigc, 1);
+    r = write(sigwrite, &sigc, 1);
+    if (r == -1) {
+        sig_errors++;
+        sig_lasterrno = errno;
+    }
     errno = origerrno;
 }
 
@@ -1655,6 +1663,7 @@
     struct pollfd fds[nfds];
     int thistimeout = -1;
     int ret;
+    sig_atomic_t errors;
 
     /* If we have no clients or vms, then timeout after
        30 seconds, letting daemon exit */
@@ -1682,6 +1691,16 @@
         return -1;
     }
 
+    /* Check for any signal handling errors and log them. */
+    errors = sig_errors;
+    if (errors) {
+        sig_errors -= errors;
+        qemudLog (QEMUD_ERR,
+                  "Signal handler reported %d errors: last error: %s",
+                  errors, strerror (sig_lasterrno));
+        return -1;
+    }
+
     if (qemudDispatchPoll(server, fds) < 0)
         return -1;
 

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