1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-11 05:17:44 +03:00

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

The previous coccinelle semantic patch that improved usage of
log_error_errno()'s return value, only looked for log_error_errno()
invocations with a single parameter after the error parameter. Update
the patch to handle arbitrary numbers of additional arguments.
This commit is contained in:
Lennart Poettering 2015-09-09 11:08:23 +02:00
parent 9c00a6adfa
commit 94c156cd45
7 changed files with 67 additions and 50 deletions

View File

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

View File

@ -294,15 +294,15 @@ static int mount_kdbus(BindMount *m) {
busnode = strjoina(root, "/bus"); busnode = strjoina(root, "/bus");
if (mknod(busnode, (st.st_mode & ~07777) | 0600, st.st_rdev) < 0) { if (mknod(busnode, (st.st_mode & ~07777) | 0600, st.st_rdev) < 0) {
log_error_errno(errno, "mknod() for %s failed: %m", busnode); r = log_error_errno(errno, "mknod() for %s failed: %m",
r = -errno; busnode);
goto fail; goto fail;
} }
r = mount(m->path, busnode, NULL, MS_BIND, NULL); r = mount(m->path, busnode, NULL, MS_BIND, NULL);
if (r < 0) { if (r < 0) {
log_error_errno(errno, "bind mount of %s failed: %m", m->path); r = log_error_errno(errno, "bind mount of %s failed: %m",
r = -errno; m->path);
goto fail; goto fail;
} }
@ -313,8 +313,8 @@ static int mount_kdbus(BindMount *m) {
} }
if (mount(root, basepath, NULL, MS_MOVE, NULL) < 0) { if (mount(root, basepath, NULL, MS_MOVE, NULL) < 0) {
log_error_errno(errno, "bind mount of %s failed: %m", basepath); r = log_error_errno(errno, "bind mount of %s failed: %m",
r = -errno; basepath);
goto fail; goto fail;
} }

View File

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

View File

@ -646,8 +646,9 @@ static int save_core(sd_journal *j, int fd, char **path, bool *unlink_temp) {
fdf = open(filename, O_RDONLY | O_CLOEXEC); fdf = open(filename, O_RDONLY | O_CLOEXEC);
if (fdf < 0) { if (fdf < 0) {
log_error_errno(errno, "Failed to open %s: %m", filename); r = log_error_errno(errno,
r = -errno; "Failed to open %s: %m",
filename);
goto error; goto error;
} }

View File

@ -1453,8 +1453,7 @@ static int setup_keys(void) {
safe_close(fd); safe_close(fd);
fd = mkostemp_safe(k, O_WRONLY|O_CLOEXEC); fd = mkostemp_safe(k, O_WRONLY|O_CLOEXEC);
if (fd < 0) { if (fd < 0) {
log_error_errno(errno, "Failed to open %s: %m", k); r = log_error_errno(errno, "Failed to open %s: %m", k);
r = -errno;
goto finish; goto finish;
} }

View File

@ -1005,22 +1005,25 @@ int session_prepare_vt(Session *s) {
r = fchown(vt, s->user->uid, -1); r = fchown(vt, s->user->uid, -1);
if (r < 0) { if (r < 0) {
r = -errno; r = log_error_errno(errno,
log_error_errno(errno, "Cannot change owner of /dev/tty%u: %m", s->vtnr); "Cannot change owner of /dev/tty%u: %m",
s->vtnr);
goto error; goto error;
} }
r = ioctl(vt, KDSKBMODE, K_OFF); r = ioctl(vt, KDSKBMODE, K_OFF);
if (r < 0) { if (r < 0) {
r = -errno; r = log_error_errno(errno,
log_error_errno(errno, "Cannot set K_OFF on /dev/tty%u: %m", s->vtnr); "Cannot set K_OFF on /dev/tty%u: %m",
s->vtnr);
goto error; goto error;
} }
r = ioctl(vt, KDSETMODE, KD_GRAPHICS); r = ioctl(vt, KDSETMODE, KD_GRAPHICS);
if (r < 0) { if (r < 0) {
r = -errno; r = log_error_errno(errno,
log_error_errno(errno, "Cannot set KD_GRAPHICS on /dev/tty%u: %m", s->vtnr); "Cannot set KD_GRAPHICS on /dev/tty%u: %m",
s->vtnr);
goto error; goto error;
} }
@ -1032,8 +1035,9 @@ int session_prepare_vt(Session *s) {
mode.acqsig = SIGRTMIN + 1; mode.acqsig = SIGRTMIN + 1;
r = ioctl(vt, VT_SETMODE, &mode); r = ioctl(vt, VT_SETMODE, &mode);
if (r < 0) { if (r < 0) {
r = -errno; r = log_error_errno(errno,
log_error_errno(errno, "Cannot set VT_PROCESS on /dev/tty%u: %m", s->vtnr); "Cannot set VT_PROCESS on /dev/tty%u: %m",
s->vtnr);
goto error; goto error;
} }

View File

@ -78,8 +78,9 @@ static int clean_sysvipc_shm(uid_t delete_uid) {
if (errno == EIDRM || errno == EINVAL) if (errno == EIDRM || errno == EINVAL)
continue; continue;
log_warning_errno(errno, "Failed to remove SysV shared memory segment %i: %m", shmid); ret = log_warning_errno(errno,
ret = -errno; "Failed to remove SysV shared memory segment %i: %m",
shmid);
} }
} }
@ -130,8 +131,9 @@ static int clean_sysvipc_sem(uid_t delete_uid) {
if (errno == EIDRM || errno == EINVAL) if (errno == EIDRM || errno == EINVAL)
continue; continue;
log_warning_errno(errno, "Failed to remove SysV semaphores object %i: %m", semid); ret = log_warning_errno(errno,
ret = -errno; "Failed to remove SysV semaphores object %i: %m",
semid);
} }
} }
@ -183,8 +185,9 @@ static int clean_sysvipc_msg(uid_t delete_uid) {
if (errno == EIDRM || errno == EINVAL) if (errno == EIDRM || errno == EINVAL)
continue; continue;
log_warning_errno(errno, "Failed to remove SysV message queue %i: %m", msgid); ret = log_warning_errno(errno,
ret = -errno; "Failed to remove SysV message queue %i: %m",
msgid);
} }
} }
@ -302,8 +305,9 @@ static int clean_posix_mq(uid_t uid) {
if (errno == ENOENT) if (errno == ENOENT)
continue; continue;
log_warning_errno(errno, "Failed to stat() MQ segment %s: %m", de->d_name); ret = log_warning_errno(errno,
ret = -errno; "Failed to stat() MQ segment %s: %m",
de->d_name);
continue; continue;
} }
@ -317,8 +321,9 @@ static int clean_posix_mq(uid_t uid) {
if (errno == ENOENT) if (errno == ENOENT)
continue; continue;
log_warning_errno(errno, "Failed to unlink POSIX message queue %s: %m", fn); ret = log_warning_errno(errno,
ret = -errno; "Failed to unlink POSIX message queue %s: %m",
fn);
} }
} }