1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

tree-wide: make use of log_error_errno() return value

Turns this:

        r = -errno;
        log_error_errno(errno, "foo");

into this:

        r = log_error_errno(errno, "foo");

and this:

        r = log_error_errno(errno, "foo");
        return r;

into this:

        return log_error_errno(errno, "foo");
This commit is contained in:
Lennart Poettering 2015-09-08 19:30:45 +02:00
parent 3cc2aff1ab
commit 76ef789d26
18 changed files with 80 additions and 62 deletions

42
coccinelle/errno.cocci Normal file
View File

@ -0,0 +1,42 @@
@@
identifier r;
expression t, e;
@@
- r = -e;
- log_error_errno(e, t);
+ r = log_error_errno(e, t);
@@
identifier r;
expression t, e;
@@
- log_error_errno(e, t);
- r = -e;
+ r = log_error_errno(e, t);
@@
identifier r;
expression t, e;
@@
- r = log_error_errno(e, t);
- return r;
+ return log_error_errno(e, t);
@@
identifier r;
expression t, e;
@@
- r = -e;
- log_warning_errno(e, t);
+ r = log_warning_errno(e, t);
@@
identifier r;
expression t, e;
@@
- log_warning_errno(e, t);
- r = -e;
+ r = log_warning_errno(e, t);
@@
identifier r;
expression t, e;
@@
- r = log_warning_errno(e, t);
- return r;
+ return log_warning_errno(e, t);

View File

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

View File

@ -288,8 +288,7 @@ static int mount_kdbus(BindMount *m) {
/* create a new /dev/null dev node copy so we have some fodder to /* create a new /dev/null dev node copy so we have some fodder to
* bind-mount the custom endpoint over. */ * bind-mount the custom endpoint over. */
if (stat("/dev/null", &st) < 0) { if (stat("/dev/null", &st) < 0) {
log_error_errno(errno, "Failed to stat /dev/null: %m"); r = log_error_errno(errno, "Failed to stat /dev/null: %m");
r = -errno;
goto fail; goto fail;
} }

View File

@ -404,8 +404,7 @@ int main(int argc, char *argv[]) {
exit(0); exit(0);
} }
log_error_errno(errno, "Failed to invoke reboot(): %m"); r = log_error_errno(errno, "Failed to invoke reboot(): %m");
r = -errno;
error: error:
log_emergency_errno(r, "Critical error while doing system shutdown: %m"); log_emergency_errno(r, "Critical error while doing system shutdown: %m");

View File

@ -269,8 +269,8 @@ static int server_init(Server *s, unsigned n_sockets) {
s->epoll_fd = epoll_create1(EPOLL_CLOEXEC); s->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (s->epoll_fd < 0) { if (s->epoll_fd < 0) {
r = -errno; r = log_error_errno(errno,
log_error_errno(errno, "Failed to create epoll object: %m"); "Failed to create epoll object: %m");
goto fail; goto fail;
} }

View File

@ -88,8 +88,7 @@ static int spawn_child(const char* child, char** argv) {
child_pid = fork(); child_pid = fork();
if (child_pid < 0) { if (child_pid < 0) {
r = -errno; r = log_error_errno(errno, "Failed to fork: %m");
log_error_errno(errno, "Failed to fork: %m");
safe_close_pair(fd); safe_close_pair(fd);
return r; return r;
} }

View File

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

View File

@ -631,8 +631,8 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) {
sz = write(fdt, data, len); sz = write(fdt, data, len);
if (sz < 0) { if (sz < 0) {
log_error_errno(errno, "Failed to write temporary file: %m"); r = log_error_errno(errno,
r = -errno; "Failed to write temporary file: %m");
goto error; goto error;
} }
if (sz != (ssize_t) len) { if (sz != (ssize_t) len) {
@ -758,8 +758,7 @@ static int run_gdb(sd_journal *j) {
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
log_error_errno(errno, "Failed to fork(): %m"); r = log_error_errno(errno, "Failed to fork(): %m");
r = -errno;
goto finish; goto finish;
} }
if (pid == 0) { if (pid == 0) {

View File

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

View File

@ -1428,8 +1428,7 @@ static int setup_keys(void) {
fd = open("/dev/random", O_RDONLY|O_CLOEXEC|O_NOCTTY); fd = open("/dev/random", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0) { if (fd < 0) {
log_error_errno(errno, "Failed to open /dev/random: %m"); r = log_error_errno(errno, "Failed to open /dev/random: %m");
r = -errno;
goto finish; goto finish;
} }
@ -1488,8 +1487,7 @@ static int setup_keys(void) {
} }
if (link(k, p) < 0) { if (link(k, p) < 0) {
log_error_errno(errno, "Failed to link file: %m"); r = log_error_errno(errno, "Failed to link file: %m");
r = -errno;
goto finish; goto finish;
} }

View File

@ -248,8 +248,7 @@ int button_open(Button *b) {
return log_warning_errno(errno, "Failed to open %s: %m", b->name); return log_warning_errno(errno, "Failed to open %s: %m", b->name);
if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) { if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
log_error_errno(errno, "Failed to get input name: %m"); r = log_error_errno(errno, "Failed to get input name: %m");
r = -errno;
goto fail; goto fail;
} }

View File

@ -619,8 +619,7 @@ int manager_read_resolv_conf(Manager *m) {
} }
if (fstat(fileno(f), &st) < 0) { if (fstat(fileno(f), &st) < 0) {
log_error_errno(errno, "Failed to stat open file: %m"); r = log_error_errno(errno, "Failed to stat open file: %m");
r = -errno;
goto clear; goto clear;
} }

View File

@ -331,8 +331,8 @@ int ask_password_agent(
fd = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC); fd = mkostemp_safe(temp, O_WRONLY|O_CLOEXEC);
if (fd < 0) { if (fd < 0) {
log_error_errno(errno, "Failed to create password file: %m"); r = log_error_errno(errno,
r = -errno; "Failed to create password file: %m");
goto finish; goto finish;
} }
@ -340,8 +340,7 @@ int ask_password_agent(
f = fdopen(fd, "w"); f = fdopen(fd, "w");
if (!f) { if (!f) {
log_error_errno(errno, "Failed to allocate FILE: %m"); r = log_error_errno(errno, "Failed to allocate FILE: %m");
r = -errno;
goto finish; goto finish;
} }
@ -349,8 +348,7 @@ int ask_password_agent(
signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC); signal_fd = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
if (signal_fd < 0) { if (signal_fd < 0) {
log_error_errno(errno, "signalfd(): %m"); r = log_error_errno(errno, "signalfd(): %m");
r = -errno;
goto finish; goto finish;
} }
@ -395,8 +393,7 @@ int ask_password_agent(
final[sizeof(final)-9] = 'k'; final[sizeof(final)-9] = 'k';
if (rename(temp, final) < 0) { if (rename(temp, final) < 0) {
log_error_errno(errno, "Failed to rename query file: %m"); r = log_error_errno(errno, "Failed to rename query file: %m");
r = -errno;
goto finish; goto finish;
} }
@ -432,8 +429,7 @@ int ask_password_agent(
if (errno == EINTR) if (errno == EINTR)
continue; continue;
log_error_errno(errno, "poll() failed: %m"); r = log_error_errno(errno, "poll() failed: %m");
r = -errno;
goto finish; goto finish;
} }
@ -471,8 +467,7 @@ int ask_password_agent(
errno == EINTR) errno == EINTR)
continue; continue;
log_error_errno(errno, "recvmsg() failed: %m"); r = log_error_errno(errno, "recvmsg() failed: %m");
r = -errno;
goto finish; goto finish;
} }

View File

@ -74,8 +74,7 @@ int pager_open(bool jump_to_end) {
pager_pid = fork(); pager_pid = fork();
if (pager_pid < 0) { if (pager_pid < 0) {
r = -errno; r = log_error_errno(errno, "Failed to fork pager: %m");
log_error_errno(errno, "Failed to fork pager: %m");
safe_close_pair(fd); safe_close_pair(fd);
return r; return r;
} }

View File

@ -122,16 +122,12 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl) {
} }
if (err < 0) { if (err < 0) {
err = -errno; return log_error_errno(errno, "bind failed: %m");
log_error_errno(errno, "bind failed: %m");
return err;
} }
err = listen(uctrl->sock, 0); err = listen(uctrl->sock, 0);
if (err < 0) { if (err < 0) {
err = -errno; return log_error_errno(errno, "listen failed: %m");
log_error_errno(errno, "listen failed: %m");
return err;
} }
uctrl->bound = true; uctrl->bound = true;

