[systemd-commits] 4 commits - TODO configure.ac src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Wed Oct 29 09:08:44 PDT 2014


 TODO                 |    7 +++----
 configure.ac         |    3 ++-
 src/shared/missing.h |   33 +++++++++++++++++++++------------
 src/shared/util.c    |   25 ++++++++++++++++++++++++-
 4 files changed, 50 insertions(+), 18 deletions(-)

New commits:
commit 793062063a27039584e9a6f968007b1e5436fc03
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Oct 29 17:08:18 2014 +0100

    missing: no tabs please, we are british

diff --git a/src/shared/missing.h b/src/shared/missing.h
index 0cfb6fa..00e0287 100644
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -420,7 +420,7 @@ static inline int setns(int fd, int nstype) {
 #define IFLA_BOND_AD_INFO 23
 #define __IFLA_BOND_MAX 24
 
-#define IFLA_BOND_MAX	(__IFLA_BOND_MAX - 1)
+#define IFLA_BOND_MAX   (__IFLA_BOND_MAX - 1)
 #endif
 
 #if !HAVE_DECL_IFLA_VLAN_PROTOCOL

commit f85857df75cfedbc0d10b8ca2400188dc8f4c22e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Oct 29 17:08:00 2014 +0100

    update TODO

diff --git a/TODO b/TODO
index b07d664..d11d73f 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,3 @@
-Fixes needed before 217:
-
-* verify that both resolved and timesyncd work OK without networkd around
-
 Bugfixes:
 
 * Should systemctl status \* work on all unit types, not just .service?
@@ -23,6 +19,7 @@ Bugfixes:
   report the failure properly.
 
 External:
+
 * Fedora: add an rpmlint check that verifies that all unit files in the RPM are listed in %systemd_post macros.
 
 * Fedora: post FPC ticket to move add %tmpfiles_create to the packaging guidelines
@@ -38,6 +35,8 @@ External:
 
 Features:
 
+* optionally support running journald from the command line for testing purposes in external projects
+
 * journald: allow per-priority and per-service retention times when rotating/vacuuming
 
 * introduce systemd-timesync-wait.service or so to sync on an NTP fix?

commit b244d9f374d607abfb24489593b4b7b6ce716cd4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Oct 29 17:07:47 2014 +0100

    missing: simplify memfd ifdeffery

diff --git a/src/shared/missing.h b/src/shared/missing.h
index 5b87e23..0cfb6fa 100644
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -115,21 +115,15 @@ static inline int pivot_root(const char *new_root, const char *put_old) {
 }
 #endif
 
-#ifdef __x86_64__
-#  ifndef __NR_memfd_create
+#ifndef __NR_memfd_create
+#  if defined __x86_64__
 #    define __NR_memfd_create 319
-#  endif
-#elif defined __arm__
-#  ifndef __NR_memfd_create
+#  elif defined __arm__
 #    define __NR_memfd_create 385
-#  endif
-#elif defined _MIPS_SIM
-#  ifndef __NR_memfd_create
+#  elif defined _MIPS_SIM
 #    warning "__NR_memfd_create not yet defined for MIPS"
 #    define __NR_memfd_create 0xffffffff
-#  endif
-#else
-#  ifndef __NR_memfd_create
+#  else
 #    define __NR_memfd_create 356
 #  endif
 #endif

commit 539618a0ddc2dc7f0fbe28de2ae0e07b34c81e60
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Oct 29 17:06:32 2014 +0100

    util: make use of the new getrandom() syscall if it is available when needing entropy
    
    Doesn't require an fd, and could be a bit faster, so let's make use of
    it, if it is available.

diff --git a/configure.ac b/configure.ac
index f8a95cb..82bc7a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -308,7 +308,7 @@ LIBS="$save_LIBS"
 
 AC_CHECK_FUNCS([memfd_create])
 AC_CHECK_FUNCS([__secure_getenv secure_getenv])
-AC_CHECK_DECLS([gettid, pivot_root, name_to_handle_at, setns, LO_FLAGS_PARTSCAN],
+AC_CHECK_DECLS([gettid, pivot_root, name_to_handle_at, setns, getrandom, LO_FLAGS_PARTSCAN],
                [], [], [[
 #include <sys/types.h>
 #include <unistd.h>
@@ -316,6 +316,7 @@ AC_CHECK_DECLS([gettid, pivot_root, name_to_handle_at, setns, LO_FLAGS_PARTSCAN]
 #include <fcntl.h>
 #include <sched.h>
 #include <linux/loop.h>
+#include <linux/random.h>
 ]])
 
 AC_CHECK_DECLS([IFLA_MACVLAN_FLAGS,
diff --git a/src/shared/missing.h b/src/shared/missing.h
index bb4f8f2..5b87e23 100644
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -140,6 +140,21 @@ static inline int memfd_create(const char *name, unsigned int flags) {
 }
 #endif
 
+#ifndef __NR_getrandom
+#  if defined __x86_64__
+#    define __NR_getrandom 278
+#  else
+#    warning "__NR_getrandom unknown for your architecture"
+#    define __NR_getrandom 0xffffffff
+#  endif
+#endif
+
+#if !HAVE_DECL_GETRANDOM
+static inline int getrandom(void *buffer, size_t count, unsigned flags) {
+        return syscall(__NR_getrandom, buffer, count, flags);
+}
+#endif
+
 #ifndef BTRFS_IOCTL_MAGIC
 #define BTRFS_IOCTL_MAGIC 0x94
 #endif
diff --git a/src/shared/util.c b/src/shared/util.c
index 4143f6d..ceafba8 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2466,14 +2466,37 @@ char* dirname_malloc(const char *path) {
 }
 
 int dev_urandom(void *p, size_t n) {
-        _cleanup_close_ int fd;
+        static int have_syscall = -1;
+        int r, fd;
         ssize_t k;
 
+        /* Use the syscall unless we know we don't have it, or when
+         * the requested size is too large for it. */
+        if (have_syscall != 0 || (size_t) (int) n != n) {
+                r = getrandom(p, n, 0);
+                if (r == (int) n) {
+                        have_syscall = true;
+                        return 0;
+                }
+
+                if (r < 0) {
+                        if (errno == ENOSYS)
+                                /* we lack the syscall, continue with reading from /dev/urandom */
+                                have_syscall = false;
+                        else
+                                return -errno;
+                } else
+                        /* too short read? */
+                        return -EIO;
+        }
+
         fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
         if (fd < 0)
                 return errno == ENOENT ? -ENOSYS : -errno;
 
         k = loop_read(fd, p, n, true);
+        safe_close(fd);
+
         if (k < 0)
                 return (int) k;
         if ((size_t) k != n)



More information about the systemd-commits mailing list