chiark / gitweb /
service: consider a process exiting with SIGTERM a clean exit
[elogind.git] / util.c
diff --git a/util.c b/util.c
index f8b3f44ad15d665aa4a25a48cf44fb62f087a665..5e3654d1d1ff383d96ec5de86381e85ed8a41d37 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1359,7 +1359,9 @@ bool fstype_is_network(const char *fstype) {
                 "smbfs",
                 "ncpfs",
                 "nfs",
-                "nfs4"
+                "nfs4",
+                "gfs",
+                "gfs2"
         };
 
         unsigned i;
@@ -1890,6 +1892,41 @@ int parse_usec(const char *t, usec_t *usec) {
         return 0;
 }
 
+int make_stdio(int fd) {
+        int r, s, t;
+
+        assert(fd >= 0);
+
+        r = dup2(fd, STDIN_FILENO);
+        s = dup2(fd, STDOUT_FILENO);
+        t = dup2(fd, STDERR_FILENO);
+
+        if (fd >= 3)
+                close_nointr_nofail(fd);
+
+        if (r < 0 || s < 0 || t < 0)
+                return -errno;
+
+        return 0;
+}
+
+bool is_clean_exit(int code, int status) {
+
+        if (code == CLD_EXITED)
+                return status == 0;
+
+        /* If a daemon does not implement handlers for some of the
+         * signals that's not considered an unclean shutdown */
+        if (code == CLD_KILLED)
+                return
+                        status == SIGHUP ||
+                        status == SIGINT ||
+                        status == SIGTERM ||
+                        status == SIGPIPE;
+
+        return false;
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",