chiark / gitweb /
Prep v235: Apply upstream fixes (3/10) [src/basic]
authorSven Eden <yamakuzure@gmx.net>
Mon, 14 Aug 2017 07:16:15 +0000 (09:16 +0200)
committerSven Eden <yamakuzure@gmx.net>
Mon, 14 Aug 2017 07:20:53 +0000 (09:20 +0200)
24 files changed:
src/basic/audit-util.c
src/basic/audit-util.h
src/basic/build.h
src/basic/bus-label.h
src/basic/cgroup-util.c
src/basic/def.h
src/basic/escape.c
src/basic/fd-util.c
src/basic/fileio.c
src/basic/fs-util.c
src/basic/hexdecoct.c
src/basic/log.c
src/basic/log.h
src/basic/parse-util.c
src/basic/process-util.c
src/basic/process-util.h
src/basic/socket-util.h
src/basic/string-util.c
src/basic/string-util.h
src/basic/terminal-util.c
src/basic/unit-name.c
src/basic/unit-name.h
src/basic/util.c
src/basic/virt.c

index 2b557839446d87d49704b9db5aa4085748dd061a..f6b448aeb20bc969440a84b8c5a9d599bf82aaec 100644 (file)
@@ -54,7 +54,7 @@ int audit_session_from_pid(pid_t pid, uint32_t *id) {
         if (r < 0)
                 return r;
 
-        if (u == AUDIT_SESSION_INVALID || u <= 0)
+        if (!audit_session_is_valid(u))
                 return -ENODATA;
 
         *id = u;
@@ -81,7 +81,7 @@ int audit_loginuid_from_pid(pid_t pid, uid_t *uid) {
         if (r < 0)
                 return r;
 
-        *uid = (uid_t) u;
+        *uid = u;
         return 0;
 }
 
index b16ca585be3d5d10595e98d09e2f66fc2e2eae12..3e354eea75e80a5f0491c1411ac6254ec02d95d6 100644 (file)
@@ -31,3 +31,7 @@ int audit_loginuid_from_pid(pid_t pid, uid_t *uid);
 #if 0 /// UNNEEDED by elogind
 bool use_audit(void);
 #endif // 0
+
+static inline bool audit_session_is_valid(uint32_t id) {
+        return id > 0 && id != AUDIT_SESSION_INVALID;
+}
index 6329a8fc39d4ce936d81ee75fef85cbd810fe95f..334383bdf5b78b0d86cc0becac867df5edc273ce 100644 (file)
 #define _PAM_FEATURE_ "-PAM"
 #endif
 
+#ifdef HAVE_AUDIT
+#define _AUDIT_FEATURE_ "+AUDIT"
+#else
+#define _AUDIT_FEATURE_ "-AUDIT"
+#endif
+
 #ifdef HAVE_SELINUX
 #define _SELINUX_FEATURE_ "+SELINUX"
 #else
@@ -53,6 +59,7 @@
 
 #define SYSTEMD_FEATURES                                                \
         _PAM_FEATURE_ " "                                               \
+        _AUDIT_FEATURE_ " "                                             \
         _SELINUX_FEATURE_ " "                                           \
         _SMACK_FEATURE_ " "                                             \
         _UTMP_FEATURE_ " "                                              \
index 62fb2c450cfbe98f5f1876bc2a7cb7a03c33671b..600268b767de6d4a6d4beb48b234e4e8a271ab6e 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+#include "string-util.h"
+
 char *bus_label_escape(const char *s);
 char *bus_label_unescape_n(const char *f, size_t l);
 
 static inline char *bus_label_unescape(const char *f) {
-        return bus_label_unescape_n(f, f ? strlen(f) : 0);
+        return bus_label_unescape_n(f, strlen_ptr(f));
 }
index 323c637fe926badb6400e8d983f6bf88bff43cec..5999af3ce40bf7f760301cd9a400a5bc1e33745e 100644 (file)
@@ -257,7 +257,7 @@ int cg_kill(
                         return -ENOMEM;
         }
 
-        my_pid = getpid();
+        my_pid = getpid_cached();
 
         do {
                 _cleanup_fclose_ FILE *f = NULL;
@@ -401,7 +401,7 @@ int cg_migrate(
         if (!s)
                 return -ENOMEM;
 
-        my_pid = getpid();
+        my_pid = getpid_cached();
 
         log_debug_elogind("Migrating \"%s\"/\"%s\" to \"%s\"/\"%s\" (%s)",
                           cfrom, pfrom, cto, pto,
@@ -831,7 +831,7 @@ int cg_attach(const char *controller, const char *path, pid_t pid) {
                 return r;
 
         if (pid == 0)
-                pid = getpid();
+                pid = getpid_cached();
 
         xsprintf(c, PID_FMT "\n", pid);
 
@@ -1004,7 +1004,7 @@ int cg_get_xattr(const char *controller, const char *path, const char *name, voi
 int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
         _cleanup_fclose_ FILE *f = NULL;
         char line[LINE_MAX];
-        const char *fs, *controller_str = NULL;
+        const char *fs, *controller_str;
         size_t cs = 0;
         int unified;
 
@@ -1111,7 +1111,6 @@ int cg_install_release_agent(const char *controller, const char *agent) {
                 return r;
 
         sc = strstrip(contents);
-
         if (isempty(sc)) {
                 r = write_string_file(fs, agent, 0);
                 if (r < 0)
index cce32da1eb54bd75f127bbb2aaf51856c33b109e..d30b4a106b9ba04ee2639a19dbb8a3969e338098 100644 (file)
 #endif
 
 #define UNIX_SYSTEM_BUS_ADDRESS "unix:path=/var/run/dbus/system_bus_socket"
-#define KERNEL_SYSTEM_BUS_ADDRESS "kernel:path=/sys/fs/kdbus/0-system/bus"
-#define DEFAULT_SYSTEM_BUS_ADDRESS KERNEL_SYSTEM_BUS_ADDRESS ";" UNIX_SYSTEM_BUS_ADDRESS
+#define DEFAULT_SYSTEM_BUS_ADDRESS UNIX_SYSTEM_BUS_ADDRESS
 #define UNIX_USER_BUS_ADDRESS_FMT "unix:path=%s/bus"
-#define KERNEL_USER_BUS_ADDRESS_FMT "kernel:path=/sys/fs/kdbus/"UID_FMT"-user/bus"
 
 #define PLYMOUTH_SOCKET {                                       \
                 .un.sun_family = AF_UNIX,                       \
index d43bdaebfc9922e0294a00a8b8dc4e2e45b3193c..2587ca8d11cbf361e6769f3a7fbcf30cf5e7795a 100644 (file)
@@ -314,7 +314,7 @@ int cunescape_length_with_prefix(const char *s, size_t length, const char *prefi
 
         /* Undoes C style string escaping, and optionally prefixes it. */
 
-        pl = prefix ? strlen(prefix) : 0;
+        pl = strlen_ptr(prefix);
 
         r = new(char, pl+length+1);
         if (!r)
index 9afec93661e0e15f79475051c4de5b850d317fe6..d12b5036b92b80f5fe1a95b6cb764f15baadd252 100644 (file)
@@ -283,7 +283,7 @@ int same_fd(int a, int b) {
                 return true;
 
         /* Try to use kcmp() if we have it. */
-        pid = getpid();
+        pid = getpid_cached();
         r = kcmp(pid, pid, KCMP_FILE, a, b);
         if (r == 0)
                 return true;
index 7bafe9038cc139ad542182a937083033faa0f580..95459819a7ece85d968bd8938aea09639811529f 100644 (file)
@@ -825,29 +825,29 @@ static void write_env_var(FILE *f, const char *v) {
         p = strchr(v, '=');
         if (!p) {
                 /* Fallback */
-                fputs(v, f);
-                fputc('\n', f);
+                fputs_unlocked(v, f);
+                fputc_unlocked('\n', f);
                 return;
         }
 
         p++;
-        fwrite(v, 1, p-v, f);
+        fwrite_unlocked(v, 1, p-v, f);
 
         if (string_has_cc(p, NULL) || chars_intersect(p, WHITESPACE SHELL_NEED_QUOTES)) {
-                fputc('\"', f);
+                fputc_unlocked('\"', f);
 
                 for (; *p; p++) {
                         if (strchr(SHELL_NEED_ESCAPE, *p))
-                                fputc('\\', f);
+                                fputc_unlocked('\\', f);
 
-                        fputc(*p, f);
+                        fputc_unlocked(*p, f);
                 }
 
-                fputc('\"', f);
+                fputc_unlocked('\"', f);
         } else
-                fputs(p, f);
+                fputs_unlocked(p, f);
 
-        fputc('\n', f);
+        fputc_unlocked('\n', f);
 }
 
 int write_env_file(const char *fname, char **l) {
@@ -1408,7 +1408,7 @@ int open_serialization_fd(const char *ident) {
         if (fd < 0) {
                 const char *path;
 
-                path = getpid() == 1 ? "/run/systemd" : "/tmp";
+                path = getpid_cached() == 1 ? "/run/systemd" : "/tmp";
                 fd = open_tmpfile_unlinkable(path, O_RDWR|O_CLOEXEC);
                 if (fd < 0)
                         return fd;
index 33624354f57dc4675366c3e4a2e188ac632cf0ad..f7e9f329d35fdb0c99385d7e749ae3a9350f07f0 100644 (file)
@@ -312,7 +312,7 @@ int fd_warn_permissions(const char *path, int fd) {
         if (st.st_mode & 0002)
                 log_warning("Configuration file %s is marked world-writable. Please remove world writability permission bits. Proceeding anyway.", path);
 
-        if (getpid() == 1 && (st.st_mode & 0044) != 0044)
+        if (getpid_cached() == 1 && (st.st_mode & 0044) != 0044)
                 log_warning("Configuration file %s is marked world-inaccessible. This has no effect as configuration data is accessible via APIs without restrictions. Proceeding anyway.", path);
 
         return 0;
index 2d6e377f0a4062cbdc693d103bfb45a21a3c4b63..db3167665cfca4f013518f675846863444de29ee 100644 (file)
@@ -569,7 +569,7 @@ static int base64_append_width(char **prefix, int plen,
 
         lines = (len + width - 1) / width;
 
-        slen = sep ? strlen(sep) : 0;
+        slen = strlen_ptr(sep);
         t = realloc(*prefix, plen + 1 + slen + (indent + width + 1) * lines);
         if (!t)
                 return -ENOMEM;
index 3924ed71f10680261e680f5ba9a39f47a7051444..82db00ed29d09b3ee6e1bea3f53ab65d64fb9728 100644 (file)
@@ -86,7 +86,7 @@ void log_close_console(void) {
         if (console_fd < 0)
                 return;
 
-        if (getpid() == 1) {
+        if (getpid_cached() == 1) {
                 if (console_fd >= 3)
                         safe_close(console_fd);
 
@@ -142,7 +142,7 @@ static int create_log_socket(int type) {
         /* We need a blocking fd here since we'd otherwise lose
         messages way too early. However, let's not hang forever in the
         unlikely case of a deadlock. */
-        if (getpid() == 1)
+        if (getpid_cached() == 1)
                 timeval_store(&tv, 10 * USEC_PER_MSEC);
         else
                 timeval_store(&tv, 10 * USEC_PER_SEC);
@@ -254,7 +254,7 @@ int log_open(void) {
         }
 
         if (!IN_SET(log_target, LOG_TARGET_AUTO, LOG_TARGET_SAFE) ||
-            getpid() == 1 ||
+            getpid_cached() == 1 ||
             isatty(STDERR_FILENO) <= 0) {
 
 #if 0 /// elogind does not support logging to systemd-journald
@@ -382,7 +382,7 @@ static int write_to_console(
 
         if (writev(console_fd, iovec, n) < 0) {
 
-                if (errno == EIO && getpid() == 1) {
+                if (errno == EIO && getpid_cached() == 1) {
 
                         /* If somebody tried to kick us from our
                          * console tty (via vhangup() or suchlike),
@@ -435,7 +435,7 @@ static int write_to_syslog(
         if (strftime(header_time, sizeof(header_time), "%h %e %T ", tm) <= 0)
                 return -EINVAL;
 
-        xsprintf(header_pid, "["PID_FMT"]: ", getpid());
+        xsprintf(header_pid, "["PID_FMT"]: ", getpid_cached());
 
         IOVEC_SET_STRING(iovec[0], header_priority);
         IOVEC_SET_STRING(iovec[1], header_time);
@@ -480,7 +480,7 @@ static int write_to_kmsg(
                 return 0;
 
         xsprintf(header_priority, "<%i>", level);
-        xsprintf(header_pid, "["PID_FMT"]: ", getpid());
+        xsprintf(header_pid, "["PID_FMT"]: ", getpid_cached());
 
         IOVEC_SET_STRING(iovec[0], header_priority);
         IOVEC_SET_STRING(iovec[1], program_invocation_short_name);
@@ -1211,7 +1211,7 @@ int log_syntax_internal(
         va_end(ap);
 
         if (unit)
-                unit_fmt = getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s";
+                unit_fmt = getpid_cached() == 1 ? "UNIT=%s" : "USER_UNIT=%s";
 
         return log_struct_internal(
                         LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, level),
index 9c796e9f13cab99ed9436326b6f6452f74f8912b..d3d6e6e73b71916e674c75322a20b088b44d2f00 100644 (file)
@@ -249,7 +249,7 @@ void log_assert_failed_return_realm(
 #define log_notice(...)    log_full(LOG_NOTICE,  __VA_ARGS__)
 #define log_warning(...)   log_full(LOG_WARNING, __VA_ARGS__)
 #define log_error(...)     log_full(LOG_ERR,     __VA_ARGS__)
-#define log_emergency(...) log_full(getpid() == 1 ? LOG_EMERG : LOG_ERR, __VA_ARGS__)
+#define log_emergency(...) log_full(getpid_cached() == 1 ? LOG_EMERG : LOG_ERR, __VA_ARGS__)
 
 /* Logging triggered by an errno-like error */
 #define log_debug_errno(error, ...)     log_full_errno(LOG_DEBUG,   error, __VA_ARGS__)
@@ -257,7 +257,7 @@ void log_assert_failed_return_realm(
 #define log_notice_errno(error, ...)    log_full_errno(LOG_NOTICE,  error, __VA_ARGS__)
 #define log_warning_errno(error, ...)   log_full_errno(LOG_WARNING, error, __VA_ARGS__)
 #define log_error_errno(error, ...)     log_full_errno(LOG_ERR,     error, __VA_ARGS__)
-#define log_emergency_errno(error, ...) log_full_errno(getpid() == 1 ? LOG_EMERG : LOG_ERR, error, __VA_ARGS__)
+#define log_emergency_errno(error, ...) log_full_errno(getpid_cached() == 1 ? LOG_EMERG : LOG_ERR, error, __VA_ARGS__)
 
 #ifdef LOG_TRACE
 #  define log_trace(...) log_debug(__VA_ARGS__)
index 01135596244836f690e31945e1a6e77761cc7734..f808ecb721c56ca848d745a799158d945a6bfc3f 100644 (file)
@@ -61,7 +61,7 @@ int parse_pid(const char *s, pid_t* ret_pid) {
         if ((unsigned long) pid != ul)
                 return -ERANGE;
 
-        if (pid <= 0)
+        if (!pid_is_valid(pid))
                 return -ERANGE;
 
         *ret_pid = pid;
index 6e855462669b42f346553154c20d73816be246d0..4993de88607c11b8b66e5780dc118c52bfa55a50 100644 (file)
@@ -850,7 +850,7 @@ bool is_main_thread(void) {
         static thread_local int cached = 0;
 
         if (_unlikely_(cached == 0))
-                cached = getpid() == gettid() ? 1 : -1;
+                cached = getpid_cached() == gettid() ? 1 : -1;
 
         return cached > 0;
 }
@@ -915,7 +915,7 @@ const char* personality_to_string(unsigned long p) {
 
 void valgrind_summary_hack(void) {
 #ifdef HAVE_VALGRIND_VALGRIND_H
-        if (getpid() == 1 && RUNNING_ON_VALGRIND) {
+        if (getpid_cached() == 1 && RUNNING_ON_VALGRIND) {
                 pid_t pid;
                 pid = raw_clone(SIGCHLD);
                 if (pid < 0)
@@ -959,6 +959,68 @@ int ioprio_parse_priority(const char *s, int *ret) {
         return 0;
 }
 
+/* The cached PID, possible values:
+ *
+ *     == UNSET [0]  → cache not initialized yet
+ *     == BUSY [-1]  → some thread is initializing it at the moment
+ *     any other     → the cached PID
+ */
+
+#define CACHED_PID_UNSET ((pid_t) 0)
+#define CACHED_PID_BUSY ((pid_t) -1)
+
+static pid_t cached_pid = CACHED_PID_UNSET;
+
+static void reset_cached_pid(void) {
+        /* Invoked in the child after a fork(), i.e. at the first moment the PID changed */
+        cached_pid = CACHED_PID_UNSET;
+}
+
+/* We use glibc __register_atfork() + __dso_handle directly here, as they are not included in the glibc
+ * headers. __register_atfork() is mostly equivalent to pthread_atfork(), but doesn't require us to link against
+ * libpthread, as it is part of glibc anyway. */
+extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
+extern void* __dso_handle __attribute__ ((__weak__));
+
+pid_t getpid_cached(void) {
+        pid_t current_value;
+
+        /* getpid_cached() is much like getpid(), but caches the value in local memory, to avoid having to invoke a
+         * system call each time. This restores glibc behaviour from before 2.24, when getpid() was unconditionally
+         * cached. Starting with 2.24 getpid() started to become prohibitively expensive when used for detecting when
+         * objects were used across fork()s. With this caching the old behaviour is somewhat restored.
+         *
+         * https://bugzilla.redhat.com/show_bug.cgi?id=1443976
+         * https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=1d2bc2eae969543b89850e35e532f3144122d80a
+         */
+
+        current_value = __sync_val_compare_and_swap(&cached_pid, CACHED_PID_UNSET, CACHED_PID_BUSY);
+
+        switch (current_value) {
+
+        case CACHED_PID_UNSET: { /* Not initialized yet, then do so now */
+                pid_t new_pid;
+
+                new_pid = getpid();
+
+                if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) {
+                        /* OOM? Let's try again later */
+                        cached_pid = CACHED_PID_UNSET;
+                        return new_pid;
+                }
+
+                cached_pid = new_pid;
+                return new_pid;
+        }
+
+        case CACHED_PID_BUSY: /* Somebody else is currently initializing */
+                return getpid();
+
+        default: /* Properly initialized */
+                return current_value;
+        }
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",
index 13888929b6bd3e12d730028e1ceebcb51f0e4f22..fec60c4af63346fb8d98a5731e52bb848102e4b7 100644 (file)
@@ -138,5 +138,11 @@ static inline bool ioprio_priority_is_valid(int i) {
         return i >= 0 && i < IOPRIO_BE_NR;
 }
 
+static inline bool pid_is_valid(pid_t p) {
+        return p > 0;
+}
+
 int ioprio_parse_priority(const char *s, int *ret);
 #endif // 0
+
+pid_t getpid_cached(void);
index db3a731972bf944b75c526cb96beaf6f4d7114a1..a85045d11cf4bb862106910317d82d7efd28573a 100644 (file)
 #include <sys/types.h>
 #include <sys/un.h>
 #include <linux/netlink.h>
+#include <linux/if_infiniband.h>
 #include <linux/if_packet.h>
 
 #include "macro.h"
+#include "missing.h"
 #include "util.h"
 
 union sockaddr_union {
@@ -45,6 +47,8 @@ union sockaddr_union {
         struct sockaddr_ll ll;
         struct sockaddr_vm vm;
 #endif // 0
+        /* Ensure there is enough space to store Infiniband addresses */
+        uint8_t ll_buffer[offsetof(struct sockaddr_ll, sll_addr) + CONST_MAX(ETH_ALEN, INFINIBAND_ALEN)];
 };
 
 #if 0 /// UNNEEDED by elogind
@@ -158,6 +162,23 @@ int flush_accept(int fd);
 struct cmsghdr* cmsg_find(struct msghdr *mh, int level, int type, socklen_t length);
 #endif // 0
 
+/*
+ * Certain hardware address types (e.g Infiniband) do not fit into sll_addr
+ * (8 bytes) and run over the structure. This macro returns the correct size that
+ * must be passed to kernel.
+ */
+#define SOCKADDR_LL_LEN(sa)                                             \
+        ({                                                              \
+                const struct sockaddr_ll *_sa = &(sa);                  \
+                size_t _mac_len = sizeof(_sa->sll_addr);                \
+                assert(_sa->sll_family == AF_PACKET);                   \
+                if (be16toh(_sa->sll_hatype) == ARPHRD_ETHER)           \
+                        _mac_len = MAX(_mac_len, (size_t) ETH_ALEN);    \
+                if (be16toh(_sa->sll_hatype) == ARPHRD_INFINIBAND)      \
+                        _mac_len = MAX(_mac_len, (size_t) INFINIBAND_ALEN); \
+                offsetof(struct sockaddr_ll, sll_addr) + _mac_len;      \
+        })
+
 /* Covers only file system and abstract AF_UNIX socket addresses, but not unnamed socket addresses. */
 #define SOCKADDR_UN_LEN(sa)                                             \
         ({                                                              \
index 5172ac7756a3c32e1f8c39f632205132343fd36b..a2569a5b0e205b9a8774ac82af11ec9662eacbf3 100644 (file)
@@ -215,7 +215,7 @@ char *strnappend(const char *s, const char *suffix, size_t b) {
 }
 
 char *strappend(const char *s, const char *suffix) {
-        return strnappend(s, suffix, suffix ? strlen(suffix) : 0);
+        return strnappend(s, suffix, strlen_ptr(suffix));
 }
 
 char *strjoin_real(const char *x, ...) {
@@ -711,7 +711,7 @@ char *strextend(char **x, ...) {
 
         assert(x);
 
-        l = f = *x ? strlen(*x) : 0;
+        l = f = strlen_ptr(*x);
 
         va_start(ap, x);
         for (;;) {
index 46df7e42c2406f5d423b814194ebc206d2cec7cb..a28ef9c4f777fa54886317281f42a3c0e4f195e4 100644 (file)
@@ -208,3 +208,10 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
 #define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)
 
 bool string_is_safe(const char *p) _pure_;
+
+static inline size_t strlen_ptr(const char *s) {
+        if (!s)
+                return 0;
+
+        return strlen(s);
+}
index 6cf623d5196fc16d7ca4b908829a406d1a6704aa..35c1a68df55f1f32ede74118604abcf697c07a5f 100644 (file)
@@ -1232,7 +1232,7 @@ bool colors_enabled(void) {
                 val = getenv_bool("SYSTEMD_COLORS");
                 if (val >= 0)
                         enabled = val;
-                else if (getpid() == 1)
+                else if (getpid_cached() == 1)
                         /* PID1 outputs to the console without holding it open all the time */
                         enabled = !getenv_terminal_is_dumb();
                 else
index fb30c2527a5e40f3ca5891fcc64fa8aa78c440d0..5d0069c931d2e7943f8e206d4d6571b1fe1fe37f 100644 (file)
@@ -611,7 +611,6 @@ const char* unit_dbus_interface_from_type(UnitType t) {
         static const char *const table[_UNIT_TYPE_MAX] = {
                 [UNIT_SERVICE] = "org.freedesktop.systemd1.Service",
                 [UNIT_SOCKET] = "org.freedesktop.systemd1.Socket",
-                [UNIT_BUSNAME] = "org.freedesktop.systemd1.BusName",
                 [UNIT_TARGET] = "org.freedesktop.systemd1.Target",
                 [UNIT_DEVICE] = "org.freedesktop.systemd1.Device",
                 [UNIT_MOUNT] = "org.freedesktop.systemd1.Mount",
@@ -843,7 +842,6 @@ bool slice_name_is_valid(const char *name) {
 static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
         [UNIT_SERVICE] = "service",
         [UNIT_SOCKET] = "socket",
-        [UNIT_BUSNAME] = "busname",
         [UNIT_TARGET] = "target",
         [UNIT_DEVICE] = "device",
         [UNIT_MOUNT] = "mount",
@@ -889,19 +887,6 @@ static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
 
 DEFINE_STRING_TABLE_LOOKUP(automount_state, AutomountState);
 
-static const char* const busname_state_table[_BUSNAME_STATE_MAX] = {
-        [BUSNAME_DEAD] = "dead",
-        [BUSNAME_MAKING] = "making",
-        [BUSNAME_REGISTERED] = "registered",
-        [BUSNAME_LISTENING] = "listening",
-        [BUSNAME_RUNNING] = "running",
-        [BUSNAME_SIGTERM] = "sigterm",
-        [BUSNAME_SIGKILL] = "sigkill",
-        [BUSNAME_FAILED] = "failed",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(busname_state, BusNameState);
-
 static const char* const device_state_table[_DEVICE_STATE_MAX] = {
         [DEVICE_DEAD] = "dead",
         [DEVICE_TENTATIVE] = "tentative",
index bba9a4e807a89e589e8d3eaabbde2266e2df10be..67cd64785c0b06b035dc961e6dc4cdceb18b588e 100644 (file)
@@ -28,7 +28,6 @@
 typedef enum UnitType {
         UNIT_SERVICE = 0,
         UNIT_SOCKET,
-        UNIT_BUSNAME,
         UNIT_TARGET,
         UNIT_DEVICE,
         UNIT_MOUNT,
@@ -74,19 +73,6 @@ typedef enum AutomountState {
         _AUTOMOUNT_STATE_INVALID = -1
 } AutomountState;
 
-typedef enum BusNameState {
-        BUSNAME_DEAD,
-        BUSNAME_MAKING,
-        BUSNAME_REGISTERED,
-        BUSNAME_LISTENING,
-        BUSNAME_RUNNING,
-        BUSNAME_SIGTERM,
-        BUSNAME_SIGKILL,
-        BUSNAME_FAILED,
-        _BUSNAME_STATE_MAX,
-        _BUSNAME_STATE_INVALID = -1
-} BusNameState;
-
 /* We simply watch devices, we cannot plug/unplug them. That
  * simplifies the state engine greatly */
 typedef enum DeviceState {
@@ -346,9 +332,6 @@ UnitActiveState unit_active_state_from_string(const char *s) _pure_;
 const char* automount_state_to_string(AutomountState i) _const_;
 AutomountState automount_state_from_string(const char *s) _pure_;
 
-const char* busname_state_to_string(BusNameState i) _const_;
-BusNameState busname_state_from_string(const char *s) _pure_;
-
 const char* device_state_to_string(DeviceState i) _const_;
 DeviceState device_state_from_string(const char *s) _pure_;
 
index cd7f0e42de3c4d4446d33fa842c8811ef890b2a9..c95e17f577d7cf93c1b5307b826d1725ed96c247 100644 (file)
@@ -224,7 +224,7 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa
         /* Spawns a temporary TTY agent, making sure it goes away when
          * we go away */
 
-        parent_pid = getpid();
+        parent_pid = getpid_cached();
 
         /* First we temporarily block all signals, so that the new
          * child has them blocked initially. This way, we can be sure
index a8f1652d2cc3bc65443dc6937195318177e31a63..36bfd2429e266b6de53ccb838f5a58958af14709 100644 (file)
@@ -423,7 +423,7 @@ int detect_container(void) {
                 goto finish;
         }
 
-        if (getpid() == 1) {
+        if (getpid_cached() == 1) {
                 /* If we are PID 1 we can just check our own environment variable, and that's authoritative. */
 
                 e = getenv("container");