chiark / gitweb /
util: replace close_nointr_nofail() by a more useful safe_close()
[elogind.git] / src / libsystemd / sd-rtnl / sd-rtnl.c
index 08b82ab2a94f3f6dca6bb5e21934d90cbb48cfcc..e5610b43358d97058e340b8ae2808b0fc85268df 100644 (file)
@@ -70,8 +70,8 @@ static bool rtnl_pid_changed(sd_rtnl *rtnl) {
         return rtnl->original_pid != getpid();
 }
 
-int sd_rtnl_open(uint32_t groups, sd_rtnl **ret) {
-        _cleanup_sd_rtnl_unref_ sd_rtnl *rtnl = NULL;
+int sd_rtnl_open(sd_rtnl **ret, uint32_t groups) {
+        _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL;
         socklen_t addrlen;
         int r;
 
@@ -132,9 +132,7 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *rtnl) {
                         free(f);
                 }
 
-                if (rtnl->fd >= 0)
-                        close_nointr_nofail(rtnl->fd);
-
+                safe_close(rtnl->fd);
                 free(rtnl);
         }
 
@@ -150,7 +148,7 @@ int sd_rtnl_send(sd_rtnl *nl,
         assert_return(!rtnl_pid_changed(nl), -ECHILD);
         assert_return(message, -EINVAL);
 
-        r = message_seal(nl, message);
+        r = rtnl_message_seal(nl, message);
         if (r < 0)
                 return r;
 
@@ -181,7 +179,7 @@ int sd_rtnl_send(sd_rtnl *nl,
         }
 
         if (serial)
-                *serial = message_get_serial(message);
+                *serial = rtnl_message_get_serial(message);
 
         return 1;
 }
@@ -241,7 +239,7 @@ static int dispatch_wqueue(sd_rtnl *rtnl) {
 }
 
 static int process_timeout(sd_rtnl *rtnl) {
-        _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *m = NULL;
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
         struct reply_callback *c;
         usec_t n;
         int r;
@@ -256,7 +254,7 @@ static int process_timeout(sd_rtnl *rtnl) {
         if (c->timeout > n)
                 return 0;
 
-        r = message_new_synthetic_error(-ETIMEDOUT, c->serial, &m);
+        r = rtnl_message_new_synthetic_error(-ETIMEDOUT, c->serial, &m);
         if (r < 0)
                 return r;
 
@@ -277,7 +275,10 @@ static int process_reply(sd_rtnl *rtnl, sd_rtnl_message *m) {
         assert(rtnl);
         assert(m);
 
-        serial = message_get_serial(m);
+        if (sd_rtnl_message_is_broadcast(m))
+                return 0;
+
+        serial = rtnl_message_get_serial(m);
         c = hashmap_remove(rtnl->reply_callbacks, &serial);
         if (!c)
                 return 0;
@@ -315,7 +316,7 @@ static int process_match(sd_rtnl *rtnl, sd_rtnl_message *m) {
 }
 
 static int process_running(sd_rtnl *rtnl, sd_rtnl_message **ret) {
-        _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *m = NULL;
+        _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
         int r;
 
         assert(rtnl);
@@ -557,7 +558,7 @@ int sd_rtnl_call(sd_rtnl *nl,
 
         for (;;) {
                 usec_t left;
-                _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *incoming = NULL;
+                _cleanup_rtnl_message_unref_ sd_rtnl_message *incoming = NULL;
 
                 if (!room) {
                         sd_rtnl_message **q;
@@ -580,7 +581,7 @@ int sd_rtnl_call(sd_rtnl *nl,
                 if (r < 0)
                         return r;
                 if (incoming) {
-                        uint32_t received_serial = message_get_serial(incoming);
+                        uint32_t received_serial = rtnl_message_get_serial(incoming);
 
                         if (received_serial == serial) {
                                 r = sd_rtnl_message_get_errno(incoming);
@@ -774,7 +775,7 @@ int sd_rtnl_attach_event(sd_rtnl *rtnl, sd_event *event, int priority) {
                         return r;
         }
 
-        r = sd_event_add_io(rtnl->event, rtnl->fd, 0, io_callback, rtnl, &rtnl->io_event_source);
+        r = sd_event_add_io(rtnl->event, &rtnl->io_event_source, rtnl->fd, 0, io_callback, rtnl);
         if (r < 0)
                 goto fail;
 
@@ -786,7 +787,7 @@ int sd_rtnl_attach_event(sd_rtnl *rtnl, sd_event *event, int priority) {
         if (r < 0)
                 goto fail;
 
-        r = sd_event_add_monotonic(rtnl->event, 0, 0, time_callback, rtnl, &rtnl->time_event_source);
+        r = sd_event_add_monotonic(rtnl->event, &rtnl->time_event_source, 0, 0, time_callback, rtnl);
         if (r < 0)
                 goto fail;
 
@@ -794,7 +795,7 @@ int sd_rtnl_attach_event(sd_rtnl *rtnl, sd_event *event, int priority) {
         if (r < 0)
                 goto fail;
 
-        r = sd_event_add_exit(rtnl->event, exit_callback, rtnl, &rtnl->exit_event_source);
+        r = sd_event_add_exit(rtnl->event, &rtnl->exit_event_source, exit_callback, rtnl);
         if (r < 0)
                 goto fail;
 
@@ -833,7 +834,9 @@ int sd_rtnl_add_match(sd_rtnl *rtnl,
         assert_return(rtnl, -EINVAL);
         assert_return(callback, -EINVAL);
         assert_return(!rtnl_pid_changed(rtnl), -ECHILD);
-        assert_return(message_type_is_link(type) || message_type_is_addr(type) || message_type_is_route(type), -ENOTSUP);
+        assert_return(rtnl_message_type_is_link(type) ||
+                      rtnl_message_type_is_addr(type) ||
+                      rtnl_message_type_is_route(type), -ENOTSUP);
 
         c = new0(struct match_callback, 1);
         if (!c)