summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-netlink
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd/sd-netlink')
-rw-r--r--src/libsystemd/sd-netlink/netlink-internal.h4
-rw-r--r--src/libsystemd/sd-netlink/netlink-message.c2
-rw-r--r--src/libsystemd/sd-netlink/sd-netlink.c134
-rw-r--r--src/libsystemd/sd-netlink/test-netlink.c3
4 files changed, 11 insertions, 132 deletions
diff --git a/src/libsystemd/sd-netlink/netlink-internal.h b/src/libsystemd/sd-netlink/netlink-internal.h
index ff663f91ef..24ebbbe7df 100644
--- a/src/libsystemd/sd-netlink/netlink-internal.h
+++ b/src/libsystemd/sd-netlink/netlink-internal.h
@@ -72,10 +72,6 @@ struct sd_netlink {
unsigned rqueue_partial_size;
size_t rqueue_partial_allocated;
- sd_netlink_message **wqueue;
- unsigned wqueue_size;
- size_t wqueue_allocated;
-
struct nlmsghdr *rbuffer;
size_t rbuffer_allocated;
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c
index 9c280b1699..fe9714ab5d 100644
--- a/src/libsystemd/sd-netlink/netlink-message.c
+++ b/src/libsystemd/sd-netlink/netlink-message.c
@@ -1410,7 +1410,7 @@ int socket_write_message(sd_netlink *nl, sd_netlink_message *m) {
k = sendto(nl->fd, m->hdr, m->hdr->nlmsg_len,
0, &addr.sa, sizeof(addr));
if (k < 0)
- return (errno == EAGAIN) ? 0 : -errno;
+ return -errno;
return k;
}
diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c
index 14cc75915d..572de90417 100644
--- a/src/libsystemd/sd-netlink/sd-netlink.c
+++ b/src/libsystemd/sd-netlink/sd-netlink.c
@@ -50,11 +50,6 @@ static int sd_netlink_new(sd_netlink **ret) {
LIST_HEAD_INIT(rtnl->match_callbacks);
- /* We guarantee that wqueue always has space for at least
- * one entry */
- if (!GREEDY_REALLOC(rtnl->wqueue, rtnl->wqueue_allocated, 1))
- return -ENOMEM;
-
/* We guarantee that the read buffer has at least space for
* a message header */
if (!greedy_realloc((void**)&rtnl->rbuffer, &rtnl->rbuffer_allocated,
@@ -204,10 +199,6 @@ sd_netlink *sd_netlink_unref(sd_netlink *rtnl) {
sd_netlink_message_unref(rtnl->rqueue_partial[i]);
free(rtnl->rqueue_partial);
- for (i = 0; i < rtnl->wqueue_size; i++)
- sd_netlink_message_unref(rtnl->wqueue[i]);
- free(rtnl->wqueue);
-
free(rtnl->rbuffer);
hashmap_free_free(rtnl->reply_callbacks);
@@ -215,7 +206,6 @@ sd_netlink *sd_netlink_unref(sd_netlink *rtnl) {
sd_event_source_unref(rtnl->io_event_source);
sd_event_source_unref(rtnl->time_event_source);
- sd_event_source_unref(rtnl->exit_event_source);
sd_event_unref(rtnl->event);
while ((f = rtnl->match_callbacks)) {
@@ -257,29 +247,9 @@ int sd_netlink_send(sd_netlink *nl,
rtnl_seal_message(nl, message);
- if (nl->wqueue_size <= 0) {
- /* send directly */
- r = socket_write_message(nl, message);
- if (r < 0)
- return r;
- else if (r == 0) {
- /* nothing was sent, so let's put it on
- * the queue */
- nl->wqueue[0] = sd_netlink_message_ref(message);
- nl->wqueue_size = 1;
- }
- } else {
- /* append to queue */
- if (nl->wqueue_size >= RTNL_WQUEUE_MAX) {
- log_debug("rtnl: exhausted the write queue size (%d)", RTNL_WQUEUE_MAX);
- return -ENOBUFS;
- }
-
- if (!GREEDY_REALLOC(nl->wqueue, nl->wqueue_allocated, nl->wqueue_size + 1))
- return -ENOMEM;
-
- nl->wqueue[nl->wqueue_size ++] = sd_netlink_message_ref(message);
- }
+ r = socket_write_message(nl, message);
+ if (r < 0)
+ return r;
if (serial)
*serial = rtnl_message_get_serial(message);
@@ -337,31 +307,6 @@ static int dispatch_rqueue(sd_netlink *rtnl, sd_netlink_message **message) {
return 1;
}
-static int dispatch_wqueue(sd_netlink *rtnl) {
- int r, ret = 0;
-
- assert(rtnl);
-
- while (rtnl->wqueue_size > 0) {
- r = socket_write_message(rtnl, rtnl->wqueue[0]);
- if (r < 0)
- return r;
- else if (r == 0)
- /* Didn't do anything this time */
- return ret;
- else {
- /* see equivalent in sd-bus.c */
- sd_netlink_message_unref(rtnl->wqueue[0]);
- rtnl->wqueue_size --;
- memmove(rtnl->wqueue, rtnl->wqueue + 1, sizeof(sd_netlink_message*) * rtnl->wqueue_size);
-
- ret = 1;
- }
- }
-
- return ret;
-}
-
static int process_timeout(sd_netlink *rtnl) {
_cleanup_netlink_message_unref_ sd_netlink_message *m = NULL;
struct reply_callback *c;
@@ -462,10 +407,6 @@ static int process_running(sd_netlink *rtnl, sd_netlink_message **ret) {
if (r != 0)
goto null_message;
- r = dispatch_wqueue(rtnl);
- if (r != 0)
- goto null_message;
-
r = dispatch_rqueue(rtnl, &m);
if (r < 0)
return r;
@@ -759,48 +700,17 @@ int sd_netlink_call(sd_netlink *rtnl,
return r;
else if (r == 0)
return -ETIMEDOUT;
-
- r = dispatch_wqueue(rtnl);
- if (r < 0)
- return r;
- }
-}
-
-int sd_netlink_flush(sd_netlink *rtnl) {
- int r;
-
- assert_return(rtnl, -EINVAL);
- assert_return(!rtnl_pid_changed(rtnl), -ECHILD);
-
- if (rtnl->wqueue_size <= 0)
- return 0;
-
- for (;;) {
- r = dispatch_wqueue(rtnl);
- if (r < 0)
- return r;
-
- if (rtnl->wqueue_size <= 0)
- return 0;
-
- r = rtnl_poll(rtnl, false, (uint64_t) -1);
- if (r < 0)
- return r;
}
}
int sd_netlink_get_events(sd_netlink *rtnl) {
- int flags = 0;
-
assert_return(rtnl, -EINVAL);
assert_return(!rtnl_pid_changed(rtnl), -ECHILD);
- if (rtnl->rqueue_size <= 0)
- flags |= POLLIN;
- if (rtnl->wqueue_size > 0)
- flags |= POLLOUT;
-
- return flags;
+ if (rtnl->rqueue_size == 0)
+ return POLLIN;
+ else
+ return 0;
}
int sd_netlink_get_timeout(sd_netlink *rtnl, uint64_t *timeout_usec) {
@@ -886,16 +796,6 @@ static int prepare_callback(sd_event_source *s, void *userdata) {
return 1;
}
-static int exit_callback(sd_event_source *event, void *userdata) {
- sd_netlink *rtnl = userdata;
-
- assert(event);
-
- sd_netlink_flush(rtnl);
-
- return 1;
-}
-
int sd_netlink_attach_event(sd_netlink *rtnl, sd_event *event, int priority) {
int r;
@@ -941,14 +841,6 @@ int sd_netlink_attach_event(sd_netlink *rtnl, sd_event *event, int priority) {
if (r < 0)
goto fail;
- r = sd_event_add_exit(rtnl->event, &rtnl->exit_event_source, exit_callback, rtnl);
- if (r < 0)
- goto fail;
-
- r = sd_event_source_set_description(rtnl->exit_event_source, "rtnl-exit");
- if (r < 0)
- goto fail;
-
return 0;
fail:
@@ -960,17 +852,11 @@ int sd_netlink_detach_event(sd_netlink *rtnl) {
assert_return(rtnl, -EINVAL);
assert_return(rtnl->event, -ENXIO);
- if (rtnl->io_event_source)
- rtnl->io_event_source = sd_event_source_unref(rtnl->io_event_source);
-
- if (rtnl->time_event_source)
- rtnl->time_event_source = sd_event_source_unref(rtnl->time_event_source);
+ rtnl->io_event_source = sd_event_source_unref(rtnl->io_event_source);
- if (rtnl->exit_event_source)
- rtnl->exit_event_source = sd_event_source_unref(rtnl->exit_event_source);
+ rtnl->time_event_source = sd_event_source_unref(rtnl->time_event_source);
- if (rtnl->event)
- rtnl->event = sd_event_unref(rtnl->event);
+ rtnl->event = sd_event_unref(rtnl->event);
return 0;
}
diff --git a/src/libsystemd/sd-netlink/test-netlink.c b/src/libsystemd/sd-netlink/test-netlink.c
index 60a4601e7e..c9cb415ca0 100644
--- a/src/libsystemd/sd-netlink/test-netlink.c
+++ b/src/libsystemd/sd-netlink/test-netlink.c
@@ -115,7 +115,6 @@ static void test_link_get(sd_netlink *rtnl, int ifindex) {
assert_se(sd_netlink_message_read_ether_addr(r, IFLA_ADDRESS, &eth_data) == 0);
- assert_se(sd_netlink_flush(rtnl) >= 0);
assert_se((m = sd_netlink_message_unref(m)) == NULL);
assert_se((r = sd_netlink_message_unref(r)) == NULL);
}
@@ -138,7 +137,6 @@ static void test_address_get(sd_netlink *rtnl, int ifindex) {
assert_se(sd_netlink_message_read_string(r, IFA_LABEL, &label) == 0);
assert_se(sd_netlink_message_read_cache_info(r, IFA_CACHEINFO, &cache) == 0);
- assert_se(sd_netlink_flush(rtnl) >= 0);
assert_se((m = sd_netlink_message_unref(m)) == NULL);
assert_se((r = sd_netlink_message_unref(r)) == NULL);
@@ -434,7 +432,6 @@ int main(void) {
test_link_get(rtnl, if_loopback);
test_address_get(rtnl, if_loopback);
- assert_se(sd_netlink_flush(rtnl) >= 0);
assert_se((m = sd_netlink_message_unref(m)) == NULL);
assert_se((r = sd_netlink_message_unref(r)) == NULL);
assert_se((rtnl = sd_netlink_unref(rtnl)) == NULL);