add a bit more error checking
diff --git a/libdaemon/dexec.c b/libdaemon/dexec.c
index 4cf162b..3df8f2f 100644
--- a/libdaemon/dexec.c
+++ b/libdaemon/dexec.c
@@ -74,10 +74,17 @@
         int i;
 
         if (p[1] != 1)
-            dup2(p[1], 1);
+            if (dup2(p[1], 1) < 0) {
+                daemon_log(LOG_ERR, "dup2: %s", strerror(errno));
+                goto fail;
+            }
 
         if (p[1] != 2)
-            dup2(p[1], 2);
+            if (dup2(p[1], 2) < 0) {
+                daemon_log(LOG_ERR, "dup2: %s", strerror(errno));
+                goto fail;
+            }
+
 
         if (p[0] > 2)
             close(p[0]);
@@ -86,9 +93,10 @@
             close(p[1]);
 
         close(0);
+
         if (open("/dev/null", O_RDONLY) != 0) {
             daemon_log(LOG_ERR, "Unable to open /dev/null as STDIN");
-            _exit(EXIT_FAILURE);
+            goto fail;
         }
 
         daemon_close_all(-1);
@@ -192,8 +200,10 @@
             daemon_log(LOG_ERR, "waitpid(): %s", strerror(errno));
             return -1;
         } else {
-            if (!WIFEXITED(r))
+            if (!WIFEXITED(r)) {
+                errno = ECANCELED;
                 return -1;
+            }
 
             if (ret)
                 *ret = WEXITSTATUS(r);