[systemd-commits] 13 commits - src/libsystemd-rtnl src/shared src/systemd src/udev

Tom Gundersen tomegun at kemper.freedesktop.org
Tue Oct 29 18:08:32 CET 2013


 src/libsystemd-rtnl/rtnl-internal.h |    4 +
 src/libsystemd-rtnl/rtnl-message.c  |   61 ++++++++++---------------
 src/libsystemd-rtnl/sd-rtnl.c       |   67 ++++++++++++++++------------
 src/libsystemd-rtnl/test-rtnl.c     |    4 -
 src/shared/path-util.c              |   16 +++---
 src/systemd/sd-rtnl.h               |    8 +--
 src/udev/net/ethtool-util.c         |   10 ++--
 src/udev/net/link-config-parse.c    |    3 -
 src/udev/net/link-config.c          |   85 ++++++++++++++++++++----------------
 src/udev/udev-rules.c               |    8 ---
 10 files changed, 139 insertions(+), 127 deletions(-)

New commits:
commit 276fc0668fdfd22ec3b38533e311e14969d42293
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 17:52:25 2013 +0100

    rtnl: cleanup socket_read_message

diff --git a/src/libsystemd-rtnl/rtnl-message.c b/src/libsystemd-rtnl/rtnl-message.c
index 17183ab..557e690 100644
--- a/src/libsystemd-rtnl/rtnl-message.c
+++ b/src/libsystemd-rtnl/rtnl-message.c
@@ -380,18 +380,10 @@ int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret) {
         if (r < 0)
                 return r;
 
-        r = message_receive_need(nl, &need);
-        if (r < 0)
-                return r;
-
-        m->hdr = realloc(m->hdr, need);
-        if (!m->hdr)
-                return -ENOMEM;
-
         k = recvfrom(nl->fd, m->hdr, need,
                         0, &nl->sockaddr.sa, &addr_len);
         if (k < 0)
-                k = (errno == EAGAIN) ? 0 : -errno; /* no data? weird... */
+                k = (errno == EAGAIN) ? 0 : -errno; /* no data */
         else if (k == 0)
                 k = -ECONNRESET; /* connection was closed by the kernel */
         else if (addr_len != sizeof(nl->sockaddr.nl) ||
@@ -402,11 +394,6 @@ int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret) {
         else if ((size_t) k < sizeof(struct nlmsghdr) ||
                         (size_t) k < m->hdr->nlmsg_len)
                 k = -EIO; /* too small (we do accept too big though) */
-        else if (m->hdr->nlmsg_type == NLMSG_NOOP)
-                k = 0;
-        else if (m->hdr->nlmsg_type == NLMSG_ERROR &&
-                        m->hdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
-                k = -EIO;
         else if ((pid_t) m->hdr->nlmsg_pid != getpid())
                 k = 0; /* not for us */
 

commit 977085794d2996320e345433403de75f662b0622
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 17:48:58 2013 +0100

    udev: link-config - split connection to sockets from loading of configs
    
    We want to load the config in _init, but not connect to the sockets before we are forked.

diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 9d6c96b..f93a4d8 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -54,7 +54,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free);
 
 int link_config_ctx_new(link_config_ctx **ret) {
         _cleanup_link_config_ctx_free_ link_config_ctx *ctx = NULL;
-        int r;
 
         if (!ret)
                 return -EINVAL;
@@ -63,16 +62,10 @@ int link_config_ctx_new(link_config_ctx **ret) {
         if (!ctx)
                 return -ENOMEM;
 
-        r = ethtool_connect(&ctx->ethtool_fd);
-        if (r < 0)
-                return r;
-
-        r = sd_rtnl_open(0, &ctx->rtnl);
-        if (r < 0)
-                return r;
-
         LIST_HEAD_INIT(ctx->links);
 
+        ctx->ethtool_fd = -1;
+
         ctx->link_dirs = strv_new("/etc/systemd/network",
                                   "/run/systemd/network",
                                   "/usr/lib/systemd/network",
@@ -93,6 +86,23 @@ int link_config_ctx_new(link_config_ctx **ret) {
         return 0;
 }
 
+static int link_config_ctx_connect(link_config_ctx *ctx) {
+        int r;
+
+        if (ctx->ethtool_fd >= 0 && ctx->rtnl)
+                return 0;
+
+        r = ethtool_connect(&ctx->ethtool_fd);
+        if (r < 0)
+                return r;
+
+        r = sd_rtnl_open(0, &ctx->rtnl);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
 static void link_configs_free(link_config_ctx *ctx) {
         link_config *link, *link_next;
 
@@ -406,6 +416,10 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
         struct ether_addr *mac = NULL;
         int r, ifindex;
 
+        r = link_config_ctx_connect(ctx);
+        if (r < 0)
+                return r;
+
         name = udev_device_get_sysname(device);
         if (!name)
                 return -EINVAL;

commit adf412b9ec7292e0c83aaf9ab93e08c2c8bd524a
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 17:38:31 2013 +0100

    rtnl: complain if used after fork

diff --git a/src/libsystemd-rtnl/rtnl-internal.h b/src/libsystemd-rtnl/rtnl-internal.h
index f9c08e1..c24d12b 100644
--- a/src/libsystemd-rtnl/rtnl-internal.h
+++ b/src/libsystemd-rtnl/rtnl-internal.h
@@ -32,6 +32,7 @@ struct sd_rtnl {
         } sockaddr;
 
         unsigned serial;
+        pid_t original_pid;
 };
 
 #define RTNL_DEFAULT_TIMEOUT ((usec_t) (10 * USEC_PER_SEC))
diff --git a/src/libsystemd-rtnl/sd-rtnl.c b/src/libsystemd-rtnl/sd-rtnl.c
index b11a813..9c1f40e 100644
--- a/src/libsystemd-rtnl/sd-rtnl.c
+++ b/src/libsystemd-rtnl/sd-rtnl.c
@@ -43,10 +43,21 @@ static int sd_rtnl_new(sd_rtnl **ret) {
 
         rtnl->sockaddr.nl.nl_family = AF_NETLINK;
 
+        rtnl->original_pid = getpid();
+
         *ret = rtnl;
         return 0;
 }
 
+static bool rtnl_pid_changed(sd_rtnl *rtnl) {
+        assert(rtnl);
+
+        /* We don't support people creating an rtnl connection and
+         * keeping it around over a fork(). Let's complain. */
+
+        return rtnl->original_pid != getpid();
+}
+
 int sd_rtnl_open(uint32_t groups, sd_rtnl **ret) {
         _cleanup_sd_rtnl_unref_ sd_rtnl *rtnl = NULL;
         int r;
@@ -98,6 +109,7 @@ int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
         int r, serial;
 
         assert_return(nl, -EINVAL);
+        assert_return(!rtnl_pid_changed(nl), -ECHILD);
         assert_return(message, -EINVAL);
 
         r = message_seal(nl, message);

commit 98dd77e86e0cc339543cc8711ff908e6929f0636
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 16:35:37 2013 +0100

    rtnl: introduce default timeout
    
    We set it to 10 secs (as we are only communicating with the kernel,
    it seems we should be able to bail out sooner than sd-bus, which
    uses 25).
    
    When passing timout 0, the default is used, use this in link-config.

diff --git a/src/libsystemd-rtnl/rtnl-internal.h b/src/libsystemd-rtnl/rtnl-internal.h
index 37b1d3d..f9c08e1 100644
--- a/src/libsystemd-rtnl/rtnl-internal.h
+++ b/src/libsystemd-rtnl/rtnl-internal.h
@@ -33,6 +33,9 @@ struct sd_rtnl {
 
         unsigned serial;
 };
+
+#define RTNL_DEFAULT_TIMEOUT ((usec_t) (10 * USEC_PER_SEC))
+
 int message_get_errno(sd_rtnl_message *m);
 int message_get_serial(sd_rtnl_message *m);
 int message_seal(sd_rtnl *nl, sd_rtnl_message *m);
diff --git a/src/libsystemd-rtnl/sd-rtnl.c b/src/libsystemd-rtnl/sd-rtnl.c
index 9938d46..b11a813 100644
--- a/src/libsystemd-rtnl/sd-rtnl.c
+++ b/src/libsystemd-rtnl/sd-rtnl.c
@@ -109,10 +109,15 @@ int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
         p[0].fd = nl->fd;
         p[0].events = POLLOUT;
 
-        timeout = now(CLOCK_MONOTONIC) + usec;
+        if (usec == (uint64_t) -1)
+                timeout = 0;
+        else if (usec == 0)
+                timeout = now(CLOCK_MONOTONIC) + RTNL_DEFAULT_TIMEOUT;
+        else
+                timeout = now(CLOCK_MONOTONIC) + usec;
 
         for (;;) {
-                if (usec != (uint64_t) -1) {
+                if (timeout) {
                         usec_t n;
 
                         n = now(CLOCK_MONOTONIC);
@@ -122,7 +127,7 @@ int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
                         timespec_store(&left, timeout - n);
                 }
 
-                r = ppoll(p, 1, usec == (uint64_t) -1 ? NULL : &left, NULL);
+                r = ppoll(p, 1, timeout ? &left : NULL, NULL);
                 if (r < 0)
                         return 0;
 
@@ -140,7 +145,7 @@ int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
         for (;;) {
                 _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *reply = NULL;
 
-                if (usec != (uint64_t) -1) {
+                if (timeout) {
                         usec_t n;
 
                         n = now(CLOCK_MONOTONIC);
@@ -150,7 +155,7 @@ int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
                         timespec_store(&left, timeout - n);
                 }
 
-                r = ppoll(p, 1, usec == (uint64_t) -1 ? NULL : &left, NULL);
+                r = ppoll(p, 1, timeout ? &left : NULL, NULL);
                 if (r < 0)
                         return r;
 
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index a86c74d..9d6c96b 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -293,7 +293,7 @@ static int rtnl_set_properties(sd_rtnl *rtnl, int ifindex, const char *name, con
         }
 
         if  (need_update) {
-                r = sd_rtnl_send_with_reply_and_block(rtnl, message, 5 * USEC_PER_SEC, NULL);
+                r = sd_rtnl_send_with_reply_and_block(rtnl, message, 0, NULL);
                 if (r < 0)
                         return r;
         }

commit f1ac700248f231b7bdac2aafe8c35650efddb89f
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 16:20:22 2013 +0100

    udev: link-config - use safe_atou instead of strtoul

diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 985fc7d..a86c74d 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -322,12 +322,15 @@ static bool enable_name_policy(void) {
 
 static bool mac_is_random(struct udev_device *device) {
         const char *s;
-        int type;
+        unsigned type;
+        int r;
 
         s = udev_device_get_sysattr_value(device, "addr_assign_type");
         if (!s)
-                return -EINVAL;
-        type = strtoul(s, NULL, 0);
+                return false; /* if we don't know, assume it is not random */
+        r = safe_atou(s, &type);
+        if (r < 0)
+                return false;
 
         /* check for NET_ADDR_RANDOM */
         return type == 1;
@@ -335,12 +338,15 @@ static bool mac_is_random(struct udev_device *device) {
 
 static bool mac_is_permanent(struct udev_device *device) {
         const char *s;
-        int type;
+        unsigned type;
+        int r;
 
         s = udev_device_get_sysattr_value(device, "addr_assign_type");
         if (!s)
-                return -EINVAL;
-        type = strtoul(s, NULL, 0);
+                return true; /* if we don't know, assume it is permanent */
+        r = safe_atou(s, &type);
+        if (r < 0)
+                return true;
 
         /* check for NET_ADDR_PERM */
         return type == 0;

commit 2a7e74e002d0df6d7021240d3310220bd19aa3fe
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 16:10:54 2013 +0100

    udev: link-config - use zero instead of memset

diff --git a/src/udev/net/ethtool-util.c b/src/udev/net/ethtool-util.c
index 4fad52b..68ddd25 100644
--- a/src/udev/net/ethtool-util.c
+++ b/src/udev/net/ethtool-util.c
@@ -73,9 +73,10 @@ int ethtool_set_speed(int fd, const char *ifname, unsigned int speed, Duplex dup
         if (speed == 0 && duplex == _DUP_INVALID)
                 return 0;
 
-        memset(&ecmd, 0x00, sizeof(struct ethtool_cmd));
+        zero(ecmd);
         ecmd.cmd = ETHTOOL_GSET;
-        memset(&ifr, 0x00, sizeof(struct ifreq));
+
+        zero(ifr);
         strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
         ifr.ifr_data = (void *)&ecmd;
 
@@ -125,9 +126,10 @@ int ethtool_set_wol(int fd, const char *ifname, WakeOnLan wol) {
         if (wol == _WOL_INVALID)
                 return 0;
 
-        memset(&ecmd, 0x00, sizeof(struct ethtool_wolinfo));
+        zero(ecmd);
         ecmd.cmd = ETHTOOL_GWOL;
-        memset(&ifr, 0x00, sizeof(struct ifreq));
+
+        zero(ifr);
         strscpy(ifr.ifr_name, IFNAMSIZ, ifname);
         ifr.ifr_data = (void *)&ecmd;
 

commit 55428d84f31b52da1c50b7469f14e15740547f20
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 16:05:27 2013 +0100

    udev: link-config - use proper return values
    
    Not sure if -ENOENT is the correct return value for when no persistent network
    name is set, but couldn't think of anything better.

diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index cc8ff6f..985fc7d 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -365,13 +365,13 @@ static int get_mac(struct udev_device *device, bool want_random, struct ether_ad
                         if (!name) {
                                 name = udev_device_get_property_value(device, "ID_NET_NAME_PATH");
                                 if (!name)
-                                        return -1;
+                                        return -ENOENT;
                         }
                 }
                 /* fetch some persistent data unique to this machine */
                 r = sd_id128_get_machine(&machine);
                 if (r < 0)
-                        return -1;
+                        return r;
 
                 /* combine the data */
                 seed_str = strappenda(name, sd_id128_to_string(machine, machineid_buf));

commit a12fa4204d7da3256537222294d02c8d340f2650
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 15:59:45 2013 +0100

    udev: link-config - use new0 instead of calloc

diff --git a/src/udev/net/link-config-parse.c b/src/udev/net/link-config-parse.c
index 54dd57b..c339d08 100644
--- a/src/udev/net/link-config-parse.c
+++ b/src/udev/net/link-config-parse.c
@@ -25,6 +25,7 @@
 #include "link-config.h"
 
 #include "utf8.h"
+#include "util.h"
 #include "conf-parser.h"
 
 static const char* const mac_policy_table[] = {
@@ -103,7 +104,7 @@ int config_parse_hwaddr(const char *unit,
         assert(rvalue);
         assert(data);
 
-        n = calloc(1, sizeof(struct ether_addr));
+        n = new0(struct ether_addr, 1);
         if (!n)
                 return log_oom();
 

commit dc7d8997aa731cf68a078d901dafb809c90bd21a
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 15:57:54 2013 +0100

    rtnl: use malloc0 instead of calloc

diff --git a/src/libsystemd-rtnl/rtnl-message.c b/src/libsystemd-rtnl/rtnl-message.c
index 80ffb34..17183ab 100644
--- a/src/libsystemd-rtnl/rtnl-message.c
+++ b/src/libsystemd-rtnl/rtnl-message.c
@@ -51,7 +51,7 @@ static int message_new(sd_rtnl_message **ret, size_t initial_size) {
         if (!m)
                 return -ENOMEM;
 
-        m->hdr = calloc(initial_size, 1);
+        m->hdr = malloc0(initial_size);
         if (!m->hdr) {
                 free(m);
                 return -ENOMEM;

commit fe5c4e493e19f5b7979235783170c231dd7d008c
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 15:56:28 2013 +0100

    rtnl: use _cleanup_ macro more

diff --git a/src/libsystemd-rtnl/sd-rtnl.c b/src/libsystemd-rtnl/sd-rtnl.c
index 9c4a218..9938d46 100644
--- a/src/libsystemd-rtnl/sd-rtnl.c
+++ b/src/libsystemd-rtnl/sd-rtnl.c
@@ -48,7 +48,7 @@ static int sd_rtnl_new(sd_rtnl **ret) {
 }
 
 int sd_rtnl_open(uint32_t groups, sd_rtnl **ret) {
-        sd_rtnl *rtnl;
+        _cleanup_sd_rtnl_unref_ sd_rtnl *rtnl = NULL;
         int r;
 
         r = sd_rtnl_new(&rtnl);
@@ -56,22 +56,17 @@ int sd_rtnl_open(uint32_t groups, sd_rtnl **ret) {
                 return r;
 
         rtnl->fd = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_ROUTE);
-        if (rtnl->fd < 0) {
-                r = -errno;
-                sd_rtnl_unref(rtnl);
-                return r;
-        }
+        if (rtnl->fd < 0)
+                return -errno;
 
         rtnl->sockaddr.nl.nl_groups = groups;
 
         r = bind(rtnl->fd, &rtnl->sockaddr.sa, sizeof(rtnl->sockaddr));
-        if (r < 0) {
-                r = -errno;
-                sd_rtnl_unref(rtnl);
-                return r;
-        }
+        if (r < 0)
+                return -errno;
 
         *ret = rtnl;
+        rtnl = NULL;
 
         return 0;
 }
@@ -98,7 +93,6 @@ int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
                 uint64_t usec,
                 sd_rtnl_message **ret) {
         struct pollfd p[1] = {};
-        sd_rtnl_message *reply;
         struct timespec left;
         usec_t timeout;
         int r, serial;
@@ -144,6 +138,8 @@ int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
         p[0].events = POLLIN;
 
         for (;;) {
+                _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *reply = NULL;
+
                 if (usec != (uint64_t) -1) {
                         usec_t n;
 
@@ -167,20 +163,16 @@ int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
 
                         if (received_serial == serial) {
                                 r = message_get_errno(reply);
-                                if (r < 0) {
-                                        sd_rtnl_message_unref(reply);
+                                if (r < 0)
                                         return r;
-                                }
 
-                                if (ret)
+                                if (ret) {
                                         *ret = reply;
-                                else
-                                        reply = sd_rtnl_message_unref(reply);
+                                        reply = NULL;
+                                }
 
                                 break;;
                         }
-
-                        reply = sd_rtnl_message_unref(reply);
                 }
         }
 

commit 5b9d4dc05560ddda89e48b6b39365824b15e1300
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 15:36:26 2013 +0100

    udev: link-config - use _cleanup_ macro locally

diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 598f93e..cc8ff6f 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -49,8 +49,11 @@ struct link_config_ctx {
         usec_t link_dirs_ts_usec;
 };
 
+DEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free);
+#define _cleanup_link_config_ctx_free_ _cleanup_(link_config_ctx_freep)
+
 int link_config_ctx_new(link_config_ctx **ret) {
-        link_config_ctx *ctx;
+        _cleanup_link_config_ctx_free_ link_config_ctx *ctx = NULL;
         int r;
 
         if (!ret)
@@ -61,16 +64,12 @@ int link_config_ctx_new(link_config_ctx **ret) {
                 return -ENOMEM;
 
         r = ethtool_connect(&ctx->ethtool_fd);
-        if (r < 0) {
-                link_config_ctx_free(ctx);
+        if (r < 0)
                 return r;
-        }
 
         r = sd_rtnl_open(0, &ctx->rtnl);
-        if (r < 0) {
-                link_config_ctx_free(ctx);
+        if (r < 0)
                 return r;
-        }
 
         LIST_HEAD_INIT(ctx->links);
 
@@ -80,16 +79,17 @@ int link_config_ctx_new(link_config_ctx **ret) {
                                   NULL);
         if (!ctx->link_dirs) {
                 log_error("failed to build link config directory array");
-                link_config_ctx_free(ctx);
                 return -ENOMEM;
         }
+
         if (!path_strv_canonicalize_uniq(ctx->link_dirs)) {
                 log_error("failed to canonicalize link config directories\n");
-                link_config_ctx_free(ctx);
                 return -ENOMEM;
         }
 
         *ret = ctx;
+        ctx = NULL;
+
         return 0;
 }
 

commit 97f2d76d4f4dfab8b0629c09926a05a1e5621125
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 15:15:53 2013 +0100

    path_check_timestamp: only keep the most recent timestamp
    
    There is no point in keeping one timestamp for each directory, as we only
    ever care about the most recent one.

diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index def7a74..fcacf54 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -474,11 +474,13 @@ int find_binary(const char *name, char **filename) {
         }
 }
 
-bool paths_check_timestamp(char **paths, usec_t *paths_ts_usec, bool update)
+bool paths_check_timestamp(char **paths, usec_t *timestamp, bool update)
 {
         unsigned int i;
         bool changed = false;
 
+        assert(timestamp);
+
         if (paths == NULL)
                 goto out;
 
@@ -488,18 +490,16 @@ bool paths_check_timestamp(char **paths, usec_t *paths_ts_usec, bool update)
                 if (stat(paths[i], &stats) < 0)
                         continue;
 
-                if (paths_ts_usec[i] == timespec_load(&stats.st_mtim))
+                /* first check */
+                if (*timestamp >= timespec_load(&stats.st_mtim))
                         continue;
 
-                /* first check */
-                if (paths_ts_usec[i] != 0) {
-                        log_debug("reload - timestamp of '%s' changed\n", paths[i]);
-                        changed = true;
-                }
+                log_debug("timestamp of '%s' changed\n", paths[i]);
+                changed = true;
 
                 /* update timestamp */
                 if (update)
-                        paths_ts_usec[i] = timespec_load(&stats.st_mtim);
+                        *timestamp = timespec_load(&stats.st_mtim);
         }
 out:
         return changed;
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 0b5916b..598f93e 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -46,7 +46,7 @@ struct link_config_ctx {
         sd_rtnl *rtnl;
 
         char **link_dirs;
-        usec_t *link_dirs_ts_usec;
+        usec_t link_dirs_ts_usec;
 };
 
 int link_config_ctx_new(link_config_ctx **ret) {
@@ -89,12 +89,6 @@ int link_config_ctx_new(link_config_ctx **ret) {
                 return -ENOMEM;
         }
 
-        ctx->link_dirs_ts_usec = calloc(strv_length(ctx->link_dirs), sizeof(usec_t));
-        if(!ctx->link_dirs_ts_usec) {
-                link_config_ctx_free(ctx);
-                return -ENOMEM;
-        }
-
         *ret = ctx;
         return 0;
 }
@@ -126,7 +120,6 @@ void link_config_ctx_free(link_config_ctx *ctx) {
         sd_rtnl_unref(ctx->rtnl);
 
         strv_free(ctx->link_dirs);
-        free(ctx->link_dirs_ts_usec);
         link_configs_free(ctx);
 
         free(ctx);
@@ -183,8 +176,8 @@ int link_config_load(link_config_ctx *ctx) {
 
         link_configs_free(ctx);
 
-        /* update timestamps */
-        paths_check_timestamp(ctx->link_dirs, ctx->link_dirs_ts_usec, true);
+        /* update timestamp */
+        paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, true);
 
         r = conf_files_list_strv(&files, ".link", NULL, (const char **)ctx->link_dirs);
         if (r < 0) {
@@ -202,7 +195,7 @@ int link_config_load(link_config_ctx *ctx) {
 }
 
 bool link_config_should_reload(link_config_ctx *ctx) {
-        return paths_check_timestamp(ctx->link_dirs, ctx->link_dirs_ts_usec, false);
+        return paths_check_timestamp(ctx->link_dirs, &ctx->link_dirs_ts_usec, false);
 }
 
 static bool match_config(link_config *match, struct udev_device *device) {
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 58da79b..4437d80 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -49,7 +49,7 @@ struct uid_gid {
 struct udev_rules {
         struct udev *udev;
         char **dirs;
-        usec_t *dirs_ts_usec;
+        usec_t dirs_ts_usec;
         int resolve_names;
 
         /* every key in the rules file becomes a token */
@@ -1653,9 +1653,6 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
         }
         strv_uniq(rules->dirs);
 
-        rules->dirs_ts_usec = calloc(strv_length(rules->dirs), sizeof(usec_t));
-        if(!rules->dirs_ts_usec)
-                return udev_rules_unref(rules);
         udev_rules_check_timestamp(rules);
 
         r = conf_files_list_strv(&files, ".rules", NULL, (const char **)rules->dirs);
@@ -1711,14 +1708,13 @@ struct udev_rules *udev_rules_unref(struct udev_rules *rules)
         free(rules->uids);
         free(rules->gids);
         strv_free(rules->dirs);
-        free(rules->dirs_ts_usec);
         free(rules);
         return NULL;
 }
 
 bool udev_rules_check_timestamp(struct udev_rules *rules)
 {
-        return paths_check_timestamp(rules->dirs, rules->dirs_ts_usec, true);
+        return paths_check_timestamp(rules->dirs, &rules->dirs_ts_usec, true);
 }
 
 static int match_key(struct udev_rules *rules, struct token *token, const char *val)

commit dabfa9d1efd0d1a7e0507d69f9789bc6404ff786
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Oct 29 15:03:27 2013 +0100

    sd-rtnl: minor fixes

diff --git a/src/libsystemd-rtnl/rtnl-message.c b/src/libsystemd-rtnl/rtnl-message.c
index 82ec1c9..80ffb34 100644
--- a/src/libsystemd-rtnl/rtnl-message.c
+++ b/src/libsystemd-rtnl/rtnl-message.c
@@ -45,7 +45,7 @@ static int message_new(sd_rtnl_message **ret, size_t initial_size) {
         sd_rtnl_message *m;
 
         assert_return(ret, -EINVAL);
-        assert_return(initial_size > 0, -EINVAL);
+        assert_return(initial_size >= sizeof(struct nlmsghdr), -EINVAL);
 
         m = new0(sd_rtnl_message, 1);
         if (!m)
@@ -67,7 +67,7 @@ static int message_new(sd_rtnl_message **ret, size_t initial_size) {
         return 0;
 }
 
-int sd_rtnl_message_link_new(__u16 nlmsg_type, int index, unsigned int type, unsigned int flags, sd_rtnl_message **ret) {
+int sd_rtnl_message_link_new(uint16_t nlmsg_type, int index, unsigned int type, unsigned int flags, sd_rtnl_message **ret) {
         struct ifinfomsg *ifi;
         int r;
 
@@ -82,7 +82,7 @@ int sd_rtnl_message_link_new(__u16 nlmsg_type, int index, unsigned int type, uns
         (*ret)->hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
         (*ret)->hdr->nlmsg_type = nlmsg_type;
 
-        ifi = (struct ifinfomsg *) NLMSG_DATA((*ret)->hdr);
+        ifi = NLMSG_DATA((*ret)->hdr);
 
         ifi->ifi_family = AF_UNSPEC;
         ifi->ifi_index = index;
@@ -93,7 +93,7 @@ int sd_rtnl_message_link_new(__u16 nlmsg_type, int index, unsigned int type, uns
         return 0;
 }
 
-int sd_rtnl_message_addr_new(__u16 nlmsg_type, int index, unsigned char family, unsigned char prefixlen, unsigned char flags, unsigned char scope, sd_rtnl_message **ret) {
+int sd_rtnl_message_addr_new(uint16_t nlmsg_type, int index, unsigned char family, unsigned char prefixlen, unsigned char flags, unsigned char scope, sd_rtnl_message **ret) {
         struct ifaddrmsg *ifa;
         int r;
 
@@ -108,7 +108,7 @@ int sd_rtnl_message_addr_new(__u16 nlmsg_type, int index, unsigned char family,
         (*ret)->hdr->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
         (*ret)->hdr->nlmsg_type = nlmsg_type;
 
-        ifa = (struct ifaddrmsg *) NLMSG_DATA((*ret)->hdr);
+        ifa = NLMSG_DATA((*ret)->hdr);
 
         ifa->ifa_family = family;
         ifa->ifa_prefixlen = prefixlen;
@@ -135,7 +135,7 @@ sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m) {
         return NULL;
 }
 
-int sd_rtnl_message_get_type(sd_rtnl_message *m, __u16 *type) {
+int sd_rtnl_message_get_type(sd_rtnl_message *m, uint16_t *type) {
         assert_return(m, -EINVAL);
         assert_return(type, -EINVAL);
 
@@ -147,7 +147,7 @@ int sd_rtnl_message_get_type(sd_rtnl_message *m, __u16 *type) {
 /* If successful the updated message will be correctly aligned, if unsuccessful the old message is
    untouched */
 static int add_rtattr(sd_rtnl_message *m, unsigned short type, const void *data, size_t data_length) {
-        __u32 rta_length, message_length;
+        uint32_t rta_length, message_length;
         struct nlmsghdr *new_hdr;
         struct rtattr *rta;
 
@@ -187,7 +187,7 @@ static int add_rtattr(sd_rtnl_message *m, unsigned short type, const void *data,
 }
 
 int sd_rtnl_message_append(sd_rtnl_message *m, unsigned short type, const void *data) {
-        __u16 rtm_type;
+        uint16_t rtm_type;
         struct ifaddrmsg *ifa;
 
         assert_return(m, -EINVAL);
@@ -258,7 +258,7 @@ static int message_read(sd_rtnl_message *m, unsigned short *type, void **data) {
 }
 
 int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data) {
-        __u16 rtm_type;
+        uint16_t rtm_type;
 
         assert_return(m, -EINVAL);
         assert_return(data, -EINVAL);
@@ -270,7 +270,7 @@ int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data)
                 case RTM_DELLINK:
                 case RTM_GETLINK:
                         if (!m->next_rta) {
-                                struct ifinfomsg *ifi = (struct ifinfomsg *) NLMSG_DATA(m->hdr);
+                                struct ifinfomsg *ifi = NLMSG_DATA(m->hdr);
 
                                 m->next_rta = IFLA_RTA(ifi);
                                 m->remaining_size = IFLA_PAYLOAD(m->hdr);
@@ -280,7 +280,7 @@ int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data)
                 case RTM_DELADDR:
                 case RTM_GETADDR:
                         if (!m->next_rta) {
-                                struct ifaddrmsg *ifa = (struct ifaddrmsg *) NLMSG_DATA(m->hdr);
+                                struct ifaddrmsg *ifa = NLMSG_DATA(m->hdr);
 
                                 m->next_rta = IFA_RTA(ifa);
                                 m->remaining_size = IFLA_PAYLOAD(m->hdr);
@@ -327,15 +327,15 @@ static int message_receive_need(sd_rtnl *rtnl, size_t *need) {
         assert_return(need, -EINVAL);
 
         /* ioctl(rtnl->fd, FIONREAD, &need)
-        Does not appear to work on netlink sockets. libnl uses
-        MSG_PEEK instead. I don't know if that is worth the
-        extra roundtrip.
-
-        For now we simply use the maximum message size the kernel
-        may use (NLMSG_GOODSIZE), and then realloc to the actual
-        size after reading the message (hence avoiding huge memory
-        usage in case many small messages are kept around) */
-        *need = getpagesize();
+           Does not appear to work on netlink sockets. libnl uses
+           MSG_PEEK instead. I don't know if that is worth the
+           extra roundtrip.
+
+           For now we simply use the maximum message size the kernel
+           may use (NLMSG_GOODSIZE), and then realloc to the actual
+           size after reading the message (hence avoiding huge memory
+           usage in case many small messages are kept around) */
+        *need = page_size();
         if (*need > 8192UL)
                 *need = 8192UL;
 
@@ -361,7 +361,7 @@ int socket_write_message(sd_rtnl *nl, sd_rtnl_message *m) {
  * which has a valid header and the correct size.
  * If nothing useful was received 0 is returned.
  * On failure, a negative error code is returned.
-*/
+ */
 int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret) {
         sd_rtnl_message *m;
         socklen_t addr_len = sizeof(nl->sockaddr);
@@ -400,12 +400,12 @@ int socket_read_message(sd_rtnl *nl, sd_rtnl_message **ret) {
         else if (nl->sockaddr.nl.nl_pid != 0)
                 k = 0; /* not from the kernel */
         else if ((size_t) k < sizeof(struct nlmsghdr) ||
-                 (size_t) k < m->hdr->nlmsg_len)
+                        (size_t) k < m->hdr->nlmsg_len)
                 k = -EIO; /* too small (we do accept too big though) */
         else if (m->hdr->nlmsg_type == NLMSG_NOOP)
                 k = 0;
         else if (m->hdr->nlmsg_type == NLMSG_ERROR &&
-                 m->hdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
+                        m->hdr->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
                 k = -EIO;
         else if ((pid_t) m->hdr->nlmsg_pid != getpid())
                 k = 0; /* not for us */
diff --git a/src/libsystemd-rtnl/sd-rtnl.c b/src/libsystemd-rtnl/sd-rtnl.c
index abf45d0..9c4a218 100644
--- a/src/libsystemd-rtnl/sd-rtnl.c
+++ b/src/libsystemd-rtnl/sd-rtnl.c
@@ -47,7 +47,7 @@ static int sd_rtnl_new(sd_rtnl **ret) {
         return 0;
 }
 
-int sd_rtnl_open(__u32 groups, sd_rtnl **ret) {
+int sd_rtnl_open(uint32_t groups, sd_rtnl **ret) {
         sd_rtnl *rtnl;
         int r;
 
@@ -94,9 +94,9 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *rtnl) {
 }
 
 int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl,
-                                        sd_rtnl_message *message,
-                                        uint64_t usec,
-                                        sd_rtnl_message **ret) {
+                sd_rtnl_message *message,
+                uint64_t usec,
+                sd_rtnl_message **ret) {
         struct pollfd p[1] = {};
         sd_rtnl_message *reply;
         struct timespec left;
diff --git a/src/libsystemd-rtnl/test-rtnl.c b/src/libsystemd-rtnl/test-rtnl.c
index 4079e9e..1cdd6e1 100644
--- a/src/libsystemd-rtnl/test-rtnl.c
+++ b/src/libsystemd-rtnl/test-rtnl.c
@@ -28,7 +28,7 @@
 
 static void test_link_configure(sd_rtnl *rtnl, int ifindex) {
         _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *message;
-        __u16 type;
+        uint16_t type;
         const char *mac = "98:fe:94:3f:c6:18", *name = "test";
         unsigned int mtu = 1450;
         void *data;
@@ -60,7 +60,7 @@ int main(void) {
         sd_rtnl_message *r;
         void *data;
         int if_loopback;
-        __u16 type;
+        uint16_t type;
         unsigned int mtu = 0;
         unsigned int *mtu_reply;
 
diff --git a/src/systemd/sd-rtnl.h b/src/systemd/sd-rtnl.h
index 5f5f3e3..a2400d8 100644
--- a/src/systemd/sd-rtnl.h
+++ b/src/systemd/sd-rtnl.h
@@ -28,7 +28,7 @@ typedef struct sd_rtnl sd_rtnl;
 typedef struct sd_rtnl_message sd_rtnl_message;
 
 /* bus */
-int sd_rtnl_open(__u32 groups, sd_rtnl **nl);
+int sd_rtnl_open(uint32_t groups, sd_rtnl **nl);
 
 sd_rtnl *sd_rtnl_ref(sd_rtnl *nl);
 sd_rtnl *sd_rtnl_unref(sd_rtnl *nl);
@@ -36,12 +36,12 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *nl);
 int sd_rtnl_send_with_reply_and_block(sd_rtnl *nl, sd_rtnl_message *message, uint64_t timeout, sd_rtnl_message **reply);
 
 /* messages */
-int sd_rtnl_message_link_new(__u16 msg_type, int index, unsigned int type, unsigned int flags, sd_rtnl_message **ret);
-int sd_rtnl_message_addr_new(__u16 msg_type, int index, unsigned char family, unsigned char prefixlen, unsigned char flags, unsigned char scope, sd_rtnl_message **ret);
+int sd_rtnl_message_link_new(uint16_t msg_type, int index, unsigned int type, unsigned int flags, sd_rtnl_message **ret);
+int sd_rtnl_message_addr_new(uint16_t msg_type, int index, unsigned char family, unsigned char prefixlen, unsigned char flags, unsigned char scope, sd_rtnl_message **ret);
 sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m);
 sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m);
 
-int sd_rtnl_message_get_type(sd_rtnl_message *m, __u16 *type);
+int sd_rtnl_message_get_type(sd_rtnl_message *m, uint16_t *type);
 int sd_rtnl_message_append(sd_rtnl_message *m, unsigned short type, const void *data);
 int sd_rtnl_message_read(sd_rtnl_message *m, unsigned short *type, void **data);
 



More information about the systemd-commits mailing list