]> xenbits.xensource.com Git - people/julieng/xen-unstable.git/commitdiff
libxl: Do not call assert() in signal handlers
authorIan Jackson <ian.jackson@eu.citrix.com>
Thu, 22 Oct 2015 15:39:12 +0000 (16:39 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 23 Oct 2015 13:32:45 +0000 (14:32 +0100)
assert is not async-signal-safe.

In practice the effect of calling assert there is that if the
assertion fails we might get a secondary crash, or other undesirable
behaviour from stdio (which is how assert usually reports failures).

Mention in a comment in libxl__self_pipe_wakeup that it has to be
async-signal-safe.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl_event.c
tools/libxl/libxl_fork.c
tools/libxl/libxl_save_helper.c

index 7d549ad4c8ef869680c4ced794263c6da2115273..0df6d6c5158d5758cb421644b95c173511f77d4d 100644 (file)
@@ -1564,6 +1564,7 @@ int libxl__pipe_nonblock(libxl_ctx *ctx, int fds[2])
 
 int libxl__self_pipe_wakeup(int fd)
 {
+    /* Called from signal handlers, so needs to be async-signal-safe */
     static const char buf[1] = "";
 
     for (;;) {
@@ -1572,7 +1573,7 @@ int libxl__self_pipe_wakeup(int fd)
         assert(r==-1);
         if (errno == EINTR) continue;
         if (errno == EWOULDBLOCK) return 0;
-        assert(errno);
+        if (!errno) abort();
         return errno;
     }
 }
index 024c1e2fb993588e02bcb9aab603853fb15c0e2d..eea3d5d4e68e5a12560662969fb6befacbbe6ba7 100644 (file)
@@ -239,7 +239,7 @@ static void sigchld_handler(int signo)
 
     LIBXL_LIST_FOREACH(notify, &sigchld_users, sigchld_users_entry) {
         int e = libxl__self_pipe_wakeup(notify->sigchld_selfpipe[1]);
-        assert(!e); /* errors are probably EBADF, very bad */
+        if (e) abort(); /* errors are probably EBADF, very bad */
     }
 
     r = pthread_mutex_unlock(&sigchld_defer_mutex);
index 57ae97889c282d0b99108babde97f265b431281a..39038f9022a52b06bdcc4c484b87fe8a49413eb7 100644 (file)
@@ -148,8 +148,11 @@ static void save_signal_handler(int num)
     int esave = errno;
 
     int r = dup2(unwriteable_fd, io_fd);
-    assert(r == io_fd); /* if not we can't write an xtl message because we
-                         * might end up interleaving on our control stream */
+    if (r != io_fd)
+        /* we can't write an xtl message because we might end up
+         * interleaving on our control stream; we can't use stdio
+         * because it's not async-signal-safe */
+        abort();
 
     errno = esave;
 }