[systemd-commits] 4 commits - TODO src/libsystemd-bus src/libsystemd-id128 src/login src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Tue Dec 17 12:45:59 PST 2013


 TODO                            |    2 ++
 src/libsystemd-bus/bus-dump.c   |    2 +-
 src/libsystemd-bus/sd-bus.c     |    4 ++--
 src/libsystemd-bus/sd-event.c   |    2 +-
 src/libsystemd-id128/sd-id128.c |    8 ++++----
 src/login/logind-inhibit.c      |    2 +-
 src/shared/capability.c         |    4 ++--
 src/shared/cgroup-util.c        |    2 +-
 src/shared/macro.h              |   12 ++++++++++++
 src/shared/util.c               |   14 +++++++-------
 src/shared/util.h               |    4 ++++
 src/shared/virt.c               |    8 ++++----
 12 files changed, 41 insertions(+), 23 deletions(-)

New commits:
commit 73020ab241866dce79b80cbebcaae537470c7086
Author: Shawn Landden <shawn at churchofgit.com>
Date:   Sun Dec 15 16:56:21 2013 -0800

    util: no need for in_initrd() cache to be thread-local
    
    the process only has one working directory, and a race is
    harmless

diff --git a/src/shared/util.c b/src/shared/util.c
index f7335cf..80dbf73 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2737,9 +2737,9 @@ int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct
 
 _pure_ static int is_temporary_fs(struct statfs *s) {
         assert(s);
-        return
-                F_TYPE_EQUAL(s->f_type, TMPFS_MAGIC) ||
-                F_TYPE_EQUAL(s->f_type, RAMFS_MAGIC);
+
+        return F_TYPE_EQUAL(s->f_type, TMPFS_MAGIC) ||
+               F_TYPE_EQUAL(s->f_type, RAMFS_MAGIC);
 }
 
 int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev) {
@@ -5154,7 +5154,7 @@ bool is_valid_documentation_url(const char *url) {
 }
 
 bool in_initrd(void) {
-        static __thread int saved = -1;
+        static int saved = -1;
         struct statfs s;
 
         if (saved >= 0)

commit ec202eae8e84a4c99f054f771cb832046cb8769f
Author: Shawn Landden <shawn at churchofgit.com>
Date:   Sun Dec 15 16:24:14 2013 -0800

    __thread --> thread_local for C11 compat
    
    Also make thread_local available w/o including <threads.h>.
    (as the latter hasn't been implemented, but this part is trivial)

diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 338ce06..9c564de 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2813,13 +2813,13 @@ static int bus_default(int (*bus_open)(sd_bus **), sd_bus **default_bus, sd_bus
 }
 
 _public_ int sd_bus_default_system(sd_bus **ret) {
-        static __thread sd_bus *default_system_bus = NULL;
+        static thread_local sd_bus *default_system_bus = NULL;
 
         return bus_default(sd_bus_open_system, &default_system_bus, ret);
 }
 
 _public_ int sd_bus_default_user(sd_bus **ret) {
-        static __thread sd_bus *default_user_bus = NULL;
+        static thread_local sd_bus *default_user_bus = NULL;
 
         return bus_default(sd_bus_open_user, &default_user_bus, ret);
 }
diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index 06c84d7..727528b 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -2116,7 +2116,7 @@ _public_ int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec) {
 
 _public_ int sd_event_default(sd_event **ret) {
 
-        static __thread sd_event *default_event = NULL;
+        static thread_local sd_event *default_event = NULL;
         sd_event *e;
         int r;
 
diff --git a/src/libsystemd-id128/sd-id128.c b/src/libsystemd-id128/sd-id128.c
index 07d2415..9ee40ab 100644
--- a/src/libsystemd-id128/sd-id128.c
+++ b/src/libsystemd-id128/sd-id128.c
@@ -104,8 +104,8 @@ static sd_id128_t make_v4_uuid(sd_id128_t id) {
 }
 
 _public_ int sd_id128_get_machine(sd_id128_t *ret) {
-        static __thread sd_id128_t saved_machine_id;
-        static __thread bool saved_machine_id_valid = false;
+        static thread_local sd_id128_t saved_machine_id;
+        static thread_local bool saved_machine_id_valid = false;
         _cleanup_close_ int fd = -1;
         char buf[33];
         ssize_t k;
@@ -153,8 +153,8 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) {
 }
 
 _public_ int sd_id128_get_boot(sd_id128_t *ret) {
-        static __thread sd_id128_t saved_boot_id;
-        static __thread bool saved_boot_id_valid = false;
+        static thread_local sd_id128_t saved_boot_id;
+        static thread_local bool saved_boot_id_valid = false;
         _cleanup_close_ int fd = -1;
         char buf[36];
         ssize_t k;
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
index ec6a722..042586d 100644
--- a/src/login/logind-inhibit.c
+++ b/src/login/logind-inhibit.c
@@ -413,7 +413,7 @@ bool manager_is_inhibited(
 }
 
 const char *inhibit_what_to_string(InhibitWhat w) {
-        static __thread char buffer[97];
+        static thread_local char buffer[97];
         char *p;
 
         if (w < 0 || w >= _INHIBIT_WHAT_MAX)
diff --git a/src/shared/capability.c b/src/shared/capability.c
index 3219520..f34f6ba 100644
--- a/src/shared/capability.c
+++ b/src/shared/capability.c
@@ -55,8 +55,8 @@ int have_effective_cap(int value) {
 }
 
 unsigned long cap_last_cap(void) {
-        static __thread unsigned long saved;
-        static __thread bool valid = false;
+        static thread_local unsigned long saved;
+        static thread_local bool valid = false;
         unsigned long p;
 
         if (valid)
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 2c2ffc5..309f65d 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -480,7 +480,7 @@ static int join_path(const char *controller, const char *path, const char *suffi
 
 int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs) {
         const char *p;
-        static __thread bool good = false;
+        static thread_local bool good = false;
 
         assert(fs);
 
diff --git a/src/shared/macro.h b/src/shared/macro.h
index fd3762e..2b5b3fd 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -300,5 +300,17 @@ do {                                                                    \
                 _found;                                                 \
         })
 
+/* Define C11 thread_local attribute even on older compilers */
+#ifndef thread_local
+/*
+ * Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
+ * see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53769
+ */
+#if __STDC_VERSION__ >= 201112L && !(defined(__STDC_NO_THREADS__) || (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
+#define thread_local _Thread_local
+#else
+#define thread_local __thread
+#endif
+#endif
 
 #include "log.h"
diff --git a/src/shared/util.c b/src/shared/util.c
index cdc58e3..f7335cf 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -86,7 +86,7 @@ static volatile unsigned cached_columns = 0;
 static volatile unsigned cached_lines = 0;
 
 size_t page_size(void) {
-        static __thread size_t pgsz = 0;
+        static thread_local size_t pgsz = 0;
         long r;
 
         if (_likely_(pgsz > 0))
@@ -4580,7 +4580,7 @@ char *strjoin(const char *x, ...) {
 }
 
 bool is_main_thread(void) {
-        static __thread int cached = 0;
+        static thread_local int cached = 0;
 
         if (_unlikely_(cached == 0))
                 cached = getpid() == gettid() ? 1 : -1;
@@ -4798,7 +4798,7 @@ static const char *const __signal_table[] = {
 DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
 
 const char *signal_to_string(int signo) {
-        static __thread char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
+        static thread_local char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
         const char *name;
 
         name = __signal_to_string(signo);
diff --git a/src/shared/virt.c b/src/shared/virt.c
index 4e18638..c79d35d 100644
--- a/src/shared/virt.c
+++ b/src/shared/virt.c
@@ -150,8 +150,8 @@ static int detect_vm_dmi(const char **_id) {
 /* Returns a short identifier for the various VM implementations */
 int detect_vm(const char **id) {
         _cleanup_free_ char *hvtype = NULL, *cpuinfo_contents = NULL;
-        static __thread int cached_found = -1;
-        static __thread const char *cached_id = NULL;
+        static thread_local int cached_found = -1;
+        static thread_local const char *cached_id = NULL;
         const char *_id = NULL;
         int r;
 
@@ -215,8 +215,8 @@ finish:
 
 int detect_container(const char **id) {
 
-        static __thread int cached_found = -1;
-        static __thread const char *cached_id = NULL;
+        static thread_local int cached_found = -1;
+        static thread_local const char *cached_id = NULL;
 
         _cleanup_free_ char *e = NULL;
         const char *_id = NULL;

commit 06db8540cdfc8259423ed90e7352dbc1d71eccd9
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Dec 17 21:36:54 2013 +0100

    update TODO

diff --git a/TODO b/TODO
index da59f79..8025169 100644
--- a/TODO
+++ b/TODO
@@ -154,6 +154,8 @@ Features:
 
 * timedatctl, localectl: possibly make some commands work without the daemon, for chroot situations...
 
+* timedatectl: print a nicer message when enabling ntp fails because ntpd/chrony are not installed
+
 * cgtop: make cgtop useful in a container
 
 * test/:

commit 5232c42ec43e86f90a850d965a33bb413b9e5a00
Author: Lukasz Skalski <l.skalski at partner.samsung.com>
Date:   Tue Dec 17 10:55:28 2013 +0100

    libsystemd-bus: true/false instead of yes/no in msg dump
    
    Due to this patch, message dump (for message which includes boolean
    type) is more consistent with dbus-send (which display true/false
    instead of yes/no for boolean). It's only simple 'cosmetics change'.
    
    ** For dbus-send **
    
    dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply / org.freedesktop.DBus.NameHasOwner string:org.freedesktop.login1
    
    method return sender=org.freedesktop.DBus -> dest=:1.97 reply_serial=2
       boolean true
    
    ** For libsystemd-bus (without this patch) **
    
    ‣ Type=method_call  Endian=l  Flags=0  Version=2 Serial=8
      Destination=org.freedesktop.DBus  Path=/org/freedesktop/DBus  Interface=org.freedesktop.DBus  Member=NameHasOwner
      MESSAGE "s" {
      	STRING "org.freedesktop.login1";
      };
    
    ‣ Type=method_return  Endian=l  Flags=1  Version=2 Serial=51  ReplySerial=8
      Sender=:1.59  Destination=:1.67
      UniqueName=:1.59  WellKnownNames={org.freedesktop.DBus}
      MESSAGE "b" {
      	BOOLEAN yes;
      };
    
    For me true/false seems to be better readable than yes/no for BOOLEAN.

diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
index ddad418..7b61479 100644
--- a/src/libsystemd-bus/bus-dump.c
+++ b/src/libsystemd-bus/bus-dump.c
@@ -200,7 +200,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
                         break;
 
                 case SD_BUS_TYPE_BOOLEAN:
-                        fprintf(f, "%sBOOLEAN %s%s%s;\n", prefix, ansi_highlight(), yes_no(basic.i), ansi_highlight_off());
+                        fprintf(f, "%sBOOLEAN %s%s%s;\n", prefix, ansi_highlight(), true_false(basic.i), ansi_highlight_off());
                         break;
 
                 case SD_BUS_TYPE_INT16:
diff --git a/src/shared/util.h b/src/shared/util.h
index dd51e89..1d17826 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -92,6 +92,10 @@ static inline const char* yes_no(bool b) {
         return b ? "yes" : "no";
 }
 
+static inline const char* true_false(bool b) {
+        return b ? "true" : "false";
+}
+
 static inline const char* strempty(const char *s) {
         return s ? s : "";
 }



More information about the systemd-commits mailing list