chiark / gitweb /
resolved: use == for comparing unsigned against zero
[elogind.git] / src / resolve / resolved-bus.c
index 0029023bcc7052aba3ef46275fae0fe2f997080b..fba2afcc8d7838c6366686dbb8fde1d9d7b37ce6 100644 (file)
@@ -19,7 +19,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "bus-errors.h"
+#include "bus-common-errors.h"
 #include "bus-util.h"
 
 #include "resolved-dns-domain.h"
@@ -76,7 +76,7 @@ static int reply_query_state(DnsQuery *q) {
                                 rc = p;
                         }
 
-                        n = strappenda(_BUS_ERROR_DNS, rc);
+                        n = strjoina(_BUS_ERROR_DNS, rc);
                         sd_bus_error_setf(&error, n, "Could not resolve '%s', server or network returned error %s", name, rc);
                 }
 
@@ -183,7 +183,7 @@ static void bus_method_resolve_hostname_complete(DnsQuery *q) {
                 }
         }
 
-        if (added <= 0) {
+        if (added == 0) {
                 if (!cname) {
                         r = sd_bus_reply_method_errorf(q->request, BUS_ERROR_NO_SUCH_RR, "'%s' does not have any RR of requested type", q->request_hostname);
                         goto finish;
@@ -220,6 +220,8 @@ static void bus_method_resolve_hostname_complete(DnsQuery *q) {
                         added++;
                 }
 
+                // what about the cache?
+
                 /* If we didn't find anything, then let's restart the
                  * query, this time with the cname */
                 if (added <= 0) {
@@ -251,7 +253,7 @@ static void bus_method_resolve_hostname_complete(DnsQuery *q) {
 
 finish:
         if (r < 0) {
-                log_error("Failed to send hostname reply: %s", strerror(-r));
+                log_error_errno(r, "Failed to send hostname reply: %m");
                 sd_bus_reply_method_errno(q->request, -r, NULL);
         }
 
@@ -398,7 +400,7 @@ static void bus_method_resolve_address_complete(DnsQuery *q) {
                 }
         }
 
-        if (added <= 0) {
+        if (added == 0) {
                 _cleanup_free_ char *ip = NULL;
 
                 in_addr_to_string(q->request_family, &q->request_address, &ip);
@@ -419,7 +421,7 @@ static void bus_method_resolve_address_complete(DnsQuery *q) {
 
 finish:
         if (r < 0) {
-                log_error("Failed to send address reply: %s", strerror(-r));
+                log_error_errno(r, "Failed to send address reply: %m");
                 sd_bus_reply_method_errno(q->request, -r, NULL);
         }
 
@@ -591,7 +593,7 @@ static void bus_method_resolve_record_complete(DnsQuery *q) {
 
 finish:
         if (r < 0) {
-                log_error("Failed to send record reply: %s", strerror(-r));
+                log_error_errno(r, "Failed to send record reply: %m");
                 sd_bus_reply_method_errno(q->request, -r, NULL);
         }
 
@@ -690,7 +692,7 @@ static int match_prepare_for_sleep(sd_bus *bus, sd_bus_message *message, void *u
 
         r = sd_bus_message_read(message, "b", &b);
         if (r < 0) {
-                log_debug("Failed to parse PrepareForSleep signal: %s", strerror(-r));
+                log_debug_errno(r, "Failed to parse PrepareForSleep signal: %m");
                 return 0;
         }
 
@@ -717,34 +719,26 @@ int manager_connect_bus(Manager *m) {
                  * boot. Let's try in 5s again. As soon as we have
                  * kdbus we can stop doing this... */
 
-                log_debug("Failed to connect to bus, trying again in 5s: %s", strerror(-r));
+                log_debug_errno(r, "Failed to connect to bus, trying again in 5s: %m");
 
                 r = sd_event_add_time(m->event, &m->bus_retry_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + 5*USEC_PER_SEC, 0, on_bus_retry, m);
-                if (r < 0) {
-                        log_error("Failed to install bus reconnect time event: %s", strerror(-r));
-                        return r;
-                }
+                if (r < 0)
+                        return log_error_errno(r, "Failed to install bus reconnect time event: %m");
 
                 return 0;
         }
 
         r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/resolve1", "org.freedesktop.resolve1.Manager", resolve_vtable, m);
-        if (r < 0) {
-                log_error("Failed to register object: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to register object: %m");
 
         r = sd_bus_request_name(m->bus, "org.freedesktop.resolve1", 0);
-        if (r < 0) {
-                log_error("Failed to register name: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to register name: %m");
 
         r = sd_bus_attach_event(m->bus, m->event, 0);
-        if (r < 0) {
-                log_error("Failed to attach bus to event loop: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to attach bus to event loop: %m");
 
         r = sd_bus_add_match(m->bus, &m->prepare_for_sleep_slot,
                              "type='signal',"
@@ -755,7 +749,7 @@ int manager_connect_bus(Manager *m) {
                              match_prepare_for_sleep,
                              m);
         if (r < 0)
-                log_error("Failed to add match for PrepareForSleep: %s", strerror(-r));
+                log_error_errno(r, "Failed to add match for PrepareForSleep: %m");
 
         return 0;
 }