chiark / gitweb /
sd-daemon: introduce sd_pid_notify() and sd_pid_notifyf()
[elogind.git] / src / shared / util.c
index 0c273943e7e671d20439dd7f7962e5c382d50032..7a4dacd2138ca52eff63e338ddf255d893e516ef 100644 (file)
@@ -1371,23 +1371,27 @@ bool ignore_file(const char *filename) {
         assert(filename);
 
         if (endswith(filename, "~"))
-                return false;
+                return true;
 
         return ignore_file_allow_backup(filename);
 }
 
 int fd_nonblock(int fd, bool nonblock) {
-        int flags;
+        int flags, nflags;
 
         assert(fd >= 0);
 
-        if ((flags = fcntl(fd, F_GETFL, 0)) < 0)
+        flags = fcntl(fd, F_GETFL, 0);
+        if (flags < 0)
                 return -errno;
 
         if (nonblock)
-                flags |= O_NONBLOCK;
+                nflags = flags | O_NONBLOCK;
         else
-                flags &= ~O_NONBLOCK;
+                nflags = flags & ~O_NONBLOCK;
+
+        if (nflags == flags)
+                return 0;
 
         if (fcntl(fd, F_SETFL, flags) < 0)
                 return -errno;
@@ -1396,17 +1400,21 @@ int fd_nonblock(int fd, bool nonblock) {
 }
 
 int fd_cloexec(int fd, bool cloexec) {
-        int flags;
+        int flags, nflags;
 
         assert(fd >= 0);
 
-        if ((flags = fcntl(fd, F_GETFD, 0)) < 0)
+        flags = fcntl(fd, F_GETFD, 0);
+        if (flags < 0)
                 return -errno;
 
         if (cloexec)
-                flags |= FD_CLOEXEC;
+                nflags = flags | FD_CLOEXEC;
         else
-                flags &= ~FD_CLOEXEC;
+                nflags = flags & ~FD_CLOEXEC;
+
+        if (nflags == flags)
+                return 0;
 
         if (fcntl(fd, F_SETFD, flags) < 0)
                 return -errno;
@@ -6480,8 +6488,7 @@ void hexdump(FILE *f, const void *p, size_t s) {
         }
 }
 
-int update_reboot_param_file(const char *param)
-{
+int update_reboot_param_file(const char *param) {
         int r = 0;
 
         if (param) {