chiark / gitweb /
hostname: read hostname for Gentoo
[elogind.git] / util.c
diff --git a/util.c b/util.c
index 9d99fefe78b8ce5e373e52e91084988d8c938893..8042214c8fae7fdd40494691d216624a26cfeee8 100644 (file)
--- a/util.c
+++ b/util.c
@@ -42,6 +42,7 @@
 #include <sys/inotify.h>
 #include <sys/poll.h>
 #include <libgen.h>
 #include <sys/inotify.h>
 #include <sys/poll.h>
 #include <libgen.h>
+#include <ctype.h>
 
 #include "macro.h"
 #include "util.h"
 
 #include "macro.h"
 #include "util.h"
@@ -141,6 +142,30 @@ bool startswith(const char *s, const char *prefix) {
         return memcmp(s, prefix, pl) == 0;
 }
 
         return memcmp(s, prefix, pl) == 0;
 }
 
+bool startswith_no_case(const char *s, const char *prefix) {
+        size_t sl, pl;
+        unsigned i;
+
+        assert(s);
+        assert(prefix);
+
+        sl = strlen(s);
+        pl = strlen(prefix);
+
+        if (pl == 0)
+                return true;
+
+        if (sl < pl)
+                return false;
+
+        for(i = 0; i < pl; ++i) {
+                if (tolower(s[i]) != tolower(prefix[i]))
+                        return false;
+        }
+
+        return true;
+}
+
 bool first_word(const char *s, const char *word) {
         size_t sl, wl;
 
 bool first_word(const char *s, const char *word) {
         size_t sl, wl;
 
@@ -1199,6 +1224,7 @@ bool ignore_file(const char *filename) {
 
         return
                 filename[0] == '.' ||
 
         return
                 filename[0] == '.' ||
+                streq(filename, "lost+found") ||
                 endswith(filename, "~") ||
                 endswith(filename, ".rpmnew") ||
                 endswith(filename, ".rpmsave") ||
                 endswith(filename, "~") ||
                 endswith(filename, ".rpmnew") ||
                 endswith(filename, ".rpmsave") ||
@@ -1677,13 +1703,24 @@ fail:
 
 int release_terminal(void) {
         int r = 0, fd;
 
 int release_terminal(void) {
         int r = 0, fd;
+        struct sigaction sa_old, sa_new;
 
 
-        if ((fd = open("/dev/tty", O_RDWR)) < 0)
+        if ((fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY)) < 0)
                 return -errno;
 
                 return -errno;
 
+        /* Temporarily ignore SIGHUP, so that we don't get SIGHUP'ed
+         * by our own TIOCNOTTY */
+
+        zero(sa_new);
+        sa_new.sa_handler = SIG_IGN;
+        sa_new.sa_flags = SA_RESTART;
+        assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
+
         if (ioctl(fd, TIOCNOTTY) < 0)
                 r = -errno;
 
         if (ioctl(fd, TIOCNOTTY) < 0)
                 r = -errno;
 
+        assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
+
         close_nointr_nofail(fd);
         return r;
 }
         close_nointr_nofail(fd);
         return r;
 }