treewide: use log_*_errno whenever %m is in the format string

If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
This commit is contained in:
Michal Schmidt 2014-11-28 19:29:59 +01:00
parent 895b3a7b44
commit 56f64d9576
139 changed files with 741 additions and 728 deletions

View File

@ -52,7 +52,7 @@ static int add_epoll(int epoll_fd, int fd) {
ev.data.fd = fd;
r = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
if (r < 0) {
log_error("Failed to add event on epoll fd:%d for fd:%d: %m", epoll_fd, fd);
log_error_errno(errno, "Failed to add event on epoll fd:%d for fd:%d: %m", epoll_fd, fd);
return -errno;
}
@ -112,7 +112,7 @@ static int open_sockets(int *epoll_fd, bool accept) {
*epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (*epoll_fd < 0) {
log_error("Failed to create epoll object: %m");
log_error_errno(errno, "Failed to create epoll object: %m");
return -errno;
}
@ -175,7 +175,7 @@ static int launch(char* name, char **argv, char **env, int fds) {
log_info("Execing %s (%s)", name, tmp);
execvpe(name, argv, envp);
log_error("Failed to execp %s (%s): %m", name, tmp);
log_error_errno(errno, "Failed to execp %s (%s): %m", name, tmp);
return -errno;
}
@ -193,7 +193,7 @@ static int launch1(const char* child, char** argv, char **env, int fd) {
child_pid = fork();
if (child_pid < 0) {
log_error("Failed to fork: %m");
log_error_errno(errno, "Failed to fork: %m");
return -errno;
}
@ -201,19 +201,19 @@ static int launch1(const char* child, char** argv, char **env, int fd) {
if (child_pid == 0) {
r = dup2(fd, STDIN_FILENO);
if (r < 0) {
log_error("Failed to dup connection to stdin: %m");
log_error_errno(errno, "Failed to dup connection to stdin: %m");
_exit(EXIT_FAILURE);
}
r = dup2(fd, STDOUT_FILENO);
if (r < 0) {
log_error("Failed to dup connection to stdout: %m");
log_error_errno(errno, "Failed to dup connection to stdout: %m");
_exit(EXIT_FAILURE);
}
r = close(fd);
if (r < 0) {
log_error("Failed to close dupped connection: %m");
log_error_errno(errno, "Failed to close dupped connection: %m");
_exit(EXIT_FAILURE);
}
@ -227,7 +227,7 @@ static int launch1(const char* child, char** argv, char **env, int fd) {
_exit(EXIT_SUCCESS);
execvp(child, argv);
log_error("Failed to exec child %s: %m", child);
log_error_errno(errno, "Failed to exec child %s: %m", child);
_exit(EXIT_FAILURE);
}
@ -242,7 +242,7 @@ static int do_accept(const char* name, char **argv, char **envp, int fd) {
fd2 = accept(fd, NULL, NULL);
if (fd2 < 0) {
log_error("Failed to accept connection on fd:%d: %m", fd);
log_error_errno(errno, "Failed to accept connection on fd:%d: %m", fd);
return fd2;
}
@ -271,7 +271,7 @@ static int install_chld_handler(void) {
r = sigaction(SIGCHLD, &act, 0);
if (r < 0)
log_error("Failed to install SIGCHLD handler: %m");
log_error_errno(errno, "Failed to install SIGCHLD handler: %m");
return r;
}
@ -389,7 +389,7 @@ int main(int argc, char **argv, char **envp) {
if (errno == EINTR)
continue;
log_error("epoll_wait() failed: %m");
log_error_errno(errno, "epoll_wait() failed: %m");
return EXIT_FAILURE;
}

View File

@ -318,7 +318,7 @@ int main(int argc, char *argv[]) {
device = udev_device_new_from_subsystem_sysname(udev, ss, sysname);
if (!device) {
if (errno != 0)
log_error("Failed to get backlight or LED device '%s:%s': %m", ss, sysname);
log_error_errno(errno, "Failed to get backlight or LED device '%s:%s': %m", ss, sysname);
else
log_oom();

View File

@ -93,7 +93,7 @@ static int apply_file(const char *path, bool ignore_enoent) {
if (feof(f))
break;
log_error("Failed to read file '%s', ignoring: %m", path);
log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
return -errno;
}

View File

@ -285,7 +285,7 @@ static void do_journal_append(char *file) {
f = open(file, O_RDONLY|O_CLOEXEC);
if (f < 0) {
log_error("Failed to read bootchart data: %m");
log_error_errno(errno, "Failed to read bootchart data: %m");
return;
}
n = loop_read(f, p + 10, BOOTCHART_MAX, false);
@ -434,7 +434,7 @@ int main(int argc, char *argv[]) {
/* caught signal, probably HUP! */
break;
}
log_error("nanosleep() failed: %m");
log_error_errno(errno, "nanosleep() failed: %m");
exit(EXIT_FAILURE);
}
} else {

View File

@ -146,7 +146,7 @@ void log_sample(int sample, struct list_sample_data **ptr) {
/* block stuff */
vmstat = openat(procfd, "vmstat", O_RDONLY);
if (vmstat == -1) {
log_error("Failed to open /proc/vmstat: %m");
log_error_errno(errno, "Failed to open /proc/vmstat: %m");
exit(EXIT_FAILURE);
}
}
@ -178,7 +178,7 @@ vmstat_next:
/* overall CPU utilization */
schedstat = openat(procfd, "schedstat", O_RDONLY);
if (schedstat == -1) {
log_error("Failed to open /proc/schedstat: %m");
log_error_errno(errno, "Failed to open /proc/schedstat: %m");
exit(EXIT_FAILURE);
}
}

View File

@ -1719,7 +1719,7 @@ int main(int argc, char *argv[]) {
r = ppoll(pollfd, 3, ts, NULL);
if (r < 0) {
log_error("ppoll() failed: %m");
log_error_errno(errno, "ppoll() failed: %m");
goto finish;
}
}

View File

@ -186,7 +186,7 @@ int main(int argc, char *argv[]) {
p = get_current_dir_name();
if (!p) {
log_error("Cannot determine current working directory: %m");
log_error_errno(errno, "Cannot determine current working directory: %m");
goto finish;
}

View File

@ -165,7 +165,7 @@ void terminal_run(Terminal *t) {
setenv("COLORTERM", "systemd-console", 1);
execve(argv[0], argv, environ);
log_error("Cannot exec %s (%d): %m", argv[0], -errno);
log_error_errno(errno, "Cannot exec %s (%d): %m", argv[0], -errno);
_exit(1);
}
}

View File

@ -41,7 +41,7 @@ int get_audit_fd(void) {
if (audit_fd < 0) {
if (errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT)
log_error("Failed to connect to audit log: %m");
log_error_errno(errno, "Failed to connect to audit log: %m");
audit_fd = errno ? -errno : -EINVAL;
}

View File

@ -75,7 +75,7 @@ static void repeat_unmount(const char *path) {
continue;
if (errno != EINVAL)
log_error("Failed to unmount: %m");
log_error_errno(errno, "Failed to unmount: %m");
break;
}
@ -301,7 +301,7 @@ static int open_dev_autofs(Manager *m) {
m->dev_autofs_fd = open("/dev/autofs", O_CLOEXEC|O_RDONLY);
if (m->dev_autofs_fd < 0) {
log_error("Failed to open /dev/autofs: %m");
log_error_errno(errno, "Failed to open /dev/autofs: %m");
return -errno;
}

View File

@ -154,7 +154,7 @@ static int lookup_blkio_device(const char *p, dev_t *dev) {
r = stat(p, &st);
if (r < 0) {
log_warning("Couldn't stat device %s: %m", p);
log_warning_errno(errno, "Couldn't stat device %s: %m", p);
return -errno;
}
@ -219,7 +219,7 @@ static int whitelist_major(const char *path, const char *name, char type, const
f = fopen("/proc/devices", "re");
if (!f) {
log_warning("Cannot open /proc/devices to resolve %s (%c): %m", name, type);
log_warning_errno(errno, "Cannot open /proc/devices to resolve %s (%c): %m", name, type);
return -errno;
}
@ -280,7 +280,7 @@ static int whitelist_major(const char *path, const char *name, char type, const
return 0;
fail:
log_warning("Failed to read /proc/devices: %m");
log_warning_errno(errno, "Failed to read /proc/devices: %m");
return -errno;
}
@ -906,7 +906,7 @@ int manager_setup_cgroup(Manager *m) {
m->pin_cgroupfs_fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY|O_NONBLOCK);
if (m->pin_cgroupfs_fd < 0) {
log_error("Failed to open pin file: %m");
log_error_errno(errno, "Failed to open pin file: %m");
return -errno;
}

View File

@ -624,7 +624,7 @@ static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void
nfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
if (nfd < 0) {
log_warning("Failed to accept private connection, ignoring: %m");
log_warning_errno(errno, "Failed to accept private connection, ignoring: %m");
return 0;
}
@ -959,19 +959,19 @@ static int bus_init_private(Manager *m) {
fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (fd < 0) {
log_error("Failed to allocate private socket: %m");
log_error_errno(errno, "Failed to allocate private socket: %m");
return -errno;
}
r = bind(fd, &sa.sa, salen);
if (r < 0) {
log_error("Failed to bind private socket: %m");
log_error_errno(errno, "Failed to bind private socket: %m");
return -errno;
}
r = listen(fd, SOMAXCONN);
if (r < 0) {
log_error("Failed to make private socket listening: %m");
log_error_errno(errno, "Failed to make private socket listening: %m");
return -errno;
}

View File

@ -628,7 +628,7 @@ static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
static RATELIMIT_DEFINE(limit, 10*USEC_PER_SEC, 5);
if (!ratelimit_test(&limit))
log_error("Failed to get udev event: %m");
log_error_errno(errno, "Failed to get udev event: %m");
if (!(revents & EPOLLIN))
return 0;
}

View File

@ -885,7 +885,7 @@ fail:
log_error("PAM failed: %s", pam_strerror(handle, pam_code));
err = -EPERM; /* PAM errors do not map to errno */
} else {
log_error("PAM failed: %m");
log_error_errno(errno, "PAM failed: %m");
err = -errno;
}

View File

@ -83,7 +83,7 @@ int hostname_setup(void) {
}
if (sethostname_idempotent(hn) < 0) {
log_warning("Failed to set hostname to <%s>: %m", hn);
log_warning_errno(errno, "Failed to set hostname to <%s>: %m", hn);
return -errno;
}

View File

@ -60,36 +60,35 @@ int ima_setup(void) {
}
if (stat(IMA_SECFS_POLICY, &st) < 0) {
log_error("Another IMA custom policy has already been loaded, "
"ignoring.");
log_error("Another IMA custom policy has already been loaded, ignoring.");
return 0;
}
policyfd = open(IMA_POLICY_PATH, O_RDONLY|O_CLOEXEC);
if (policyfd < 0) {
log_error("Failed to open the IMA custom policy file %s (%m), "
"ignoring.", IMA_POLICY_PATH);
log_error_errno(errno, "Failed to open the IMA custom policy file %s (%m), ignoring.",
IMA_POLICY_PATH);
return 0;
}
imafd = open(IMA_SECFS_POLICY, O_WRONLY|O_CLOEXEC);
if (imafd < 0) {
log_error("Failed to open the IMA kernel interface %s (%m), "
"ignoring.", IMA_SECFS_POLICY);
log_error_errno(errno, "Failed to open the IMA kernel interface %s (%m), ignoring.",
IMA_SECFS_POLICY);
goto out;
}
policy = mmap(NULL, policy_size, PROT_READ, MAP_PRIVATE, policyfd, 0);
if (policy == MAP_FAILED) {
log_error("mmap() failed (%m), freezing");
log_error_errno(errno, "mmap() failed (%m), freezing");
result = -errno;
goto out;
}
written = loop_write(imafd, policy, (size_t)policy_size, false);
if (written != policy_size) {
log_error("Failed to load the IMA custom policy file %s (%m), "
"ignoring.", IMA_POLICY_PATH);
log_error_errno(errno, "Failed to load the IMA custom policy file %s (%m), ignoring.",
IMA_POLICY_PATH);
goto out_mmap;
}

View File

@ -102,7 +102,7 @@ static void wait_for_children(Set *pids, sigset_t *mask) {
if (errno == ECHILD)
break;
log_error("waitpid() failed: %m");
log_error_errno(errno, "waitpid() failed: %m");
return;
}
@ -136,7 +136,7 @@ static void wait_for_children(Set *pids, sigset_t *mask) {
if (k != SIGCHLD) {
if (k < 0 && errno != EAGAIN) {
log_error("sigtimedwait() failed: %m");
log_error_errno(errno, "sigtimedwait() failed: %m");
return;
}
@ -178,7 +178,7 @@ static int killall(int sig, Set *pids, bool send_sighup) {
if (pids)
set_put(pids, ULONG_TO_PTR(pid));
} else if (errno != ENOENT)
log_warning("Could not kill %d: %m", pid);
log_warning_errno(errno, "Could not kill %d: %m", pid);
if (send_sighup) {
/* Optionally, also send a SIGHUP signal, but
@ -212,12 +212,12 @@ void broadcast_signal(int sig, bool wait_for_exit, bool send_sighup) {
assert_se(sigprocmask(SIG_BLOCK, &mask, &oldmask) == 0);
if (kill(-1, SIGSTOP) < 0 && errno != ESRCH)
log_warning("kill(-1, SIGSTOP) failed: %m");
log_warning_errno(errno, "kill(-1, SIGSTOP) failed: %m");
killall(sig, pids, send_sighup);
if (kill(-1, SIGCONT) < 0 && errno != ESRCH)
log_warning("kill(-1, SIGCONT) failed: %m");
log_warning_errno(errno, "kill(-1, SIGCONT) failed: %m");
if (wait_for_exit)
wait_for_children(pids, &mask);

View File

@ -58,7 +58,7 @@ static int iterate_dir(
if (errno == ENOENT)
return 0;
log_error("Failed to open directory %s: %m", path);
log_error_errno(errno, "Failed to open directory %s: %m", path);
return -errno;
}

View File

@ -196,7 +196,7 @@ int machine_id_setup(const char *root) {
"2) /etc/machine-id exists and is empty.\n"
"3) /etc/machine-id is missing and /etc is writable.\n");
else
log_error("Cannot open %s: %m", etc_machine_id);
log_error_errno(errno, "Cannot open %s: %m", etc_machine_id);
return -errno;
}
@ -205,7 +205,7 @@ int machine_id_setup(const char *root) {
}
if (fstat(fd, &st) < 0) {
log_error("fstat() failed: %m");
log_error_errno(errno, "fstat() failed: %m");
return -errno;
}
@ -248,7 +248,7 @@ int machine_id_setup(const char *root) {
/* And now, let's mount it over */
r = mount(run_machine_id, etc_machine_id, NULL, MS_BIND, NULL);
if (r < 0) {
log_error("Failed to mount %s: %m", etc_machine_id);
log_error_errno(errno, "Failed to mount %s: %m", etc_machine_id);
unlink_noerrno(run_machine_id);
return -errno;
}
@ -257,7 +257,7 @@ int machine_id_setup(const char *root) {
/* Mark the mount read-only */
if (mount(NULL, etc_machine_id, NULL, MS_BIND|MS_RDONLY|MS_REMOUNT, NULL) < 0)
log_warning("Failed to make transient %s read-only: %m", etc_machine_id);
log_warning_errno(errno, "Failed to make transient %s read-only: %m", etc_machine_id);
return 0;
}

View File

@ -144,7 +144,7 @@ noreturn static void crash(int sig) {
pid = fork();
if (pid < 0)
log_emergency("Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
log_emergency_errno(errno, "Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
else if (pid == 0) {
struct rlimit rl = {};
@ -201,12 +201,12 @@ noreturn static void crash(int sig) {
pid = fork();
if (pid < 0)
log_emergency("Failed to fork off crash shell: %m");
log_emergency_errno(errno, "Failed to fork off crash shell: %m");
else if (pid == 0) {
make_console_stdio();
execl("/bin/sh", "/bin/sh", NULL);
log_emergency("execl() failed: %m");
log_emergency_errno(errno, "execl() failed: %m");
_exit(1);
}
@ -885,7 +885,7 @@ static int parse_argv(int argc, char *argv[]) {
f = fdopen(fd, "r");
if (!f) {
log_error("Failed to open serialization fd: %m");
log_error_errno(errno, "Failed to open serialization fd: %m");
return -errno;
}
@ -1006,7 +1006,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching
}
if (fseeko(f, 0, SEEK_SET) < 0) {
log_error("Failed to rewind serialization fd: %m");
log_error_errno(errno, "Failed to rewind serialization fd: %m");
goto fail;
}
@ -1046,7 +1046,7 @@ static int bump_rlimit_nofile(struct rlimit *saved_rlimit) {
* later when transitioning from the initrd to the main
* systemd or suchlike. */
if (getrlimit(RLIMIT_NOFILE, saved_rlimit) < 0) {
log_error("Reading RLIMIT_NOFILE failed: %m");
log_error_errno(errno, "Reading RLIMIT_NOFILE failed: %m");
return -errno;
}
@ -1234,7 +1234,7 @@ int main(int argc, char *argv[]) {
errno = -ENOENT;
execv(SYSTEMCTL_BINARY_PATH, argv);
log_error("Failed to exec " SYSTEMCTL_BINARY_PATH ": %m");
log_error_errno(errno, "Failed to exec " SYSTEMCTL_BINARY_PATH ": %m");
return 1;
}
#endif
@ -1578,7 +1578,7 @@ int main(int argc, char *argv[]) {
if (arg_timer_slack_nsec != NSEC_INFINITY)
if (prctl(PR_SET_TIMERSLACK, arg_timer_slack_nsec) < 0)
log_error("Failed to adjust timer slack: %m");
log_error_errno(errno, "Failed to adjust timer slack: %m");
if (arg_capability_bounding_set_drop) {
r = capability_bounding_set_drop_usermode(arg_capability_bounding_set_drop);
@ -1606,7 +1606,7 @@ int main(int argc, char *argv[]) {
if (arg_running_as == SYSTEMD_USER) {
/* Become reaper of our children */
if (prctl(PR_SET_CHILD_SUBREAPER, 1) < 0) {
log_warning("Failed to make us a subreaper: %m");
log_warning_errno(errno, "Failed to make us a subreaper: %m");
if (errno == EINVAL)
log_info("Perhaps the kernel version is too old (< 3.4?)");
}
@ -1937,7 +1937,7 @@ finish:
if (switch_root_init) {
args[0] = switch_root_init;
execv(args[0], (char* const*) args);
log_warning("Failed to execute configured init, trying fallback: %m");
log_warning_errno(errno, "Failed to execute configured init, trying fallback: %m");
}
args[0] = "/sbin/init";
@ -1949,9 +1949,9 @@ finish:
args[0] = "/bin/sh";
args[1] = NULL;
execv(args[0], (char* const*) args);
log_error("Failed to execute /bin/sh, giving up: %m");
log_error_errno(errno, "Failed to execute /bin/sh, giving up: %m");
} else
log_warning("Failed to execute /sbin/init, giving up: %m");
log_warning_errno(errno, "Failed to execute /sbin/init, giving up: %m");
}
if (arg_serialization) {
@ -2032,7 +2032,7 @@ finish:
cg_uninstall_release_agent(SYSTEMD_CGROUP_CONTROLLER);
execve(SYSTEMD_SHUTDOWN_BINARY_PATH, (char **) command_line, env_block);
log_error("Failed to execute shutdown binary, %s: %m",
log_error_errno(errno, "Failed to execute shutdown binary, %s: %m",
getpid() == 1 ? "freezing" : "quitting");
}

View File

@ -263,12 +263,12 @@ static int manager_check_ask_password(Manager *m) {
m->ask_password_inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
if (m->ask_password_inotify_fd < 0) {
log_error("inotify_init1() failed: %m");
log_error_errno(errno, "inotify_init1() failed: %m");
return -errno;
}
if (inotify_add_watch(m->ask_password_inotify_fd, "/run/systemd/ask-password", IN_CREATE|IN_DELETE|IN_MOVE) < 0) {
log_error("Failed to add watch on /run/systemd/ask-password: %m");
log_error_errno(errno, "Failed to add watch on /run/systemd/ask-password: %m");
manager_close_ask_password(m);
return -errno;
}
@ -277,7 +277,7 @@ static int manager_check_ask_password(Manager *m) {
m->ask_password_inotify_fd, EPOLLIN,
manager_dispatch_ask_password_fd, m);
if (r < 0) {
log_error("Failed to add event source for /run/systemd/ask-password: %m");
log_error_errno(errno, "Failed to add event source for /run/systemd/ask-password: %m");
manager_close_ask_password(m);
return -errno;
}
@ -335,12 +335,12 @@ static int manager_setup_time_change(Manager *m) {
m->time_change_fd = timerfd_create(CLOCK_REALTIME, TFD_NONBLOCK|TFD_CLOEXEC);
if (m->time_change_fd < 0) {
log_error("Failed to create timerfd: %m");
log_error_errno(errno, "Failed to create timerfd: %m");
return -errno;
}
if (timerfd_settime(m->time_change_fd, TFD_TIMER_ABSTIME|TFD_TIMER_CANCEL_ON_SET, &its, NULL) < 0) {
log_debug("Failed to set up TFD_TIMER_CANCEL_ON_SET, ignoring: %m");
log_debug_errno(errno, "Failed to set up TFD_TIMER_CANCEL_ON_SET, ignoring: %m");
m->time_change_fd = safe_close(m->time_change_fd);
return 0;
}
@ -363,17 +363,17 @@ static int enable_special_signals(Manager *m) {
* this will fail with EPERM (older) or EINVAL (newer), so
* ignore that. */
if (reboot(RB_DISABLE_CAD) < 0 && errno != EPERM && errno != EINVAL)
log_warning("Failed to enable ctrl-alt-del handling: %m");
log_warning_errno(errno, "Failed to enable ctrl-alt-del handling: %m");
fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0) {
/* Support systems without virtual console */
if (fd != -ENOENT)
log_warning("Failed to open /dev/tty0: %m");
log_warning_errno(errno, "Failed to open /dev/tty0: %m");
} else {
/* Enable that we get SIGWINCH on kbrequest */
if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0)
log_warning("Failed to enable kbrequest handling: %m");
log_warning_errno(errno, "Failed to enable kbrequest handling: %m");
}
return 0;
@ -648,7 +648,7 @@ static int manager_setup_notify(Manager *m) {
fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (fd < 0) {
log_error("Failed to allocate notification socket: %m");
log_error_errno(errno, "Failed to allocate notification socket: %m");
return -errno;
}
@ -659,7 +659,7 @@ static int manager_setup_notify(Manager *m) {
e = getenv("XDG_RUNTIME_DIR");
if (!e) {
log_error("XDG_RUNTIME_DIR is not set: %m");
log_error_errno(errno, "XDG_RUNTIME_DIR is not set: %m");
return -EINVAL;
}
@ -674,13 +674,13 @@ static int manager_setup_notify(Manager *m) {
strncpy(sa.un.sun_path, m->notify_socket, sizeof(sa.un.sun_path)-1);
r = bind(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path));
if (r < 0) {
log_error("bind(%s) failed: %m", sa.un.sun_path);
log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
return -errno;
}
r = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
if (r < 0) {
log_error("SO_PASSCRED failed: %m");
log_error_errno(errno, "SO_PASSCRED failed: %m");
return -errno;
}
@ -1022,7 +1022,7 @@ static void manager_build_unit_path_cache(Manager *m) {
d = opendir(*i);
if (!d) {
if (errno != ENOENT)
log_error("Failed to open directory %s: %m", *i);
log_error_errno(errno, "Failed to open directory %s: %m", *i);
continue;
}
@ -2070,7 +2070,7 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
* Then let's not retry again. */
close_audit_fd();
else
log_warning("Failed to send audit message: %m");
log_warning_errno(errno, "Failed to send audit message: %m");
}
#endif
@ -2103,14 +2103,14 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
* message then wait for plymouth */
fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (fd < 0) {
log_error("socket() failed: %m");
log_error_errno(errno, "socket() failed: %m");
return;
}
if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
if (!IN_SET(errno, EPIPE, EAGAIN, ENOENT, ECONNREFUSED, ECONNRESET, ECONNABORTED))
log_error("connect() failed: %m");
log_error_errno(errno, "connect() failed: %m");
return;
}
@ -2122,7 +2122,7 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
errno = 0;
if (write(fd, message, n + 1) != n + 1)
if (!IN_SET(errno, EPIPE, EAGAIN, ENOENT, ECONNREFUSED, ECONNRESET, ECONNABORTED))
log_error("Failed to write Plymouth message: %m");
log_error_errno(errno, "Failed to write Plymouth message: %m");
}
void manager_dispatch_bus_name_owner_changed(
@ -2715,7 +2715,7 @@ static int create_generator_dir(Manager *m, char **generator, const char *name)
return log_oom();
if (!mkdtemp(p)) {
log_error("Failed to create generator directory %s: %m",
log_error_errno(errno, "Failed to create generator directory %s: %m",
p);
free(p);
return -errno;
@ -2758,7 +2758,7 @@ void manager_run_generators(Manager *m) {
if (errno == ENOENT)
return;
log_error("Failed to enumerate generator directory %s: %m",
log_error_errno(errno, "Failed to enumerate generator directory %s: %m",
generator_path);
return;
}

View File

@ -235,7 +235,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
f = fopen("/proc/cgroups", "re");
if (!f) {
log_error("Failed to enumerate cgroup controllers: %m");
log_error_errno(errno, "Failed to enumerate cgroup controllers: %m");
return 0;
}
@ -341,7 +341,7 @@ int mount_cgroup_controllers(char ***join_controllers) {
r = symlink(options, t);
if (r < 0 && errno != EEXIST) {
log_error("Failed to create symlink %s: %m", t);
log_error_errno(errno, "Failed to create symlink %s: %m", t);
return -errno;
}
}
@ -428,7 +428,7 @@ int mount_setup(bool loaded_policy) {
* propagation mode to private if needed. */
if (detect_container(NULL) <= 0)
if (mount(NULL, "/", NULL, MS_REC|MS_SHARED, NULL) < 0)
log_warning("Failed to set up the root directory for shared mount propagation: %m");
log_warning_errno(errno, "Failed to set up the root directory for shared mount propagation: %m");
/* Create a few directories we always want around, Note that
* sd_booted() checks for /run/systemd/system, so this mkdir

View File

@ -277,7 +277,7 @@ static int mount_kdbus(BindMount *m) {
u = umask(0000);
if (!mkdtemp(temporary_mount)) {
log_error("Failed create temp dir: %m");
log_error_errno(errno, "Failed create temp dir: %m");
return -errno;
}
@ -291,21 +291,21 @@ static int mount_kdbus(BindMount *m) {
/* create a new /dev/null dev node copy so we have some fodder to
* bind-mount the custom endpoint over. */
if (stat("/dev/null", &st) < 0) {
log_error("Failed to stat /dev/null: %m");
log_error_errno(errno, "Failed to stat /dev/null: %m");
r = -errno;
goto fail;
}
busnode = strappenda(root, "/bus");
if (mknod(busnode, (st.st_mode & ~07777) | 0600, st.st_rdev) < 0) {
log_error("mknod() for %s failed: %m", busnode);
log_error_errno(errno, "mknod() for %s failed: %m", busnode);
r = -errno;
goto fail;
}
r = mount(m->path, busnode, "bind", MS_BIND, NULL);
if (r < 0) {
log_error("bind mount of %s failed: %m", m->path);
log_error_errno(errno, "bind mount of %s failed: %m", m->path);
r = -errno;
goto fail;
}
@ -317,7 +317,7 @@ static int mount_kdbus(BindMount *m) {
}
if (mount(root, basepath, NULL, MS_MOVE, NULL) < 0) {
log_error("bind mount of %s failed: %m", basepath);
log_error_errno(errno, "bind mount of %s failed: %m", basepath);
r = -errno;
goto fail;
}

View File

@ -136,7 +136,7 @@ int path_spec_watch(PathSpec *s, sd_event_io_handler_t handler) {
}
if (!exists) {
log_error("Failed to add watch on any of the components of %s: %m",
log_error_errno(errno, "Failed to add watch on any of the components of %s: %m",
s->path);
r = -errno; /* either EACCESS or ENOENT */
goto fail;
@ -169,7 +169,7 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) {
}
if (ioctl(s->inotify_fd, FIONREAD, &l) < 0) {
log_error("FIONREAD failed: %m");
log_error_errno(errno, "FIONREAD failed: %m");
return -errno;
}
@ -181,7 +181,7 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) {
k = read(s->inotify_fd, buf, l);
if (k < 0) {
log_error("Failed to read inotify event: %m");
log_error_errno(errno, "Failed to read inotify event: %m");
return -errno;
}

View File

@ -127,7 +127,7 @@ static int access_init(void) {
int r = 0;
if (avc_open(NULL, 0)) {
log_error("avc_open() failed: %m");
log_error_errno(errno, "avc_open() failed: %m");
return -errno;
}

View File

@ -139,12 +139,12 @@ static int parse_argv(int argc, char *argv[]) {
static int switch_root_initramfs(void) {
if (mount("/run/initramfs", "/run/initramfs", NULL, MS_BIND, NULL) < 0) {
log_error("Failed to mount bind /run/initramfs on /run/initramfs: %m");
log_error_errno(errno, "Failed to mount bind /run/initramfs on /run/initramfs: %m");
return -errno;
}
if (mount(NULL, "/run/initramfs", NULL, MS_PRIVATE, NULL) < 0) {
log_error("Failed to make /run/initramfs private mount: %m");
log_error_errno(errno, "Failed to make /run/initramfs private mount: %m");
return -errno;
}
@ -327,7 +327,7 @@ int main(int argc, char *argv[]) {
"Returning to initrd...");
execv("/shutdown", argv);
log_error("Failed to execute shutdown binary: %m");
log_error_errno(errno, "Failed to execute shutdown binary: %m");
} else
log_error_errno(r, "Failed to switch root to \"/run/initramfs\": %m");
@ -359,7 +359,7 @@ int main(int argc, char *argv[]) {
pid = fork();
if (pid < 0)
log_error("Failed to fork: %m");
log_error_errno(errno, "Failed to fork: %m");
else if (pid == 0) {
const char * const args[] = {
@ -412,7 +412,7 @@ int main(int argc, char *argv[]) {
exit(0);
}
log_error("Failed to invoke reboot(): %m");
log_error_errno(errno, "Failed to invoke reboot(): %m");
r = -errno;
error:

View File

@ -56,7 +56,7 @@ static int write_rules(const char* dstpath, const char* srcdir) {
dst = fopen(dstpath, "we");
if (!dst) {
if (errno != ENOENT)
log_warning("Failed to open %s: %m", dstpath);
log_warning_errno(errno, "Failed to open %s: %m", dstpath);
return -errno; /* negative error */
}
@ -64,7 +64,7 @@ static int write_rules(const char* dstpath, const char* srcdir) {
dir = opendir(srcdir);
if (!dir) {
if (errno != ENOENT)
log_warning("Failed to opendir %s: %m", srcdir);
log_warning_errno(errno, "Failed to opendir %s: %m", srcdir);
return errno; /* positive on purpose */
}
@ -79,7 +79,7 @@ static int write_rules(const char* dstpath, const char* srcdir) {
if (fd < 0) {
if (r == 0)
r = -errno;
log_warning("Failed to open %s: %m", entry->d_name);
log_warning_errno(errno, "Failed to open %s: %m", entry->d_name);
continue;
}
@ -88,13 +88,13 @@ static int write_rules(const char* dstpath, const char* srcdir) {
if (r == 0)
r = -errno;
safe_close(fd);
log_error("Failed to open %s: %m", entry->d_name);
log_error_errno(errno, "Failed to open %s: %m", entry->d_name);
continue;
}
/* load2 write rules in the kernel require a line buffered stream */
FOREACH_LINE(buf, policy,
log_error("Failed to read line from %s: %m",
log_error_errno(errno, "Failed to read line from %s: %m",
entry->d_name)) {
if (!fputs(buf, dst)) {
if (r == 0)
@ -105,7 +105,7 @@ static int write_rules(const char* dstpath, const char* srcdir) {
if (fflush(dst)) {
if (r == 0)
r = -errno;
log_error("Failed to flush writes to %s: %m", dstpath);
log_error_errno(errno, "Failed to flush writes to %s: %m", dstpath);
break;
}
}

View File

@ -401,7 +401,7 @@ static int mount_points_list_umount(MountPoint **head, bool *changed, bool log_e
mount_point_free(head, m);
} else if (log_error) {
log_warning("Could not unmount %s: %m", m->path);
log_warning_errno(errno, "Could not unmount %s: %m", m->path);
n_failed++;
}
}
@ -423,7 +423,7 @@ static int swap_points_list_off(MountPoint **head, bool *changed) {
mount_point_free(head, m);
} else {
log_warning("Could not deactivate swap %s: %m", m->path);
log_warning_errno(errno, "Could not deactivate swap %s: %m", m->path);
n_failed++;
}
}
@ -460,7 +460,7 @@ static int loopback_points_list_detach(MountPoint **head, bool *changed) {
mount_point_free(head, m);
} else {
log_warning("Could not detach loopback %s: %m", m->path);
log_warning_errno(errno, "Could not detach loopback %s: %m", m->path);
n_failed++;
}
}
@ -495,7 +495,7 @@ static int dm_points_list_detach(MountPoint **head, bool *changed) {
mount_point_free(head, m);
} else {
log_warning("Could not detach DM %s: %m", m->path);
log_warning_errno(errno, "Could not detach DM %s: %m", m->path);
n_failed++;
}
}

View File

@ -117,7 +117,7 @@ static int create_disk(
f = fopen(p, "wxe");
if (!f) {
log_error("Failed to create unit file %s: %m", p);
log_error_errno(errno, "Failed to create unit file %s: %m", p);
return -errno;
}
@ -201,7 +201,7 @@ static int create_disk(
fflush(f);
if (ferror(f)) {
log_error("Failed to write file %s: %m", p);
log_error_errno(errno, "Failed to write file %s: %m", p);
return -errno;
}
@ -215,7 +215,7 @@ static int create_disk(
mkdir_parents_label(to, 0755);
if (symlink(from, to) < 0) {
log_error("Failed to create symlink %s: %m", to);
log_error_errno(errno, "Failed to create symlink %s: %m", to);
return -errno;
}
@ -229,7 +229,7 @@ static int create_disk(
mkdir_parents_label(to, 0755);
if (symlink(from, to) < 0) {
log_error("Failed to create symlink %s: %m", to);
log_error_errno(errno, "Failed to create symlink %s: %m", to);
return -errno;
}
}
@ -241,7 +241,7 @@ static int create_disk(
mkdir_parents_label(to, 0755);
if (symlink(from, to) < 0) {
log_error("Failed to create symlink %s: %m", to);
log_error_errno(errno, "Failed to create symlink %s: %m", to);
return -errno;
}
@ -342,13 +342,13 @@ int main(int argc, char *argv[]) {
if (errno == ENOENT)
r = EXIT_SUCCESS;
else
log_error("Failed to open /etc/crypttab: %m");
log_error_errno(errno, "Failed to open /etc/crypttab: %m");
goto next;
}
if (fstat(fileno(f), &st) < 0) {
log_error("Failed to stat /etc/crypttab: %m");
log_error_errno(errno, "Failed to stat /etc/crypttab: %m");
goto next;
}

View File

@ -59,7 +59,7 @@ static int create_dbus_files(
f = fopen(a, "wxe");
if (!f) {
log_error("Failed to create %s: %m", a);
log_error_errno(errno, "Failed to create %s: %m", a);
return -errno;
}
@ -117,7 +117,7 @@ static int create_dbus_files(
f = fopen(b, "wxe");
if (!f) {
log_error("Failed to create %s: %m", b);
log_error_errno(errno, "Failed to create %s: %m", b);
return -errno;
}
@ -146,7 +146,7 @@ static int create_dbus_files(
mkdir_parents_label(lnk, 0755);
if (symlink(b, lnk)) {
log_error("Failed to create symlink %s: %m", lnk);
log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
return -errno;
}
@ -229,7 +229,7 @@ static int parse_dbus_fragments(const char *path, const char *type) {
if (errno == -ENOENT)
return 0;
log_error("Failed to enumerate D-Bus activated services: %m");
log_error_errno(errno, "Failed to enumerate D-Bus activated services: %m");
return -errno;
}
@ -248,7 +248,7 @@ static int parse_dbus_fragments(const char *path, const char *type) {
return r;
fail:
log_error("Failed to read D-Bus services directory: %m");
log_error_errno(errno, "Failed to read D-Bus services directory: %m");
return -errno;
}
@ -260,7 +260,7 @@ static int link_busnames_target(const char *units) {
mkdir_parents_label(t, 0755);
if (symlink(f, t) < 0) {
log_error("Failed to create symlink %s: %m", t);
log_error_errno(errno, "Failed to create symlink %s: %m", t);
return -errno;
}
@ -274,7 +274,7 @@ static int link_compatibility(const char *units) {
t = strappenda(arg_dest, "/" SPECIAL_DBUS_SOCKET);
mkdir_parents_label(t, 0755);
if (symlink(f, t) < 0) {
log_error("Failed to create symlink %s: %m", t);
log_error_errno(errno, "Failed to create symlink %s: %m", t);
return -errno;
}
@ -282,13 +282,13 @@ static int link_compatibility(const char *units) {
t = strappenda(arg_dest, "/" SPECIAL_SOCKETS_TARGET ".wants/systemd-bus-proxyd.socket");
mkdir_parents_label(t, 0755);
if (symlink(f, t) < 0) {
log_error("Failed to create symlink %s: %m", t);
log_error_errno(errno, "Failed to create symlink %s: %m", t);
return -errno;
}
t = strappenda(arg_dest, "/" SPECIAL_DBUS_SERVICE);
if (symlink("/dev/null", t) < 0) {
log_error("Failed to mask %s: %m", t);
log_error_errno(errno, "Failed to mask %s: %m", t);
return -errno;
}

View File

@ -96,7 +96,7 @@ static int generate_mask_symlinks(void) {
return log_oom();
if (symlink("/dev/null", p) < 0) {
log_error("Failed to create mask symlink %s: %m", p);
log_error_errno(errno, "Failed to create mask symlink %s: %m", p);
r = -errno;
}
}
@ -125,7 +125,7 @@ static int generate_wants_symlinks(void) {
mkdir_parents_label(p, 0755);
if (symlink(f, p) < 0) {
log_error("Failed to create wants symlink %s: %m", p);
log_error_errno(errno, "Failed to create wants symlink %s: %m", p);
r = -errno;
}
}

View File

@ -186,11 +186,11 @@ static int found_override(const char *top, const char *bottom) {
pid = fork();
if (pid < 0) {
log_error("Failed to fork off diff: %m");
log_error_errno(errno, "Failed to fork off diff: %m");
return -errno;
} else if (pid == 0) {
execlp("diff", "diff", "-us", "--", bottom, top, NULL);
log_error("Failed to execute diff: %m");
log_error_errno(errno, "Failed to execute diff: %m");
_exit(1);
}
@ -305,7 +305,7 @@ static int enumerate_dir(Hashmap *top, Hashmap *bottom, Hashmap *drops, const ch
if (errno == ENOENT)
return 0;
log_error("Failed to open %s: %m", path);
log_error_errno(errno, "Failed to open %s: %m", path);
return -errno;
}

View File

@ -87,7 +87,7 @@ int main(int argc, char *argv[]) {
name = strappenda(arg_dest, "/boot.mount");
f = fopen(name, "wxe");
if (!f) {
log_error("Failed to create mount unit file %s: %m", name);
log_error_errno(errno, "Failed to create mount unit file %s: %m", name);
return EXIT_FAILURE;
}
@ -120,7 +120,7 @@ int main(int argc, char *argv[]) {
fflush(f);
if (ferror(f)) {
log_error("Failed to write mount unit file: %m");
log_error_errno(errno, "Failed to write mount unit file: %m");
return EXIT_FAILURE;
}
@ -128,7 +128,7 @@ int main(int argc, char *argv[]) {
fclose(f);
f = fopen(name, "wxe");
if (!f) {
log_error("Failed to create automount unit file %s: %m", name);
log_error_errno(errno, "Failed to create automount unit file %s: %m", name);
return EXIT_FAILURE;
}
@ -140,7 +140,7 @@ int main(int argc, char *argv[]) {
fflush(f);
if (ferror(f)) {
log_error("Failed to write automount unit file: %m");
log_error_errno(errno, "Failed to write automount unit file: %m");
return EXIT_FAILURE;
}
@ -148,7 +148,7 @@ int main(int argc, char *argv[]) {
mkdir_parents(name, 0755);
if (symlink("../boot.automount", name) < 0) {
log_error("Failed to create symlink %s: %m", name);
log_error_errno(errno, "Failed to create symlink %s: %m", name);
return EXIT_FAILURE;
}

View File

@ -337,7 +337,7 @@ static int process_timezone(void) {
mkdir_parents(etc_localtime, 0755);
if (symlink(p, etc_localtime) < 0) {
log_error("Failed to create %s symlink: %m", etc_localtime);
log_error_errno(errno, "Failed to create %s symlink: %m", etc_localtime);
return -errno;
}
@ -357,7 +357,7 @@ static int process_timezone(void) {
mkdir_parents(etc_localtime, 0755);
if (symlink(e, etc_localtime) < 0) {
log_error("Failed to create %s symlink: %m", etc_localtime);
log_error_errno(errno, "Failed to create %s symlink: %m", etc_localtime);
return -errno;
}
@ -566,7 +566,7 @@ static int process_root_password(void) {
if (!errno)
errno = EIO;
log_error("Failed to find shadow entry for root: %m");
log_error_errno(errno, "Failed to find shadow entry for root: %m");
return -errno;
}
@ -604,7 +604,7 @@ static int process_root_password(void) {
if (!errno)
errno = -EINVAL;
log_error("Failed to encrypt password: %m");
log_error_errno(errno, "Failed to encrypt password: %m");
return -errno;
}

View File

@ -256,7 +256,7 @@ int main(int argc, char *argv[]) {
root_directory = false;
if (stat(device, &st) < 0) {
log_error("Failed to stat '%s': %m", device);
log_error_errno(errno, "Failed to stat '%s': %m", device);
return EXIT_FAILURE;
}
@ -271,7 +271,7 @@ int main(int argc, char *argv[]) {
/* Find root device */
if (stat("/", &st) < 0) {
log_error("Failed to stat() the root directory: %m");
log_error_errno(errno, "Failed to stat() the root directory: %m");
return EXIT_FAILURE;
}
@ -314,7 +314,7 @@ int main(int argc, char *argv[]) {
if (arg_show_progress)
if (pipe(progress_pipe) < 0) {
log_error("pipe(): %m");
log_error_errno(errno, "pipe(): %m");
return EXIT_FAILURE;
}
@ -346,7 +346,7 @@ int main(int argc, char *argv[]) {
pid = fork();
if (pid < 0) {
log_error("fork(): %m");
log_error_errno(errno, "fork(): %m");
goto finish;
} else if (pid == 0) {
/* Child */

View File

@ -111,7 +111,7 @@ static int add_swap(
if (errno == EEXIST)
log_error("Failed to create swap unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
else
log_error("Failed to create unit file %s: %m", unit);
log_error_errno(errno, "Failed to create unit file %s: %m", unit);
return -errno;
}
@ -149,7 +149,7 @@ static int add_swap(
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
log_error("Failed to create symlink %s: %m", lnk);
log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
return -errno;
}
}
@ -229,7 +229,7 @@ static int add_mount(
if (errno == EEXIST)
log_error("Failed to create mount unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
else
log_error("Failed to create unit file %s: %m", unit);
log_error_errno(errno, "Failed to create unit file %s: %m", unit);
return -errno;
}
@ -269,7 +269,7 @@ static int add_mount(
fflush(f);
if (ferror(f)) {
log_error("Failed to write unit file %s: %m", unit);
log_error_errno(errno, "Failed to write unit file %s: %m", unit);
return -errno;
}
@ -280,7 +280,7 @@ static int add_mount(
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
log_error("Failed to create symlink %s: %m", lnk);
log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
return -errno;
}
}
@ -297,7 +297,7 @@ static int add_mount(
fclose(f);
f = fopen(automount_unit, "wxe");
if (!f) {
log_error("Failed to create unit file %s: %m", automount_unit);
log_error_errno(errno, "Failed to create unit file %s: %m", automount_unit);
return -errno;
}
@ -320,7 +320,7 @@ static int add_mount(
fflush(f);
if (ferror(f)) {
log_error("Failed to write unit file %s: %m", automount_unit);
log_error_errno(errno, "Failed to write unit file %s: %m", automount_unit);
return -errno;
}
@ -331,7 +331,7 @@ static int add_mount(
mkdir_parents_label(lnk, 0755);
if (symlink(automount_unit, lnk) < 0) {
log_error("Failed to create symlink %s: %m", lnk);
log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
return -errno;
}
}
@ -351,7 +351,7 @@ static int parse_fstab(bool initrd) {
if (errno == ENOENT)
return 0;
log_error("Failed to open %s: %m", fstab_path);
log_error_errno(errno, "Failed to open %s: %m", fstab_path);
return -errno;
}

View File

@ -52,7 +52,7 @@ static int add_symlink(const char *fservice, const char *tservice) {
/* In case console=hvc0 is passed this will very likely result in EEXIST */
return 0;
else {
log_error("Failed to create symlink %s: %m", to);
log_error_errno(errno, "Failed to create symlink %s: %m", to);
return -errno;
}
}

View File

@ -69,7 +69,7 @@ static int add_swap(const char *path) {
f = fopen(unit, "wxe");
if (!f) {
log_error("Failed to create unit file %s: %m", unit);
log_error_errno(errno, "Failed to create unit file %s: %m", unit);
return -errno;
}
@ -84,7 +84,7 @@ static int add_swap(const char *path) {
fflush(f);
if (ferror(f)) {
log_error("Failed to write unit file %s: %m", unit);
log_error_errno(errno, "Failed to write unit file %s: %m", unit);
return -errno;
}
@ -94,7 +94,7 @@ static int add_swap(const char *path) {
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
log_error("Failed to create symlink %s: %m", lnk);
log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
return -errno;
}
@ -129,7 +129,7 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi
f = fopen(p, "wxe");
if (!f) {
log_error("Failed to create unit file %s: %m", p);
log_error_errno(errno, "Failed to create unit file %s: %m", p);
return -errno;
}
@ -156,7 +156,7 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi
fflush(f);
if (ferror(f)) {
log_error("Failed to write file %s: %m", p);
log_error_errno(errno, "Failed to write file %s: %m", p);
return -errno;
}
@ -168,7 +168,7 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi
mkdir_parents_label(to, 0755);
if (symlink(from, to) < 0) {
log_error("Failed to create symlink %s: %m", to);
log_error_errno(errno, "Failed to create symlink %s: %m", to);
return -errno;
}
@ -179,7 +179,7 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi
mkdir_parents_label(to, 0755);
if (symlink(from, to) < 0) {
log_error("Failed to create symlink %s: %m", to);
log_error_errno(errno, "Failed to create symlink %s: %m", to);
return -errno;
}
@ -190,7 +190,7 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, char **devi
mkdir_parents_label(to, 0755);
if (symlink(from, to) < 0) {
log_error("Failed to create symlink %s: %m", to);
log_error_errno(errno, "Failed to create symlink %s: %m", to);
return -errno;
}
@ -255,7 +255,7 @@ static int add_mount(
f = fopen(p, "wxe");
if (!f) {
log_error("Failed to create unit file %s: %m", unit);
log_error_errno(errno, "Failed to create unit file %s: %m", unit);
return -errno;
}
@ -287,7 +287,7 @@ static int add_mount(
fflush(f);
if (ferror(f)) {
log_error("Failed to write unit file %s: %m", p);
log_error_errno(errno, "Failed to write unit file %s: %m", p);
return -errno;
}
@ -298,7 +298,7 @@ static int add_mount(
mkdir_parents_label(lnk, 0755);
if (symlink(p, lnk) < 0) {
log_error("Failed to create symlink %s: %m", lnk);
log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
return -errno;
}
}
@ -337,7 +337,7 @@ static int probe_and_add_mount(
if (!b) {
if (errno == 0)
return log_oom();
log_error("Failed to allocate prober: %m");
log_error_errno(errno, "Failed to allocate prober: %m");
return -errno;
}
@ -351,7 +351,7 @@ static int probe_and_add_mount(
else if (r != 0) {
if (errno == 0)
errno = EIO;
log_error("Failed to probe %s: %m", what);
log_error_errno(errno, "Failed to probe %s: %m", what);
return -errno;
}
@ -429,7 +429,7 @@ static int enumerate_partitions(dev_t devnum) {
if (errno == 0)
return log_oom();
log_error("Failed allocate prober: %m");
log_error_errno(errno, "Failed allocate prober: %m");
return -errno;
}
@ -443,7 +443,7 @@ static int enumerate_partitions(dev_t devnum) {
else if (r != 0) {
if (errno == 0)
errno = EIO;
log_error("Failed to probe %s: %m", node);
log_error_errno(errno, "Failed to probe %s: %m", node);
return -errno;
}
@ -452,7 +452,7 @@ static int enumerate_partitions(dev_t devnum) {
if (r != 0) {
if (errno == 0)
errno = EIO;
log_error("Failed to determine partition table type of %s: %m", node);
log_error_errno(errno, "Failed to determine partition table type of %s: %m", node);
return -errno;
}
@ -468,7 +468,7 @@ static int enumerate_partitions(dev_t devnum) {
if (errno == 0)
return log_oom();
log_error("Failed to list partitions of %s: %m", node);
log_error_errno(errno, "Failed to list partitions of %s: %m", node);
return -errno;
}

View File

@ -58,7 +58,7 @@ static int process_resume(void) {
mkdir_parents_label(lnk, 0755);
if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-hibernate-resume@.service", lnk) < 0) {
log_error("Failed to create symlink %s: %m", lnk);
log_error_errno(errno, "Failed to create symlink %s: %m", lnk);
return -errno;
}

View File

@ -53,7 +53,7 @@ int main(int argc, char *argv[]) {
device = argv[1];
if (stat(device, &st) < 0) {
log_error("Failed to stat '%s': %m", device);
log_error_errno(errno, "Failed to stat '%s': %m", device);
return EXIT_FAILURE;
}

View File

@ -162,7 +162,7 @@ static void request_process(Server *s, const struct init_request *req) {
case 'u':
case 'U':
if (kill(1, SIGTERM) < 0)
log_error("kill() failed: %m");
log_error_errno(errno, "kill() failed: %m");
/* The bus connection will be
* terminated if PID 1 is reexecuted,
@ -175,7 +175,7 @@ static void request_process(Server *s, const struct init_request *req) {
case 'q':
case 'Q':
if (kill(1, SIGHUP) < 0)
log_error("kill() failed: %m");
log_error_errno(errno, "kill() failed: %m");
break;
default:
@ -217,7 +217,7 @@ static int fifo_process(Fifo *f) {
if (errno == EAGAIN)
return 0;
log_warning("Failed to read from fifo: %m");
log_warning_errno(errno, "Failed to read from fifo: %m");
return -errno;
}
@ -277,7 +277,7 @@ static int server_init(Server *s, unsigned n_sockets) {
s->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (s->epoll_fd < 0) {
r = -errno;
log_error("Failed to create epoll object: %m");
log_error_errno(errno, "Failed to create epoll object: %m");
goto fail;
}
@ -303,7 +303,7 @@ static int server_init(Server *s, unsigned n_sockets) {
f = new0(Fifo, 1);
if (!f) {
r = -ENOMEM;
log_error("Failed to create fifo object: %m");
log_error_errno(errno, "Failed to create fifo object: %m");
goto fail;
}
@ -315,7 +315,7 @@ static int server_init(Server *s, unsigned n_sockets) {
if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) {
r = -errno;
fifo_free(f);
log_error("Failed to add fifo fd to epoll object: %m");
log_error_errno(errno, "Failed to add fifo fd to epoll object: %m");
goto fail;
}
@ -413,7 +413,7 @@ int main(int argc, char *argv[]) {
if (errno == EINTR)
continue;
log_error("epoll_wait() failed: %m");
log_error_errno(errno, "epoll_wait() failed: %m");
goto fail;
}

View File

@ -198,7 +198,7 @@ static ssize_t request_reader_entries(
else {
m->tmp = tmpfile();
if (!m->tmp) {
log_error("Failed to create temporary file: %m");
log_error_errno(errno, "Failed to create temporary file: %m");
return MHD_CONTENT_READER_END_WITH_ERROR;
}
}
@ -211,7 +211,7 @@ static ssize_t request_reader_entries(
sz = ftello(m->tmp);
if (sz == (off_t) -1) {
log_error("Failed to retrieve file position: %m");
log_error_errno(errno, "Failed to retrieve file position: %m");
return MHD_CONTENT_READER_END_WITH_ERROR;
}
@ -219,7 +219,7 @@ static ssize_t request_reader_entries(
}
if (fseeko(m->tmp, pos, SEEK_SET) < 0) {
log_error("Failed to seek to position: %m");
log_error_errno(errno, "Failed to seek to position: %m");
return MHD_CONTENT_READER_END_WITH_ERROR;
}
@ -559,7 +559,7 @@ static ssize_t request_reader_fields(
else {
m->tmp = tmpfile();
if (!m->tmp) {
log_error("Failed to create temporary file: %m");
log_error_errno(errno, "Failed to create temporary file: %m");
return MHD_CONTENT_READER_END_WITH_ERROR;
}
}
@ -572,7 +572,7 @@ static ssize_t request_reader_fields(
sz = ftello(m->tmp);
if (sz == (off_t) -1) {
log_error("Failed to retrieve file position: %m");
log_error_errno(errno, "Failed to retrieve file position: %m");
return MHD_CONTENT_READER_END_WITH_ERROR;
}
@ -580,7 +580,7 @@ static ssize_t request_reader_fields(
}
if (fseeko(m->tmp, pos, SEEK_SET) < 0) {
log_error("Failed to seek to position: %m");
log_error_errno(errno, "Failed to seek to position: %m");
return MHD_CONTENT_READER_END_WITH_ERROR;
}

View File

@ -125,7 +125,7 @@ static int get_line(RemoteSource *source, char **line, size_t *size) {
source->size - source->filled);
if (n < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK)
log_error("read(%d, ..., %zd): %m", source->fd,
log_error_errno(errno, "read(%d, ..., %zd): %m", source->fd,
source->size - source->filled);
return -errno;
} else if (n == 0)
@ -186,7 +186,7 @@ static int fill_fixed_size(RemoteSource *source, void **data, size_t size) {
source->size - source->filled);
if (n < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK)
log_error("read(%d, ..., %zd): %m", source->fd,
log_error_errno(errno, "read(%d, ..., %zd): %m", source->fd,
source->size - source->filled);
return -errno;
} else if (n == 0)

View File

@ -85,7 +85,7 @@ static int spawn_child(const char* child, char** argv) {
int r;
if (pipe(fd) < 0) {
log_error("Failed to create pager pipe: %m");
log_error_errno(errno, "Failed to create pager pipe: %m");
return -errno;
}
@ -94,7 +94,7 @@ static int spawn_child(const char* child, char** argv) {
child_pid = fork();
if (child_pid < 0) {
r = -errno;
log_error("Failed to fork: %m");
log_error_errno(errno, "Failed to fork: %m");
safe_close_pair(fd);
return r;
}
@ -103,7 +103,7 @@ static int spawn_child(const char* child, char** argv) {
if (child_pid == 0) {
r = dup2(fd[1], STDOUT_FILENO);
if (r < 0) {
log_error("Failed to dup pipe to stdout: %m");
log_error_errno(errno, "Failed to dup pipe to stdout: %m");
_exit(EXIT_FAILURE);
}
@ -119,13 +119,13 @@ static int spawn_child(const char* child, char** argv) {
_exit(EXIT_SUCCESS);
execvp(child, argv);
log_error("Failed to exec child %s: %m", child);
log_error_errno(errno, "Failed to exec child %s: %m", child);
_exit(EXIT_FAILURE);
}
r = close(fd[1]);
if (r < 0)
log_warning("Failed to close write end of pipe: %m");
log_warning_errno(errno, "Failed to close write end of pipe: %m");
return fd[0];
}
@ -140,7 +140,7 @@ static int spawn_curl(const char* url) {
r = spawn_child("curl", argv);
if (r < 0)
log_error("Failed to spawn curl: %m");
log_error_errno(errno, "Failed to spawn curl: %m");
return r;
}
@ -159,7 +159,7 @@ static int spawn_getter(const char *getter, const char *url) {
r = spawn_child(words[0], words);
if (r < 0)
log_error("Failed to spawn getter %s: %m", getter);
log_error_errno(errno, "Failed to spawn getter %s: %m", getter);
return r;
}
@ -941,7 +941,7 @@ static int remoteserver_init(RemoteServer *s,
fd = open(*file, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (fd < 0) {
log_error("Failed to open %s: %m", *file);
log_error_errno(errno, "Failed to open %s: %m", *file);
return -errno;
}
output_name = *file;
@ -1054,7 +1054,7 @@ static int accept_connection(const char* type, int fd,
log_debug("Accepting new %s connection on fd:%d", type, fd);
fd2 = accept4(fd, &addr->sockaddr.sa, &addr->size, SOCK_NONBLOCK|SOCK_CLOEXEC);
if (fd2 < 0) {
log_error("accept() on fd:%d failed: %m", fd);
log_error_errno(errno, "accept() on fd:%d failed: %m", fd);
return -errno;
}

View File

@ -308,7 +308,7 @@ static size_t fd_input_callback(void *buf, size_t size, size_t nmemb, void *user
close_fd_input(u);
return 0;
} else {
log_error("Aborting transfer after read error on input: %m.");
log_error_errno(errno, "Aborting transfer after read error on input: %m.");
return CURL_READFUNC_ABORT;
}
}
@ -358,7 +358,7 @@ static int open_file_for_upload(Uploader *u, const char *filename) {
else {
fd = open(filename, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
log_error("Failed to open %s: %m", filename);
log_error_errno(errno, "Failed to open %s: %m", filename);
return -errno;
}
}

View File

@ -143,7 +143,7 @@ int main(int argc, char *argv[]) {
if (dup3(fd, STDOUT_FILENO, 0) < 0 ||
dup3(fd, STDERR_FILENO, 0) < 0) {
log_error("Failed to duplicate fd: %m");
log_error_errno(errno, "Failed to duplicate fd: %m");
r = -errno;
goto finish;
}

View File

@ -210,13 +210,13 @@ int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) {
f = fopen(path, "re");
if (!f) {
log_error("Failed to open file %s: %m", path);
log_error_errno(errno, "Failed to open file %s: %m", path);
return -errno;
}
r = catalog_file_lang(path, &deflang);
if (r < 0)
log_error("Failed to determine language for file %s: %m", path);
log_error_errno(errno, "Failed to determine language for file %s: %m", path);
if (r == 1)
log_debug("File %s has language %s.", path, deflang);
@ -229,7 +229,7 @@ int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) {
if (feof(f))
break;
log_error("Failed to read file %s: %m", path);
log_error_errno(errno, "Failed to read file %s: %m", path);
return -errno;
}
@ -385,7 +385,7 @@ static long write_catalog(const char *database, Hashmap *h, struct strbuf *sb,
fchmod(fileno(w), 0644);
if (rename(p, database) < 0) {
log_error("rename (%s -> %s) failed: %m", p, database);
log_error_errno(errno, "rename (%s -> %s) failed: %m", p, database);
r = -errno;
goto error;
}

View File

@ -140,7 +140,7 @@ int coredump_vacuum(int exclude_fd, off_t keep_free, off_t max_use) {
if (exclude_fd >= 0) {
if (fstat(exclude_fd, &exclude_st) < 0) {
log_error("Failed to fstat(): %m");
log_error_errno(errno, "Failed to fstat(): %m");
return -errno;
}
}
@ -156,7 +156,7 @@ int coredump_vacuum(int exclude_fd, off_t keep_free, off_t max_use) {
if (errno == ENOENT)
return 0;
log_error("Can't open coredump directory: %m");
log_error_errno(errno, "Can't open coredump directory: %m");
return -errno;
}
@ -258,7 +258,7 @@ int coredump_vacuum(int exclude_fd, off_t keep_free, off_t max_use) {
if (errno == ENOENT)
continue;
log_error("Failed to remove file %s: %m", worst->oldest_file);
log_error_errno(errno, "Failed to remove file %s: %m", worst->oldest_file);
return -errno;
} else
log_info("Removed old coredump %s.", worst->oldest_file);
@ -267,6 +267,6 @@ int coredump_vacuum(int exclude_fd, off_t keep_free, off_t max_use) {
return 0;
fail:
log_error("Failed to read directory: %m");
log_error_errno(errno, "Failed to read directory: %m");
return -errno;
}

View File

@ -143,26 +143,26 @@ static int fix_acl(int fd, uid_t uid) {
acl = acl_get_fd(fd);
if (!acl) {
log_error("Failed to get ACL: %m");
log_error_errno(errno, "Failed to get ACL: %m");
return -errno;
}
if (acl_create_entry(&acl, &entry) < 0 ||
acl_set_tag_type(entry, ACL_USER) < 0 ||
acl_set_qualifier(entry, &uid) < 0) {
log_error("Failed to patch ACL: %m");
log_error_errno(errno, "Failed to patch ACL: %m");
return -errno;
}
if (acl_get_permset(entry, &permset) < 0 ||
acl_add_perm(permset, ACL_READ) < 0 ||
calc_acl_mask_if_needed(&acl) < 0) {
log_warning("Failed to patch ACL: %m");
log_warning_errno(errno, "Failed to patch ACL: %m");
return -errno;
}
if (acl_set_fd(fd, acl) < 0) {
log_error("Failed to apply ACL: %m");
log_error_errno(errno, "Failed to apply ACL: %m");
return -errno;
}
#endif
@ -224,12 +224,12 @@ static int fix_permissions(
fix_xattr(fd, info);
if (fsync(fd) < 0) {
log_error("Failed to sync coredump %s: %m", filename);
log_error_errno(errno, "Failed to sync coredump %s: %m", filename);
return -errno;
}
if (rename(filename, target) < 0) {
log_error("Failed to rename coredump %s -> %s: %m", filename, target);
log_error_errno(errno, "Failed to rename coredump %s -> %s: %m", filename, target);
return -errno;
}
@ -248,7 +248,7 @@ static int maybe_remove_external_coredump(const char *filename, off_t size) {
return 1;
if (unlink(filename) < 0 && errno != ENOENT) {
log_error("Failed to unlink %s: %m", filename);
log_error_errno(errno, "Failed to unlink %s: %m", filename);
return -errno;
}
@ -323,7 +323,7 @@ static int save_external_coredump(
fd = open(tmp, O_CREAT|O_EXCL|O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0640);
if (fd < 0) {
log_error("Failed to create coredump file %s: %m", tmp);
log_error_errno(errno, "Failed to create coredump file %s: %m", tmp);
return -errno;
}
@ -340,12 +340,12 @@ static int save_external_coredump(
}
if (fstat(fd, &st) < 0) {
log_error("Failed to fstat coredump %s: %m", tmp);
log_error_errno(errno, "Failed to fstat coredump %s: %m", tmp);
goto fail;
}
if (lseek(fd, 0, SEEK_SET) == (off_t) -1) {
log_error("Failed to seek on %s: %m", tmp);
log_error_errno(errno, "Failed to seek on %s: %m", tmp);
goto fail;
}
@ -371,7 +371,7 @@ static int save_external_coredump(
fd_compressed = open(tmp_compressed, O_CREAT|O_EXCL|O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0640);
if (fd_compressed < 0) {
log_error("Failed to create file %s: %m", tmp_compressed);
log_error_errno(errno, "Failed to create file %s: %m", tmp_compressed);
goto uncompressed;
}
@ -430,7 +430,7 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s
assert(ret_size);
if (lseek(fd, 0, SEEK_SET) == (off_t) -1) {
log_warning("Failed to seek: %m");
log_warning_errno(errno, "Failed to seek: %m");
return -errno;
}
@ -821,7 +821,7 @@ int main(int argc, char* argv[]) {
* thus making sure the user gets access to the core dump. */
if (setresgid(gid, gid, gid) < 0 ||
setresuid(uid, uid, uid) < 0) {
log_error("Failed to drop privileges: %m");
log_error_errno(errno, "Failed to drop privileges: %m");
r = -errno;
goto finish;
}

View File

@ -191,7 +191,7 @@ static int parse_argv(int argc, char *argv[], Set *matches) {
output = fopen(optarg, "we");
if (!output) {
log_error("writing to '%s': %m", optarg);
log_error_errno(errno, "writing to '%s': %m", optarg);
return -errno;
}
@ -610,7 +610,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) {
fdt = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC);
if (fdt < 0) {
log_error("Failed to create temporary file: %m");
log_error_errno(errno, "Failed to create temporary file: %m");
return -errno;
}
log_debug("Created temporary file %s", temp);
@ -628,7 +628,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) {
sz = write(fdt, data, len);
if (sz < 0) {
log_error("Failed to write temporary file: %m");
log_error_errno(errno, "Failed to write temporary file: %m");
r = -errno;
goto error;
}
@ -643,7 +643,7 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) {
fdf = open(filename, O_RDONLY | O_CLOEXEC);
if (fdf < 0) {
log_error("Failed to open %s: %m", filename);
log_error_errno(errno, "Failed to open %s: %m", filename);
r = -errno;
goto error;
}
@ -755,20 +755,20 @@ static int run_gdb(sd_journal *j) {
pid = fork();
if (pid < 0) {
log_error("Failed to fork(): %m");
log_error_errno(errno, "Failed to fork(): %m");
r = -errno;
goto finish;
}
if (pid == 0) {
execlp("gdb", "gdb", exe, path, NULL);
log_error("Failed to invoke gdb: %m");
log_error_errno(errno, "Failed to invoke gdb: %m");
_exit(1);
}
r = wait_for_terminate(pid, &st);
if (r < 0) {
log_error("Failed to wait for gdb: %m");
log_error_errno(errno, "Failed to wait for gdb: %m");
goto finish;
}

View File

@ -339,7 +339,7 @@ int journal_file_fss_load(JournalFile *f) {
fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY, 0600);
if (fd < 0) {
if (errno != ENOENT)
log_error("Failed to open %s: %m", p);
log_error_errno(errno, "Failed to open %s: %m", p);
r = -errno;
goto finish;

View File

@ -1292,7 +1292,7 @@ void journal_file_post_change(JournalFile *f) {
__sync_synchronize();
if (ftruncate(f->fd, f->last_stat.st_size) < 0)
log_error("Failed to truncate file to its own size: %m");
log_error_errno(errno, "Failed to truncate file to its own size: %m");
}
static int entry_item_cmp(const void *_a, const void *_b) {

View File

@ -275,7 +275,7 @@ int journal_directory_vacuum(
log_full(verbose ? LOG_INFO : LOG_DEBUG, "Deleted empty archived journal %s/%s (%s).", directory, p, format_bytes(sbytes, sizeof(sbytes), size));
freed += size;
} else if (errno != ENOENT)
log_warning("Failed to delete empty archived journal %s/%s: %m", directory, p);
log_warning_errno(errno, "Failed to delete empty archived journal %s/%s: %m", directory, p);
free(p);
continue;
@ -318,7 +318,7 @@ int journal_directory_vacuum(
sum = 0;
} else if (errno != ENOENT)
log_warning("Failed to delete archived journal %s/%s: %m", directory, list[i].filename);
log_warning_errno(errno, "Failed to delete archived journal %s/%s: %m", directory, list[i].filename);
}
if (oldest_usec && i < n_list && (*oldest_usec == 0 || list[i].realtime < *oldest_usec))

View File

@ -825,21 +825,21 @@ int journal_file_verify(
data_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC);
if (data_fd < 0) {
log_error("Failed to create data file: %m");
log_error_errno(errno, "Failed to create data file: %m");
r = -errno;
goto fail;
}
entry_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC);
if (entry_fd < 0) {
log_error("Failed to create entry file: %m");
log_error_errno(errno, "Failed to create entry file: %m");
r = -errno;
goto fail;
}
entry_array_fd = open_tmpfile("/var/tmp", O_RDWR | O_CLOEXEC);
if (entry_array_fd < 0) {
log_error("Failed to create entry array file: %m");
log_error_errno(errno, "Failed to create entry array file: %m");
r = -errno;
goto fail;
}

View File

@ -795,7 +795,7 @@ static int add_matches(sd_journal *j, char **args) {
path = p ? p : *i;
if (stat(path, &st) < 0) {
log_error("Couldn't stat file: %m");
log_error_errno(errno, "Couldn't stat file: %m");
return -errno;
}
@ -1304,7 +1304,7 @@ static int setup_keys(void) {
r = stat("/var/log/journal", &st);
if (r < 0 && errno != ENOENT && errno != ENOTDIR) {
log_error("stat(\"%s\") failed: %m", "/var/log/journal");
log_error_errno(errno, "stat(\"%s\") failed: %m", "/var/log/journal");
return -errno;
}
@ -1330,7 +1330,7 @@ static int setup_keys(void) {
if (arg_force) {
r = unlink(p);
if (r < 0) {
log_error("unlink(\"%s\") failed: %m", p);
log_error_errno(errno, "unlink(\"%s\") failed: %m", p);
r = -errno;
goto finish;
}
@ -1358,7 +1358,7 @@ static int setup_keys(void) {
fd = open("/dev/random", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
log_error("Failed to open /dev/random: %m");
log_error_errno(errno, "Failed to open /dev/random: %m");
r = -errno;
goto finish;
}
@ -1385,7 +1385,7 @@ static int setup_keys(void) {
safe_close(fd);
fd = mkostemp_safe(k, O_WRONLY|O_CLOEXEC);
if (fd < 0) {
log_error("Failed to open %s: %m", k);
log_error_errno(errno, "Failed to open %s: %m", k);
r = -errno;
goto finish;
}
@ -1393,12 +1393,12 @@ static int setup_keys(void) {
/* Enable secure remove, exclusion from dump, synchronous
* writing and in-place updating */
if (ioctl(fd, FS_IOC_GETFLAGS, &attr) < 0)
log_warning("FS_IOC_GETFLAGS failed: %m");
log_warning_errno(errno, "FS_IOC_GETFLAGS failed: %m");
attr |= FS_SECRM_FL|FS_NODUMP_FL|FS_SYNC_FL|FS_NOCOW_FL;
if (ioctl(fd, FS_IOC_SETFLAGS, &attr) < 0)
log_warning("FS_IOC_SETFLAGS failed: %m");
log_warning_errno(errno, "FS_IOC_SETFLAGS failed: %m");
zero(h);
memcpy(h.signature, "KSHHRHLP", 8);
@ -1425,7 +1425,7 @@ static int setup_keys(void) {
}
if (link(k, p) < 0) {
log_error("Failed to link file: %m");
log_error_errno(errno, "Failed to link file: %m");
r = -errno;
goto finish;
}
@ -1686,13 +1686,13 @@ static int flush_to_var(void) {
watch_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
if (watch_fd < 0) {
log_error("Failed to create inotify watch: %m");
log_error_errno(errno, "Failed to create inotify watch: %m");
return -errno;
}
r = inotify_add_watch(watch_fd, "/run/systemd/journal", IN_CREATE|IN_DONT_FOLLOW|IN_ONLYDIR);
if (r < 0) {
log_error("Failed to watch journal directory: %m");
log_error_errno(errno, "Failed to watch journal directory: %m");
return -errno;
}
@ -1701,7 +1701,7 @@ static int flush_to_var(void) {
break;
if (errno != ENOENT) {
log_error("Failed to check for existance of /run/systemd/journal/flushed: %m");
log_error_errno(errno, "Failed to check for existance of /run/systemd/journal/flushed: %m");
return -errno;
}

View File

@ -523,14 +523,14 @@ int server_open_audit(Server *s) {
if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)
log_debug("Audit not supported in the kernel.");
else
log_warning("Failed to create audit socket, ignoring: %m");
log_warning_errno(errno, "Failed to create audit socket, ignoring: %m");
return 0;
}
r = bind(s->audit_fd, &sa.sa, sizeof(sa.nl));
if (r < 0) {
log_error("Failed to join audit multicast group: %m");
log_error_errno(errno, "Failed to join audit multicast group: %m");
return -errno;
}
} else
@ -538,7 +538,7 @@ int server_open_audit(Server *s) {
r = setsockopt(s->audit_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
if (r < 0) {
log_error("Failed to set SO_PASSCRED on audit socket: %m");
log_error_errno(errno, "Failed to set SO_PASSCRED on audit socket: %m");
return -errno;
}

View File

@ -100,12 +100,12 @@ void server_forward_console(
fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC);
if (fd < 0) {
log_debug("Failed to open %s for logging: %m", tty);
log_debug_errno(errno, "Failed to open %s for logging: %m", tty);
return;
}
if (writev(fd, iovec, n) < 0)
log_debug("Failed to write to %s for logging: %m", tty);
log_debug_errno(errno, "Failed to write to %s for logging: %m", tty);
safe_close(fd);
}

View File

@ -88,7 +88,7 @@ void server_forward_kmsg(
IOVEC_SET_STRING(iovec[n++], "\n");
if (writev(s->dev_kmsg_fd, iovec, n) < 0)
log_debug("Failed to write to /dev/kmsg for logging: %m");
log_debug_errno(errno, "Failed to write to /dev/kmsg for logging: %m");
free(ident_buf);
}
@ -342,7 +342,7 @@ static int server_read_dev_kmsg(Server *s) {
if (errno == EAGAIN || errno == EINTR || errno == EPIPE)
return 0;
log_error("Failed to read from kernel: %m");
log_error_errno(errno, "Failed to read from kernel: %m");
return -errno;
}
@ -446,18 +446,18 @@ int server_open_kernel_seqnum(Server *s) {
fd = open("/run/systemd/journal/kernel-seqnum", O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0644);
if (fd < 0) {
log_error("Failed to open /run/systemd/journal/kernel-seqnum, ignoring: %m");
log_error_errno(errno, "Failed to open /run/systemd/journal/kernel-seqnum, ignoring: %m");
return 0;
}
if (posix_fallocate(fd, 0, sizeof(uint64_t)) < 0) {
log_error("Failed to allocate sequential number file, ignoring: %m");
log_error_errno(errno, "Failed to allocate sequential number file, ignoring: %m");
return 0;
}
p = mmap(NULL, sizeof(uint64_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (p == MAP_FAILED) {
log_error("Failed to map sequential number file, ignoring: %m");
log_error_errno(errno, "Failed to map sequential number file, ignoring: %m");
return 0;
}

View File

@ -336,7 +336,7 @@ void server_process_native_file(
r = readlink_malloc(sl, &k);
if (r < 0) {
log_error("readlink(%s) failed: %m", sl);
log_error_errno(errno, "readlink(%s) failed: %m", sl);
return;
}
@ -357,7 +357,7 @@ void server_process_native_file(
}
if (fstat(fd, &st) < 0) {
log_error("Failed to stat passed file, ignoring: %m");
log_error_errno(errno, "Failed to stat passed file, ignoring: %m");
return;
}
@ -383,7 +383,7 @@ void server_process_native_file(
ps = PAGE_ALIGN(st.st_size);
p = mmap(NULL, ps, PROT_READ, MAP_PRIVATE, fd, 0);
if (p == MAP_FAILED) {
log_error("Failed to map memfd, ignoring: %m");
log_error_errno(errno, "Failed to map memfd, ignoring: %m");
return;
}
@ -425,7 +425,7 @@ int server_open_native_socket(Server*s) {
s->native_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (s->native_fd < 0) {
log_error("socket() failed: %m");
log_error_errno(errno, "socket() failed: %m");
return -errno;
}
@ -433,7 +433,7 @@ int server_open_native_socket(Server*s) {
r = bind(s->native_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
if (r < 0) {
log_error("bind(%s) failed: %m", sa.un.sun_path);
log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
return -errno;
}
@ -443,7 +443,7 @@ int server_open_native_socket(Server*s) {
r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
if (r < 0) {
log_error("SO_PASSCRED failed: %m");
log_error_errno(errno, "SO_PASSCRED failed: %m");
return -errno;
}
@ -451,13 +451,13 @@ int server_open_native_socket(Server*s) {
if (mac_selinux_use()) {
r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
if (r < 0)
log_warning("SO_PASSSEC failed: %m");
log_warning_errno(errno, "SO_PASSSEC failed: %m");
}
#endif
r = setsockopt(s->native_fd, SOL_SOCKET, SO_TIMESTAMP, &one, sizeof(one));
if (r < 0) {
log_error("SO_TIMESTAMP failed: %m");
log_error_errno(errno, "SO_TIMESTAMP failed: %m");
return -errno;
}

View File

@ -212,7 +212,7 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
acl = acl_get_fd(f->fd);
if (!acl) {
log_warning("Failed to read ACL on %s, ignoring: %m", f->path);
log_warning_errno(errno, "Failed to read ACL on %s, ignoring: %m", f->path);
return;
}
@ -222,7 +222,7 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
if (acl_create_entry(&acl, &entry) < 0 ||
acl_set_tag_type(entry, ACL_USER) < 0 ||
acl_set_qualifier(entry, &uid) < 0) {
log_warning("Failed to patch ACL on %s, ignoring: %m", f->path);
log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path);
goto finish;
}
}
@ -232,12 +232,12 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t uid) {
if (acl_get_permset(entry, &permset) < 0 ||
acl_add_perm(permset, ACL_READ) < 0 ||
calc_acl_mask_if_needed(&acl) < 0) {
log_warning("Failed to patch ACL on %s, ignoring: %m", f->path);
log_warning_errno(errno, "Failed to patch ACL on %s, ignoring: %m", f->path);
goto finish;
}
if (acl_set_fd(f->fd, acl) < 0)
log_warning("Failed to set ACL on %s, ignoring: %m", f->path);
log_warning_errno(errno, "Failed to set ACL on %s, ignoring: %m", f->path);
finish:
acl_free(acl);
@ -1174,7 +1174,7 @@ int process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userda
if (errno == EINTR || errno == EAGAIN)
return 0;
log_error("recvmsg() failed: %m");
log_error_errno(errno, "recvmsg() failed: %m");
return -errno;
}
@ -1432,7 +1432,7 @@ static int server_open_hostname(Server *s) {
s->hostname_fd = open("/proc/sys/kernel/hostname", O_RDONLY|O_CLOEXEC|O_NDELAY|O_NOCTTY);
if (s->hostname_fd < 0) {
log_error("Failed to open /proc/sys/kernel/hostname: %m");
log_error_errno(errno, "Failed to open /proc/sys/kernel/hostname: %m");
return -errno;
}

View File

@ -306,7 +306,7 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents,
if (errno == EAGAIN)
return 0;
log_warning("Failed to read from stream: %m");
log_warning_errno(errno, "Failed to read from stream: %m");
goto terminate;
}
@ -370,7 +370,7 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
if (errno == EAGAIN)
return 0;
log_error("Failed to accept stdout connection: %m");
log_error_errno(errno, "Failed to accept stdout connection: %m");
return -errno;
}
@ -390,19 +390,19 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
r = getpeercred(fd, &stream->ucred);
if (r < 0) {
log_error("Failed to determine peer credentials: %m");
log_error_errno(errno, "Failed to determine peer credentials: %m");
goto fail;
}
#ifdef HAVE_SELINUX
if (mac_selinux_use()) {
if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT)
log_error("Failed to determine peer security context: %m");
log_error_errno(errno, "Failed to determine peer security context: %m");
}
#endif
if (shutdown(fd, SHUT_WR) < 0) {
log_error("Failed to shutdown writing side of socket: %m");
log_error_errno(errno, "Failed to shutdown writing side of socket: %m");
goto fail;
}
@ -442,7 +442,7 @@ int server_open_stdout_socket(Server *s) {
s->stdout_fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (s->stdout_fd < 0) {
log_error("socket() failed: %m");
log_error_errno(errno, "socket() failed: %m");
return -errno;
}
@ -450,14 +450,14 @@ int server_open_stdout_socket(Server *s) {
r = bind(s->stdout_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
if (r < 0) {
log_error("bind(%s) failed: %m", sa.un.sun_path);
log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
return -errno;
}
chmod(sa.un.sun_path, 0666);
if (listen(s->stdout_fd, SOMAXCONN) < 0) {
log_error("listen(%s) failed: %m", sa.un.sun_path);
log_error_errno(errno, "listen(%s) failed: %m", sa.un.sun_path);
return -errno;
}
} else

View File

@ -106,7 +106,7 @@ static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned
}
if (errno != ENOENT)
log_debug("Failed to forward syslog message: %m");
log_debug_errno(errno, "Failed to forward syslog message: %m");
}
static void forward_syslog_raw(Server *s, int priority, const char *buffer, const struct ucred *ucred, const struct timeval *tv) {
@ -429,7 +429,7 @@ int server_open_syslog_socket(Server *s) {
s->syslog_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (s->syslog_fd < 0) {
log_error("socket() failed: %m");
log_error_errno(errno, "socket() failed: %m");
return -errno;
}
@ -437,7 +437,7 @@ int server_open_syslog_socket(Server *s) {
r = bind(s->syslog_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
if (r < 0) {
log_error("bind(%s) failed: %m", sa.un.sun_path);
log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
return -errno;
}
@ -447,7 +447,7 @@ int server_open_syslog_socket(Server *s) {
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
if (r < 0) {
log_error("SO_PASSCRED failed: %m");
log_error_errno(errno, "SO_PASSCRED failed: %m");
return -errno;
}
@ -455,13 +455,13 @@ int server_open_syslog_socket(Server *s) {
if (mac_selinux_use()) {
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
if (r < 0)
log_warning("SO_PASSSEC failed: %m");
log_warning_errno(errno, "SO_PASSSEC failed: %m");
}
#endif
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_TIMESTAMP, &one, sizeof(one));
if (r < 0) {
log_error("SO_TIMESTAMP failed: %m");
log_error_errno(errno, "SO_TIMESTAMP failed: %m");
return -errno;
}

View File

@ -1410,7 +1410,7 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
d = opendir(path);
if (!d) {
log_debug("Failed to open %s: %m", path);
log_debug_errno(errno, "Failed to open %s: %m", path);
if (errno == ENOENT)
return 0;
return -errno;
@ -1456,7 +1456,7 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
de = readdir(d);
if (!de && errno != 0) {
r = -errno;
log_debug("Failed to read directory %s: %m", m->path);
log_debug_errno(errno, "Failed to read directory %s: %m", m->path);
return r;
}
if (!de)
@ -1546,7 +1546,7 @@ static int add_root_directory(sd_journal *j, const char *p) {
de = readdir(d);
if (!de && errno != 0) {
r = -errno;
log_debug("Failed to read directory %s: %m", m->path);
log_debug_errno(errno, "Failed to read directory %s: %m", m->path);
return r;
}
if (!de)

View File

@ -359,13 +359,13 @@ static int evcat_sysview_fn(sysview_context *c, void *userdata, sysview_event *e
r = ioctl(1, KDSKBMODE, K_UNICODE);
if (r < 0) {
log_error("Cannot set K_UNICODE on stdout: %m");
log_error_errno(errno, "Cannot set K_UNICODE on stdout: %m");
return -errno;
}
r = ioctl(1, KDSETMODE, KD_TEXT);
if (r < 0) {
log_error("Cannot set KD_TEXT on stdout: %m");
log_error_errno(errno, "Cannot set KD_TEXT on stdout: %m");
return -errno;
}

View File

@ -468,9 +468,11 @@ static int grdrm_plane_resync(grdrm_plane *plane) {
if (r == -ENOENT) {
card->async_hotplug = true;
r = 0;
log_debug("grdrm: %s: plane %u removed during resync", card->base.name, plane->object.id);
log_debug("grdrm: %s: plane %u removed during resync",
card->base.name, plane->object.id);
} else {
log_debug("grdrm: %s: cannot retrieve plane %u: %m", card->base.name, plane->object.id);
log_debug_errno(errno, "grdrm: %s: cannot retrieve plane %u: %m",
card->base.name, plane->object.id);
}
return r;
@ -625,9 +627,11 @@ static int grdrm_connector_resync(grdrm_connector *connector) {
if (r == -ENOENT) {
card->async_hotplug = true;
r = 0;
log_debug("grdrm: %s: connector %u removed during resync", card->base.name, connector->object.id);
log_debug("grdrm: %s: connector %u removed during resync",
card->base.name, connector->object.id);
} else {
log_debug("grdrm: %s: cannot retrieve connector %u: %m", card->base.name, connector->object.id);
log_debug_errno(errno, "grdrm: %s: cannot retrieve connector %u: %m",
card->base.name, connector->object.id);
}
return r;
@ -783,9 +787,11 @@ static int grdrm_encoder_resync(grdrm_encoder *encoder) {
if (r == -ENOENT) {
card->async_hotplug = true;
r = 0;
log_debug("grdrm: %s: encoder %u removed during resync", card->base.name, encoder->object.id);
log_debug("grdrm: %s: encoder %u removed during resync",
card->base.name, encoder->object.id);
} else {
log_debug("grdrm: %s: cannot retrieve encoder %u: %m", card->base.name, encoder->object.id);
log_debug_errno(errno, "grdrm: %s: cannot retrieve encoder %u: %m",
card->base.name, encoder->object.id);
}
return r;
@ -916,9 +922,11 @@ static int grdrm_crtc_resync(grdrm_crtc *crtc) {
if (r == -ENOENT) {
card->async_hotplug = true;
r = 0;
log_debug("grdrm: %s: crtc %u removed during resync", card->base.name, crtc->object.id);
log_debug("grdrm: %s: crtc %u removed during resync",
card->base.name, crtc->object.id);
} else {
log_debug("grdrm: %s: cannot retrieve crtc %u: %m", card->base.name, crtc->object.id);
log_debug_errno(errno, "grdrm: %s: cannot retrieve crtc %u: %m",
card->base.name, crtc->object.id);
}
return r;
@ -1119,8 +1127,8 @@ static void grdrm_crtc_commit_deep(grdrm_crtc *crtc, grdev_fb *basefb) {
r = ioctl(card->fd, DRM_IOCTL_MODE_SETCRTC, &set_crtc);
if (r < 0) {
r = -errno;
log_debug("grdrm: %s: cannot set crtc %" PRIu32 ": %m",
card->base.name, crtc->object.id);
log_debug_errno(errno, "grdrm: %s: cannot set crtc %" PRIu32 ": %m",
card->base.name, crtc->object.id);
grdrm_card_async(card, r);
return;
@ -1188,8 +1196,8 @@ static int grdrm_crtc_commit_flip(grdrm_crtc *crtc, grdev_fb *basefb) {
* possible to see whether cards support page-flipping, so
* avoid logging on each frame. */
if (r != -EINVAL)
log_debug("grdrm: %s: cannot schedule page-flip on crtc %" PRIu32 ": %m",
card->base.name, crtc->object.id);
log_debug_errno(errno, "grdrm: %s: cannot schedule page-flip on crtc %" PRIu32 ": %m",
card->base.name, crtc->object.id);
if (grdrm_card_async(card, r))
return r;
@ -1241,8 +1249,8 @@ static void grdrm_crtc_commit(grdrm_crtc *crtc) {
r = ioctl(card->fd, DRM_IOCTL_MODE_SETCRTC, &set_crtc);
if (r < 0) {
r = -errno;
log_debug("grdrm: %s: cannot shutdown crtc %" PRIu32 ": %m",
card->base.name, crtc->object.id);
log_debug_errno(errno, "grdrm: %s: cannot shutdown crtc %" PRIu32 ": %m",
card->base.name, crtc->object.id);
grdrm_card_async(card, r);
return;
@ -1298,8 +1306,8 @@ static void grdrm_crtc_restore(grdrm_crtc *crtc) {
r = ioctl(card->fd, DRM_IOCTL_MODE_SETCRTC, &set_crtc);
if (r < 0) {
r = -errno;
log_debug("grdrm: %s: cannot restore crtc %" PRIu32 ": %m",
card->base.name, crtc->object.id);
log_debug_errno(errno, "grdrm: %s: cannot restore crtc %" PRIu32 ": %m",
card->base.name, crtc->object.id);
grdrm_card_async(card, r);
return;
@ -1394,8 +1402,8 @@ static int grdrm_fb_new(grdrm_fb **out, grdrm_card *card, const struct drm_mode_
r = ioctl(card->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
if (r < 0) {
r = negative_errno();
log_debug("grdrm: %s: cannot create dumb buffer %" PRIu32 "x%" PRIu32": %m",
card->base.name, fb->base.width, fb->base.height);
log_debug_errno(errno, "grdrm: %s: cannot create dumb buffer %" PRIu32 "x%" PRIu32": %m",
card->base.name, fb->base.width, fb->base.height);
return r;
}
@ -1408,16 +1416,16 @@ static int grdrm_fb_new(grdrm_fb **out, grdrm_card *card, const struct drm_mode_
r = ioctl(card->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_dumb);
if (r < 0) {
r = negative_errno();
log_debug("grdrm: %s: cannot map dumb buffer %" PRIu32 "x%" PRIu32": %m",
card->base.name, fb->base.width, fb->base.height);
log_debug_errno(errno, "grdrm: %s: cannot map dumb buffer %" PRIu32 "x%" PRIu32": %m",
card->base.name, fb->base.width, fb->base.height);
return r;
}
fb->base.maps[0] = mmap(0, fb->sizes[0], PROT_WRITE, MAP_SHARED, card->fd, map_dumb.offset);
if (fb->base.maps[0] == MAP_FAILED) {
r = negative_errno();
log_debug("grdrm: %s: cannot memory-map dumb buffer %" PRIu32 "x%" PRIu32": %m",
card->base.name, fb->base.width, fb->base.height);
log_debug_errno(errno, "grdrm: %s: cannot memory-map dumb buffer %" PRIu32 "x%" PRIu32": %m",
card->base.name, fb->base.width, fb->base.height);
return r;
}
@ -1434,8 +1442,8 @@ static int grdrm_fb_new(grdrm_fb **out, grdrm_card *card, const struct drm_mode_
r = ioctl(card->fd, DRM_IOCTL_MODE_ADDFB2, &add_fb);
if (r < 0) {
r = negative_errno();
log_debug("grdrm: %s: cannot add framebuffer %" PRIu32 "x%" PRIu32": %m",
card->base.name, fb->base.width, fb->base.height);
log_debug_errno(errno, "grdrm: %s: cannot add framebuffer %" PRIu32 "x%" PRIu32": %m",
card->base.name, fb->base.width, fb->base.height);
return r;
}
@ -1461,8 +1469,8 @@ grdrm_fb *grdrm_fb_free(grdrm_fb *fb) {
if (fb->id > 0 && fb->card->fd >= 0) {
r = ioctl(fb->card->fd, DRM_IOCTL_MODE_RMFB, fb->id);
if (r < 0)
log_debug("grdrm: %s: cannot delete framebuffer %" PRIu32 ": %m",
fb->card->base.name, fb->id);
log_debug_errno(errno, "grdrm: %s: cannot delete framebuffer %" PRIu32 ": %m",
fb->card->base.name, fb->id);
}
for (i = 0; i < ELEMENTSOF(fb->handles); ++i) {
@ -1475,8 +1483,8 @@ grdrm_fb *grdrm_fb_free(grdrm_fb *fb) {
destroy_dumb.handle = fb->handles[i];
r = ioctl(fb->card->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
if (r < 0)
log_debug("grdrm: %s: cannot destroy dumb-buffer %" PRIu32 ": %m",
fb->card->base.name, fb->handles[i]);
log_debug_errno(errno, "grdrm: %s: cannot destroy dumb-buffer %" PRIu32 ": %m",
fb->card->base.name, fb->handles[i]);
}
}
@ -1777,7 +1785,8 @@ static int grdrm_card_resync(grdrm_card *card) {
r = ioctl(card->fd, DRM_IOCTL_MODE_GETRESOURCES, &res);
if (r < 0) {
r = -errno;
log_debug("grdrm: %s: cannot retrieve drm resources: %m", card->base.name);
log_debug_errno(errno, "grdrm: %s: cannot retrieve drm resources: %m",
card->base.name);
return r;
}
@ -1788,7 +1797,8 @@ static int grdrm_card_resync(grdrm_card *card) {
r = ioctl(card->fd, DRM_IOCTL_MODE_GETPLANERESOURCES, &pres);
if (r < 0) {
r = -errno;
log_debug("grdrm: %s: cannot retrieve drm plane-resources: %m", card->base.name);
log_debug_errno(errno, "grdrm: %s: cannot retrieve drm plane-resources: %m",
card->base.name);
return r;
}
@ -1799,7 +1809,8 @@ static int grdrm_card_resync(grdrm_card *card) {
n = ALIGN_POWER2(max);
if (!n || n > UINT16_MAX) {
log_debug("grdrm: %s: excessive DRM resource limit: %" PRIu32, card->base.name, max);
log_debug("grdrm: %s: excessive DRM resource limit: %" PRIu32,
card->base.name, max);
return -ERANGE;
}
@ -2228,7 +2239,8 @@ static int grdrm_card_io_fn(sd_event_source *s, int fd, uint32_t revents, void *
if (errno == EAGAIN || errno == EINTR)
return 0;
log_debug("grdrm: %s/%s: read error: %m", card->base.session->name, card->base.name);
log_debug_errno(errno, "grdrm: %s/%s: read error: %m",
card->base.session->name, card->base.name);
grdrm_card_close(card);
return 0;
}
@ -2237,7 +2249,8 @@ static int grdrm_card_io_fn(sd_event_source *s, int fd, uint32_t revents, void *
event = (void*)buf;
if (len < sizeof(*event) || len < event->length) {
log_debug("grdrm: %s/%s: truncated event", card->base.session->name, card->base.name);
log_debug("grdrm: %s/%s: truncated event",
card->base.session->name, card->base.name);
break;
}
@ -2245,7 +2258,8 @@ static int grdrm_card_io_fn(sd_event_source *s, int fd, uint32_t revents, void *
case DRM_EVENT_FLIP_COMPLETE:
vblank = (void*)event;
if (event->length < sizeof(*vblank)) {
log_debug("grdrm: %s/%s: truncated vblank event", card->base.session->name, card->base.name);
log_debug("grdrm: %s/%s: truncated vblank event",
card->base.session->name, card->base.name);
break;
}
@ -2498,8 +2512,8 @@ static void unmanaged_card_enable(grdev_card *basecard) {
fd = open(cu->devnode, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK);
if (fd < 0) {
/* not fatal; simply ignore the device */
log_debug("grdrm: %s/%s: cannot open node %s: %m",
basecard->session->name, basecard->name, cu->devnode);
log_debug_errno(errno, "grdrm: %s/%s: cannot open node %s: %m",
basecard->session->name, basecard->name, cu->devnode);
return;
}
@ -2515,8 +2529,8 @@ static void unmanaged_card_enable(grdev_card *basecard) {
r = ioctl(cu->card.fd, DRM_IOCTL_SET_MASTER, 0);
if (r < 0) {
log_debug("grdrm: %s/%s: cannot acquire DRM-Master: %m",
basecard->session->name, basecard->name);
log_debug_errno(errno, "grdrm: %s/%s: cannot acquire DRM-Master: %m",
basecard->session->name, basecard->name);
return;
}
@ -2566,8 +2580,8 @@ static int unmanaged_card_new(grdev_card **out, grdev_session *session, struct u
fd = open(cu->devnode, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK);
if (fd < 0) {
/* not fatal; allow uaccess based control on activation */
log_debug("grdrm: %s/%s: cannot open node %s: %m",
basecard->session->name, basecard->name, cu->devnode);
log_debug_errno(errno, "grdrm: %s/%s: cannot open node %s: %m",
basecard->session->name, basecard->name, cu->devnode);
} else {
/* We might get DRM-Master implicitly on open(); drop it immediately
* so we acquire it only once we're actually enabled. We don't
@ -2575,8 +2589,8 @@ static int unmanaged_card_new(grdev_card **out, grdev_session *session, struct u
* weird errors, anyway. */
r = ioctl(fd, DRM_IOCTL_DROP_MASTER, 0);
if (r < 0 && errno != EACCES && errno != EINVAL)
log_debug("grdrm: %s/%s: cannot drop DRM-Master: %m",
basecard->session->name, basecard->name);
log_debug_errno(errno, "grdrm: %s/%s: cannot drop DRM-Master: %m",
basecard->session->name, basecard->name);
r = grdrm_card_open(&cu->card, fd);
if (r < 0)
@ -2771,8 +2785,8 @@ static int managed_card_resume_device_fn(sd_bus *bus,
* and our code works fine this way. */
fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
if (fd < 0) {
log_debug("grdrm: %s/%s: cannot duplicate fd: %m",
session->name, cm->card.base.name);
log_debug_errno(errno, "grdrm: %s/%s: cannot duplicate fd: %m",
session->name, cm->card.base.name);
return 0;
}
@ -2863,8 +2877,8 @@ static int managed_card_take_device_fn(sd_bus *bus,
fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
if (fd < 0) {
log_debug("grdrm: %s/%s: cannot duplicate fd: %m",
session->name, cm->card.base.name);
log_debug_errno(errno, "grdrm: %s/%s: cannot duplicate fd: %m",
session->name, cm->card.base.name);
return 0;
}

View File

@ -426,15 +426,15 @@ static void unmanaged_evdev_resume(idev_element *e) {
fd = open(eu->devnode, O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK);
if (fd < 0) {
if (errno != EACCES && errno != EPERM) {
log_debug("idev-evdev: %s/%s: cannot open node %s: %m",
e->session->name, e->name, eu->devnode);
log_debug_errno(errno, "idev-evdev: %s/%s: cannot open node %s: %m",
e->session->name, e->name, eu->devnode);
return;
}
fd = open(eu->devnode, O_RDONLY | O_CLOEXEC | O_NOCTTY | O_NONBLOCK);
if (fd < 0) {
log_debug("idev-evdev: %s/%s: cannot open node %s: %m",
e->session->name, e->name, eu->devnode);
log_debug_errno(errno, "idev-evdev: %s/%s: cannot open node %s: %m",
e->session->name, e->name, eu->devnode);
return;
}
@ -565,7 +565,7 @@ static int managed_evdev_take_device_fn(sd_bus *bus,
fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
if (fd < 0) {
log_debug("idev-evdev: %s/%s: cannot duplicate evdev fd: %m", s->name, e->name);
log_debug_errno(errno, "idev-evdev: %s/%s: cannot duplicate evdev fd: %m", s->name, e->name);
return 0;
}
@ -698,8 +698,8 @@ static void managed_evdev_resume(idev_element *e, int fd) {
fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
if (fd < 0) {
log_debug("idev-evdev: %s/%s: cannot duplicate evdev fd: %m",
s->name, e->name);
log_debug_errno(errno, "idev-evdev: %s/%s: cannot duplicate evdev fd: %m",
s->name, e->name);
return;
}

View File

@ -355,7 +355,7 @@ static int modeset_sysview_fn(sysview_context *c, void *userdata, sysview_event
r = ioctl(1, KDSKBMODE, K_UNICODE);
if (r < 0) {
log_error("Cannot set K_UNICODE on stdout: %m");
log_error_errno(errno, "Cannot set K_UNICODE on stdout: %m");
return -errno;
}

View File

@ -103,7 +103,7 @@ static int output_winch(Output *o) {
r = ioctl(o->fd, TIOCGWINSZ, &wsz);
if (r < 0) {
log_error("error: cannot read window-size: %m");
log_error_errno(errno, "error: cannot read window-size: %m");
return -errno;
}
@ -707,7 +707,7 @@ static int terminal_io_fn(sd_event_source *source, int fd, uint32_t revents, voi
if (errno == EAGAIN || errno == EINTR)
return 0;
log_error("error: cannot read from TTY (%d): %m", -errno);
log_error_errno(errno, "error: cannot read from TTY (%d): %m", -errno);
return -errno;
}
@ -823,13 +823,13 @@ static int terminal_new(Terminal **out, int in_fd, int out_fd) {
r = tcgetattr(in_fd, &in_attr);
if (r < 0) {
log_error("error: tcgetattr() (%d): %m", -errno);
log_error_errno(errno, "error: tcgetattr() (%d): %m", -errno);
return -errno;
}
r = tcgetattr(out_fd, &out_attr);
if (r < 0) {
log_error("error: tcgetattr() (%d): %m", -errno);
log_error_errno(errno, "error: tcgetattr() (%d): %m", -errno);
return -errno;
}
@ -955,7 +955,7 @@ static int terminal_run(Terminal *t) {
setenv("COLORTERM", "systemd-subterm", 1);
execve(argv[0], argv, environ);
log_error("error: cannot exec %s (%d): %m", argv[0], -errno);
log_error_errno(errno, "error: cannot exec %s (%d): %m", argv[0], -errno);
_exit(1);
}

View File

@ -229,7 +229,7 @@ static int server(sd_bus *bus) {
log_info("Received fd=%d", fd);
if (write(fd, &x, 1) < 0) {
log_error("Failed to write to fd: %m");
log_error_errno(errno, "Failed to write to fd: %m");
safe_close(fd);
goto fail;
}
@ -302,7 +302,7 @@ static void* client1(void*p) {
assert(streq(hello, "hello"));
if (pipe2(pp, O_CLOEXEC|O_NONBLOCK) < 0) {
log_error("Failed to allocate pipe: %m");
log_error_errno(errno, "Failed to allocate pipe: %m");
r = -errno;
goto finish;
}

View File

@ -129,7 +129,7 @@ int udev_device_update_db(struct udev_device *udev_device)
mkdir_parents(filename_tmp, 0755);
f = fopen(filename_tmp, "we");
if (f == NULL) {
log_debug("unable to create temporary db file '%s': %m", filename_tmp);
log_debug_errno(errno, "unable to create temporary db file '%s': %m", filename_tmp);
return -errno;
}

View File

@ -535,7 +535,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile)
f = fopen(dbfile, "re");
if (f == NULL) {
log_debug("no db file to read %s: %m", dbfile);
log_debug_errno(errno, "no db file to read %s: %m", dbfile);
return -errno;
}

View File

@ -289,7 +289,7 @@ _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) {
else if (errno == ENOENT)
continue;
else {
log_debug("error reading %s: %m", hwdb_bin_path);
log_debug_errno(errno, "error reading %s: %m", hwdb_bin_path);
udev_hwdb_unref(hwdb);
return NULL;
}
@ -303,14 +303,14 @@ _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) {
if (fstat(fileno(hwdb->f), &hwdb->st) < 0 ||
(size_t)hwdb->st.st_size < offsetof(struct trie_header_f, strings_len) + 8) {
log_debug("error reading %s: %m", hwdb_bin_path);
log_debug_errno(errno, "error reading %s: %m", hwdb_bin_path);
udev_hwdb_unref(hwdb);
return NULL;
}
hwdb->map = mmap(0, hwdb->st.st_size, PROT_READ, MAP_SHARED, fileno(hwdb->f), 0);
if (hwdb->map == MAP_FAILED) {
log_debug("error mapping %s: %m", hwdb_bin_path);
log_debug_errno(errno, "error mapping %s: %m", hwdb_bin_path);
udev_hwdb_unref(hwdb);
return NULL;
}

View File

@ -121,7 +121,7 @@ static bool udev_has_devtmpfs(struct udev *udev) {
r = name_to_handle_at(AT_FDCWD, "/dev", &h.handle, &mount_id, 0);
if (r < 0) {
if (errno != EOPNOTSUPP)
log_debug("name_to_handle_at on /dev: %m");
log_debug_errno(errno, "name_to_handle_at on /dev: %m");
return false;
}
@ -190,7 +190,7 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c
if (fd < 0) {
udev_monitor->sock = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT);
if (udev_monitor->sock == -1) {
log_debug("error getting socket: %m");
log_debug_errno(errno, "error getting socket: %m");
free(udev_monitor);
return NULL;
}
@ -407,14 +407,14 @@ _public_ int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor)
if (err == 0)
udev_monitor->snl.nl.nl_pid = snl.nl.nl_pid;
} else {
log_debug("bind failed: %m");
log_debug_errno(errno, "bind failed: %m");
return -errno;
}
/* enable receiving of sender credentials */
err = setsockopt(udev_monitor->sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
if (err < 0)
log_debug("setting SO_PASSCRED failed: %m");
log_debug_errno(errno, "setting SO_PASSCRED failed: %m");
return 0;
}

View File

@ -402,7 +402,7 @@ static int list_x11_keymaps(sd_bus *bus, char **args, unsigned n) {
f = fopen("/usr/share/X11/xkb/rules/base.lst", "re");
if (!f) {
log_error("Failed to open keyboard mapping list. %m");
log_error_errno(errno, "Failed to open keyboard mapping list. %m");
return -errno;
}

View File

@ -266,7 +266,7 @@ int main(int argc, char *argv[]) {
pid = fork();
if (pid < 0) {
log_error("Failed to fork: %m");
log_error_errno(errno, "Failed to fork: %m");
return EXIT_FAILURE;
}
@ -276,7 +276,7 @@ int main(int argc, char *argv[]) {
close_all_fds(NULL, 0);
execvp(argv[optind], argv + optind);
log_error("Failed to execute %s: %m", argv[optind]);
log_error_errno(errno, "Failed to execute %s: %m", argv[optind]);
_exit(EXIT_FAILURE);
}

View File

@ -251,12 +251,12 @@ int button_open(Button *b) {
b->fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (b->fd < 0) {
log_warning("Failed to open %s: %m", b->name);
log_warning_errno(errno, "Failed to open %s: %m", b->name);
return -errno;
}
if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
log_error("Failed to get input name: %m");
log_error_errno(errno, "Failed to get input name: %m");
r = -errno;
goto fail;
}

View File

@ -1159,7 +1159,7 @@ static int flush_devices(Manager *m) {
d = opendir("/etc/udev/rules.d");
if (!d) {
if (errno != ENOENT)
log_warning("Failed to open /etc/udev/rules.d: %m");
log_warning_errno(errno, "Failed to open /etc/udev/rules.d: %m");
} else {
struct dirent *de;
@ -1175,7 +1175,7 @@ static int flush_devices(Manager *m) {
continue;
if (unlinkat(dirfd(d), de->d_name, 0) < 0)
log_warning("Failed to unlink %s: %m", de->d_name);
log_warning_errno(errno, "Failed to unlink %s: %m", de->d_name);
}
}

View File

@ -968,7 +968,7 @@ static int session_open_vt(Session *s) {
sprintf(path, "/dev/tty%u", s->vtnr);
s->vtfd = open(path, O_RDWR | O_CLOEXEC | O_NONBLOCK | O_NOCTTY);
if (s->vtfd < 0) {
log_error("cannot open VT %s of session %s: %m", path, s->id);
log_error_errno(errno, "cannot open VT %s of session %s: %m", path, s->id);
return -errno;
}
@ -989,21 +989,21 @@ int session_prepare_vt(Session *s) {
r = fchown(vt, s->user->uid, -1);
if (r < 0) {
r = -errno;
log_error("Cannot change owner of /dev/tty%u: %m", s->vtnr);
log_error_errno(errno, "Cannot change owner of /dev/tty%u: %m", s->vtnr);
goto error;
}
r = ioctl(vt, KDSKBMODE, K_OFF);
if (r < 0) {
r = -errno;
log_error("Cannot set K_OFF on /dev/tty%u: %m", s->vtnr);
log_error_errno(errno, "Cannot set K_OFF on /dev/tty%u: %m", s->vtnr);
goto error;
}
r = ioctl(vt, KDSETMODE, KD_GRAPHICS);
if (r < 0) {
r = -errno;
log_error("Cannot set KD_GRAPHICS on /dev/tty%u: %m", s->vtnr);
log_error_errno(errno, "Cannot set KD_GRAPHICS on /dev/tty%u: %m", s->vtnr);
goto error;
}
@ -1016,7 +1016,7 @@ int session_prepare_vt(Session *s) {
r = ioctl(vt, VT_SETMODE, &mode);
if (r < 0) {
r = -errno;
log_error("Cannot set VT_PROCESS on /dev/tty%u: %m", s->vtnr);
log_error_errno(errno, "Cannot set VT_PROCESS on /dev/tty%u: %m", s->vtnr);
goto error;
}
@ -1073,7 +1073,7 @@ void session_leave_vt(Session *s) {
session_device_pause_all(s);
r = ioctl(s->vtfd, VT_RELDISP, 1);
if (r < 0)
log_debug("Cannot release VT of session %s: %m", s->id);
log_debug_errno(errno, "Cannot release VT of session %s: %m", s->id);
}
bool session_is_controller(Session *s, const char *sender) {

View File

@ -511,7 +511,7 @@ static int user_remove_runtime_path(User *u) {
log_error_errno(r, "Failed to remove runtime directory %s: %m", u->runtime_path);
if (umount2(u->runtime_path, MNT_DETACH) < 0)
log_error("Failed to unmount user runtime directory %s: %m", u->runtime_path);
log_error_errno(errno, "Failed to unmount user runtime directory %s: %m", u->runtime_path);
r = rm_rf(u->runtime_path, false, true, false);
if (r < 0)

View File

@ -290,7 +290,7 @@ static int manager_enumerate_seats(Manager *m) {
if (errno == ENOENT)
return 0;
log_error("Failed to open /run/systemd/seats: %m");
log_error_errno(errno, "Failed to open /run/systemd/seats: %m");
return -errno;
}
@ -327,7 +327,7 @@ static int manager_enumerate_linger_users(Manager *m) {
if (errno == ENOENT)
return 0;
log_error("Failed to open /var/lib/systemd/linger/: %m");
log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m");
return -errno;
}
@ -363,7 +363,7 @@ static int manager_enumerate_users(Manager *m) {
if (errno == ENOENT)
return 0;
log_error("Failed to open /run/systemd/users: %m");
log_error_errno(errno, "Failed to open /run/systemd/users: %m");
return -errno;
}
@ -404,7 +404,7 @@ static int manager_enumerate_sessions(Manager *m) {
if (errno == ENOENT)
return 0;
log_error("Failed to open /run/systemd/sessions: %m");
log_error_errno(errno, "Failed to open /run/systemd/sessions: %m");
return -errno;
}
@ -451,7 +451,7 @@ static int manager_enumerate_inhibitors(Manager *m) {
if (errno == ENOENT)
return 0;
log_error("Failed to open /run/systemd/inhibit: %m");
log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m");
return -errno;
}
@ -568,7 +568,7 @@ static int manager_reserve_vt(Manager *m) {
/* Don't complain on VT-less systems */
if (errno != ENOENT)
log_warning("Failed to pin reserved VT: %m");
log_warning_errno(errno, "Failed to pin reserved VT: %m");
return -errno;
}
@ -753,7 +753,7 @@ static int manager_connect_console(Manager *m) {
if (errno == ENOENT)
return 0;
log_error("Failed to open /sys/class/tty/tty0/active: %m");
log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m");
return -errno;
}

View File

@ -44,7 +44,7 @@ int main(int argc, char*argv[]) {
int r = 0;
if (unlink("/run/nologin") < 0 && errno != ENOENT) {
log_error("Failed to remove /run/nologin file: %m");
log_error_errno(errno, "Failed to remove /run/nologin file: %m");
r = -errno;
}
@ -55,7 +55,7 @@ int main(int argc, char*argv[]) {
* exist), don't complain */
if (errno != EROFS || access("/etc/nologin", F_OK) >= 0) {
log_error("Failed to remove /etc/nologin file: %m");
log_error_errno(errno, "Failed to remove /etc/nologin file: %m");
return EXIT_FAILURE;
}
}

View File

@ -726,7 +726,7 @@ static int login_machine(sd_bus *bus, char **args, unsigned n) {
pty = ptsname(master);
if (!pty) {
log_error("Failed to get pty name: %m");
log_error_errno(errno, "Failed to get pty name: %m");
return -errno;
}
@ -745,7 +745,7 @@ static int login_machine(sd_bus *bus, char **args, unsigned n) {
return log_oom();
if (unlockpt(master) < 0) {
log_error("Failed to unlock tty: %m");
log_error_errno(errno, "Failed to unlock tty: %m");
return -errno;
}

View File

@ -96,7 +96,7 @@ int manager_enumerate_machines(Manager *m) {
if (errno == ENOENT)
return 0;
log_error("Failed to open /run/systemd/machines: %m");
log_error_errno(errno, "Failed to open /run/systemd/machines: %m");
return -errno;
}

View File

@ -151,7 +151,7 @@ static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent
if (feof(f))
break;
log_error("Failed to read file '%s', ignoring: %m", path);
log_error_errno(errno, "Failed to read file '%s', ignoring: %m", path);
return -errno;
}

View File

@ -195,7 +195,7 @@ static int list_links(char **args, unsigned n) {
udev = udev_new();
if (!udev) {
log_error("Failed to connect to udev: %m");
log_error_errno(errno, "Failed to connect to udev: %m");
return -errno;
}
@ -446,7 +446,7 @@ static int link_status(char **args, unsigned n) {
udev = udev_new();
if (!udev) {
log_error("Failed to connect to udev: %m");
log_error_errno(errno, "Failed to connect to udev: %m");
return -errno;
}

View File

@ -302,7 +302,7 @@ static int parse_argv(int argc, char *argv[]) {
free(arg_directory);
arg_directory = canonicalize_file_name(optarg);
if (!arg_directory) {
log_error("Invalid root directory: %m");
log_error_errno(errno, "Invalid root directory: %m");
return -ENOMEM;
}
@ -718,12 +718,12 @@ static int mount_all(const char *dest) {
o) < 0) {
if (mount_table[k].fatal) {
log_error("mount(%s) failed: %m", where);
log_error_errno(errno, "mount(%s) failed: %m", where);
if (r == 0)
r = -errno;
} else
log_warning("mount(%s) failed: %m", where);
log_warning_errno(errno, "mount(%s) failed: %m", where);
}
}
@ -739,7 +739,7 @@ static int mount_binds(const char *dest, char **l, bool ro) {
int r;
if (stat(*x, &source_st) < 0) {
log_error("Failed to stat %s: %m", *x);
log_error_errno(errno, "Failed to stat %s: %m", *x);
return -errno;
}
@ -758,7 +758,7 @@ static int mount_binds(const char *dest, char **l, bool ro) {
if (r < 0)
return log_error_errno(r, "Failed to bind mount %s: %m", *x);
} else {
log_error("Failed to bind mount %s: %m", *x);
log_error_errno(errno, "Failed to bind mount %s: %m", *x);
return -errno;
}
@ -771,14 +771,14 @@ static int mount_binds(const char *dest, char **l, bool ro) {
} else if (S_ISFIFO(source_st.st_mode)) {
r = mkfifo(where, 0644);
if (r < 0 && errno != EEXIST) {
log_error("Failed to create mount point %s: %m", where);
log_error_errno(errno, "Failed to create mount point %s: %m", where);
return -errno;
}
} else if (S_ISSOCK(source_st.st_mode)) {
r = mknod(where, 0644 | S_IFSOCK, 0);
if (r < 0 && errno != EEXIST) {
log_error("Failed to create mount point %s: %m", where);
log_error_errno(errno, "Failed to create mount point %s: %m", where);
return -errno;
}
@ -792,7 +792,7 @@ static int mount_binds(const char *dest, char **l, bool ro) {
}
if (mount(*x, where, "bind", MS_BIND, NULL) < 0) {
log_error("mount(%s) failed: %m", where);
log_error_errno(errno, "mount(%s) failed: %m", where);
return -errno;
}
@ -822,7 +822,7 @@ static int mount_tmpfs(const char *dest) {
return log_error_errno(r, "creating mount point for tmpfs %s failed: %m", where);
if (mount("tmpfs", where, "tmpfs", MS_NODEV|MS_STRICTATIME, *o) < 0) {
log_error("tmpfs mount to %s failed: %m", where);
log_error_errno(errno, "tmpfs mount to %s failed: %m", where);
return -errno;
}
}
@ -889,13 +889,13 @@ static int setup_timezone(const char *dest) {
r = unlink(where);
if (r < 0 && errno != ENOENT) {
log_error("Failed to remove existing timezone info %s in container: %m", where);
log_error_errno(errno, "Failed to remove existing timezone info %s in container: %m", where);
return 0;
}
if (symlink(what, where) < 0) {
log_error("Failed to correct timezone of container: %m");
log_error_errno(errno, "Failed to correct timezone of container: %m");
return 0;
}
@ -954,12 +954,12 @@ static int setup_volatile_state(const char *directory) {
p = strappenda(directory, "/var");
r = mkdir(p, 0755);
if (r < 0 && errno != EEXIST) {
log_error("Failed to create %s: %m", directory);
log_error_errno(errno, "Failed to create %s: %m", directory);
return -errno;
}
if (mount("tmpfs", p, "tmpfs", MS_STRICTATIME, "mode=755") < 0) {
log_error("Failed to mount tmpfs to /var: %m");
log_error_errno(errno, "Failed to mount tmpfs to /var: %m");
return -errno;
}
@ -981,12 +981,12 @@ static int setup_volatile(const char *directory) {
the original /usr to use inside it, and that read-only. */
if (!mkdtemp(template)) {
log_error("Failed to create temporary directory: %m");
log_error_errno(errno, "Failed to create temporary directory: %m");
return -errno;
}
if (mount("tmpfs", template, "tmpfs", MS_STRICTATIME, "mode=755") < 0) {
log_error("Failed to mount tmpfs for root directory: %m");
log_error_errno(errno, "Failed to mount tmpfs for root directory: %m");
r = -errno;
goto fail;
}
@ -998,13 +998,13 @@ static int setup_volatile(const char *directory) {
r = mkdir(t, 0755);
if (r < 0 && errno != EEXIST) {
log_error("Failed to create %s: %m", t);
log_error_errno(errno, "Failed to create %s: %m", t);
r = -errno;
goto fail;
}
if (mount(f, t, "bind", MS_BIND|MS_REC, NULL) < 0) {
log_error("Failed to create /usr bind mount: %m");
log_error_errno(errno, "Failed to create /usr bind mount: %m");
r = -errno;
goto fail;
}
@ -1018,7 +1018,7 @@ static int setup_volatile(const char *directory) {
}
if (mount(template, directory, NULL, MS_MOVE, NULL) < 0) {
log_error("Failed to move root mount: %m");
log_error_errno(errno, "Failed to move root mount: %m");
r = -errno;
goto fail;
}
@ -1075,10 +1075,10 @@ static int setup_boot_id(const char *dest) {
return log_error_errno(r, "Failed to write boot id: %m");
if (mount(from, to, "bind", MS_BIND, NULL) < 0) {
log_error("Failed to bind mount boot id: %m");
log_error_errno(errno, "Failed to bind mount boot id: %m");
r = -errno;
} else if (mount(from, to, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL))
log_warning("Failed to make boot id read-only: %m");
log_warning_errno(errno, "Failed to make boot id read-only: %m");
unlink(from);
return r;
@ -1115,7 +1115,7 @@ static int copy_devnodes(const char *dest) {
if (stat(from, &st) < 0) {
if (errno != ENOENT) {
log_error("Failed to stat %s: %m", from);
log_error_errno(errno, "Failed to stat %s: %m", from);
return -errno;
}
@ -1132,7 +1132,7 @@ static int copy_devnodes(const char *dest) {
}
if (mknod(to, st.st_mode, st.st_rdev) < 0) {
log_error("mknod(%s) failed: %m", dest);
log_error_errno(errno, "mknod(%s) failed: %m", dest);
return -errno;
}
}
@ -1149,7 +1149,7 @@ static int setup_ptmx(const char *dest) {
return log_oom();
if (symlink("pts/ptmx", p) < 0) {
log_error("Failed to create /dev/ptmx symlink: %m");
log_error_errno(errno, "Failed to create /dev/ptmx symlink: %m");
return -errno;
}
@ -1168,7 +1168,7 @@ static int setup_dev_console(const char *dest, const char *console) {
u = umask(0000);
if (stat("/dev/null", &st) < 0) {
log_error("Failed to stat /dev/null: %m");
log_error_errno(errno, "Failed to stat /dev/null: %m");
return -errno;
}
@ -1186,12 +1186,12 @@ static int setup_dev_console(const char *dest, const char *console) {
to = strappenda(dest, "/dev/console");
if (mknod(to, (st.st_mode & ~07777) | 0600, st.st_rdev) < 0) {
log_error("mknod() for /dev/console failed: %m");
log_error_errno(errno, "mknod() for /dev/console failed: %m");
return -errno;
}
if (mount(console, to, "bind", MS_BIND, NULL) < 0) {
log_error("Bind mount for /dev/console failed: %m");
log_error_errno(errno, "Bind mount for /dev/console failed: %m");
return -errno;
}
@ -1229,7 +1229,7 @@ static int setup_kmsg(const char *dest, int kmsg_socket) {
return log_oom();
if (mkfifo(from, 0600) < 0) {
log_error("mkfifo() for /dev/kmsg failed: %m");
log_error_errno(errno, "mkfifo() for /dev/kmsg failed: %m");
return -errno;
}
@ -1238,13 +1238,13 @@ static int setup_kmsg(const char *dest, int kmsg_socket) {
return log_error_errno(r, "Failed to correct access mode for /dev/kmsg: %m");
if (mount(from, to, "bind", MS_BIND, NULL) < 0) {
log_error("Bind mount for /proc/kmsg failed: %m");
log_error_errno(errno, "Bind mount for /proc/kmsg failed: %m");
return -errno;
}
fd = open(from, O_RDWR|O_NDELAY|O_CLOEXEC);
if (fd < 0) {
log_error("Failed to open fifo: %m");
log_error_errno(errno, "Failed to open fifo: %m");
return -errno;
}
@ -1262,7 +1262,7 @@ static int setup_kmsg(const char *dest, int kmsg_socket) {
safe_close(fd);
if (k < 0) {
log_error("Failed to send FIFO fd: %m");
log_error_errno(errno, "Failed to send FIFO fd: %m");
return -errno;
}
@ -1355,12 +1355,12 @@ static int setup_journal(const char *directory) {
r = mkdir_p(q, 0755);
if (r < 0)
log_warning("Failed to create directory %s: %m", q);
log_warning_errno(errno, "Failed to create directory %s: %m", q);
return 0;
}
if (unlink(p) < 0) {
log_error("Failed to remove symlink %s: %m", p);
log_error_errno(errno, "Failed to remove symlink %s: %m", p);
return -errno;
}
} else if (r == -EINVAL) {
@ -1372,12 +1372,12 @@ static int setup_journal(const char *directory) {
log_error("%s already exists and is neither a symlink nor a directory", p);
return r;
} else {
log_error("Failed to remove %s: %m", p);
log_error_errno(errno, "Failed to remove %s: %m", p);
return -errno;
}
}
} else if (r != -ENOENT) {
log_error("readlink(%s) failed: %m", p);
log_error_errno(errno, "readlink(%s) failed: %m", p);
return r;
}
@ -1385,17 +1385,17 @@ static int setup_journal(const char *directory) {
if (symlink(q, p) < 0) {
if (arg_link_journal_try) {
log_debug("Failed to symlink %s to %s, skipping journal setup: %m", q, p);
log_debug_errno(errno, "Failed to symlink %s to %s, skipping journal setup: %m", q, p);
return 0;
} else {
log_error("Failed to symlink %s to %s: %m", q, p);
log_error_errno(errno, "Failed to symlink %s to %s: %m", q, p);
return -errno;
}
}
r = mkdir_p(q, 0755);
if (r < 0)
log_warning("Failed to create directory %s: %m", q);
log_warning_errno(errno, "Failed to create directory %s: %m", q);
return 0;
}
@ -1405,10 +1405,10 @@ static int setup_journal(const char *directory) {
r = mkdir(p, 0755);
if (r < 0) {
if (arg_link_journal_try) {
log_debug("Failed to create %s, skipping journal setup: %m", p);
log_debug_errno(errno, "Failed to create %s, skipping journal setup: %m", p);
return 0;
} else {
log_error("Failed to create %s: %m", p);
log_error_errno(errno, "Failed to create %s: %m", p);
return r;
}
}
@ -1421,12 +1421,12 @@ static int setup_journal(const char *directory) {
r = mkdir_p(q, 0755);
if (r < 0) {
log_error("Failed to create %s: %m", q);
log_error_errno(errno, "Failed to create %s: %m", q);
return r;
}
if (mount(p, q, "bind", MS_BIND, NULL) < 0) {
log_error("Failed to bind mount journal from host into guest: %m");
log_error_errno(errno, "Failed to bind mount journal from host into guest: %m");
return -errno;
}
@ -1753,7 +1753,7 @@ static int setup_veth(pid_t pid, char iface_name[IFNAMSIZ], int *ifi) {
i = (int) if_nametoindex(iface_name);
if (i <= 0) {
log_error("Failed to resolve interface %s: %m", iface_name);
log_error_errno(errno, "Failed to resolve interface %s: %m", iface_name);
return -errno;
}
@ -1778,7 +1778,7 @@ static int setup_bridge(const char veth_name[], int *ifi) {
bridge = (int) if_nametoindex(arg_network_bridge);
if (bridge <= 0) {
log_error("Failed to resolve interface %s: %m", arg_network_bridge);
log_error_errno(errno, "Failed to resolve interface %s: %m", arg_network_bridge);
return -errno;
}
@ -1818,14 +1818,14 @@ static int parse_interface(struct udev *udev, const char *name) {
ifi = (int) if_nametoindex(name);
if (ifi <= 0) {
log_error("Failed to resolve interface %s: %m", name);
log_error_errno(errno, "Failed to resolve interface %s: %m", name);
return -errno;
}
sprintf(ifi_str, "n%i", ifi);
d = udev_device_new_from_device_id(udev, ifi_str);
if (!d) {
log_error("Failed to get udev device for interface %s: %m", name);
log_error_errno(errno, "Failed to get udev device for interface %s: %m", name);
return -errno;
}
@ -2058,12 +2058,12 @@ static int setup_image(char **device_path, int *loop_nr) {
fd = open(arg_image, O_CLOEXEC|(arg_read_only ? O_RDONLY : O_RDWR)|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
log_error("Failed to open %s: %m", arg_image);
log_error_errno(errno, "Failed to open %s: %m", arg_image);
return -errno;
}
if (fstat(fd, &st) < 0) {
log_error("Failed to stat %s: %m", arg_image);
log_error_errno(errno, "Failed to stat %s: %m", arg_image);
return -errno;
}
@ -2085,19 +2085,19 @@ static int setup_image(char **device_path, int *loop_nr) {
}
if (!S_ISREG(st.st_mode)) {
log_error("%s is not a regular file or block device: %m", arg_image);
log_error_errno(errno, "%s is not a regular file or block device: %m", arg_image);
return -EINVAL;
}
control = open("/dev/loop-control", O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (control < 0) {
log_error("Failed to open /dev/loop-control: %m");
log_error_errno(errno, "Failed to open /dev/loop-control: %m");
return -errno;
}
nr = ioctl(control, LOOP_CTL_GET_FREE);
if (nr < 0) {
log_error("Failed to allocate loop device: %m");
log_error_errno(errno, "Failed to allocate loop device: %m");
return -errno;
}
@ -2106,12 +2106,12 @@ static int setup_image(char **device_path, int *loop_nr) {
loop = open(loopdev, O_CLOEXEC|(arg_read_only ? O_RDONLY : O_RDWR)|O_NONBLOCK|O_NOCTTY);
if (loop < 0) {
log_error("Failed to open loop device %s: %m", loopdev);
log_error_errno(errno, "Failed to open loop device %s: %m", loopdev);
return -errno;
}
if (ioctl(loop, LOOP_SET_FD, fd) < 0) {
log_error("Failed to set loopback file descriptor on %s: %m", loopdev);
log_error_errno(errno, "Failed to set loopback file descriptor on %s: %m", loopdev);
return -errno;
}
@ -2119,7 +2119,7 @@ static int setup_image(char **device_path, int *loop_nr) {
info.lo_flags |= LO_FLAGS_READ_ONLY;
if (ioctl(loop, LOOP_SET_STATUS64, &info) < 0) {
log_error("Failed to set loopback settings on %s: %m", loopdev);
log_error_errno(errno, "Failed to set loopback settings on %s: %m", loopdev);
return -errno;
}
@ -2171,7 +2171,7 @@ static int dissect_image(
if (errno == 0)
return log_oom();
log_error("Failed to set device on blkid probe: %m");
log_error_errno(errno, "Failed to set device on blkid probe: %m");
return -errno;
}
@ -2187,7 +2187,7 @@ static int dissect_image(
} else if (r != 0) {
if (errno == 0)
errno = EIO;
log_error("Failed to probe: %m");
log_error_errno(errno, "Failed to probe: %m");
return -errno;
}
@ -2213,7 +2213,7 @@ static int dissect_image(
return log_oom();
if (fstat(fd, &st) < 0) {
log_error("Failed to stat block device: %m");
log_error_errno(errno, "Failed to stat block device: %m");
return -errno;
}
@ -2249,7 +2249,7 @@ static int dissect_image(
if (!errno)
errno = ENOMEM;
log_error("Failed to get partition device of %s: %m", arg_image);
log_error_errno(errno, "Failed to get partition device of %s: %m", arg_image);
return -errno;
}
@ -2404,7 +2404,7 @@ static int mount_device(const char *what, const char *where, const char *directo
if (!b) {
if (errno == 0)
return log_oom();
log_error("Failed to allocate prober for %s: %m", what);
log_error_errno(errno, "Failed to allocate prober for %s: %m", what);
return -errno;
}
@ -2419,7 +2419,7 @@ static int mount_device(const char *what, const char *where, const char *directo
} else if (r != 0) {
if (errno == 0)
errno = EIO;
log_error("Failed to probe %s: %m", what);
log_error_errno(errno, "Failed to probe %s: %m", what);
return -errno;
}
@ -2437,7 +2437,7 @@ static int mount_device(const char *what, const char *where, const char *directo
}
if (mount(what, p, fstype, MS_NODEV|(rw ? 0 : MS_RDONLY), NULL) < 0) {
log_error("Failed to mount %s: %m", what);
log_error_errno(errno, "Failed to mount %s: %m", what);
return -errno;
}
@ -2488,19 +2488,19 @@ static void loop_remove(int nr, int *image_fd) {
if (image_fd && *image_fd >= 0) {
r = ioctl(*image_fd, LOOP_CLR_FD);
if (r < 0)
log_warning("Failed to close loop image: %m");
log_warning_errno(errno, "Failed to close loop image: %m");
*image_fd = safe_close(*image_fd);
}
control = open("/dev/loop-control", O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
if (control < 0) {
log_warning("Failed to open /dev/loop-control: %m");
log_warning_errno(errno, "Failed to open /dev/loop-control: %m");
return;
}
r = ioctl(control, LOOP_CTL_REMOVE, nr);
if (r < 0)
log_warning("Failed to remove loop %d: %m", nr);
log_warning_errno(errno, "Failed to remove loop %d: %m", nr);
}
static int spawn_getent(const char *database, const char *key, pid_t *rpid) {
@ -2512,13 +2512,13 @@ static int spawn_getent(const char *database, const char *key, pid_t *rpid) {
assert(rpid);
if (pipe2(pipe_fds, O_CLOEXEC) < 0) {
log_error("Failed to allocate pipe: %m");
log_error_errno(errno, "Failed to allocate pipe: %m");
return -errno;
}
pid = fork();
if (pid < 0) {
log_error("Failed to fork getent child: %m");
log_error_errno(errno, "Failed to fork getent child: %m");
return -errno;
} else if (pid == 0) {
int nullfd;
@ -2580,17 +2580,17 @@ static int change_uid_gid(char **_home) {
/* Reset everything fully to 0, just in case */
if (setgroups(0, NULL) < 0) {
log_error("setgroups() failed: %m");
log_error_errno(errno, "setgroups() failed: %m");
return -errno;
}
if (setresgid(0, 0, 0) < 0) {
log_error("setregid() failed: %m");
log_error_errno(errno, "setregid() failed: %m");
return -errno;
}
if (setresuid(0, 0, 0) < 0) {
log_error("setreuid() failed: %m");
log_error_errno(errno, "setreuid() failed: %m");
return -errno;
}
@ -2615,7 +2615,7 @@ static int change_uid_gid(char **_home) {
return -ESRCH;
}
log_error("Failed to read from getent: %m");
log_error_errno(errno, "Failed to read from getent: %m");
return -errno;
}
@ -2699,7 +2699,7 @@ static int change_uid_gid(char **_home) {
return -ESRCH;
}
log_error("Failed to read from getent: %m");
log_error_errno(errno, "Failed to read from getent: %m");
return -errno;
}
@ -2741,17 +2741,17 @@ static int change_uid_gid(char **_home) {
fchown(STDERR_FILENO, uid, gid);
if (setgroups(n_uids, uids) < 0) {
log_error("Failed to set auxiliary groups: %m");
log_error_errno(errno, "Failed to set auxiliary groups: %m");
return -errno;
}
if (setresgid(gid, gid, gid) < 0) {
log_error("setregid() failed: %m");
log_error_errno(errno, "setregid() failed: %m");
return -errno;
}
if (setresuid(uid, uid, uid) < 0) {
log_error("setreuid() failed: %m");
log_error_errno(errno, "setreuid() failed: %m");
return -errno;
}
@ -2950,7 +2950,7 @@ int main(int argc, char *argv[]) {
char template[] = "/tmp/nspawn-root-XXXXXX";
if (!mkdtemp(template)) {
log_error("Failed to create temporary directory: %m");
log_error_errno(errno, "Failed to create temporary directory: %m");
r = -errno;
goto finish;
}
@ -2978,13 +2978,13 @@ int main(int argc, char *argv[]) {
master = posix_openpt(O_RDWR|O_NOCTTY|O_CLOEXEC|O_NDELAY);
if (master < 0) {
log_error("Failed to acquire pseudo tty: %m");
log_error_errno(errno, "Failed to acquire pseudo tty: %m");
goto finish;
}
console = ptsname(master);
if (!console) {
log_error("Failed to determine tty name: %m");
log_error_errno(errno, "Failed to determine tty name: %m");
goto finish;
}
@ -2993,12 +2993,12 @@ int main(int argc, char *argv[]) {
arg_machine, arg_image ? arg_image : arg_directory);
if (unlockpt(master) < 0) {
log_error("Failed to unlock tty: %m");
log_error_errno(errno, "Failed to unlock tty: %m");
goto finish;
}
if (socketpair(AF_UNIX, SOCK_DGRAM|SOCK_NONBLOCK|SOCK_CLOEXEC, 0, kmsg_socket_pair) < 0) {
log_error("Failed to create kmsg socket pair: %m");
log_error_errno(errno, "Failed to create kmsg socket pair: %m");
goto finish;
}
@ -3032,13 +3032,13 @@ int main(int argc, char *argv[]) {
* give it a chance to call wait() and terminate. */
r = sigprocmask(SIG_UNBLOCK, &mask_chld, NULL);
if (r < 0) {
log_error("Failed to change the signal mask: %m");
log_error_errno(errno, "Failed to change the signal mask: %m");
goto finish;
}
r = sigaction(SIGCHLD, &sa, NULL);
if (r < 0) {
log_error("Failed to install SIGCHLD handler: %m");
log_error_errno(errno, "Failed to install SIGCHLD handler: %m");
goto finish;
}
@ -3047,9 +3047,9 @@ int main(int argc, char *argv[]) {
(arg_private_network ? CLONE_NEWNET : 0), NULL);
if (pid < 0) {
if (errno == EINVAL)
log_error("clone() failed, do you have namespace support enabled in your kernel? (You need UTS, IPC, PID and NET namespacing built in): %m");
log_error_errno(errno, "clone() failed, do you have namespace support enabled in your kernel? (You need UTS, IPC, PID and NET namespacing built in): %m");
else
log_error("clone() failed: %m");
log_error_errno(errno, "clone() failed: %m");
r = pid;
goto finish;
@ -3103,12 +3103,12 @@ int main(int argc, char *argv[]) {
if (dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO ||
dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO) {
log_error("Failed to duplicate console: %m");
log_error_errno(errno, "Failed to duplicate console: %m");
_exit(EXIT_FAILURE);
}
if (setsid() < 0) {
log_error("setsid() failed: %m");
log_error_errno(errno, "setsid() failed: %m");
_exit(EXIT_FAILURE);
}
@ -3116,7 +3116,7 @@ int main(int argc, char *argv[]) {
_exit(EXIT_FAILURE);
if (prctl(PR_SET_PDEATHSIG, SIGKILL) < 0) {
log_error("PR_SET_PDEATHSIG failed: %m");
log_error_errno(errno, "PR_SET_PDEATHSIG failed: %m");
_exit(EXIT_FAILURE);
}
@ -3124,7 +3124,7 @@ int main(int argc, char *argv[]) {
* receive mounts from the real root, but don't
* propagate mounts to the real root. */
if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL) < 0) {
log_error("MS_SLAVE|MS_REC failed: %m");
log_error_errno(errno, "MS_SLAVE|MS_REC failed: %m");
_exit(EXIT_FAILURE);
}
@ -3136,7 +3136,7 @@ int main(int argc, char *argv[]) {
/* Turn directory into bind mount */
if (mount(arg_directory, arg_directory, "bind", MS_BIND|MS_REC, NULL) < 0) {
log_error("Failed to make bind mount: %m");
log_error_errno(errno, "Failed to make bind mount: %m");
_exit(EXIT_FAILURE);
}
@ -3208,22 +3208,22 @@ int main(int argc, char *argv[]) {
(void)barrier_place(&barrier);
if (chdir(arg_directory) < 0) {
log_error("chdir(%s) failed: %m", arg_directory);
log_error_errno(errno, "chdir(%s) failed: %m", arg_directory);
_exit(EXIT_FAILURE);
}
if (mount(arg_directory, "/", NULL, MS_MOVE, NULL) < 0) {
log_error("mount(MS_MOVE) failed: %m");
log_error_errno(errno, "mount(MS_MOVE) failed: %m");
_exit(EXIT_FAILURE);
}
if (chroot(".") < 0) {
log_error("chroot() failed: %m");
log_error_errno(errno, "chroot() failed: %m");
_exit(EXIT_FAILURE);
}
if (chdir("/") < 0) {
log_error("chdir() failed: %m");
log_error_errno(errno, "chdir() failed: %m");
_exit(EXIT_FAILURE);
}
@ -3233,7 +3233,7 @@ int main(int argc, char *argv[]) {
loopback_setup();
if (drop_capabilities() < 0) {
log_error("drop_capabilities() failed: %m");
log_error_errno(errno, "drop_capabilities() failed: %m");
_exit(EXIT_FAILURE);
}
@ -3275,12 +3275,12 @@ int main(int argc, char *argv[]) {
if (arg_personality != 0xffffffffLU) {
if (personality(arg_personality) < 0) {
log_error("personality() failed: %m");
log_error_errno(errno, "personality() failed: %m");
_exit(EXIT_FAILURE);
}
} else if (secondary) {
if (personality(PER_LINUX32) < 0) {
log_error("personality() failed: %m");
log_error_errno(errno, "personality() failed: %m");
_exit(EXIT_FAILURE);
}
}
@ -3288,7 +3288,7 @@ int main(int argc, char *argv[]) {
#ifdef HAVE_SELINUX
if (arg_selinux_context)
if (setexeccon((security_context_t) arg_selinux_context) < 0) {
log_error("setexeccon(\"%s\") failed: %m", arg_selinux_context);
log_error_errno(errno, "setexeccon(\"%s\") failed: %m", arg_selinux_context);
_exit(EXIT_FAILURE);
}
#endif
@ -3336,7 +3336,7 @@ int main(int argc, char *argv[]) {
execle("/bin/sh", "-sh", NULL, env_use);
}
log_error("execv() failed: %m");
log_error_errno(errno, "execv() failed: %m");
_exit(EXIT_FAILURE);
}

View File

@ -103,7 +103,7 @@ int main(int argc, char *argv[]) {
pid = fork();
if (pid < 0) {
log_error("fork(): %m");
log_error_errno(errno, "fork(): %m");
return EXIT_FAILURE;
} else if (pid == 0) {
/* Child */

View File

@ -86,7 +86,7 @@ int main(int argc, char *argv[]) {
if (seed_fd < 0) {
seed_fd = open(RANDOM_SEED, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (seed_fd < 0) {
log_error("Failed to open " RANDOM_SEED ": %m");
log_error_errno(errno, "Failed to open " RANDOM_SEED ": %m");
r = -errno;
goto finish;
}
@ -96,7 +96,7 @@ int main(int argc, char *argv[]) {
if (random_fd < 0) {
random_fd = open("/dev/urandom", O_WRONLY|O_CLOEXEC|O_NOCTTY, 0600);
if (random_fd < 0) {
log_error("Failed to open /dev/urandom: %m");
log_error_errno(errno, "Failed to open /dev/urandom: %m");
r = -errno;
goto finish;
}
@ -106,7 +106,7 @@ int main(int argc, char *argv[]) {
if (k <= 0) {
if (r != 0)
log_error("Failed to read seed from " RANDOM_SEED ": %m");
log_error_errno(errno, "Failed to read seed from " RANDOM_SEED ": %m");
r = k == 0 ? -EIO : (int) k;
@ -125,14 +125,14 @@ int main(int argc, char *argv[]) {
seed_fd = open(RANDOM_SEED, O_WRONLY|O_CLOEXEC|O_NOCTTY|O_CREAT, 0600);
if (seed_fd < 0) {
log_error("Failed to open " RANDOM_SEED ": %m");
log_error_errno(errno, "Failed to open " RANDOM_SEED ": %m");
r = -errno;
goto finish;
}
random_fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (random_fd < 0) {
log_error("Failed to open /dev/urandom: %m");
log_error_errno(errno, "Failed to open /dev/urandom: %m");
r = -errno;
goto finish;
}

View File

@ -60,7 +60,7 @@ static int add_symlink(const char *service, const char *where) {
if (errno == EEXIST)
return 0;
log_error("Failed to create symlink %s: %m", to);
log_error_errno(errno, "Failed to create symlink %s: %m", to);
return -errno;
}

View File

@ -60,7 +60,7 @@ int main(int argc, char *argv[]) {
if (errno == ENOENT)
return EXIT_SUCCESS;
log_error("Failed to open /etc/fstab: %m");
log_error_errno(errno, "Failed to open /etc/fstab: %m");
return EXIT_FAILURE;
}
@ -87,7 +87,7 @@ int main(int argc, char *argv[]) {
pid = fork();
if (pid < 0) {
log_error("Failed to fork: %m");
log_error_errno(errno, "Failed to fork: %m");
ret = EXIT_FAILURE;
continue;
}
@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
execv("/bin/mount", (char **) arguments);
log_error("Failed to execute /bin/mount: %m");
log_error_errno(errno, "Failed to execute /bin/mount: %m");
_exit(EXIT_FAILURE);
}
@ -135,7 +135,7 @@ int main(int argc, char *argv[]) {
if (errno == EINTR)
continue;
log_error("waitid() failed: %m");
log_error_errno(errno, "waitid() failed: %m");
ret = EXIT_FAILURE;
break;
}

View File

@ -52,7 +52,7 @@ static int send_on_socket(int fd, const char *socket_name, const void *packet, s
strncpy(sa.un.sun_path, socket_name, sizeof(sa.un.sun_path));
if (sendto(fd, packet, size, MSG_NOSIGNAL, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(socket_name)) < 0) {
log_error("Failed to send: %m");
log_error_errno(errno, "Failed to send: %m");
return -errno;
}
@ -77,7 +77,7 @@ int main(int argc, char *argv[]) {
packet[0] = '+';
if (!fgets(packet+1, sizeof(packet)-1, stdin)) {
log_error("Failed to read password: %m");
log_error_errno(errno, "Failed to read password: %m");
goto finish;
}
@ -93,7 +93,7 @@ int main(int argc, char *argv[]) {
fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (fd < 0) {
log_error("socket() failed: %m");
log_error_errno(errno, "socket() failed: %m");
goto finish;
}

View File

@ -514,7 +514,7 @@ static int parse_argv(int argc, char *argv[]) {
case 'i':
arg_ifindex = if_nametoindex(optarg);
if (arg_ifindex <= 0) {
log_error("Unknown interfaces %s: %m", optarg);
log_error_errno(errno, "Unknown interfaces %s: %m", optarg);
return -errno;
}
break;

View File

@ -172,11 +172,11 @@ static int dns_stream_identify(DnsStream *s) {
if (s->local.sa.sa_family == AF_INET) {
r = setsockopt(s->fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex, sizeof(ifindex));
if (r < 0)
log_debug("Failed to invoke IP_UNICAST_IF: %m");
log_debug_errno(errno, "Failed to invoke IP_UNICAST_IF: %m");
} else if (s->local.sa.sa_family == AF_INET6) {
r = setsockopt(s->fd, IPPROTO_IPV6, IPV6_UNICAST_IF, &ifindex, sizeof(ifindex));
if (r < 0)
log_debug("Failed to invoke IPV6_UNICAST_IF: %m");
log_debug_errno(errno, "Failed to invoke IPV6_UNICAST_IF: %m");
}
}

View File

@ -370,7 +370,7 @@ static int manager_watch_hostname(Manager *m) {
m->hostname_fd = open("/proc/sys/kernel/hostname", O_RDONLY|O_CLOEXEC|O_NDELAY|O_NOCTTY);
if (m->hostname_fd < 0) {
log_warning("Failed to watch hostname: %m");
log_warning_errno(errno, "Failed to watch hostname: %m");
return 0;
}
@ -591,7 +591,7 @@ int manager_read_resolv_conf(Manager *m) {
r = stat("/etc/resolv.conf", &st);
if (r < 0) {
if (errno != ENOENT)
log_warning("Failed to open /etc/resolv.conf: %m");
log_warning_errno(errno, "Failed to open /etc/resolv.conf: %m");
r = -errno;
goto clear;
}
@ -614,13 +614,13 @@ int manager_read_resolv_conf(Manager *m) {
f = fopen("/etc/resolv.conf", "re");
if (!f) {
if (errno != ENOENT)
log_warning("Failed to open /etc/resolv.conf: %m");
log_warning_errno(errno, "Failed to open /etc/resolv.conf: %m");
r = -errno;
goto clear;
}
if (fstat(fileno(f), &st) < 0) {
log_error("Failed to stat open file: %m");
log_error_errno(errno, "Failed to stat open file: %m");
r = -errno;
goto clear;
}

View File

@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
device = udev_device_new_from_subsystem_sysname(udev, "rfkill", argv[2]);
if (!device) {
if (errno != 0)
log_error("Failed to get rfkill device '%s': %m", argv[2]);
log_error_errno(errno, "Failed to get rfkill device '%s': %m", argv[2]);
else
log_oom();

View File

@ -489,7 +489,7 @@ static int start_transient_scope(
if (arg_nice_set) {
if (setpriority(PRIO_PROCESS, 0, arg_nice) < 0) {
log_error("Failed to set nice level: %m");
log_error_errno(errno, "Failed to set nice level: %m");
return -errno;
}
}
@ -502,7 +502,7 @@ static int start_transient_scope(
return log_error_errno(r, "Failed to resolve group %s: %m", arg_exec_group);
if (setresgid(gid, gid, gid) < 0) {
log_error("Failed to change GID to " GID_FMT ": %m", gid);
log_error_errno(errno, "Failed to change GID to " GID_FMT ": %m", gid);
return -errno;
}
}
@ -534,13 +534,13 @@ static int start_transient_scope(
if (!arg_exec_group) {
if (setresgid(gid, gid, gid) < 0) {
log_error("Failed to change GID to " GID_FMT ": %m", gid);
log_error_errno(errno, "Failed to change GID to " GID_FMT ": %m", gid);
return -errno;
}
}
if (setresuid(uid, uid, uid) < 0) {
log_error("Failed to change UID to " UID_FMT ": %m", uid);
log_error_errno(errno, "Failed to change UID to " UID_FMT ": %m", uid);
return -errno;
}
}
@ -552,7 +552,7 @@ static int start_transient_scope(
log_info("Running as unit %s.", name);
execvpe(argv[0], argv, env);
log_error("Failed to execute: %m");
log_error_errno(errno, "Failed to execute: %m");
return -errno;
}

View File

@ -259,7 +259,7 @@ static int create_socket(char **name) {
fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
if (fd < 0) {
log_error("socket() failed: %m");
log_error_errno(errno, "socket() failed: %m");
return -errno;
}
@ -271,13 +271,13 @@ static int create_socket(char **name) {
if (r < 0) {
r = -errno;
log_error("bind(%s) failed: %m", sa.un.sun_path);
log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
goto fail;
}
if (setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) {
r = -errno;
log_error("SO_PASSCRED failed: %m");
log_error_errno(errno, "SO_PASSCRED failed: %m");
goto fail;
}
@ -330,7 +330,7 @@ int ask_password_agent(
fd = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC);
if (fd < 0) {
log_error("Failed to create password file: %m");
log_error_errno(errno, "Failed to create password file: %m");
r = -errno;
goto finish;
}
@ -339,7 +339,7 @@ int ask_password_agent(
f = fdopen(fd, "w");
if (!f) {
log_error("Failed to allocate FILE: %m");
log_error_errno(errno, "Failed to allocate FILE: %m");
r = -errno;
goto finish;
}
@ -348,7 +348,7 @@ int ask_password_agent(
signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
if (signal_fd < 0) {
log_error("signalfd(): %m");
log_error_errno(errno, "signalfd(): %m");
r = -errno;
goto finish;
}
@ -384,7 +384,7 @@ int ask_password_agent(
fflush(f);
if (ferror(f)) {
log_error("Failed to write query file: %m");
log_error_errno(errno, "Failed to write query file: %m");
r = -errno;
goto finish;
}
@ -396,7 +396,7 @@ int ask_password_agent(
final[sizeof(final)-9] = 'k';
if (rename(temp, final) < 0) {
log_error("Failed to rename query file: %m");
log_error_errno(errno, "Failed to rename query file: %m");
r = -errno;
goto finish;
}
@ -433,7 +433,7 @@ int ask_password_agent(
if (errno == EINTR)
continue;
log_error("poll() failed: %m");
log_error_errno(errno, "poll() failed: %m");
r = -errno;
goto finish;
}
@ -472,7 +472,7 @@ int ask_password_agent(
errno == EINTR)
continue;
log_error("recvmsg() failed: %m");
log_error_errno(errno, "recvmsg() failed: %m");
r = -errno;
goto finish;
}

View File

@ -59,7 +59,7 @@ int base_filesystem_create(const char *root) {
fd = open(root, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
if (fd < 0) {
log_error("Failed to open root file system: %m");
log_error_errno(errno, "Failed to open root file system: %m");
return -errno;
}
@ -96,7 +96,7 @@ int base_filesystem_create(const char *root) {
r = symlinkat(target, fd, table[i].dir);
if (r < 0 && errno != EEXIST) {
log_error("Failed to create symlink at %s/%s: %m", root, table[i].dir);
log_error_errno(errno, "Failed to create symlink at %s/%s: %m", root, table[i].dir);
return -errno;
}
continue;
@ -105,7 +105,7 @@ int base_filesystem_create(const char *root) {
RUN_WITH_UMASK(0000)
r = mkdirat(fd, table[i].dir, table[i].mode);
if (r < 0 && errno != EEXIST) {
log_error("Failed to create directory at %s/%s: %m", root, table[i].dir);
log_error_errno(errno, "Failed to create directory at %s/%s: %m", root, table[i].dir);
return -errno;
}
}

View File

@ -228,28 +228,28 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) {
* which we want to avoid. */
if (setresgid(gid, gid, gid) < 0) {
log_error("Failed to change group ID: %m");
log_error_errno(errno, "Failed to change group ID: %m");
return -errno;
}
if (setgroups(0, NULL) < 0) {
log_error("Failed to drop auxiliary groups list: %m");
log_error_errno(errno, "Failed to drop auxiliary groups list: %m");
return -errno;
}
if (prctl(PR_SET_KEEPCAPS, 1) < 0) {
log_error("Failed to enable keep capabilities flag: %m");
log_error_errno(errno, "Failed to enable keep capabilities flag: %m");
return -errno;
}
r = setresuid(uid, uid, uid);
if (r < 0) {
log_error("Failed to change user ID: %m");
log_error_errno(errno, "Failed to change user ID: %m");
return -errno;
}
if (prctl(PR_SET_KEEPCAPS, 0) < 0) {
log_error("Failed to disable keep capabilities flag: %m");
log_error_errno(errno, "Failed to disable keep capabilities flag: %m");
return -errno;
}
@ -271,13 +271,13 @@ int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) {
if (cap_set_flag(d, CAP_EFFECTIVE, j, bits, CAP_SET) < 0 ||
cap_set_flag(d, CAP_PERMITTED, j, bits, CAP_SET) < 0) {
log_error("Failed to enable capabilities bits: %m");
log_error_errno(errno, "Failed to enable capabilities bits: %m");
return -errno;
}
}
if (cap_set_proc(d) < 0) {
log_error("Failed to increase capabilities: %m");
log_error_errno(errno, "Failed to increase capabilities: %m");
return -errno;
}

View File

@ -44,7 +44,7 @@ static int clean_sysvipc_shm(uid_t delete_uid) {
if (errno == ENOENT)
return 0;
log_warning("Failed to open /proc/sysvipc/shm: %m");
log_warning_errno(errno, "Failed to open /proc/sysvipc/shm: %m");
return -errno;
}
@ -78,7 +78,7 @@ static int clean_sysvipc_shm(uid_t delete_uid) {
if (errno == EIDRM || errno == EINVAL)
continue;
log_warning("Failed to remove SysV shared memory segment %i: %m", shmid);
log_warning_errno(errno, "Failed to remove SysV shared memory segment %i: %m", shmid);
ret = -errno;
}
}
@ -86,7 +86,7 @@ static int clean_sysvipc_shm(uid_t delete_uid) {
return ret;
fail:
log_warning("Failed to read /proc/sysvipc/shm: %m");
log_warning_errno(errno, "Failed to read /proc/sysvipc/shm: %m");
return -errno;
}
@ -101,7 +101,7 @@ static int clean_sysvipc_sem(uid_t delete_uid) {
if (errno == ENOENT)
return 0;
log_warning("Failed to open /proc/sysvipc/sem: %m");
log_warning_errno(errno, "Failed to open /proc/sysvipc/sem: %m");
return -errno;
}
@ -130,7 +130,7 @@ static int clean_sysvipc_sem(uid_t delete_uid) {
if (errno == EIDRM || errno == EINVAL)
continue;
log_warning("Failed to remove SysV semaphores object %i: %m", semid);
log_warning_errno(errno, "Failed to remove SysV semaphores object %i: %m", semid);
ret = -errno;
}
}
@ -138,7 +138,7 @@ static int clean_sysvipc_sem(uid_t delete_uid) {
return ret;
fail:
log_warning("Failed to read /proc/sysvipc/sem: %m");
log_warning_errno(errno, "Failed to read /proc/sysvipc/sem: %m");
return -errno;
}
@ -153,7 +153,7 @@ static int clean_sysvipc_msg(uid_t delete_uid) {
if (errno == ENOENT)
return 0;
log_warning("Failed to open /proc/sysvipc/msg: %m");
log_warning_errno(errno, "Failed to open /proc/sysvipc/msg: %m");
return -errno;
}
@ -183,7 +183,7 @@ static int clean_sysvipc_msg(uid_t delete_uid) {
if (errno == EIDRM || errno == EINVAL)
continue;
log_warning("Failed to remove SysV message queue %i: %m", msgid);
log_warning_errno(errno, "Failed to remove SysV message queue %i: %m", msgid);
ret = -errno;
}
}
@ -191,7 +191,7 @@ static int clean_sysvipc_msg(uid_t delete_uid) {
return ret;
fail:
log_warning("Failed to read /proc/sysvipc/msg: %m");
log_warning_errno(errno, "Failed to read /proc/sysvipc/msg: %m");
return -errno;
}
@ -211,7 +211,7 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
if (errno == ENOENT)
continue;
log_warning("Failed to stat() POSIX shared memory segment %s: %m", de->d_name);
log_warning_errno(errno, "Failed to stat() POSIX shared memory segment %s: %m", de->d_name);
ret = -errno;
continue;
}
@ -225,7 +225,7 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
kid = xopendirat(dirfd(dir), de->d_name, O_NOFOLLOW|O_NOATIME);
if (!kid) {
if (errno != ENOENT) {
log_warning("Failed to enter shared memory directory %s: %m", de->d_name);
log_warning_errno(errno, "Failed to enter shared memory directory %s: %m", de->d_name);
ret = -errno;
}
} else {
@ -239,7 +239,7 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
if (errno == ENOENT)
continue;
log_warning("Failed to remove POSIX shared memory directory %s: %m", de->d_name);
log_warning_errno(errno, "Failed to remove POSIX shared memory directory %s: %m", de->d_name);
ret = -errno;
}
} else {
@ -249,7 +249,7 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
if (errno == ENOENT)
continue;
log_warning("Failed to remove POSIX shared memory segment %s: %m", de->d_name);
log_warning_errno(errno, "Failed to remove POSIX shared memory segment %s: %m", de->d_name);
ret = -errno;
}
}
@ -258,7 +258,7 @@ static int clean_posix_shm_internal(DIR *dir, uid_t uid) {
return ret;
fail:
log_warning("Failed to read /dev/shm: %m");
log_warning_errno(errno, "Failed to read /dev/shm: %m");
return -errno;
}
@ -270,7 +270,7 @@ static int clean_posix_shm(uid_t uid) {
if (errno == ENOENT)
return 0;
log_warning("Failed to open /dev/shm: %m");
log_warning_errno(errno, "Failed to open /dev/shm: %m");
return -errno;
}
@ -287,7 +287,7 @@ static int clean_posix_mq(uid_t uid) {
if (errno == ENOENT)
return 0;
log_warning("Failed to open /dev/mqueue: %m");
log_warning_errno(errno, "Failed to open /dev/mqueue: %m");
return -errno;
}
@ -302,7 +302,7 @@ static int clean_posix_mq(uid_t uid) {
if (errno == ENOENT)
continue;
log_warning("Failed to stat() MQ segment %s: %m", de->d_name);
log_warning_errno(errno, "Failed to stat() MQ segment %s: %m", de->d_name);
ret = -errno;
continue;
}
@ -317,7 +317,7 @@ static int clean_posix_mq(uid_t uid) {
if (errno == ENOENT)
continue;
log_warning("Failed to unlink POSIX message queue %s: %m", fn);
log_warning_errno(errno, "Failed to unlink POSIX message queue %s: %m", fn);
ret = -errno;
}
}
@ -325,7 +325,7 @@ static int clean_posix_mq(uid_t uid) {
return ret;
fail:
log_warning("Failed to read /dev/mqueue: %m");
log_warning_errno(errno, "Failed to read /dev/mqueue: %m");
return -errno;
}

Some files were not shown because too many files have changed in this diff Show More