]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd/sd-resolve/sd-resolve.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / libsystemd / sd-resolve / sd-resolve.c
index 653dbfbe57e19c4a943d09d3343b1f58b41ce54f..986768e7b398dc4f2e08714fe68a1ea152cf9576 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -217,9 +218,8 @@ static void *serialize_addrinfo(void *p, const struct addrinfo *ai, size_t *leng
 
         memcpy((uint8_t*) p, &s, sizeof(AddrInfoSerialization));
         memcpy((uint8_t*) p + sizeof(AddrInfoSerialization), ai->ai_addr, ai->ai_addrlen);
-
-        if (ai->ai_canonname)
-                memcpy((char*) p + sizeof(AddrInfoSerialization) + ai->ai_addrlen, ai->ai_canonname, cnl);
+        memcpy_safe((char*) p + sizeof(AddrInfoSerialization) + ai->ai_addrlen,
+                    ai->ai_canonname, cnl);
 
         *length += l;
         return (uint8_t*) p + l;
@@ -404,7 +404,7 @@ static void* thread_worker(void *p) {
         assert_se(pthread_sigmask(SIG_BLOCK, &fullset, NULL) == 0);
 
         /* Assign a pretty name to this thread */
-        prctl(PR_SET_NAME, (unsigned long) "sd-resolve");
+        (void) prctl(PR_SET_NAME, (unsigned long) "sd-resolve");
 
         while (!resolve->dead) {
                 union {
@@ -448,7 +448,7 @@ static int start_threads(sd_resolve *resolve, unsigned extra) {
                 if (r != 0)
                         return -r;
 
-                resolve->n_valid_workers ++;
+                resolve->n_valid_workers++;
         }
 
         return 0;
@@ -460,7 +460,7 @@ static bool resolve_pid_changed(sd_resolve *r) {
         /* We don't support people creating a resolver and keeping it
          * around after fork(). Let's complain. */
 
-        return r->original_pid != getpid();
+        return r->original_pid != getpid_cached();
 }
 
 _public_ int sd_resolve_new(sd_resolve **ret) {
@@ -474,7 +474,7 @@ _public_ int sd_resolve_new(sd_resolve **ret) {
                 return -ENOMEM;
 
         resolve->n_ref = 1;
-        resolve->original_pid = getpid();
+        resolve->original_pid = getpid_cached();
 
         for (i = 0; i < _FD_MAX; i++)
                 resolve->fds[i] = -1;
@@ -580,14 +580,13 @@ static void resolve_free(sd_resolve *resolve) {
                         (void) send(resolve->fds[REQUEST_SEND_FD], &req, req.length, MSG_NOSIGNAL);
         }
 
-        /* Now terminate them and wait until they are gone. */
+        /* Now terminate them and wait until they are gone.
+           If we get an error than most likely the thread already exited. */
         for (i = 0; i < resolve->n_valid_workers; i++)
-                pthread_join(resolve->workers[i], NULL);
+                (void) pthread_join(resolve->workers[i], NULL);
 
         /* Close all communication channels */
-        for (i = 0; i < _FD_MAX; i++)
-                safe_close(resolve->fds[i]);
-
+        close_many(resolve->fds, _FD_MAX);
         free(resolve);
 }
 
@@ -658,7 +657,7 @@ static int complete_query(sd_resolve *resolve, sd_resolve_query *q) {
         assert(q->resolve == resolve);
 
         q->done = true;
-        resolve->n_done ++;
+        resolve->n_done++;
 
         resolve->current = sd_resolve_query_ref(q);
 
@@ -1192,7 +1191,7 @@ static int io_callback(sd_event_source *s, int fd, uint32_t revents, void *userd
         return 1;
 }
 
-_public_ int sd_resolve_attach_event(sd_resolve *resolve, sd_event *event, int priority) {
+_public_ int sd_resolve_attach_event(sd_resolve *resolve, sd_event *event, int64_t priority) {
         int r;
 
         assert_return(resolve, -EINVAL);