[systemd-commits] 4 commits - src/core src/shared

David Herrmann dvdhrm at kemper.freedesktop.org
Mon Jun 16 06:24:36 PDT 2014


 src/core/main.c    |    8 ++++++++
 src/shared/macro.h |    4 ++++
 src/shared/util.h  |   11 +++++++++--
 3 files changed, 21 insertions(+), 2 deletions(-)

New commits:
commit 5a85ca1cb622fda4a39c8a6f00dccea7f8a1e82a
Author: Ruediger Oertel <ro at suse.de>
Date:   Fri Jun 13 16:41:06 2014 +0200

    Reset signal-mask on re-exec to init=..
    
    Process 1 (aka init) needs to be started with an empty signal mask.
    That includes the process 1 that's started after the initrd is finished.
    When the initrd is using systemd (as it does with dracut based initrds)
    then it is systemd that calls the real init.  Normally this is systemd
    again, except when the user uses for instance "init=/bin/bash" on the
    kernel command line.

diff --git a/src/core/main.c b/src/core/main.c
index 3aac5d1..3e57f07 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1843,6 +1843,7 @@ finish:
         if (reexecute) {
                 const char **args;
                 unsigned i, args_size;
+                sigset_t ss, o_ss;
 
                 /* Close and disarm the watchdog, so that the new
                  * instance can reinitialize it, but doesn't get
@@ -1926,6 +1927,11 @@ finish:
                 args[i++] = NULL;
                 assert(i <= args_size);
 
+                /* reenable any blocked signals, especially important
+                 * if we switch from initial ramdisk to init=... */
+                sigemptyset(&ss);
+                sigprocmask(SIG_SETMASK, &ss, &o_ss);
+
                 if (switch_root_init) {
                         args[0] = switch_root_init;
                         execv(args[0], (char* const*) args);
@@ -1944,6 +1950,8 @@ finish:
                         log_error("Failed to execute /bin/sh, giving up: %m");
                 } else
                         log_warning("Failed to execute /sbin/init, giving up: %m");
+
+                sigprocmask(SIG_SETMASK, &o_ss, NULL);
         }
 
         if (arg_serialization) {

commit 9489490a693ec5d1e3b49eecedb0ca5511568665
Author: David Herrmann <dh.herrmann at gmail.com>
Date:   Fri Jun 13 18:43:22 2014 +0200

    util: add realloc_multiply() helper
    
    This is similar to malloc_multiply() and friends. It is realloc() with a
    multiplication-overflow check.

diff --git a/src/shared/util.h b/src/shared/util.h
index 5a2f103..8ddd1a5 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -672,6 +672,13 @@ _malloc_  _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b)
         return malloc(a * b);
 }
 
+_alloc_(2, 3) static inline void *realloc_multiply(void *p, size_t a, size_t b) {
+        if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
+                return NULL;
+
+        return realloc(p, a * b);
+}
+
 _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_t b) {
         if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
                 return NULL;

commit 368504f485d09b9fd48b7538e71981f648eb32bb
Author: David Herrmann <dh.herrmann at gmail.com>
Date:   Fri Jun 13 18:38:15 2014 +0200

    util: fix multiply-alloc helpers with size==0
    
    Passing 0 to malloc() is not required to return NULL. Therefore, don't
    bail out if "b" is 0. This is not of importance to the existing helpers,
    but the upcoming realloc_multiply() requires this. To keep consistence, we
    keep the same behavior for the other helpers.

diff --git a/src/shared/util.h b/src/shared/util.h
index e855241..5a2f103 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -666,14 +666,14 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, endmntent);
 #define _cleanup_close_pair_ _cleanup_(close_pairp)
 
 _malloc_  _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {
-        if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
+        if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
                 return NULL;
 
         return malloc(a * b);
 }
 
 _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_t b) {
-        if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
+        if (_unlikely_(b != 0 && a > ((size_t) -1) / b))
                 return NULL;
 
         return memdup(p, a * b);

commit d442e2ec6e896c312bc616be7607332d978a45c9
Author: David Herrmann <dh.herrmann at gmail.com>
Date:   Thu Jun 12 17:54:48 2014 +0200

    macro: add DISABLE_WARNING_SHADOW
    
    As it turns out, we cannot use _Pragma in compound-statements. Therefore,
    constructs like MIN(MAX(a, b), x) will warn due to shadowed variable
    declarations. The DISABLE_WARNING_SHADOW macro can be used to suppress
    these.
    
    Note that using UNIQUE(_var) does not work either as GCC uses the last
    line of a macro-expansion for __LINE__, therefore, still causing both
    macros to have the same variables. We could use different variable-names
    for MIN and MAX, but that just hides the problem and still fails for
    MIN(something(MIN(a, b)), c).
    
    The only working solution is to use __COUNTER__ and pass it pre-evaluated
    as extra argument to a macro to use as name-prefix. This, however, makes
    all these macros much more complicated so I'll go with manual
    DISABLE_WARNING_SHADOW so far.

diff --git a/src/shared/macro.h b/src/shared/macro.h
index 53bd578..32cf714 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -63,6 +63,10 @@
         _Pragma("GCC diagnostic push");                                 \
         _Pragma("GCC diagnostic ignored \"-Wnonnull\"")
 
+#define DISABLE_WARNING_SHADOW                                          \
+        _Pragma("GCC diagnostic push");                                 \
+        _Pragma("GCC diagnostic ignored \"-Wshadow\"")
+
 #define REENABLE_WARNING                                                \
         _Pragma("GCC diagnostic pop")
 



More information about the systemd-commits mailing list