+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
***/
#include <sys/prctl.h>
+#include <sys/wait.h>
#include "sd-bus.h"
safe_close(t->stdin_fd);
safe_close(t->stdout_fd);
- free(t);
- return NULL;
+ return mfree(t);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(Transfer*, transfer_unref);
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);
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
}
}
- 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) {
safe_close(null_fd);
}
- fd_cloexec(STDIN_FILENO, false);
- fd_cloexec(STDOUT_FILENO, false);
- fd_cloexec(STDERR_FILENO, false);
+ 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;
m->bus = sd_bus_flush_close_unref(m->bus);
sd_event_unref(m->event);
- free(m);
- return NULL;
+ return mfree(m);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref);
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;