chiark / gitweb /
Prep v235: Apply pending upstream updates in src/basic [1/4]
authorSven Eden <yamakuzure@gmx.net>
Wed, 30 Aug 2017 05:49:50 +0000 (07:49 +0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 Aug 2017 05:49:50 +0000 (07:49 +0200)
src/basic/capability-util.c
src/basic/capability-util.h
src/basic/fileio.c
src/basic/fileio.h
src/basic/path-util.h
src/basic/terminal-util.c

index 952bcc2d7d434782c987031a0d7e7d56ea54aee5..294dcc8d4aaeccf6a332d20912b23651956df6f7 100644 (file)
@@ -372,4 +372,19 @@ int drop_capability(cap_value_t cv) {
 
         return 0;
 }
+
+bool ambient_capabilities_supported(void) {
+        static int cache = -1;
+
+        if (cache >= 0)
+                return cache;
+
+        /* If PR_CAP_AMBIENT returns something valid, or an unexpected error code we assume that ambient caps are
+         * available. */
+
+        cache = prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_KILL, 0, 0) >= 0 ||
+                !IN_SET(errno, EINVAL, EOPNOTSUPP, ENOSYS);
+
+        return cache;
+}
 #endif // 0
index 913048e4c6804e85344dbad919d83a99d418af0c..feaa3735e27ed3916effcea68f537f862d361018 100644 (file)
@@ -57,3 +57,7 @@ static inline bool cap_test_all(uint64_t caps) {
         m = (UINT64_C(1) << (cap_last_cap() + 1)) - 1;
         return (caps & m) == m;
 }
+
+#if 0 /// UNNEEDED by elogind
+bool ambient_capabilities_supported(void);
+#endif // 0
index 13b2e312fd901b7e2393295919cc4a02b4e875a6..7edc31d0aff2bbbdc75413a4d529fe2830fec3d4 100644 (file)
@@ -70,7 +70,7 @@ int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, stru
         return fflush_and_check(f);
 }
 