View File

@ -731,15 +731,13 @@ int udev_event_spawn(struct udev_event *event,
/* pipes from child to parent */ /* pipes from child to parent */
if (result != NULL || log_get_max_level() >= LOG_INFO) { if (result != NULL || log_get_max_level() >= LOG_INFO) {
if (pipe2(outpipe, O_NONBLOCK) != 0) { if (pipe2(outpipe, O_NONBLOCK) != 0) {
err = -errno; err = log_error_errno(errno, "pipe failed: %m");
log_error_errno(errno, "pipe failed: %m");
goto out; goto out;
} }
} }
if (log_get_max_level() >= LOG_INFO) { if (log_get_max_level() >= LOG_INFO) {
if (pipe2(errpipe, O_NONBLOCK) != 0) { if (pipe2(errpipe, O_NONBLOCK) != 0) {
err = -errno; err = log_error_errno(errno, "pipe failed: %m");
log_error_errno(errno, "pipe failed: %m");
goto out; goto out;
} }
} }

View File

@ -130,8 +130,8 @@ static int on_reboot(Context *c) {
if (c->audit_fd >= 0) if (c->audit_fd >= 0)
if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
errno != EPERM) { errno != EPERM) {
log_error_errno(errno, "Failed to send audit message: %m"); r = log_error_errno(errno,
r = -errno; "Failed to send audit message: %m");
} }
#endif #endif
@ -160,8 +160,8 @@ static int on_shutdown(Context *c) {
if (c->audit_fd >= 0) if (c->audit_fd >= 0)
if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
errno != EPERM) { errno != EPERM) {
log_error_errno(errno, "Failed to send audit message: %m"); r = log_error_errno(errno,
r = -errno; "Failed to send audit message: %m");
} }
#endif #endif
@ -212,8 +212,8 @@ static int on_runlevel(Context *c) {
if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s, "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 && if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s, "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
errno != EPERM) { errno != EPERM) {
log_error_errno(errno, "Failed to send audit message: %m"); r = log_error_errno(errno,
r = -errno; "Failed to send audit message: %m");
} }
} }
#endif #endif

View File

@ -43,8 +43,8 @@ int main(int argc, char*argv[]) {
int r = 0; int r = 0;
if (unlink("/run/nologin") < 0 && errno != ENOENT) { if (unlink("/run/nologin") < 0 && errno != ENOENT) {
log_error_errno(errno, "Failed to remove /run/nologin file: %m"); r = log_error_errno(errno,
r = -errno; "Failed to remove /run/nologin file: %m");
} }
if (unlink("/etc/nologin") < 0 && errno != ENOENT) { if (unlink("/etc/nologin") < 0 && errno != ENOENT) {