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));
err = -EPERM; /* PAM errors do not map to errno */
} else {
log_error_errno(errno, "PAM failed: %m");
err = -errno;
err = log_error_errno(errno, "PAM failed: %m");
}
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
* bind-mount the custom endpoint over. */
if (stat("/dev/null", &st) < 0) {
log_error_errno(errno, "Failed to stat /dev/null: %m");
r = -errno;
r = log_error_errno(errno, "Failed to stat /dev/null: %m");
goto fail;
}

View File

@ -404,8 +404,7 @@ int main(int argc, char *argv[]) {
exit(0);
}
log_error_errno(errno, "Failed to invoke reboot(): %m");
r = -errno;
r = log_error_errno(errno, "Failed to invoke reboot(): %m");
error:
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);
if (s->epoll_fd < 0) {
r = -errno;
log_error_errno(errno, "Failed to create epoll object: %m");
r = log_error_errno(errno,
"Failed to create epoll object: %m");
goto fail;
}

View File

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

View File

@ -142,8 +142,7 @@ int main(int argc, char *argv[]) {
if (dup3(fd, STDOUT_FILENO, 0) < 0 ||
dup3(fd, STDERR_FILENO, 0) < 0) {
log_error_errno(errno, "Failed to duplicate fd: %m");
r = -errno;
r = log_error_errno(errno, "Failed to duplicate fd: %m");
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);
if (sz < 0) {
log_error_errno(errno, "Failed to write temporary file: %m");
r = -errno;
r = log_error_errno(errno,
"Failed to write temporary file: %m");
goto error;
}
if (sz != (ssize_t) len) {
@ -758,8 +758,7 @@ static int run_gdb(sd_journal *j) {
pid = fork();
if (pid < 0) {
log_error_errno(errno, "Failed to fork(): %m");
r = -errno;
r = log_error_errno(errno, "Failed to fork(): %m");
goto finish;
}
if (pid == 0) {

View File

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

View File

@ -1428,8 +1428,7 @@ static int setup_keys(void) {
fd = open("/dev/random", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
log_error_errno(errno, "Failed to open /dev/random: %m");
r = -errno;
r = log_error_errno(errno, "Failed to open /dev/random: %m");
goto finish;
}
@ -1488,8 +1487,7 @@ static int setup_keys(void) {
}
if (link(k, p) < 0) {
log_error_errno(errno, "Failed to link file: %m");
r = -errno;
r = log_error_errno(errno, "Failed to link file: %m");
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);
if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
log_error_errno(errno, "Failed to get input name: %m");
r = -errno;
r = log_error_errno(errno, "Failed to get input name: %m");
goto fail;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -130,8 +130,8 @@ static int on_reboot(Context *c) {
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 &&
errno != EPERM) {
log_error_errno(errno, "Failed to send audit message: %m");
r = -errno;
r = log_error_errno(errno,
"Failed to send audit message: %m");
}
#endif
@ -160,8 +160,8 @@ static int on_shutdown(Context *c) {
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 &&
errno != EPERM) {
log_error_errno(errno, "Failed to send audit message: %m");
r = -errno;
r = log_error_errno(errno,
"Failed to send audit message: %m");
}
#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 &&
errno != EPERM) {
log_error_errno(errno, "Failed to send audit message: %m");
r = -errno;
r = log_error_errno(errno,
"Failed to send audit message: %m");
}
}
#endif

View File

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