summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README6
-rw-r--r--coccinelle/empty-if.cocci47
-rw-r--r--coccinelle/errno.cocci42
-rw-r--r--coccinelle/while-true.cocci12
-rw-r--r--src/basic/smack-util.c21
-rw-r--r--src/basic/smack-util.h2
-rw-r--r--src/basic/util.h5
-rw-r--r--src/boot/efi/graphics.c3
-rw-r--r--src/bootchart/bootchart.c3
-rw-r--r--src/bootchart/svg.c2
-rw-r--r--src/core/execute.c3
-rw-r--r--src/core/main.c10
-rw-r--r--src/core/mount-setup.c5
-rw-r--r--src/core/namespace.c15
-rw-r--r--src/core/service.c7
-rw-r--r--src/debug-generator/debug-generator.c16
-rw-r--r--src/hostname/hostnamed.c3
-rw-r--r--src/journal-remote/journal-remote-parse.c2
-rw-r--r--src/journal-remote/journal-remote.c5
-rw-r--r--src/journal-remote/journal-upload-journal.c2
-rw-r--r--src/journal-remote/journal-upload.c2
-rw-r--r--src/journal/coredumpctl.c5
-rw-r--r--src/journal/journalctl.c3
-rw-r--r--src/journal/journald-native.c2
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c2
-rw-r--r--src/libsystemd/sd-daemon/sd-daemon.c5
-rw-r--r--src/libsystemd/sd-netlink/netlink-message.c3
-rw-r--r--src/locale/localed.c54
-rw-r--r--src/login/logind-session.c20
-rw-r--r--src/shared/clean-ipc.c25
-rw-r--r--src/shared/pty.c6
-rw-r--r--src/test/test-ratelimit.c9
-rw-r--r--src/udev/ata_id/ata_id.c2
-rw-r--r--src/udev/cdrom_id/cdrom_id.c5
-rw-r--r--src/udev/collect/collect.c2
-rw-r--r--src/udev/scsi_id/scsi_id.c15
-rw-r--r--src/udev/scsi_id/scsi_serial.c6
-rw-r--r--src/udev/udev-builtin-keyboard.c3
-rw-r--r--src/udev/udev-rules.c8
-rw-r--r--src/udev/udev-watch.c5
40 files changed, 231 insertions, 162 deletions
diff --git a/README b/README
index 27cc9a0168..62fd248775 100644
--- a/README
+++ b/README
@@ -244,9 +244,9 @@ SYSV INIT.D SCRIPTS:
needs to look like, and provide an implementation at the marked places.
WARNINGS:
- systemd will warn you during boot if /etc/mtab is not a
- symlink to /proc/mounts. Please ensure that /etc/mtab is a
- proper symlink.
+ systemd will freeze execution during boot if /etc/mtab exists
+ but is not a symlink to /proc/mounts. Please ensure that
+ /etc/mtab is a proper symlink.
systemd will warn you during boot if /usr is on a different
file system than /. While in systemd itself very little will
diff --git a/coccinelle/empty-if.cocci b/coccinelle/empty-if.cocci
index ebd0bfddce..026c461ee6 100644
--- a/coccinelle/empty-if.cocci
+++ b/coccinelle/empty-if.cocci
@@ -1,19 +1,56 @@
@@
-expression e, f;
+expression e, f, g, h, i, j;
statement s, t;
@@
(
if (e) {
-if (f) s
+(
+if (h) s
+|
+if (h) s else t
+|
+while (h) s
+|
+for (h; i; j) s
+)
}
|
-if (e) {
-if (f) s
-else t
+while (e) {
+(
+if (h) s
+|
+if (h) s else t
+|
+while (h) s
+|
+for (h; i; j) s
+)
+}
+|
+for (e; f; g) {
+(
+if (h) s
+|
+if (h) s else t
+|
+while (h) s
+|
+for (h; i; j) s
+)
}
|
- if (e) {
+ if (e)
s
- }
+|
+- while (e) {
++ while (e)
+s
+- }
+|
+- for (e; f; g) {
++ for (e; f; g)
+s
+- }
)
diff --git a/coccinelle/errno.cocci b/coccinelle/errno.cocci
index 073d905141..45f2b6e9d5 100644
--- a/coccinelle/errno.cocci
+++ b/coccinelle/errno.cocci
@@ -1,42 +1,48 @@
@@
identifier r;
-expression t, e;
+expression e;
@@
- r = -e;
-- log_error_errno(e, t);
-+ r = log_error_errno(e, t);
+- log_error_errno(e,
++ r = log_error_errno(e,
+ ...);
@@
identifier r;
-expression t, e;
+expression e;
@@
-- log_error_errno(e, t);
+- log_error_errno(e,
++ r = log_error_errno(e,
+ ...);
- r = -e;
-+ r = log_error_errno(e, t);
@@
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 log_error_errno(e, t);
@@
identifier r;
-expression t, e;
+expression e;
@@
- r = -e;
-- log_warning_errno(e, t);
-+ r = log_warning_errno(e, t);
+- log_warning_errno(e,
++ r = log_warning_errno(e,
+ ...);
@@
identifier r;
-expression t, e;
+expression e;
@@
-- log_warning_errno(e, t);
+- log_warning_errno(e,
++ r = log_warning_errno(e,
+ ...);
- r = -e;
-+ r = log_warning_errno(e, t);
@@
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 log_warning_errno(e, t);
diff --git a/coccinelle/while-true.cocci b/coccinelle/while-true.cocci
new file mode 100644
index 0000000000..c23fb11f22
--- /dev/null
+++ b/coccinelle/while-true.cocci
@@ -0,0 +1,12 @@
+@@
+statement s;
+@@
+- while (true)
++ for (;;)
+s
+@@
+statement s;
+@@
+- while (1)
++ for (;;)
+s
diff --git a/src/basic/smack-util.c b/src/basic/smack-util.c
index 6d5c205117..9e221d6eab 100644
--- a/src/basic/smack-util.c
+++ b/src/basic/smack-util.c
@@ -185,6 +185,23 @@ int mac_smack_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
return r;
}
+int mac_smack_copy(const char *dest, const char *src) {
+ int r = 0;
+ _cleanup_free_ char *label = NULL;
+
+ assert(dest);
+ assert(src);
+
+ r = mac_smack_read(src, SMACK_ATTR_ACCESS, &label);
+ if (r < 0)
+ return r;
+
+ r = mac_smack_apply(dest, SMACK_ATTR_ACCESS, label);
+ if (r < 0)
+ return r;
+
+ return r;
+}
#else
bool mac_smack_use(void) {
@@ -214,4 +231,8 @@ int mac_smack_apply_pid(pid_t pid, const char *label) {
int mac_smack_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
return 0;
}
+
+int mac_smack_copy(const char *dest, const char *src) {
+ return 0;
+}
#endif
diff --git a/src/basic/smack-util.h b/src/basic/smack-util.h
index 1052cecf4c..b3aa55eb8a 100644
--- a/src/basic/smack-util.h
+++ b/src/basic/smack-util.h
@@ -48,5 +48,5 @@ int mac_smack_read(const char *path, SmackAttr attr, char **label);
int mac_smack_read_fd(int fd, SmackAttr attr, char **label);
int mac_smack_apply(const char *path, SmackAttr attr, const char *label);
int mac_smack_apply_fd(int fd, SmackAttr attr, const char *label);
-
int mac_smack_apply_pid(pid_t pid, const char *label);
+int mac_smack_copy(const char *dest, const char *src);
diff --git a/src/basic/util.h b/src/basic/util.h
index 48567756b9..5fa44b5cf3 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -877,11 +877,6 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
int extract_first_word_and_warn(const char **p, char **ret, const char *separators, ExtractFlags flags, const char *unit, const char *filename, unsigned line, const char *rvalue);
int extract_many_words(const char **p, const char *separators, ExtractFlags flags, ...) _sentinel_;
-static inline void free_and_replace(char **s, char *v) {
- free(*s);
- *s = v;
-}
-
int free_and_strdup(char **p, const char *s);
#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1)
diff --git a/src/boot/efi/graphics.c b/src/boot/efi/graphics.c
index 2e9c11f5a0..f732428216 100644
--- a/src/boot/efi/graphics.c
+++ b/src/boot/efi/graphics.c
@@ -67,10 +67,9 @@ EFI_STATUS graphics_mode(BOOLEAN on) {
EFI_STATUS err;
err = LibLocateProtocol(&ConsoleControlProtocolGuid, (VOID **)&ConsoleControl);
- if (EFI_ERROR(err)) {
+ if (EFI_ERROR(err))
/* console control protocol is nonstandard and might not exist. */
return err == EFI_NOT_FOUND ? EFI_SUCCESS : err;
- }
/* check current mode */
err = uefi_call_wrapper(ConsoleControl->GetMode, 4, ConsoleControl, &current, &uga_exists, &stdin_locked);
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index 14b630c6f9..83ad90c222 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -338,10 +338,9 @@ int main(int argc, char *argv[]) {
* - child logs data
*/
if (getpid() == 1) {
- if (fork()) {
+ if (fork())
/* parent */
execl(arg_init_path, arg_init_path, NULL);
- }
}
argv[0][0] = '@';
diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
index 1231e6eace..c66f12e3a6 100644
--- a/src/bootchart/svg.c
+++ b/src/bootchart/svg.c
@@ -888,7 +888,7 @@ static struct ps_struct *get_next_ps(struct ps_struct *ps, struct ps_struct *ps_
return ps->next;
/* go back for parent siblings */
- while (1) {
+ for (;;) {
if (ps->parent && ps->parent->next)
return ps->parent->next;
diff --git a/src/core/execute.c b/src/core/execute.c
index cd3592b847..6abb0a5d5d 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1998,9 +1998,8 @@ void exec_context_done(ExecContext *c) {
strv_free(c->environment_files);
c->environment_files = NULL;
- for (l = 0; l < ELEMENTSOF(c->rlimit); l++) {
+ for (l = 0; l < ELEMENTSOF(c->rlimit); l++)
c->rlimit[l] = mfree(c->rlimit[l]);
- }
c->working_directory = mfree(c->working_directory);
c->root_directory = mfree(c->root_directory);
diff --git a/src/core/main.c b/src/core/main.c
index 6577a06621..be95dc68b2 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1116,9 +1116,10 @@ static void test_mtab(void) {
if (r >= 0 && nulstr_contains(ok, p))
return;
- log_warning("/etc/mtab is not a symlink or not pointing to /proc/self/mounts. "
- "This is not supported anymore. "
- "Please make sure to replace this file by a symlink to avoid incorrect or misleading mount(8) output.");
+ log_error("/etc/mtab is not a symlink or not pointing to /proc/self/mounts. "
+ "This is not supported anymore. "
+ "Please make sure to replace this file by a symlink to avoid incorrect or misleading mount(8) output.");
+ freeze();
}
static void test_usr(void) {
@@ -1836,9 +1837,8 @@ finish:
arg_shutdown_watchdog = m->shutdown_watchdog;
m = manager_free(m);
- for (j = 0; j < ELEMENTSOF(arg_default_rlimit); j++) {
+ for (j = 0; j < ELEMENTSOF(arg_default_rlimit); j++)
arg_default_rlimit[j] = mfree(arg_default_rlimit[j]);
- }
arg_default_unit = mfree(arg_default_unit);
diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c
index e84f80b61b..65f3d06ad0 100644
--- a/src/core/mount-setup.c
+++ b/src/core/mount-setup.c
@@ -303,6 +303,11 @@ int mount_cgroup_controllers(char ***join_controllers) {
r = symlink(options, t);
if (r < 0 && errno != EEXIST)
return log_error_errno(errno, "Failed to create symlink %s: %m", t);
+#ifdef SMACK_RUN_LABEL
+ r = mac_smack_copy(t, options);
+ if (r < 0 && r != -EOPNOTSUPP)
+ return log_error_errno(r, "Failed to copy smack label from %s to %s: %m", options, t);
+#endif
}
}
}
diff --git a/src/core/namespace.c b/src/core/namespace.c
index 0b85b859fa..eb88574f8f 100644
--- a/src/core/namespace.c
+++ b/src/core/namespace.c
@@ -294,15 +294,15 @@ static int mount_kdbus(BindMount *m) {
busnode = strjoina(root, "/bus");
if (mknod(busnode, (st.st_mode & ~07777) | 0600, st.st_rdev) < 0) {
- log_error_errno(errno, "mknod() for %s failed: %m", busnode);
- r = -errno;
+ r = log_error_errno(errno, "mknod() for %s failed: %m",
+ busnode);
goto fail;
}
r = mount(m->path, busnode, NULL, MS_BIND, NULL);
if (r < 0) {
- log_error_errno(errno, "bind mount of %s failed: %m", m->path);
- r = -errno;
+ r = log_error_errno(errno, "bind mount of %s failed: %m",
+ m->path);
goto fail;
}
@@ -313,8 +313,8 @@ static int mount_kdbus(BindMount *m) {
}
if (mount(root, basepath, NULL, MS_MOVE, NULL) < 0) {
- log_error_errno(errno, "bind mount of %s failed: %m", basepath);
- r = -errno;
+ r = log_error_errno(errno, "bind mount of %s failed: %m",
+ basepath);
goto fail;
}
@@ -555,10 +555,9 @@ int setup_namespace(
/* Remount / as the desired mode. Not that this will not
* reestablish propagation from our side to the host, since
* what's disconnected is disconnected. */
- if (mount(NULL, "/", NULL, mount_flags | MS_REC, NULL) < 0) {
+ if (mount(NULL, "/", NULL, mount_flags | MS_REC, NULL) < 0)
/* at this point, we cannot rollback */
return -errno;
- }
return 0;
diff --git a/src/core/service.c b/src/core/service.c
index e396dbe213..248a9e8c62 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -2937,14 +2937,11 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags, FDSet *fds)
}
/* Interpret WATCHDOG= */
- if (strv_find(tags, "WATCHDOG=1")) {
+ if (strv_find(tags, "WATCHDOG=1"))
service_reset_watchdog(s);
- }
- /* Add the passed fds to the fd store */
- if (strv_find(tags, "FDSTORE=1")) {
+ if (strv_find(tags, "FDSTORE=1"))
service_add_fd_store_set(s, fds);
- }
/* Notify clients about changed status or main pid */
if (notify_dbus)
diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c
index 9d0ab06e2f..8b29e8fd09 100644
--- a/src/debug-generator/debug-generator.c
+++ b/src/debug-generator/debug-generator.c
@@ -95,10 +95,10 @@ static int generate_mask_symlinks(void) {
if (!p)
return log_oom();
- if (symlink("/dev/null", p) < 0) {
- log_error_errno(errno, "Failed to create mask symlink %s: %m", p);
- r = -errno;
- }
+ if (symlink("/dev/null", p) < 0)
+ r = log_error_errno(errno,
+ "Failed to create mask symlink %s: %m",
+ p);
}
return r;
@@ -124,10 +124,10 @@ static int generate_wants_symlinks(void) {
mkdir_parents_label(p, 0755);
- if (symlink(f, p) < 0) {
- log_error_errno(errno, "Failed to create wants symlink %s: %m", p);
- r = -errno;
- }
+ if (symlink(f, p) < 0)
+ r = log_error_errno(errno,
+ "Failed to create wants symlink %s: %m",
+ p);
}
return r;
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index cb837e9d03..96cc8951e6 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -63,9 +63,8 @@ static void context_reset(Context *c) {
assert(c);
- for (p = 0; p < _PROP_MAX; p++) {
+ for (p = 0; p < _PROP_MAX; p++)
c->data[p] = mfree(c->data[p]);
- }
}
static void context_free(Context *c) {
diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c
index 5ff05d3ad6..2e0f78701a 100644
--- a/src/journal-remote/journal-remote-parse.c
+++ b/src/journal-remote/journal-remote-parse.c
@@ -94,7 +94,7 @@ static int get_line(RemoteSource *source, char **line, size_t *size) {
assert(source->buf == NULL || source->size > 0);
assert(source->fd >= 0);
- while (true) {
+ for (;;) {
if (source->buf) {
size_t start = MAX(source->scanned, source->offset);
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c
index bdf01f582c..d6ebca20ec 100644
--- a/src/journal-remote/journal-remote.c
+++ b/src/journal-remote/journal-remote.c
@@ -518,7 +518,7 @@ static int process_http_upload(
} else
finished = true;
- while (true) {
+ for (;;) {
r = process_source(source, arg_compress, arg_seal);
if (r == -EAGAIN)
break;
@@ -614,10 +614,9 @@ static int request_handler(
return code;
} else {
r = getnameinfo_pretty(fd, &hostname);
- if (r < 0) {
+ if (r < 0)
return mhd_respond(connection, MHD_HTTP_INTERNAL_SERVER_ERROR,
"Cannot check remote hostname");
- }
}
assert(hostname);
diff --git a/src/journal-remote/journal-upload-journal.c b/src/journal-remote/journal-upload-journal.c
index 507210f51c..6b3ad924a7 100644
--- a/src/journal-remote/journal-upload-journal.c
+++ b/src/journal-remote/journal-upload-journal.c
@@ -17,7 +17,7 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
assert(size <= SSIZE_MAX);
- while (true) {
+ for (;;) {
switch(u->entry_state) {
case ENTRY_CURSOR: {
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c
index 172fd80a12..311bd3fdda 100644
--- a/src/journal-remote/journal-upload.c
+++ b/src/journal-remote/journal-upload.c
@@ -828,7 +828,7 @@ int main(int argc, char **argv) {
"READY=1\n"
"STATUS=Processing input...");
- while (true) {
+ for (;;) {
r = sd_event_get_state(u.events);
if (r < 0)
break;
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 0fa427003b..0546290318 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -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);
if (fdf < 0) {
- log_error_errno(errno, "Failed to open %s: %m", filename);
- r = -errno;
+ r = log_error_errno(errno,
+ "Failed to open %s: %m",
+ filename);
goto error;
}
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index d31ab1c6d7..576e4e4d03 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1453,8 +1453,7 @@ static int setup_keys(void) {
safe_close(fd);
fd = mkostemp_safe(k, O_WRONLY|O_CLOEXEC);
if (fd < 0) {
- log_error_errno(errno, "Failed to open %s: %m", k);
- r = -errno;
+ r = log_error_errno(errno, "Failed to open %s: %m", k);
goto finish;
}
diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c
index da3faef93e..3e8a7a05f6 100644
--- a/src/journal/journald-native.c
+++ b/src/journal/journald-native.c
@@ -184,6 +184,7 @@ void server_process_native_message(
free(identifier);
identifier = t;
}
+
} else if (l >= 8 &&
startswith(p, "MESSAGE=")) {
char *t;
@@ -193,6 +194,7 @@ void server_process_native_message(
free(message);
message = t;
}
+
} else if (l > strlen("OBJECT_PID=") &&
l < strlen("OBJECT_PID=") + DECIMAL_STR_MAX(pid_t) &&
startswith(p, "OBJECT_PID=") &&
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 2ac4b9be8e..25fd3b5c52 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -1023,7 +1023,6 @@ static int bus_start_address(sd_bus *b) {
if (b->exec_path)
r = bus_socket_exec(b);
-
else if ((b->nspid > 0 || b->machine) && b->kernel) {
r = bus_container_connect_kernel(b);
if (r < 0 && !IN_SET(r, -ENOENT, -ESOCKTNOSUPPORT))
@@ -1045,7 +1044,6 @@ static int bus_start_address(sd_bus *b) {
r = bus_socket_connect(b);
else
skipped = true;
-
} else
skipped = true;
diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c
index d230a48daf..9ec73406c6 100644
--- a/src/libsystemd/sd-daemon/sd-daemon.c
+++ b/src/libsystemd/sd-daemon/sd-daemon.c
@@ -395,8 +395,9 @@ _public_ int sd_pid_notify_with_fds(pid_t pid, int unset_environment, const char
have_pid = pid != 0 && pid != getpid();
if (n_fds > 0 || have_pid) {
- msghdr.msg_controllen = CMSG_SPACE(sizeof(int) * n_fds) +
- CMSG_SPACE(sizeof(struct ucred) * have_pid);
+ /* CMSG_SPACE(0) may return value different then zero, which results in miscalculated controllen. */
+ msghdr.msg_controllen = (n_fds ? CMSG_SPACE(sizeof(int) * n_fds) : 0) +
+ CMSG_SPACE(sizeof(struct ucred)) * have_pid;
msghdr.msg_control = alloca(msghdr.msg_controllen);
cmsg = CMSG_FIRSTHDR(&msghdr);
diff --git a/src/libsystemd/sd-netlink/netlink-message.c b/src/libsystemd/sd-netlink/netlink-message.c
index 7ac8949830..0d8e37b856 100644
--- a/src/libsystemd/sd-netlink/netlink-message.c
+++ b/src/libsystemd/sd-netlink/netlink-message.c
@@ -892,9 +892,8 @@ int sd_netlink_message_rewind(sd_netlink_message *m) {
if (!m->sealed)
rtnl_message_seal(m);
- for (i = 1; i <= m->n_containers; i++) {
+ for (i = 1; i <= m->n_containers; i++)
m->containers[i].attributes = mfree(m->containers[i].attributes);
- }
m->n_containers = 0;
diff --git a/src/locale/localed.c b/src/locale/localed.c
index e304588c58..e3eef4a610 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -106,22 +106,22 @@ static bool startswith_comma(const char *s, const char *prefix) {
}
static void context_free_x11(Context *c) {
- free_and_replace(&c->x11_layout, NULL);
- free_and_replace(&c->x11_model, NULL);
- free_and_replace(&c->x11_variant, NULL);
- free_and_replace(&c->x11_options, NULL);
+ c->x11_layout = mfree(c->x11_layout);
+ c->x11_options = mfree(c->x11_options);
+ c->x11_model = mfree(c->x11_model);
+ c->x11_variant = mfree(c->x11_variant);
}
static void context_free_vconsole(Context *c) {
- free_and_replace(&c->vc_keymap, NULL);
- free_and_replace(&c->vc_keymap_toggle, NULL);
+ c->vc_keymap = mfree(c->vc_keymap);
+ c->vc_keymap_toggle = mfree(c->vc_keymap_toggle);
}
static void context_free_locale(Context *c) {
int p;
for (p = 0; p < _LOCALE_MAX; p++)
- free_and_replace(&c->locale[p], NULL);
+ c->locale[p] = mfree(c->locale[p]);
}
static void context_free(Context *c) {
@@ -137,7 +137,7 @@ static void locale_simplify(Context *c) {
for (p = LOCALE_LANG+1; p < _LOCALE_MAX; p++)
if (isempty(c->locale[p]) || streq_ptr(c->locale[LOCALE_LANG], c->locale[p]))
- free_and_replace(&c->locale[p], NULL);
+ c->locale[p] = mfree(c->locale[p]);
}
static int locale_read_data(Context *c) {
@@ -227,17 +227,20 @@ static int x11_read_data(Context *c) {
return r;
if (strv_length(a) == 3) {
- if (streq(a[1], "XkbLayout")) {
- free_and_replace(&c->x11_layout, a[2]);
- a[2] = NULL;
- } else if (streq(a[1], "XkbModel")) {
- free_and_replace(&c->x11_model, a[2]);
- a[2] = NULL;
- } else if (streq(a[1], "XkbVariant")) {
- free_and_replace(&c->x11_variant, a[2]);
- a[2] = NULL;
- } else if (streq(a[1], "XkbOptions")) {
- free_and_replace(&c->x11_options, a[2]);
+ char **p = NULL;
+
+ if (streq(a[1], "XkbLayout"))
+ p = &c->x11_layout;
+ else if (streq(a[1], "XkbModel"))
+ p = &c->x11_model;
+ else if (streq(a[1], "XkbVariant"))
+ p = &c->x11_variant;
+ else if (streq(a[1], "XkbOptions"))
+ p = &c->x11_options;
+
+ if (p) {
+ free(*p);
+ *p = a[2];
a[2] = NULL;
}
}
@@ -753,8 +756,10 @@ static int find_legacy_keymap(Context *c, char **new_keymap) {
r = find_converted_keymap(l, v, &converted);
if (r < 0)
return r;
- if (r > 0)
- free_and_replace(new_keymap, converted);
+ if (r > 0) {
+ free(*new_keymap);
+ *new_keymap = converted;
+ }
}
return 0;
@@ -815,8 +820,9 @@ static int x11_convert_to_vconsole(Context *c, sd_bus *bus) {
}
if (!streq_ptr(c->vc_keymap, new_keymap)) {
- free_and_replace(&c->vc_keymap, new_keymap);
- free_and_replace(&c->vc_keymap_toggle, NULL);
+ free(c->vc_keymap);
+ c->vc_keymap = new_keymap;
+ c->vc_keymap_toggle = mfree(c->vc_keymap_toggle);
modified = true;
} else
free(new_keymap);
@@ -987,7 +993,7 @@ static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *er
if (have[p])
continue;
- free_and_replace(&c->locale[p], NULL);
+ c->locale[p] = mfree(c->locale[p]);
}
locale_simplify(c);
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index d2c5a29801..f5fe030b07 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -1005,22 +1005,25 @@ int session_prepare_vt(Session *s) {
r = fchown(vt, s->user->uid, -1);
if (r < 0) {
- r = -errno;
- log_error_errno(errno, "Cannot change owner of /dev/tty%u: %m", s->vtnr);
+ r = 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_errno(errno, "Cannot set K_OFF on /dev/tty%u: %m", s->vtnr);
+ r = 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_errno(errno, "Cannot set KD_GRAPHICS on /dev/tty%u: %m", s->vtnr);
+ r = log_error_errno(errno,
+ "Cannot set KD_GRAPHICS on /dev/tty%u: %m",
+ s->vtnr);
goto error;
}
@@ -1032,8 +1035,9 @@ int session_prepare_vt(Session *s) {
mode.acqsig = SIGRTMIN + 1;
r = ioctl(vt, VT_SETMODE, &mode);
if (r < 0) {
- r = -errno;
- log_error_errno(errno, "Cannot set VT_PROCESS on /dev/tty%u: %m", s->vtnr);
+ r = log_error_errno(errno,
+ "Cannot set VT_PROCESS on /dev/tty%u: %m",
+ s->vtnr);
goto error;
}
diff --git a/src/shared/clean-ipc.c b/src/shared/clean-ipc.c
index 48b10865da..d1cdb151b2 100644
--- a/src/shared/clean-ipc.c
+++ b/src/shared/clean-ipc.c
@@ -78,8 +78,9 @@ static int clean_sysvipc_shm(uid_t delete_uid) {
if (errno == EIDRM || errno == EINVAL)
continue;
- log_warning_errno(errno, "Failed to remove SysV shared memory segment %i: %m", shmid);
- ret = -errno;
+ ret = log_warning_errno(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)
continue;
- log_warning_errno(errno, "Failed to remove SysV semaphores object %i: %m", semid);
- ret = -errno;
+ ret = log_warning_errno(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)
continue;
- log_warning_errno(errno, "Failed to remove SysV message queue %i: %m", msgid);
- ret = -errno;
+ ret = log_warning_errno(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)
continue;
- log_warning_errno(errno, "Failed to stat() MQ segment %s: %m", de->d_name);
- ret = -errno;
+ ret = log_warning_errno(errno,
+ "Failed to stat() MQ segment %s: %m",
+ de->d_name);
continue;
}
@@ -317,8 +321,9 @@ static int clean_posix_mq(uid_t uid) {
if (errno == ENOENT)
continue;
- log_warning_errno(errno, "Failed to unlink POSIX message queue %s: %m", fn);
- ret = -errno;
+ ret = log_warning_errno(errno,
+ "Failed to unlink POSIX message queue %s: %m",
+ fn);
}
}
diff --git a/src/shared/pty.c b/src/shared/pty.c
index a87b3ce6f0..35d9ff5f4d 100644
--- a/src/shared/pty.c
+++ b/src/shared/pty.c
@@ -311,9 +311,8 @@ static int pty_dispatch_read(Pty *pty) {
continue;
return (errno == EAGAIN) ? 0 : -errno;
- } else if (len == 0) {
+ } else if (len == 0)
continue;
- }
/* set terminating zero for debugging safety */
pty->in_buf[len] = 0;
@@ -356,9 +355,8 @@ static int pty_dispatch_write(Pty *pty) {
continue;
return (errno == EAGAIN) ? 1 : -errno;
- } else if (len == 0) {
+ } else if (len == 0)
continue;
- }
ring_pull(&pty->out_buf, (size_t)len);
}
diff --git a/src/test/test-ratelimit.c b/src/test/test-ratelimit.c
index b7f6dfe246..462b55cdb3 100644
--- a/src/test/test-ratelimit.c
+++ b/src/test/test-ratelimit.c
@@ -27,19 +27,16 @@ static void test_ratelimit_test(void) {
int i;
RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10);
- for (i = 0; i < 10; i++) {
+ for (i = 0; i < 10; i++)
assert_se(ratelimit_test(&ratelimit));
- }
assert_se(!ratelimit_test(&ratelimit));
sleep(1);
- for (i = 0; i < 10; i++) {
+ for (i = 0; i < 10; i++)
assert_se(ratelimit_test(&ratelimit));
- }
RATELIMIT_INIT(ratelimit, 0, 10);
- for (i = 0; i < 10000; i++) {
+ for (i = 0; i < 10000; i++)
assert_se(ratelimit_test(&ratelimit));
- }
}
int main(int argc, char *argv[]) {
diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c
index c6a2c56e77..e265aa5f53 100644
--- a/src/udev/ata_id/ata_id.c
+++ b/src/udev/ata_id/ata_id.c
@@ -432,7 +432,7 @@ int main(int argc, char *argv[])
if (udev == NULL)
return 0;
- while (1) {
+ for (;;) {
int option;
option = getopt_long(argc, argv, "xh", options, NULL);
diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c
index 775da0355d..001bae7a24 100644
--- a/src/udev/cdrom_id/cdrom_id.c
+++ b/src/udev/cdrom_id/cdrom_id.c
@@ -565,9 +565,8 @@ static int cd_profiles(struct udev *udev, int fd)
if (len > sizeof(features)) {
log_debug("can not get features in a single query, truncating");
len = sizeof(features);
- } else if (len <= 8) {
+ } else if (len <= 8)
len = sizeof(features);
- }
/* Now get the full feature buffer */
scsi_cmd_init(udev, &sc);
@@ -869,7 +868,7 @@ int main(int argc, char *argv[])
if (udev == NULL)
goto exit;
- while (1) {
+ for (;;) {
int option;
option = getopt_long(argc, argv, "deluh", options, NULL);
diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c
index 6cf41c67bb..b3a1f0bca1 100644
--- a/src/udev/collect/collect.c
+++ b/src/udev/collect/collect.c
@@ -364,7 +364,7 @@ int main(int argc, char **argv)
goto exit;
}
- while (1) {
+ for (;;) {
int option;
option = getopt_long(argc, argv, "ardh", options, NULL);
diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c
index a1b8e75fac..adb91869df 100644
--- a/src/udev/scsi_id/scsi_id.c
+++ b/src/udev/scsi_id/scsi_id.c
@@ -190,7 +190,7 @@ static int get_file_options(struct udev *udev,
*newargv = NULL;
lineno = 0;
- while (1) {
+ for (;;) {
vendor_in = model_in = options_in = NULL;
buf = fgets(buffer, MAX_BUFFER_LEN, f);
@@ -279,9 +279,9 @@ static int get_file_options(struct udev *udev,
strcpy(buffer, options_in);
c = argc_count(buffer) + 2;
*newargv = calloc(c, sizeof(**newargv));
- if (!*newargv) {
+ if (!*newargv)
retval = log_oom();
- } else {
+ else {
*argc = c;
c = 0;
/*
@@ -537,16 +537,13 @@ static int scsi_id(struct udev *udev, char *maj_min_dev)
if (dev_scsi.wwn_vendor_extension[0] != '\0') {
printf("ID_WWN_VENDOR_EXTENSION=0x%s\n", dev_scsi.wwn_vendor_extension);
printf("ID_WWN_WITH_EXTENSION=0x%s%s\n", dev_scsi.wwn, dev_scsi.wwn_vendor_extension);
- } else {
+ } else
printf("ID_WWN_WITH_EXTENSION=0x%s\n", dev_scsi.wwn);
- }
}
- if (dev_scsi.tgpt_group[0] != '\0') {
+ if (dev_scsi.tgpt_group[0] != '\0')
printf("ID_TARGET_PORT=%s\n", dev_scsi.tgpt_group);
- }
- if (dev_scsi.unit_serial_number[0] != '\0') {
+ if (dev_scsi.unit_serial_number[0] != '\0')
printf("ID_SCSI_SERIAL=%s\n", dev_scsi.unit_serial_number);
- }
goto out;
}
diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c
index 69260cb1a0..de3b4f7581 100644
--- a/src/udev/scsi_id/scsi_serial.c
+++ b/src/udev/scsi_id/scsi_serial.c
@@ -135,9 +135,8 @@ static int sg_err_category_new(struct udev *udev,
return SG_ERR_CAT_MEDIA_CHANGED;
if (0x29 == asc)
return SG_ERR_CAT_RESET;
- } else if (sense_key == ILLEGAL_REQUEST) {
+ } else if (sense_key == ILLEGAL_REQUEST)
return SG_ERR_CAT_NOTSUPPORTED;
- }
}
return SG_ERR_CAT_SENSE;
}
@@ -490,9 +489,8 @@ static int check_fill_0x83_id(struct udev *udev,
if ((page_83[1] & 0x30) == 0x10) {
if (id_search->id_type != SCSI_ID_TGTGROUP)
return 1;
- } else if ((page_83[1] & 0x30) != 0) {
+ } else if ((page_83[1] & 0x30) != 0)
return 1;
- }
if ((page_83[1] & 0x0f) != id_search->id_type)
return 1;
diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c
index 01f3879f37..d63a8e2760 100644
--- a/src/udev/udev-builtin-keyboard.c
+++ b/src/udev/udev-builtin-keyboard.c
@@ -255,9 +255,8 @@ static int builtin_keyboard(struct udev_device *dev, int argc, char *argv[], boo
}
override_abs(fd, node, evcode, udev_list_entry_get_value(entry));
- } else if (streq(key, "POINTINGSTICK_SENSITIVITY")) {
+ } else if (streq(key, "POINTINGSTICK_SENSITIVITY"))
set_trackpoint_sensitivity(dev, udev_list_entry_get_value(entry));
- }
}
/* install list of force-release codes */
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 822f292217..98c33171d4 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1428,9 +1428,9 @@ static int add_rule(struct udev_rules *rules, char *line,
} else if ((rules->resolve_names > 0) && strchr("$%", value[0]) == NULL) {
uid = add_uid(rules, value);
rule_add_key(&rule_tmp, TK_A_OWNER_ID, op, NULL, &uid);
- } else if (rules->resolve_names >= 0) {
+ } else if (rules->resolve_names >= 0)
rule_add_key(&rule_tmp, TK_A_OWNER, op, value, NULL);
- }
+
rule_tmp.rule.rule.can_set_name = true;
continue;
}
@@ -1450,9 +1450,9 @@ static int add_rule(struct udev_rules *rules, char *line,
} else if ((rules->resolve_names > 0) && strchr("$%", value[0]) == NULL) {
gid = add_gid(rules, value);
rule_add_key(&rule_tmp, TK_A_GROUP_ID, op, NULL, &gid);
- } else if (rules->resolve_names >= 0) {
+ } else if (rules->resolve_names >= 0)
rule_add_key(&rule_tmp, TK_A_GROUP, op, value, NULL);
- }
+
rule_tmp.rule.rule.can_set_name = true;
continue;
}
diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c
index 15b76dd6ab..9aa5ab185d 100644
--- a/src/udev/udev-watch.c
+++ b/src/udev/udev-watch.c
@@ -83,9 +83,8 @@ unlink:
closedir(dir);
rmdir("/run/udev/watch.old");
- } else if (errno != ENOENT) {
+ } else if (errno != ENOENT)
log_error_errno(errno, "unable to move watches dir /run/udev/watch; old watches will not be restored: %m");
- }
}
void udev_watch_begin(struct udev *udev, struct udev_device *dev) {
@@ -100,7 +99,7 @@ void udev_watch_begin(struct udev *udev, struct udev_device *dev) {
wd = inotify_add_watch(inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
if (wd < 0) {
log_error_errno(errno, "inotify_add_watch(%d, %s, %o) failed: %m",
- inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
+ inotify_fd, udev_device_get_devnode(dev), IN_CLOSE_WRITE);
return;
}