-static int write_string_file_atomic(const char *fn, const char *line, bool enforce_newline, bool do_fsync) {
+static int write_string_file_atomic(const char *fn, const char *line, bool enforce_newline) {
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_free_ char *p = NULL;
         int r;
@@ -85,9 +85,6 @@ static int write_string_file_atomic(const char *fn, const char *line, bool enfor
         (void) fchmod_umask(fileno(f), 0644);
 
         r = write_string_stream(f, line, enforce_newline);
-        if (r >= 0 && do_fsync)
-                r = fflush_sync_and_check(f);
-
         if (r >= 0) {
                 if (rename(p, fn) < 0)
                         r = -errno;
@@ -106,14 +103,10 @@ int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags
         assert(fn);
         assert(line);
 
-        /* We don't know how to verify whether the file contents was already on-disk. */
-        assert(!((flags & WRITE_STRING_FILE_VERIFY_ON_FAILURE) && (flags & WRITE_STRING_FILE_SYNC)));
-
         if (flags & WRITE_STRING_FILE_ATOMIC) {
                 assert(flags & WRITE_STRING_FILE_CREATE);
 
-                r = write_string_file_atomic(fn, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE),
-                                                       flags & WRITE_STRING_FILE_SYNC);
+                r = write_string_file_atomic(fn, line, !(flags & WRITE_STRING_FILE_AVOID_NEWLINE));
                 if (r < 0)
                         goto fail;
 
@@ -150,12 +143,6 @@ int write_string_file_ts(const char *fn, const char *line, WriteStringFileFlags
         if (r < 0)
                 goto fail;
 
-        if (flags & WRITE_STRING_FILE_SYNC) {
-                r = fflush_sync_and_check(f);
-                if (r < 0)
-                        return r;
-        }
-
         return 0;
 
 fail:
@@ -1144,21 +1131,6 @@ int fflush_and_check(FILE *f) {
         return 0;
 }
 
-int fflush_sync_and_check(FILE *f) {
-        int r;
-
-        assert(f);
-
-        r = fflush_and_check(f);
-        if (r < 0)
-                return r;
-
-        if (fsync(fileno(f)) < 0)
-                return -errno;
-
-        return 0;
-}
-
 /* This is much like mkostemp() but is subject to umask(). */
 int mkostemp_safe(char *pattern) {
         _cleanup_umask_ mode_t u = 0;
index f76c3243e39b246927bcb0ccdf7e85a9fc32d52f..fa223fdf52d021ace998f9be72c16e43ae45a244 100644 (file)
 #include "time-util.h"
 
 typedef enum {
-        WRITE_STRING_FILE_CREATE = 1<<0,
-        WRITE_STRING_FILE_ATOMIC = 1<<1,
-        WRITE_STRING_FILE_AVOID_NEWLINE = 1<<2,
-        WRITE_STRING_FILE_VERIFY_ON_FAILURE = 1<<3,
-        WRITE_STRING_FILE_SYNC = 1<<4,
+        WRITE_STRING_FILE_CREATE = 1,
+        WRITE_STRING_FILE_ATOMIC = 2,
+        WRITE_STRING_FILE_AVOID_NEWLINE = 4,
+        WRITE_STRING_FILE_VERIFY_ON_FAILURE = 8,
 } WriteStringFileFlags;
 
 int write_string_stream_ts(FILE *f, const char *line, bool enforce_newline, struct timespec *ts);
@@ -84,7 +83,6 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *root
                 } else
 
 int fflush_and_check(FILE *f);
-int fflush_sync_and_check(FILE *f);
 
 int fopen_temporary(const char *path, FILE **_f, char **_temp_path);
 int mkostemp_safe(char *pattern);
index 3c0dbb321ee09d06f504cfcd8c1da0942c0c3355..0d162bac2f3479d24d81c4b574946dd6db0c042f 100644 (file)
@@ -157,3 +157,13 @@ int systemd_installation_has_version(const char *root, unsigned minimal_version)
 #endif // 0
 
 bool dot_or_dot_dot(const char *path);
+
+static inline const char *skip_dev_prefix(const char *p) {
+        const char *e;
+
+        /* Drop any /dev prefix if there is any */
+
+        e = path_startswith(p, "/dev/");
+
+        return e ?: p;
+}
index 35c1a68df55f1f32ede74118604abcf697c07a5f..f9d62978b80e22a5ef71c3f66f0685ddf5aea779 100644 (file)
@@ -45,6 +45,7 @@
 #include "io-util.h"
 #include "log.h"
 #include "macro.h"
+#include "path-util.h"
 #include "parse-util.h"
 #include "process-util.h"
 #include "socket-util.h"
@@ -560,6 +561,7 @@ int terminal_vhangup(const char *name) {
 
 int vt_disallocate(const char *name) {
         _cleanup_close_ int fd = -1;
+        const char *e, *n;
         unsigned u;
         int r;
 
@@ -567,7 +569,8 @@ int vt_disallocate(const char *name) {
          * (i.e. because it is the active one), at least clear it
          * entirely (including the scrollback buffer) */
 
-        if (!startswith(name, "/dev/"))
+        e = path_startswith(name, "/dev/");
+        if (!e)
                 return -EINVAL;
 
         if (!tty_is_vc(name)) {
@@ -586,10 +589,11 @@ int vt_disallocate(const char *name) {
                 return 0;
         }
 
-        if (!startswith(name, "/dev/tty"))
+        n = startswith(e, "tty");
+        if (!n)
                 return -EINVAL;
 
-        r = safe_atou(name+8, &u);
+        r = safe_atou(n, &u);
         if (r < 0)
                 return r;
 
@@ -654,10 +658,7 @@ bool tty_is_vc(const char *tty) {
 bool tty_is_console(const char *tty) {
         assert(tty);
 
-        if (startswith(tty, "/dev/"))
-                tty += 5;
-
-        return streq(tty, "console");
+        return streq(skip_dev_prefix(tty), "console");
 }
 
 int vtnr_from_tty(const char *tty) {
@@ -665,8 +666,7 @@ int vtnr_from_tty(const char *tty) {
 
         assert(tty);
 
-        if (startswith(tty, "/dev/"))
-                tty += 5;
+        tty = skip_dev_prefix(tty);
 
         if (!startswith(tty, "tty") )
                 return -EINVAL;
@@ -781,8 +781,7 @@ bool tty_is_vc_resolve(const char *tty) {
 
         assert(tty);
 
-        if (startswith(tty, "/dev/"))
-                tty += 5;
+        tty = skip_dev_prefix(tty);
 
         if (streq(tty, "console")) {
                 tty = resolve_dev_console(&active);
@@ -927,11 +926,9 @@ int getttyname_malloc(int fd, char **ret) {
 
                 r = ttyname_r(fd, path, sizeof(path));
                 if (r == 0) {
-                        const char *p;
                         char *c;
 
-                        p = startswith(path, "/dev/");
-                        c = strdup(p ?: path);
+                        c = strdup(skip_dev_prefix(path));
                         if (!c)
                                 return -ENOMEM;