[systemd-commits] src/libsystemd-bus

Tom Gundersen tomegun at kemper.freedesktop.org
Sun Jan 12 15:09:04 PST 2014


 src/libsystemd-bus/sd-dns.c   |   34 ++++++++++++++++++++--------------
 src/libsystemd-bus/test-dns.c |   21 ++++++++++-----------
 2 files changed, 30 insertions(+), 25 deletions(-)

New commits:
commit 8e50b5a77cd980ee57e0f75c59d0012d8df9a4f2
Author: Daniel Buch <boogiewasthere at gmail.com>
Date:   Sun Jan 12 19:42:33 2014 +0100

    sd-dns: coding style cleanup

diff --git a/src/libsystemd-bus/sd-dns.c b/src/libsystemd-bus/sd-dns.c
index 8126cb3..0f90d02 100644
--- a/src/libsystemd-bus/sd-dns.c
+++ b/src/libsystemd-bus/sd-dns.c
@@ -229,7 +229,8 @@ static int send_addrinfo_reply(int out_fd, unsigned id, int ret, struct addrinfo
                 struct addrinfo *k;
 
                 for (k = ai; k; k = k->ai_next) {
-                        if (!(p = serialize_addrinfo(p, k, &resp->header.length, (char*) data + BUFSIZE - (char*) p))) {
+                        p = serialize_addrinfo(p, k, &resp->header.length, (char*) data + BUFSIZE - (char*) p);
+                        if (!p) {
                                 resp->ret = EAI_MEMORY;
                                 break;
                         }
@@ -457,8 +458,8 @@ asyncns_t* asyncns_new(unsigned n_proc) {
 
         for (asyncns->valid_workers = 0; asyncns->valid_workers < n_proc; asyncns->valid_workers++) {
                 int r;
-
-                if ((r = pthread_create(&asyncns->workers[asyncns->valid_workers], NULL, thread_worker, asyncns)) != 0) {
+                r = pthread_create(&asyncns->workers[asyncns->valid_workers], NULL, thread_worker, asyncns);
+                if (r) {
                         errno = r;
                         goto fail;
                 }
@@ -532,7 +533,8 @@ static asyncns_query_t *lookup_query(asyncns_t *asyncns, unsigned id) {
         asyncns_query_t *q;
         assert(asyncns);
 
-        if ((q = asyncns->queries[id % MAX_QUERIES]))
+        q = asyncns->queries[id % MAX_QUERIES];
+        if (q)
                 if (q->id == id)
                         return q;
 
@@ -572,7 +574,8 @@ static const void *unserialize_addrinfo(const void *p, struct addrinfo **ret_ai,
         if (*length < l)
                 return NULL;
 
-        if (!(ai = malloc(sizeof(struct addrinfo))))
+        ai = malloc(sizeof(struct addrinfo));
+        if (!ai)
                 goto fail;
 
         ai->ai_addr = NULL;
@@ -626,7 +629,8 @@ static int handle_response(asyncns_t *asyncns, const packet_t *packet, size_t le
                 return 0;
         }
 
-        if (!(q = lookup_query(asyncns, resp->id)))
+        q = lookup_query(asyncns, resp->id);
+        if (!q)
                 return 0;
 
         switch (resp->type) {
@@ -730,7 +734,8 @@ int asyncns_wait(asyncns_t *asyncns, int block) {
                         return -1;
                 }
 
-                if (((l = recv(asyncns->fds[RESPONSE_RECV_FD], buf, sizeof(buf), 0)) < 0)) {
+                l = recv(asyncns->fds[RESPONSE_RECV_FD], buf, sizeof(buf), 0);
+                if (l < 0) {
                         fd_set fds;
 
                         if (errno != EAGAIN)
@@ -765,7 +770,6 @@ static asyncns_query_t *alloc_query(asyncns_t *asyncns) {
         }
 
         while (asyncns->queries[asyncns->current_index]) {
-
                 asyncns->current_index++;
                 asyncns->current_id++;
 
@@ -773,7 +777,8 @@ static asyncns_query_t *alloc_query(asyncns_t *asyncns) {
                         asyncns->current_index -= MAX_QUERIES;
         }
 
-        if (!(q = asyncns->queries[asyncns->current_index] = malloc(sizeof(asyncns_query_t)))) {
+        q = asyncns->queries[asyncns->current_index] = malloc(sizeof(asyncns_query_t));
+        if (!q) {
                 errno = ENOMEM;
                 return NULL;
         }
@@ -806,10 +811,10 @@ asyncns_query_t* asyncns_getaddrinfo(asyncns_t *asyncns, const char *node, const
                 return NULL;
         }
 
-        if (!(q = alloc_query(asyncns)))
+        q = alloc_query(asyncns);
+        if (!q)
                 return NULL;
 
-
         req->node_len = node ? strlen(node)+1 : 0;
         req->service_len = service ? strlen(service)+1 : 0;
 
@@ -892,10 +897,10 @@ asyncns_query_t* asyncns_getnameinfo(asyncns_t *asyncns, const struct sockaddr *
                 return NULL;
         }
 
-        if (!(q = alloc_query(asyncns)))
+        q = alloc_query(asyncns);
+        if (!q)
                 return NULL;
 
-
         req->header.id = q->id;
         req->header.type = q->type = REQUEST_NAMEINFO;
         req->header.length = sizeof(nameinfo_request_t) + salen;
@@ -977,7 +982,8 @@ static asyncns_query_t * asyncns_res(asyncns_t *asyncns, query_type_t qtype, con
                 return NULL;
         }
 
-        if (!(q = alloc_query(asyncns)))
+        q = alloc_query(asyncns);
+        if (!q)
                 return NULL;
 
         req->dname_len = strlen(dname) + 1;
diff --git a/src/libsystemd-bus/test-dns.c b/src/libsystemd-bus/test-dns.c
index 3e326ba..b4f064f 100644
--- a/src/libsystemd-bus/test-dns.c
+++ b/src/libsystemd-bus/test-dns.c
@@ -56,7 +56,6 @@ int main(int argc, char *argv[]) {
         hints.ai_socktype = SOCK_STREAM;
 
         q1 = asyncns_getaddrinfo(asyncns, argc >= 2 ? argv[1] : "www.heise.de", NULL, &hints);
-
         if (!q1)
                 fprintf(stderr, "asyncns_getaddrinfo(): %s\n", strerror(errno));
 
@@ -66,27 +65,25 @@ int main(int argc, char *argv[]) {
         sa.sin_port = htons(80);
 
         q2 = asyncns_getnameinfo(asyncns, (struct sockaddr*) &sa, sizeof(sa), 0, 1, 1);
-
         if (!q2)
                 fprintf(stderr, "asyncns_getnameinfo(): %s\n", strerror(errno));
 
         /* Make a res_query() call */
         q3 = asyncns_res_query(asyncns, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV);
-
         if (!q3)
                 fprintf(stderr, "asyncns_res_query(): %s\n", strerror(errno));
 
         /* Wait until the three queries are completed */
-        while (!asyncns_isdone(asyncns, q1)
-                        || !asyncns_isdone(asyncns, q2)
-                        || !asyncns_isdone(asyncns, q3)) {
-                if (asyncns_wait(asyncns, 1) < 0) {
+        while (!asyncns_isdone(asyncns, q1) ||
+               !asyncns_isdone(asyncns, q2) ||
+               !asyncns_isdone(asyncns, q3)) {
+                if (asyncns_wait(asyncns, 1) < 0)
                         fprintf(stderr, "asyncns_wait(): %s\n", strerror(errno));
-                }
         }
 
         /* Interpret the result of the name -> addr query */
-        if ((ret = asyncns_getaddrinfo_done(asyncns, q1, &ai)))
+        ret = asyncns_getaddrinfo_done(asyncns, q1, &ai);
+        if (ret)
                 fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret);
         else {
                 struct addrinfo *i;
@@ -105,13 +102,15 @@ int main(int argc, char *argv[]) {
         }
 
         /* Interpret the result of the addr -> name query */
-        if ((ret = asyncns_getnameinfo_done(asyncns, q2, host, sizeof(host), serv, sizeof(serv))))
+        ret = asyncns_getnameinfo_done(asyncns, q2, host, sizeof(host), serv, sizeof(serv));
+        if (ret)
                 fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret);
         else
                 printf("%s -- %s\n", host, serv);
 
         /* Interpret the result of the SRV lookup */
-        if ((ret = asyncns_res_done(asyncns, q3, &srv)) < 0) {
+        ret = asyncns_res_done(asyncns, q3, &srv);
+        if (ret < 0) {
                 fprintf(stderr, "error: %s %i\n", strerror(errno), ret);
         } else if (ret == 0) {
                 fprintf(stderr, "No reply for SRV lookup\n");



More information about the systemd-commits mailing list