]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/import/importd.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / import / importd.c
index 9d31a956a548e0362b644b822ae65e488c5827a3..9c7694c0ad1e5c238179594585c20a1942f74b10 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -18,6 +19,7 @@
 ***/
 
 #include <sys/prctl.h>
+#include <sys/wait.h>
 
 #include "sd-bus.h"
 
@@ -250,7 +252,7 @@ static void transfer_send_logs(Transfer *t, bool flush) {
                 n = strndup(t->log_message, e - t->log_message);
 
                 /* Skip over NUL and newlines */
-                while ((e < t->log_message + t->log_message_size) && (*e == 0 || *e == '\n'))
+                while (e < t->log_message + t->log_message_size && (*e == 0 || *e == '\n'))
                         e++;
 
                 memmove(t->log_message, e, t->log_message + sizeof(t->log_message) - e);
@@ -321,8 +323,7 @@ static int transfer_on_pid(sd_event_source *s, const siginfo_t *si, void *userda
                         success = true;
                 }
 
-        } else if (si->si_code == CLD_KILLED ||
-                   si->si_code == CLD_DUMPED)
+        } else if (IN_SET(si->si_code, CLD_KILLED, CLD_DUMPED))
 
                 log_error("Import process terminated by signal %s.", signal_to_string(si->si_status));
         else
@@ -418,7 +419,7 @@ static int transfer_start(Transfer *t) {
                         }
                 }
 
-                if (pipefd[1] != STDOUT_FILENO && pipefd[1] != STDERR_FILENO)
+                if (!IN_SET(pipefd[1], STDOUT_FILENO, STDERR_FILENO))
                         pipefd[1] = safe_close(pipefd[1]);
 
                 if (t->stdin_fd >= 0) {
@@ -449,8 +450,11 @@ static int transfer_start(Transfer *t) {
 
                 stdio_unset_cloexec();
 
-                setenv("SYSTEMD_LOG_TARGET", "console-prefixed", 1);
-                setenv("NOTIFY_SOCKET", "/run/systemd/import/notify", 1);
+                if (setenv("SYSTEMD_LOG_TARGET", "console-prefixed", 1) < 0 ||
+                    setenv("NOTIFY_SOCKET", "/run/systemd/import/notify", 1) < 0) {
+                        log_error_errno(errno, "setenv() failed: %m");
+                        _exit(EXIT_FAILURE);
+                }
 
                 if (IN_SET(t->type, TRANSFER_IMPORT_TAR, TRANSFER_IMPORT_RAW))
                         cmd[k++] = SYSTEMD_IMPORT_PATH;
@@ -582,7 +586,7 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void
 
         n = recvmsg(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
         if (n < 0) {
-                if (errno == EAGAIN || errno == EINTR)
+                if (IN_SET(errno, EAGAIN, EINTR))
                         return 0;
 
                 return -errno;