[systemd-commits] 3 commits - src/libsystemd src/libsystemd-dhcp src/network

Tom Gundersen tomegun at kemper.freedesktop.org
Sat Feb 22 12:24:29 PST 2014


 src/libsystemd-dhcp/dhcp-internal.h    |    2 
 src/libsystemd-dhcp/sd-dhcp-client.c   |   28 ++-
 src/libsystemd-dhcp/test-dhcp-client.c |  140 ++++++++--------
 src/libsystemd-dhcp/test-dhcp-option.c |   64 +++----
 src/libsystemd/sd-rtnl/test-rtnl.c     |  286 ++++++++++++++++-----------------
 src/network/networkd-link.c            |    2 
 src/network/networkd-manager.c         |   38 ++++
 src/network/networkd.h                 |    2 
 src/network/test-network.c             |   35 +---
 9 files changed, 330 insertions(+), 267 deletions(-)

New commits:
commit 0c2f9b84698b25e6065b9febd21486669a13870f
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Feb 22 20:19:49 2014 +0100

    networkd: handle SIGINT and SIGTERM

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index e2d61ae..1f495b3 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -35,6 +35,8 @@ int link_new(Manager *manager, struct udev_device *device, Link **ret) {
         const char *ifname;
         int r;
 
+        assert(manager);
+        assert(manager->links);
         assert(device);
         assert(ret);
 
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 55e5caf..c89adfb 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -38,6 +38,38 @@ const char* const network_dirs[] = {
 #endif
         NULL};
 
+static int dispatch_sigterm(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
+        Manager *m = userdata;
+
+        assert(m);
+
+        log_received_signal(LOG_INFO, si);
+
+        sd_event_exit(m->event, 0);
+        return 0;
+}
+
+static int setup_signals(Manager *m) {
+        sigset_t mask;
+        int r;
+
+        assert(m);
+
+        assert_se(sigemptyset(&mask) == 0);
+        sigset_add_many(&mask, SIGINT, SIGTERM, -1);
+        assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
+
+        r = sd_event_add_signal(m->event, &m->sigterm_event_source, SIGTERM, dispatch_sigterm, m);
+        if (r < 0)
+                return r;
+
+        r = sd_event_add_signal(m->event, &m->sigint_event_source, SIGINT, dispatch_sigterm, m);
+        if (r < 0)
+                return r;
+
+        return 0;
+}
+
 int manager_new(Manager **ret) {
         _cleanup_manager_free_ Manager *m = NULL;
         int r;
@@ -60,6 +92,10 @@ int manager_new(Manager **ret) {
         if (r < 0 && r != -ENOENT) /* TODO: drop when we can rely on kdbus */
                 return r;
 
+        r = setup_signals(m);
+        if (r < 0)
+                return r;
+
         m->udev = udev_new();
         if (!m->udev)
                 return -ENOMEM;
@@ -105,6 +141,8 @@ void manager_free(Manager *m) {
         udev_unref(m->udev);
         sd_bus_unref(m->bus);
         sd_event_source_unref(m->udev_event_source);
+        sd_event_source_unref(m->sigterm_event_source);
+        sd_event_source_unref(m->sigint_event_source);
         sd_event_unref(m->event);
 
         while ((network = m->networks))
diff --git a/src/network/networkd.h b/src/network/networkd.h
index fb09764..8307bb5 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -201,6 +201,8 @@ struct Manager {
         struct udev *udev;
         struct udev_monitor *udev_monitor;
         sd_event_source *udev_event_source;
+        sd_event_source *sigterm_event_source;
+        sd_event_source *sigint_event_source;
 
         Hashmap *links;
         Hashmap *netdevs;
diff --git a/src/network/test-network.c b/src/network/test-network.c
index 46afeec..9c372c7 100644
--- a/src/network/test-network.c
+++ b/src/network/test-network.c
@@ -21,12 +21,9 @@
 
 #include "networkd.h"
 
-static void test_link(struct udev_device *loopback) {
-        _cleanup_manager_free_ Manager *manager = NULL;
+static void test_link(Manager *manager, struct udev_device *loopback) {
         Link *link = NULL;
 
-        manager_new(&manager);
-
         assert_se(link_new(manager, loopback, &link) >= 0);
         assert_se(link);
 }
@@ -69,7 +66,7 @@ int main(void) {
 
         test_network_get(manager, loopback);
 
-        test_link(loopback);
+        test_link(manager, loopback);
 
         assert_se(manager_udev_listen(manager) >= 0);
         assert_se(manager_udev_enumerate_links(manager) >= 0);

commit 12e0f830f592ec4c6bb49ac7ae1e0e84f74105e3
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Feb 22 20:22:41 2014 +0100

    test: always use assert_se in tests

diff --git a/src/libsystemd-dhcp/test-dhcp-client.c b/src/libsystemd-dhcp/test-dhcp-client.c
index 005d6c2..8061e5f 100644
--- a/src/libsystemd-dhcp/test-dhcp-client.c
+++ b/src/libsystemd-dhcp/test-dhcp-client.c
@@ -56,50 +56,50 @@ static void test_request_basic(sd_event *e)
 
         r = sd_dhcp_client_new(&client);
 
-        assert(r >= 0);
-        assert(client);
+        assert_se(r >= 0);
+        assert_se(client);
 
         r = sd_dhcp_client_attach_event(client, e, 0);
-        assert(r >= 0);
+        assert_se(r >= 0);
 
-        assert(sd_dhcp_client_set_request_option(NULL, 0) == -EINVAL);
-        assert(sd_dhcp_client_set_request_address(NULL, NULL) == -EINVAL);
-        assert(sd_dhcp_client_set_index(NULL, 0) == -EINVAL);
+        assert_se(sd_dhcp_client_set_request_option(NULL, 0) == -EINVAL);
+        assert_se(sd_dhcp_client_set_request_address(NULL, NULL) == -EINVAL);
+        assert_se(sd_dhcp_client_set_index(NULL, 0) == -EINVAL);
 
-        assert(sd_dhcp_client_set_index(client, 15) == 0);
-        assert(sd_dhcp_client_set_index(client, -42) == -EINVAL);
-        assert(sd_dhcp_client_set_index(client, -1) == 0);
+        assert_se(sd_dhcp_client_set_index(client, 15) == 0);
+        assert_se(sd_dhcp_client_set_index(client, -42) == -EINVAL);
+        assert_se(sd_dhcp_client_set_index(client, -1) == 0);
 
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_SUBNET_MASK) == -EEXIST);
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_ROUTER) == -EEXIST);
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_HOST_NAME) == -EEXIST);
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_DOMAIN_NAME) == -EEXIST);
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_DOMAIN_NAME_SERVER)
                         == -EEXIST);
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_NTP_SERVER) == -EEXIST);
 
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_PAD) == -EINVAL);
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_END) == -EINVAL);
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_MESSAGE_TYPE) == -EINVAL);
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_OVERLOAD) == -EINVAL);
-        assert(sd_dhcp_client_set_request_option(client,
+        assert_se(sd_dhcp_client_set_request_option(client,
                                         DHCP_OPTION_PARAMETER_REQUEST_LIST)
                         == -EINVAL);
 
-        assert(sd_dhcp_client_set_request_option(client, 33) == 0);
-        assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
-        assert(sd_dhcp_client_set_request_option(client, 44) == 0);
-        assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
+        assert_se(sd_dhcp_client_set_request_option(client, 33) == 0);
+        assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
+        assert_se(sd_dhcp_client_set_request_option(client, 44) == 0);
+        assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
 }
 
 static uint16_t client_checksum(void *buf, int len)
@@ -137,7 +137,7 @@ static void test_checksum(void)
         if (verbose)
                 printf("* %s\n", __FUNCTION__);
 
-        assert(client_checksum(&buf, 20) == be16toh(0x78ae));
+        assert_se(client_checksum(&buf, 20) == be16toh(0x78ae));
 }
 
 static int check_options(uint8_t code, uint8_t len, const uint8_t *option,
@@ -153,20 +153,20 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
         _cleanup_free_ DHCPPacket *discover;
         uint16_t ip_check, udp_check;
 
-        assert(s >= 0);
-        assert(packet);
+        assert_se(s >= 0);
+        assert_se(packet);
 
         size = sizeof(DHCPPacket) + 4;
-        assert(len > size);
+        assert_se(len > size);
 
         discover = memdup(packet, len);
 
-        assert(discover->ip.ttl == IPDEFTTL);
-        assert(discover->ip.protocol == IPPROTO_UDP);
-        assert(discover->ip.saddr == INADDR_ANY);
-        assert(discover->ip.daddr == INADDR_BROADCAST);
-        assert(discover->udp.source == be16toh(DHCP_PORT_CLIENT));
-        assert(discover->udp.dest == be16toh(DHCP_PORT_SERVER));
+        assert_se(discover->ip.ttl == IPDEFTTL);
+        assert_se(discover->ip.protocol == IPPROTO_UDP);
+        assert_se(discover->ip.saddr == INADDR_ANY);
+        assert_se(discover->ip.daddr == INADDR_BROADCAST);
+        assert_se(discover->udp.source == be16toh(DHCP_PORT_CLIENT));
+        assert_se(discover->udp.dest == be16toh(DHCP_PORT_SERVER));
 
         ip_check = discover->ip.check;
 
@@ -174,21 +174,21 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link,
         discover->ip.check = discover->udp.len;
 
         udp_check = ~client_checksum(&discover->ip.ttl, len - 8);
-        assert(udp_check == 0xffff);
+        assert_se(udp_check == 0xffff);
 
         discover->ip.ttl = IPDEFTTL;
         discover->ip.check = ip_check;
 
         ip_check = ~client_checksum(&discover->ip, sizeof(discover->ip));
-        assert(ip_check == 0xffff);
+        assert_se(ip_check == 0xffff);
 
-        assert(discover->dhcp.xid);
-        assert(memcmp(discover->dhcp.chaddr,
+        assert_se(discover->dhcp.xid);
+        assert_se(memcmp(discover->dhcp.chaddr,
                       &mac_addr.ether_addr_octet, 6) == 0);
 
         size = len - sizeof(struct iphdr) - sizeof(struct udphdr);
 
-        assert(callback_recv);
+        assert_se(callback_recv);
         callback_recv(size, &discover->dhcp);
 
         return 575;
@@ -218,7 +218,7 @@ static int test_discover_message_verify(size_t size, struct DHCPMessage *dhcp)
         int res;
 
         res = dhcp_option_parse(dhcp, size, check_options, NULL);
-        assert(res == DHCP_DISCOVER);
+        assert_se(res == DHCP_DISCOVER);
 
         if (verbose)
                 printf("  recv DHCP Discover 0x%08x\n", be32toh(dhcp->xid));
@@ -235,22 +235,22 @@ static void test_discover_message(sd_event *e)
                 printf("* %s\n", __FUNCTION__);
 
         r = sd_dhcp_client_new(&client);
-        assert(r >= 0);
-        assert(client);
+        assert_se(r >= 0);
+        assert_se(client);
 
         r = sd_dhcp_client_attach_event(client, e, 0);
-        assert(r >= 0);
+        assert_se(r >= 0);
 
-        assert(sd_dhcp_client_set_index(client, 42) >= 0);
-        assert(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
+        assert_se(sd_dhcp_client_set_index(client, 42) >= 0);
+        assert_se(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
 
-        assert(sd_dhcp_client_set_request_option(client, 248) >= 0);
+        assert_se(sd_dhcp_client_set_request_option(client, 248) >= 0);
 
         callback_recv = test_discover_message_verify;
 
         res = sd_dhcp_client_start(client);
 
-        assert(res == 0 || res == -EINPROGRESS);
+        assert_se(res == 0 || res == -EINPROGRESS);
 
         sd_event_run(e, (uint64_t) -1);
 
@@ -358,22 +358,22 @@ static void test_addr_acq_acquired(sd_dhcp_client *client, int event,
         sd_dhcp_lease *lease;
         struct in_addr addr;
 
-        assert(client);
-        assert(event == DHCP_EVENT_IP_ACQUIRE);
+        assert_se(client);
+        assert_se(event == DHCP_EVENT_IP_ACQUIRE);
 
-        assert(sd_dhcp_client_get_lease(client, &lease) >= 0);
-        assert(lease);
+        assert_se(sd_dhcp_client_get_lease(client, &lease) >= 0);
+        assert_se(lease);
 
-        assert(sd_dhcp_lease_get_address(lease, &addr) >= 0);
-        assert(memcmp(&addr.s_addr, &test_addr_acq_ack[44],
+        assert_se(sd_dhcp_lease_get_address(lease, &addr) >= 0);
+        assert_se(memcmp(&addr.s_addr, &test_addr_acq_ack[44],
                       sizeof(addr.s_addr)) == 0);
 
-        assert(sd_dhcp_lease_get_netmask(lease, &addr) >= 0);
-        assert(memcmp(&addr.s_addr, &test_addr_acq_ack[285],
+        assert_se(sd_dhcp_lease_get_netmask(lease, &addr) >= 0);
+        assert_se(memcmp(&addr.s_addr, &test_addr_acq_ack[285],
                       sizeof(addr.s_addr)) == 0);
 
-        assert(sd_dhcp_lease_get_router(lease, &addr) >= 0);
-        assert(memcmp(&addr.s_addr, &test_addr_acq_ack[308],
+        assert_se(sd_dhcp_lease_get_router(lease, &addr) >= 0);
+        assert_se(memcmp(&addr.s_addr, &test_addr_acq_ack[308],
                       sizeof(addr.s_addr)) == 0);
 
         if (verbose)
@@ -388,8 +388,8 @@ static int test_addr_acq_recv_request(size_t size, DHCPMessage *request)
         int res;
 
         res = dhcp_option_parse(request, size, check_options, NULL);
-        assert(res == DHCP_REQUEST);
-        assert(xid == request->xid);
+        assert_se(res == DHCP_REQUEST);
+        assert_se(xid == request->xid);
 
         if (verbose)
                 printf("  recv DHCP Request  0x%08x\n", be32toh(xid));
@@ -403,7 +403,7 @@ static int test_addr_acq_recv_request(size_t size, DHCPMessage *request)
 
         res = write(test_fd[1], test_addr_acq_ack,
                     sizeof(test_addr_acq_ack));
-        assert(res == sizeof(test_addr_acq_ack));
+        assert_se(res == sizeof(test_addr_acq_ack));
 
         if (verbose)
                 printf("  send DHCP Ack\n");
@@ -417,7 +417,7 @@ static int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover)
         int res;
 
         res = dhcp_option_parse(discover, size, check_options, NULL);
-        assert(res == DHCP_DISCOVER);
+        assert_se(res == DHCP_DISCOVER);
 
         xid = discover->xid;
 
@@ -433,7 +433,7 @@ static int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover)
 
         res = write(test_fd[1], test_addr_acq_offer,
                     sizeof(test_addr_acq_offer));
-        assert(res == sizeof(test_addr_acq_offer));
+        assert_se(res == sizeof(test_addr_acq_offer));
 
         if (verbose)
                 printf("  send DHCP Offer\n");
@@ -450,22 +450,22 @@ static void test_addr_acq(sd_event *e)
                 printf("* %s\n", __FUNCTION__);
 
         r = sd_dhcp_client_new(&client);
-        assert(r >= 0);
-        assert(client);
+        assert_se(r >= 0);
+        assert_se(client);
 
         r = sd_dhcp_client_attach_event(client, e, 0);
-        assert(r >= 0);
+        assert_se(r >= 0);
 
-        assert(sd_dhcp_client_set_index(client, 42) >= 0);
-        assert(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
+        assert_se(sd_dhcp_client_set_index(client, 42) >= 0);
+        assert_se(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
 
-        assert(sd_dhcp_client_set_callback(client, test_addr_acq_acquired, e)
+        assert_se(sd_dhcp_client_set_callback(client, test_addr_acq_acquired, e)
                 >= 0);
 
         callback_recv = test_addr_acq_recv_discover;
 
         res = sd_dhcp_client_start(client);
-        assert(res == 0 || res == -EINPROGRESS);
+        assert_se(res == 0 || res == -EINPROGRESS);
 
         sd_event_loop(e);
 
@@ -484,7 +484,7 @@ int main(int argc, char *argv[])
 {
         sd_event *e;
 
-        assert(sd_event_new(&e) >= 0);
+        assert_se(sd_event_new(&e) >= 0);
 
         test_request_basic(e);
         test_checksum();
diff --git a/src/libsystemd-dhcp/test-dhcp-option.c b/src/libsystemd-dhcp/test-dhcp-option.c
index ac0b0a4..8659fd5 100644
--- a/src/libsystemd-dhcp/test-dhcp-option.c
+++ b/src/libsystemd-dhcp/test-dhcp-option.c
@@ -77,8 +77,8 @@ static void test_invalid_buffer_length(void)
 {
         DHCPMessage message;
 
-        assert(dhcp_option_parse(&message, 0, NULL, NULL) == -EINVAL);
-        assert(dhcp_option_parse(&message, sizeof(DHCPMessage), NULL, NULL)
+        assert_se(dhcp_option_parse(&message, 0, NULL, NULL) == -EINVAL);
+        assert_se(dhcp_option_parse(&message, sizeof(DHCPMessage), NULL, NULL)
                == -EINVAL);
 }
 
@@ -93,14 +93,14 @@ static void test_cookie(void)
         opt = (uint8_t *)(message + 1);
         opt[0] = 0xff;
 
-        assert(dhcp_option_parse(message, len, NULL, NULL) == -EINVAL);
+        assert_se(dhcp_option_parse(message, len, NULL, NULL) == -EINVAL);
 
         opt[0] = 99;
         opt[1] = 130;
         opt[2] = 83;
         opt[3] = 99;
 
-        assert(dhcp_option_parse(message, len, NULL, NULL) == -ENOMSG);
+        assert_se(dhcp_option_parse(message, len, NULL, NULL) == -ENOMSG);
 }
 
 static DHCPMessage *create_message(uint8_t *options, uint16_t optlen,
@@ -160,15 +160,15 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
         uint8_t optlen = 0;
         uint8_t i;
 
-        assert((!desc && !code && !len) || desc);
+        assert_se((!desc && !code && !len) || desc);
 
         if (!desc)
                 return -EINVAL;
 
-        assert(code != DHCP_OPTION_PAD);
-        assert(code != DHCP_OPTION_END);
-        assert(code != DHCP_OPTION_MESSAGE_TYPE);
-        assert(code != DHCP_OPTION_OVERLOAD);
+        assert_se(code != DHCP_OPTION_PAD);
+        assert_se(code != DHCP_OPTION_END);
+        assert_se(code != DHCP_OPTION_MESSAGE_TYPE);
+        assert_se(code != DHCP_OPTION_OVERLOAD);
 
         while (desc->pos >= 0 || desc->filepos >= 0 || desc->snamepos >= 0) {
 
@@ -186,7 +186,7 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
                         descpos = &desc->snamepos;
                 }
 
-                assert(descoption && desclen && descpos);
+                assert_se(descoption && desclen && descpos);
 
                 if (*desclen)
                         test_ignore_opts(descoption, descpos, desclen);
@@ -198,8 +198,8 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
                         *descpos = -1;
         }
 
-        assert(descpos);
-        assert(*descpos != -1);
+        assert_se(descpos);
+        assert_se(*descpos != -1);
 
         optcode = descoption[*descpos];
         optlen = descoption[*descpos + 1];
@@ -208,8 +208,8 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
                 printf("DHCP code %2d(%2d) len %2d(%2d) ", code, optcode,
                                 len, optlen);
 
-        assert(code == optcode);
-        assert(len == optlen);
+        assert_se(code == optcode);
+        assert_se(len == optlen);
 
         for (i = 0; i < len; i++) {
 
@@ -217,7 +217,7 @@ static int test_options_cb(uint8_t code, uint8_t len, const uint8_t *option,
                         printf("0x%02x(0x%02x) ", option[i],
                                         descoption[*descpos + 2 + i]);
 
-                assert(option[i] == descoption[*descpos + 2 + i]);
+                assert_se(option[i] == descoption[*descpos + 2 + i]);
         }
 
         if (verbose)
@@ -272,17 +272,17 @@ static void test_options(struct option_desc *desc)
         buflen = sizeof(DHCPMessage) + 4 + optlen;
 
         if (!desc) {
-                assert((res = dhcp_option_parse(message, buflen,
+                assert_se((res = dhcp_option_parse(message, buflen,
                                                 test_options_cb,
                                                 NULL)) == -ENOMSG);
         } else if (desc->success) {
-                assert((res = dhcp_option_parse(message, buflen,
+                assert_se((res = dhcp_option_parse(message, buflen,
                                                 test_options_cb,
                                                 desc)) >= 0);
-                assert(desc->pos == -1 && desc->filepos == -1 &&
+                assert_se(desc->pos == -1 && desc->filepos == -1 &&
                                 desc->snamepos == -1);
         } else
-                assert((res = dhcp_option_parse(message, buflen,
+                assert_se((res = dhcp_option_parse(message, buflen,
                                                 test_options_cb,
                                                 desc)) < 0);
 
@@ -311,22 +311,22 @@ static void test_option_set(void)
         int pos, i;
         uint8_t *opt;
 
-        assert(dhcp_option_append(NULL, NULL, 0, 0, NULL) == -EINVAL);
+        assert_se(dhcp_option_append(NULL, NULL, 0, 0, NULL) == -EINVAL);
 
         len = 0;
         opt = &result[0];
-        assert(dhcp_option_append(&opt, NULL, 0, 0, NULL) == -EINVAL);
-        assert(opt == &result[0] && len == 0);
+        assert_se(dhcp_option_append(&opt, NULL, 0, 0, NULL) == -EINVAL);
+        assert_se(opt == &result[0] && len == 0);
 
-        assert(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
+        assert_se(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
                                   0, NULL) == -ENOBUFS);
-        assert(opt == &result[0] && len == 0);
+        assert_se(opt == &result[0] && len == 0);
 
         opt = &result[4];
         len = 1;
-        assert(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
+        assert_se(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
                                     0, NULL) >= 0);
-        assert(opt == &result[5] && len == 0);
+        assert_se(opt == &result[5] && len == 0);
 
         pos = 4;
         len = 60;
@@ -334,17 +334,17 @@ static void test_option_set(void)
                 opt = &result[pos];
                 oldlen = len;
 
-                assert(dhcp_option_append(&opt, &len, options[pos],
+                assert_se(dhcp_option_append(&opt, &len, options[pos],
                                           options[pos + 1],
                                           &options[pos + 2]) >= 0);
 
                 if (options[pos] == DHCP_OPTION_PAD) {
-                        assert(opt == &result[pos + 1]);
-                        assert(len == oldlen - 1);
+                        assert_se(opt == &result[pos + 1]);
+                        assert_se(len == oldlen - 1);
                         pos++;
                 } else {
-                        assert(opt == &result[pos + 2 + options[pos + 1]]);
-                        assert(len == oldlen - 2 - options[pos + 1]);
+                        assert_se(opt == &result[pos + 2 + options[pos + 1]]);
+                        assert_se(len == oldlen - 2 - options[pos + 1]);
                         pos += 2 + options[pos + 1];
                 }
         }
@@ -353,7 +353,7 @@ static void test_option_set(void)
                 if (verbose)
                         printf("%2d: 0x%02x(0x%02x)\n", i, result[i],
                                options[i]);
-                assert(result[i] == options[i]);
+                assert_se(result[i] == options[i]);
         }
 
         if (verbose)
diff --git a/src/libsystemd/sd-rtnl/test-rtnl.c b/src/libsystemd/sd-rtnl/test-rtnl.c
index 497cefd..dd74e76 100644
--- a/src/libsystemd/sd-rtnl/test-rtnl.c
+++ b/src/libsystemd/sd-rtnl/test-rtnl.c
@@ -37,24 +37,24 @@ static void test_link_configure(sd_rtnl *rtnl, int ifindex) {
         void *data;
 
         /* we'd really like to test NEWLINK, but let's not mess with the running kernel */
-        assert(sd_rtnl_message_new_link(rtnl, &message, RTM_GETLINK, ifindex) >= 0);
-        assert(sd_rtnl_message_append_string(message, IFLA_IFNAME, name) >= 0);
-        assert(sd_rtnl_message_append_ether_addr(message, IFLA_ADDRESS, ether_aton(mac)) >= 0);
-        assert(sd_rtnl_message_append_u32(message, IFLA_MTU, mtu) >= 0);
+        assert_se(sd_rtnl_message_new_link(rtnl, &message, RTM_GETLINK, ifindex) >= 0);
+        assert_se(sd_rtnl_message_append_string(message, IFLA_IFNAME, name) >= 0);
+        assert_se(sd_rtnl_message_append_ether_addr(message, IFLA_ADDRESS, ether_aton(mac)) >= 0);
+        assert_se(sd_rtnl_message_append_u32(message, IFLA_MTU, mtu) >= 0);
 
-        assert(sd_rtnl_call(rtnl, message, 0, NULL) == 1);
+        assert_se(sd_rtnl_call(rtnl, message, 0, NULL) == 1);
 
-        assert(sd_rtnl_message_read(message, &type, &data) > 0);
-        assert(type == IFLA_IFNAME);
-        assert(streq(name, (char *) data));
+        assert_se(sd_rtnl_message_read(message, &type, &data) > 0);
+        assert_se(type == IFLA_IFNAME);
+        assert_se(streq(name, (char *) data));
 
-        assert(sd_rtnl_message_read(message, &type, &data) > 0);
-        assert(type == IFLA_ADDRESS);
-        assert(streq(mac, ether_ntoa(data)));
+        assert_se(sd_rtnl_message_read(message, &type, &data) > 0);
+        assert_se(type == IFLA_ADDRESS);
+        assert_se(streq(mac, ether_ntoa(data)));
 
-        assert(sd_rtnl_message_read(message, &type, &data) > 0);
-        assert(type == IFLA_MTU);
-        assert(mtu == *(unsigned int *) data);
+        assert_se(sd_rtnl_message_read(message, &type, &data) > 0);
+        assert_se(type == IFLA_MTU);
+        assert_se(mtu == *(unsigned int *) data);
 }
 
 static void test_link_get(sd_rtnl *rtnl, int ifindex) {
@@ -65,66 +65,66 @@ static void test_link_get(sd_rtnl *rtnl, int ifindex) {
         void *data;
         uint16_t type;
 
-        assert(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
-        assert(m);
+        assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
+        assert_se(m);
 
         /* u8 test cases  */
-        assert(sd_rtnl_message_append_u8(m, IFLA_CARRIER, 0) >= 0);
-        assert(sd_rtnl_message_append_u8(m, IFLA_OPERSTATE, 0) >= 0);
-        assert(sd_rtnl_message_append_u8(m, IFLA_LINKMODE, 0) >= 0);
+        assert_se(sd_rtnl_message_append_u8(m, IFLA_CARRIER, 0) >= 0);
+        assert_se(sd_rtnl_message_append_u8(m, IFLA_OPERSTATE, 0) >= 0);
+        assert_se(sd_rtnl_message_append_u8(m, IFLA_LINKMODE, 0) >= 0);
 
         /* u32 test cases */
-        assert(sd_rtnl_message_append_u32(m, IFLA_MTU, mtu) >= 0);
-        assert(sd_rtnl_message_append_u32(m, IFLA_GROUP, 0) >= 0);
-        assert(sd_rtnl_message_append_u32(m, IFLA_TXQLEN, 0) >= 0);
-        assert(sd_rtnl_message_append_u32(m, IFLA_NUM_TX_QUEUES, 0) >= 0);
-        assert(sd_rtnl_message_append_u32(m, IFLA_NUM_RX_QUEUES, 0) >= 0);
+        assert_se(sd_rtnl_message_append_u32(m, IFLA_MTU, mtu) >= 0);
+        assert_se(sd_rtnl_message_append_u32(m, IFLA_GROUP, 0) >= 0);
+        assert_se(sd_rtnl_message_append_u32(m, IFLA_TXQLEN, 0) >= 0);
+        assert_se(sd_rtnl_message_append_u32(m, IFLA_NUM_TX_QUEUES, 0) >= 0);
+        assert_se(sd_rtnl_message_append_u32(m, IFLA_NUM_RX_QUEUES, 0) >= 0);
 
-        assert(sd_rtnl_call(rtnl, m, -1, &r) == 1);
+        assert_se(sd_rtnl_call(rtnl, m, -1, &r) == 1);
 
         /* u8 read back */
-        assert(sd_rtnl_message_read(m, &type, &data) == 1);
-        assert(type == IFLA_CARRIER);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+        assert_se(type == IFLA_CARRIER);
 
-        assert(sd_rtnl_message_read(m, &type, &data) == 1);
-        assert(type == IFLA_OPERSTATE);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+        assert_se(type == IFLA_OPERSTATE);
 
-        assert(sd_rtnl_message_read(m, &type, &data) == 1);
-        assert(type == IFLA_LINKMODE);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+        assert_se(type == IFLA_LINKMODE);
 
         /* u32 read back */
-        assert(sd_rtnl_message_read(m, &type, (void **) &mtu_reply) == 1);
-        assert(type == IFLA_MTU);
-        assert(*mtu_reply == mtu);
+        assert_se(sd_rtnl_message_read(m, &type, (void **) &mtu_reply) == 1);
+        assert_se(type == IFLA_MTU);
+        assert_se(*mtu_reply == mtu);
 
-        assert(sd_rtnl_message_read(m, &type, &data) == 1);
-        assert(type == IFLA_GROUP);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+        assert_se(type == IFLA_GROUP);
 
-        assert(sd_rtnl_message_read(m, &type, &data) == 1);
-        assert(type == IFLA_TXQLEN);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+        assert_se(type == IFLA_TXQLEN);
 
-        assert(sd_rtnl_message_read(m, &type, &data) == 1);
-        assert(type == IFLA_NUM_TX_QUEUES);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+        assert_se(type == IFLA_NUM_TX_QUEUES);
 
-        assert(sd_rtnl_message_read(m, &type, &data) == 1);
-        assert(type == IFLA_NUM_RX_QUEUES);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 1);
+        assert_se(type == IFLA_NUM_RX_QUEUES);
 
         while (sd_rtnl_message_read(r, &type, &data) > 0) {
                 switch (type) {
 //                        case IFLA_MTU:
-//                                assert(*(unsigned int *) data == 65536);
+//                                assert_se(*(unsigned int *) data == 65536);
 //                                break;
 //                        case IFLA_QDISC:
-//                                assert(streq((char *) data, "noqueue"));
+//                                assert_se(streq((char *) data, "noqueue"));
 //                                break;
                         case IFLA_IFNAME:
-                                assert(streq((char *) data, "lo"));
+                                assert_se(streq((char *) data, "lo"));
                                 break;
                 }
         }
 
-        assert(sd_rtnl_flush(rtnl) >= 0);
-        assert((m = sd_rtnl_message_unref(m)) == NULL);
+        assert_se(sd_rtnl_flush(rtnl) >= 0);
+        assert_se((m = sd_rtnl_message_unref(m)) == NULL);
 
 }
 
@@ -156,22 +156,22 @@ static void test_route(void) {
                 return;
         }
 
-        assert(rtnl_message_seal(NULL, req) >= 0);
+        assert_se(rtnl_message_seal(NULL, req) >= 0);
 
-        assert(sd_rtnl_message_read(req, &type, &data) > 0);
-        assert(type == RTA_GATEWAY);
-        assert(((struct in_addr *)data)->s_addr == addr.s_addr);
+        assert_se(sd_rtnl_message_read(req, &type, &data) > 0);
+        assert_se(type == RTA_GATEWAY);
+        assert_se(((struct in_addr *)data)->s_addr == addr.s_addr);
 
-        assert(sd_rtnl_message_read(req, &type, &data) > 0);
-        assert(type == RTA_OIF);
-        assert(*(uint32_t *) data == index);
+        assert_se(sd_rtnl_message_read(req, &type, &data) > 0);
+        assert_se(type == RTA_OIF);
+        assert_se(*(uint32_t *) data == index);
 }
 
 static void test_multiple(void) {
         sd_rtnl *rtnl1, *rtnl2;
 
-        assert(sd_rtnl_open(&rtnl1, 0) >= 0);
-        assert(sd_rtnl_open(&rtnl2, 0) >= 0);
+        assert_se(sd_rtnl_open(&rtnl1, 0) >= 0);
+        assert_se(sd_rtnl_open(&rtnl2, 0) >= 0);
 
         rtnl1 = sd_rtnl_unref(rtnl1);
         rtnl2 = sd_rtnl_unref(rtnl2);
@@ -182,8 +182,8 @@ static int link_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         uint16_t type;
         char *ifname = userdata;
 
-        assert(rtnl);
-        assert(m);
+        assert_se(rtnl);
+        assert_se(m);
 
         log_info("got link info about %s", ifname);
         free(ifname);
@@ -191,13 +191,13 @@ static int link_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
         while (sd_rtnl_message_read(m, &type, &data) > 0) {
                 switch (type) {
 //                        case IFLA_MTU:
-//                                assert(*(unsigned int *) data == 65536);
+//                                assert_se(*(unsigned int *) data == 65536);
 //                                break;
 //                        case IFLA_QDISC:
-//                                assert(streq((char *) data, "noqueue"));
+//                                assert_se(streq((char *) data, "noqueue"));
 //                                break;
                         case IFLA_IFNAME:
-                                assert(streq((char *) data, "lo"));
+                                assert_se(streq((char *) data, "lo"));
                                 break;
                 }
         }
@@ -212,20 +212,20 @@ static void test_event_loop(int ifindex) {
         char *ifname;
 
         ifname = strdup("lo2");
-        assert(ifname);
+        assert_se(ifname);
 
-        assert(sd_rtnl_open(&rtnl, 0) >= 0);
-        assert(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
+        assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
+        assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
 
-        assert(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, NULL) >= 0);
+        assert_se(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, NULL) >= 0);
 
-        assert(sd_event_default(&event) >= 0);
+        assert_se(sd_event_default(&event) >= 0);
 
-        assert(sd_rtnl_attach_event(rtnl, event, 0) >= 0);
+        assert_se(sd_rtnl_attach_event(rtnl, event, 0) >= 0);
 
-        assert(sd_event_run(event, 0) >= 0);
+        assert_se(sd_event_run(event, 0) >= 0);
 
-        assert(sd_rtnl_detach_event(rtnl) >= 0);
+        assert_se(sd_rtnl_detach_event(rtnl) >= 0);
 }
 
 static int pipe_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) {
@@ -245,16 +245,16 @@ static void test_async(int ifindex) {
         char *ifname;
 
         ifname = strdup("lo");
-        assert(ifname);
+        assert_se(ifname);
 
-        assert(sd_rtnl_open(&rtnl, 0) >= 0);
+        assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
 
-        assert(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
+        assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, ifindex) >= 0);
 
-        assert(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, &serial) >= 0);
+        assert_se(sd_rtnl_call_async(rtnl, m, &link_handler, ifname, 0, &serial) >= 0);
 
-        assert(sd_rtnl_wait(rtnl, 0) >= 0);
-        assert(sd_rtnl_process(rtnl, &r) >= 0);
+        assert_se(sd_rtnl_wait(rtnl, 0) >= 0);
+        assert_se(sd_rtnl_process(rtnl, &r) >= 0);
 }
 
 static void test_pipe(int ifindex) {
@@ -262,20 +262,20 @@ static void test_pipe(int ifindex) {
         _cleanup_rtnl_message_unref_ sd_rtnl_message *m1 = NULL, *m2 = NULL;
         int counter = 0;
 
-        assert(sd_rtnl_open(&rtnl, 0) >= 0);
+        assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
 
-        assert(sd_rtnl_message_new_link(rtnl, &m1, RTM_GETLINK, ifindex) >= 0);
-        assert(sd_rtnl_message_new_link(rtnl, &m2, RTM_GETLINK, ifindex) >= 0);
+        assert_se(sd_rtnl_message_new_link(rtnl, &m1, RTM_GETLINK, ifindex) >= 0);
+        assert_se(sd_rtnl_message_new_link(rtnl, &m2, RTM_GETLINK, ifindex) >= 0);
 
         counter ++;
-        assert(sd_rtnl_call_async(rtnl, m1, &pipe_handler, &counter, 0, NULL) >= 0);
+        assert_se(sd_rtnl_call_async(rtnl, m1, &pipe_handler, &counter, 0, NULL) >= 0);
 
         counter ++;
-        assert(sd_rtnl_call_async(rtnl, m2, &pipe_handler, &counter, 0, NULL) >= 0);
+        assert_se(sd_rtnl_call_async(rtnl, m2, &pipe_handler, &counter, 0, NULL) >= 0);
 
         while (counter > 0) {
-                assert(sd_rtnl_wait(rtnl, 0) >= 0);
-                assert(sd_rtnl_process(rtnl, NULL) >= 0);
+                assert_se(sd_rtnl_wait(rtnl, 0) >= 0);
+                assert_se(sd_rtnl_process(rtnl, NULL) >= 0);
         }
 }
 
@@ -284,54 +284,54 @@ static void test_container(void) {
         uint16_t type;
         void *data;
 
-        assert(sd_rtnl_message_new_link(NULL, &m, RTM_NEWLINK, 0) >= 0);
-
-        assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
-        assert(sd_rtnl_message_open_container(m, IFLA_LINKINFO) == -ENOTSUP);
-        assert(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
-        assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) >= 0);
-        assert(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) == -ENOTSUP);
-        assert(sd_rtnl_message_append_u16(m, IFLA_VLAN_ID, 100) >= 0);
-        assert(sd_rtnl_message_close_container(m) >= 0);
-        assert(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
-        assert(sd_rtnl_message_close_container(m) >= 0);
-        assert(sd_rtnl_message_close_container(m) == -EINVAL);
-
-        assert(rtnl_message_seal(NULL, m) >= 0);
-
-        assert(sd_rtnl_message_read(m, &type, &data) >= 0);
-        assert(type == IFLA_LINKINFO);
-        assert(data == NULL);
-        assert(sd_rtnl_message_read(m, &type, &data) >= 0);
-        assert(type == IFLA_INFO_KIND);
-        assert(streq("kind", (char *)data));
-        assert(sd_rtnl_message_read(m, &type, &data) >= 0);
-        assert(type == IFLA_INFO_DATA);
-        assert(data == NULL);
-        assert(sd_rtnl_message_read(m, &type, &data) >= 0);
-        assert(type == IFLA_VLAN_ID);
-        assert(*(uint16_t *)data == 100);
-        assert(sd_rtnl_message_read(m, &type, &data) == 0);
-        assert(sd_rtnl_message_exit_container(m) >= 0);
-        assert(sd_rtnl_message_read(m, &type, &data) >= 0);
-        assert(type == IFLA_INFO_KIND);
-        assert(streq("kind", (char *)data));
-        assert(sd_rtnl_message_read(m, &type, &data) == 0);
-        assert(sd_rtnl_message_exit_container(m) >= 0);
-        assert(sd_rtnl_message_exit_container(m) == -EINVAL);
+        assert_se(sd_rtnl_message_new_link(NULL, &m, RTM_NEWLINK, 0) >= 0);
+
+        assert_se(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
+        assert_se(sd_rtnl_message_open_container(m, IFLA_LINKINFO) == -ENOTSUP);
+        assert_se(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
+        assert_se(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) >= 0);
+        assert_se(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) == -ENOTSUP);
+        assert_se(sd_rtnl_message_append_u16(m, IFLA_VLAN_ID, 100) >= 0);
+        assert_se(sd_rtnl_message_close_container(m) >= 0);
+        assert_se(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
+        assert_se(sd_rtnl_message_close_container(m) >= 0);
+        assert_se(sd_rtnl_message_close_container(m) == -EINVAL);
+
+        assert_se(rtnl_message_seal(NULL, m) >= 0);
+
+        assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+        assert_se(type == IFLA_LINKINFO);
+        assert_se(data == NULL);
+        assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+        assert_se(type == IFLA_INFO_KIND);
+        assert_se(streq("kind", (char *)data));
+        assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+        assert_se(type == IFLA_INFO_DATA);
+        assert_se(data == NULL);
+        assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+        assert_se(type == IFLA_VLAN_ID);
+        assert_se(*(uint16_t *)data == 100);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 0);
+        assert_se(sd_rtnl_message_exit_container(m) >= 0);
+        assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
+        assert_se(type == IFLA_INFO_KIND);
+        assert_se(streq("kind", (char *)data));
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 0);
+        assert_se(sd_rtnl_message_exit_container(m) >= 0);
+        assert_se(sd_rtnl_message_exit_container(m) == -EINVAL);
 }
 
 static void test_match(void) {
         _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
 
-        assert(sd_rtnl_open(&rtnl, 0) >= 0);
+        assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
 
-        assert(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
-        assert(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
+        assert_se(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
+        assert_se(sd_rtnl_add_match(rtnl, RTM_NEWLINK, &link_handler, NULL) >= 0);
 
-        assert(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
-        assert(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
-        assert(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 0);
+        assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
+        assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 1);
+        assert_se(sd_rtnl_remove_match(rtnl, RTM_NEWLINK, &link_handler, NULL) == 0);
 }
 
 int main(void) {
@@ -350,11 +350,11 @@ int main(void) {
 
         test_container();
 
-        assert(sd_rtnl_open(&rtnl, 0) >= 0);
-        assert(rtnl);
+        assert_se(sd_rtnl_open(&rtnl, 0) >= 0);
+        assert_se(rtnl);
 
         if_loopback = (int) if_nametoindex("lo");
-        assert(if_loopback > 0);
+        assert_se(if_loopback > 0);
 
         test_async(if_loopback);
 
@@ -364,31 +364,31 @@ int main(void) {
 
         test_link_configure(rtnl, if_loopback);
 
-        assert(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, if_loopback) >= 0);
-        assert(m);
+        assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_GETLINK, if_loopback) >= 0);
+        assert_se(m);
 
-        assert(sd_rtnl_message_get_type(m, &type) >= 0);
-        assert(type == RTM_GETLINK);
+        assert_se(sd_rtnl_message_get_type(m, &type) >= 0);
+        assert_se(type == RTM_GETLINK);
 
-        assert(sd_rtnl_message_read(m, &type, &data) == -EPERM);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == -EPERM);
 
-        assert(sd_rtnl_call(rtnl, m, 0, &r) == 1);
-        assert(sd_rtnl_message_get_type(r, &type) >= 0);
-        assert(type == RTM_NEWLINK);
+        assert_se(sd_rtnl_call(rtnl, m, 0, &r) == 1);
+        assert_se(sd_rtnl_message_get_type(r, &type) >= 0);
+        assert_se(type == RTM_NEWLINK);
 
-        assert(sd_rtnl_message_read(m, &type, &data) == 0);
-        assert((r = sd_rtnl_message_unref(r)) == NULL);
+        assert_se(sd_rtnl_message_read(m, &type, &data) == 0);
+        assert_se((r = sd_rtnl_message_unref(r)) == NULL);
 
-        assert(sd_rtnl_call(rtnl, m, -1, &r) == -EPERM);
-        assert((m = sd_rtnl_message_unref(m)) == NULL);
-        assert((r = sd_rtnl_message_unref(r)) == NULL);
+        assert_se(sd_rtnl_call(rtnl, m, -1, &r) == -EPERM);
+        assert_se((m = sd_rtnl_message_unref(m)) == NULL);
+        assert_se((r = sd_rtnl_message_unref(r)) == NULL);
 
         test_link_get(rtnl, if_loopback);
 
-        assert(sd_rtnl_flush(rtnl) >= 0);
-        assert((m = sd_rtnl_message_unref(m)) == NULL);
-        assert((r = sd_rtnl_message_unref(r)) == NULL);
-        assert((rtnl = sd_rtnl_unref(rtnl)) == NULL);
+        assert_se(sd_rtnl_flush(rtnl) >= 0);
+        assert_se((m = sd_rtnl_message_unref(m)) == NULL);
+        assert_se((r = sd_rtnl_message_unref(r)) == NULL);
+        assert_se((rtnl = sd_rtnl_unref(rtnl)) == NULL);
 
         return EXIT_SUCCESS;
 }
diff --git a/src/network/test-network.c b/src/network/test-network.c
index 5e27997..46afeec 100644
--- a/src/network/test-network.c
+++ b/src/network/test-network.c
@@ -27,8 +27,8 @@ static void test_link(struct udev_device *loopback) {
 
         manager_new(&manager);
 
-        assert(link_new(manager, loopback, &link) >= 0);
-        assert(link);
+        assert_se(link_new(manager, loopback, &link) >= 0);
+        assert_se(link);
 }
 
 static void test_load_config(Manager *manager) {
@@ -36,10 +36,10 @@ static void test_load_config(Manager *manager) {
  *        so we can't do this test here, move it to a test for paths_check_timestamps
  *        directly
  *
- *        assert(network_should_reload(manager) == true);
+ *        assert_se(network_should_reload(manager) == true);
 */
-        assert(manager_load_config(manager) >= 0);
-        assert(manager_should_reload(manager) == false);
+        assert_se(manager_load_config(manager) >= 0);
+        assert_se(manager_should_reload(manager) == false);
 }
 
 static void test_network_get(Manager *manager, struct udev_device *loopback) {
@@ -47,8 +47,8 @@ static void test_network_get(Manager *manager, struct udev_device *loopback) {
 
         /* let's assume that the test machine does not have a .network file
            that applies to the loopback device... */
-        assert(network_get(manager, loopback, &network) == -ENOENT);
-        assert(!network);
+        assert_se(network_get(manager, loopback, &network) == -ENOENT);
+        assert_se(!network);
 }
 
 int main(void) {
@@ -56,24 +56,24 @@ int main(void) {
         struct udev *udev;
         struct udev_device *loopback;
 
-        assert(manager_new(&manager) >= 0);
+        assert_se(manager_new(&manager) >= 0);
 
         test_load_config(manager);
 
         udev = udev_new();
-        assert(udev);
+        assert_se(udev);
 
         loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
-        assert(loopback);
-        assert(udev_device_get_ifindex(loopback) == 1);
+        assert_se(loopback);
+        assert_se(udev_device_get_ifindex(loopback) == 1);
 
         test_network_get(manager, loopback);
 
         test_link(loopback);
 
-        assert(manager_udev_listen(manager) >= 0);
-        assert(manager_udev_enumerate_links(manager) >= 0);
-        assert(manager_rtnl_listen(manager) >= 0);
+        assert_se(manager_udev_listen(manager) >= 0);
+        assert_se(manager_udev_enumerate_links(manager) >= 0);
+        assert_se(manager_rtnl_listen(manager) >= 0);
 
         udev_device_unref(loopback);
         udev_unref(udev);

commit ee57a737a5b72bc3f3f46aafd2bbc452b61dcaa7
Author: Tom Gundersen <teg at jklm.no>
Date:   Sat Feb 22 19:53:45 2014 +0100

    sd-dhcp: add very basic debug logging

diff --git a/src/libsystemd-dhcp/dhcp-internal.h b/src/libsystemd-dhcp/dhcp-internal.h
index 7639069..efb8ea5 100644
--- a/src/libsystemd-dhcp/dhcp-internal.h
+++ b/src/libsystemd-dhcp/dhcp-internal.h
@@ -51,3 +51,5 @@ int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid, uint8_t ty
 void dhcp_packet_append_ip_headers(DHCPPacket *packet, uint8_t op, uint16_t len);
 
 int dhcp_packet_verify_headers(DHCPPacket *packet, uint8_t op, size_t len);
+
+#define log_dhcp_client(client, fmt, ...) log_meta(LOG_DEBUG, __FILE__, __LINE__, __func__, "DHCP CLIENT: " fmt, ##__VA_ARGS__)
diff --git a/src/libsystemd-dhcp/sd-dhcp-client.c b/src/libsystemd-dhcp/sd-dhcp-client.c
index 53abe22..3506755 100644
--- a/src/libsystemd-dhcp/sd-dhcp-client.c
+++ b/src/libsystemd-dhcp/sd-dhcp-client.c
@@ -195,6 +195,8 @@ static int client_stop(sd_dhcp_client *client, int error) {
         if (client->lease)
                 client->lease = sd_dhcp_lease_unref(client->lease);
 
+        log_dhcp_client(client, "STOPPED");
+
         return 0;
 }
 
@@ -214,7 +216,7 @@ static int client_message_init(sd_dhcp_client *client, DHCPMessage *message,
             client->state == DHCP_STATE_REBINDING)
                 message->ciaddr = client->lease->address;
 
-        /* Some DHCP servers will refuse to issue an DHCP lease if the Cliient
+        /* Some DHCP servers will refuse to issue an DHCP lease if the Client
            Identifier option is not set */
         r = dhcp_option_append(opt, optlen, DHCP_OPTION_CLIENT_IDENTIFIER,
                                ETH_ALEN, &client->mac_addr);
@@ -282,6 +284,8 @@ static int client_send_discover(sd_dhcp_client *client, uint16_t secs) {
         err = dhcp_network_send_raw_socket(client->fd, &client->link,
                                            discover, len);
 
+        log_dhcp_client(client, "DISCOVER");
+
         return err;
 }
 
@@ -334,6 +338,8 @@ static int client_send_request(sd_dhcp_client *client, uint16_t secs) {
                                                    request, len);
         }
 
+        log_dhcp_client(client, "REQUEST");
+
         return err;
 }
 
@@ -503,6 +509,8 @@ static int client_timeout_expire(sd_event_source *s, uint64_t usec,
                                  void *userdata) {
         sd_dhcp_client *client = userdata;
 
+        log_dhcp_client(client, "EXPIRED");
+
         client_stop(client, DHCP_EVENT_EXPIRED);
 
         return 0;
@@ -530,6 +538,8 @@ static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
 
         client->fd = r;
 
+        log_dhcp_client(client, "TIMEOUT T2");
+
         return client_initialize_events(client, client_receive_message_raw,
                                         usec);
 }
@@ -552,6 +562,8 @@ static int client_timeout_t1(sd_event_source *s, uint64_t usec,
 
         client->fd = r;
 
+        log_dhcp_client(client, "TIMEOUT T1");
+
         return client_initialize_events(client, client_receive_message_udp, usec);
 }
 
@@ -579,6 +591,8 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer,
         client->lease = lease;
         lease = NULL;
 
+        log_dhcp_client(client, "OFFER");
+
         return 0;
 }
 
@@ -592,8 +606,10 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
                 return r;
 
         r = dhcp_option_parse(ack, len, dhcp_lease_parse_options, lease);
-        if (r == DHCP_NAK)
+        if (r == DHCP_NAK) {
+                log_dhcp_client(client, "NAK");
                 return DHCP_EVENT_NO_LEASE;
+        }
 
         if (r != DHCP_ACK)
                 return -ENOMSG;
@@ -619,6 +635,8 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack,
         client->lease = lease;
         lease = NULL;
 
+        log_dhcp_client(client, "ACK");
+
         return r;
 }
 
@@ -852,8 +870,10 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
         packet = (DHCPPacket *) buf;
 
         r = dhcp_packet_verify_headers(packet, BOOTREPLY, len);
-        if (r < 0)
+        if (r < 0) {
+                log_dhcp_client(client, "ignoring DHCP packet with invalid headers");
                 return 0;
+        }
 
         len -= DHCP_IP_UDP_SIZE;
 
@@ -886,6 +906,8 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
         client->start_time = now(CLOCK_MONOTONIC);
         client->secs = 0;
 
+        log_dhcp_client(client, "STARTED");
+
         return client_initialize_events(client, client_receive_message_raw,
                                         client->start_time);
 }



More information about the systemd-commits mailing list