summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rammhold <andreas@rammhold.de>2017-09-29 00:37:23 +0200
committerAndreas Rammhold <andreas@rammhold.de>2017-10-02 13:09:54 +0200
commit3742095b27f8df4b195d530b52d15bc5fea70bf1 (patch)
tree3fc7c3503845b733f1d58366436c0bb672d3613a
parent01a65d4180446661732d90d23a24ab692d279295 (diff)
downloadsystemd-3742095b27f8df4b195d530b52d15bc5fea70bf1.tar.gz
tree-wide: use IN_SET where possible
In addition to the changes from #6933 this handles cases that could be matched with the included cocci file.
-rw-r--r--coccinelle/in_set.cocci35
-rw-r--r--src/basic/barrier.c2
-rw-r--r--src/basic/barrier.h7
-rw-r--r--src/basic/hashmap.c2
-rw-r--r--src/basic/in-addr-util.h2
-rw-r--r--src/basic/journal-importer.c4
-rw-r--r--src/basic/process-util.c3
-rw-r--r--src/basic/signal-util.c2
-rw-r--r--src/basic/socket-util.c5
-rw-r--r--src/basic/terminal-util.c2
-rw-r--r--src/basic/util.c2
-rw-r--r--src/core/automount.c4
-rw-r--r--src/core/dbus-unit.c4
-rw-r--r--src/core/dynamic-user.c2
-rw-r--r--src/core/job.c14
-rw-r--r--src/core/manager.c4
-rw-r--r--src/core/path.c15
-rw-r--r--src/core/scope.c9
-rw-r--r--src/core/service.c8
-rw-r--r--src/core/socket.c6
-rw-r--r--src/core/timer.c7
-rw-r--r--src/core/transaction.c6
-rw-r--r--src/core/unit.c4
-rw-r--r--src/core/unit.h8
-rw-r--r--src/cryptsetup/cryptsetup.c2
-rw-r--r--src/fsck/fsck.c2
-rw-r--r--src/import/importd.c5
-rw-r--r--src/import/pull-job.c5
-rw-r--r--src/journal/journal-file.c3
-rw-r--r--src/journal/journalctl.c6
-rw-r--r--src/journal/journald-audit.c2
-rw-r--r--src/journal/journald-kmsg.c2
-rw-r--r--src/journal/journald-server.c2
-rw-r--r--src/journal/journald-syslog.c2
-rw-r--r--src/journal/sd-journal.c4
-rw-r--r--src/libsystemd-network/dhcp-packet.c4
-rw-r--r--src/libsystemd-network/icmp6-util.c2
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c2
-rw-r--r--src/libsystemd-network/sd-ipv4acd.c2
-rw-r--r--src/network/networkd-util.c3
-rw-r--r--src/nspawn/nspawn.c5
-rw-r--r--src/resolve/resolved-dns-stub.c2
-rw-r--r--src/resolve/resolved-dns-synthesize.c8
-rw-r--r--src/resolve/resolved-dns-transaction.c3
-rw-r--r--src/resolve/resolved-link.c2
-rw-r--r--src/resolve/resolved-llmnr.c2
-rw-r--r--src/shared/ask-password-api.c5
-rw-r--r--src/shared/clean-ipc.c6
-rw-r--r--src/shared/ptyfwd.c10
-rw-r--r--src/shared/utmp-wtmp.c2
-rw-r--r--src/sysv-generator/sysv-generator.c4
-rw-r--r--src/tmpfiles/tmpfiles.c2
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c5
-rw-r--r--src/udev/collect/collect.c2
-rw-r--r--src/udev/scsi_id/scsi_serial.c2
-rw-r--r--src/udev/udevadm-monitor.c2
-rw-r--r--src/udev/udevd.c2
-rw-r--r--src/veritysetup/veritysetup.c2
58 files changed, 140 insertions, 131 deletions
diff --git a/coccinelle/in_set.cocci b/coccinelle/in_set.cocci
new file mode 100644
index 0000000000..f5ddd3d334
--- /dev/null
+++ b/coccinelle/in_set.cocci
@@ -0,0 +1,35 @@
+@@
+expression e;
+identifier n1, n2, n3, n4, n5, n6;
+statement s;
+@@
+- e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6
++ IN_SET(e, n1, n2, n3, n4, n5, n6)
+@@
+expression e;
+identifier n1, n2, n3, n4, n5;
+statement s;
+@@
+- e == n1 || e == n2 || e == n3 || e == n4 || e == n5
++ IN_SET(e, n1, n2, n3, n4, n5)
+@@
+expression e;
+identifier n1, n2, n3, n4;
+statement s;
+@@
+- e == n1 || e == n2 || e == n3 || e == n4
++ IN_SET(e, n1, n2, n3, n4)
+@@
+expression e;
+identifier n1, n2, n3;
+statement s;
+@@
+- e == n1 || e == n2 || e == n3
++ IN_SET(e, n1, n2, n3)
+@@
+expression e;
+identifier n, p;
+statement s;
+@@
+- e == n || e == p
++ IN_SET(e, n, p)
diff --git a/src/basic/barrier.c b/src/basic/barrier.c
index 2da633b311..0c44e47b12 100644
--- a/src/basic/barrier.c
+++ b/src/basic/barrier.c
@@ -171,7 +171,7 @@ void barrier_set_role(Barrier *b, unsigned int role) {
int fd;
assert(b);
- assert(role == BARRIER_PARENT || role == BARRIER_CHILD);
+ assert(IN_SET(role, BARRIER_PARENT, BARRIER_CHILD));
/* make sure this is only called once */
assert(b->pipe[0] >= 0 && b->pipe[1] >= 0);
diff --git a/src/basic/barrier.h b/src/basic/barrier.h
index 6347fddc4d..1e54c82425 100644
--- a/src/basic/barrier.h
+++ b/src/basic/barrier.h
@@ -70,11 +70,11 @@ bool barrier_sync_next(Barrier *b);
bool barrier_sync(Barrier *b);
static inline bool barrier_i_aborted(Barrier *b) {
- return b->barriers == BARRIER_I_ABORTED || b->barriers == BARRIER_WE_ABORTED;
+ return IN_SET(b->barriers, BARRIER_I_ABORTED, BARRIER_WE_ABORTED);
}
static inline bool barrier_they_aborted(Barrier *b) {
- return b->barriers == BARRIER_THEY_ABORTED || b->barriers == BARRIER_WE_ABORTED;
+ return IN_SET(b->barriers, BARRIER_THEY_ABORTED, BARRIER_WE_ABORTED);
}
static inline bool barrier_we_aborted(Barrier *b) {
@@ -82,7 +82,8 @@ static inline bool barrier_we_aborted(Barrier *b) {
}
static inline bool barrier_is_aborted(Barrier *b) {
- return b->barriers == BARRIER_I_ABORTED || b->barriers == BARRIER_THEY_ABORTED || b->barriers == BARRIER_WE_ABORTED;
+ return IN_SET(b->barriers, BARRIER_I_ABORTED, BARRIER_THEY_ABORTED,
+ BARRIER_WE_ABORTED);
}
static inline bool barrier_place_and_sync(Barrier *b) {
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 50fefb0b54..6ef1b0ba35 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -927,7 +927,7 @@ static bool hashmap_put_robin_hood(HashmapBase *h, unsigned idx,
for (distance = 0; ; distance++) {
raw_dib = dibs[idx];
- if (raw_dib == DIB_RAW_FREE || raw_dib == DIB_RAW_REHASH) {
+ if (IN_SET(raw_dib, DIB_RAW_FREE, DIB_RAW_REHASH)) {
if (raw_dib == DIB_RAW_REHASH)
bucket_move_entry(h, swap, idx, IDX_TMP);
diff --git a/src/basic/in-addr-util.h b/src/basic/in-addr-util.h
index d129bf5585..59f8eb7edf 100644
--- a/src/basic/in-addr-util.h
+++ b/src/basic/in-addr-util.h
@@ -66,7 +66,7 @@ int in_addr_prefix_from_string(const char *p, int family, union in_addr_union *r
int in_addr_prefix_from_string_auto(const char *p, int *ret_family, union in_addr_union *ret_prefix, unsigned char *ret_prefixlen);
static inline size_t FAMILY_ADDRESS_SIZE(int family) {
- assert(family == AF_INET || family == AF_INET6);
+ assert(IN_SET(family, AF_INET, AF_INET6));
return family == AF_INET6 ? 16 : 4;
}
diff --git a/src/basic/journal-importer.c b/src/basic/journal-importer.c
index 38ac8deaf3..e750101165 100644
--- a/src/basic/journal-importer.c
+++ b/src/basic/journal-importer.c
@@ -154,9 +154,7 @@ static int get_line(JournalImporter *imp, char **line, size_t *size) {
static int fill_fixed_size(JournalImporter *imp, void **data, size_t size) {
assert(imp);
- assert(imp->state == IMPORTER_STATE_DATA_START ||
- imp->state == IMPORTER_STATE_DATA ||
- imp->state == IMPORTER_STATE_DATA_FINISH);
+ assert(IN_SET(imp->state, IMPORTER_STATE_DATA_START, IMPORTER_STATE_DATA, IMPORTER_STATE_DATA_FINISH));
assert(size <= DATA_SIZE_MAX);
assert(imp->offset <= imp->filled);
assert(imp->filled <= imp->size);
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index b77d83c99f..ab661a8f16 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -688,8 +688,7 @@ int wait_for_terminate_and_warn(const char *name, pid_t pid, bool check_exit_cod
log_debug("%s succeeded.", name);
return status.si_status;
- } else if (status.si_code == CLD_KILLED ||
- status.si_code == CLD_DUMPED) {
+ } else if (IN_SET(status.si_code, CLD_KILLED, CLD_DUMPED)) {
log_warning("%s terminated by signal %s.", name, signal_to_string(status.si_status));
return -EPROTO;
diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c
index 280b5c3251..df6b742fde 100644
--- a/src/basic/signal-util.c
+++ b/src/basic/signal-util.c
@@ -38,7 +38,7 @@ int reset_all_signal_handlers(void) {
for (sig = 1; sig < _NSIG; sig++) {
/* These two cannot be caught... */
- if (sig == SIGKILL || sig == SIGSTOP)
+ if (IN_SET(sig, SIGKILL, SIGSTOP))
continue;
/* On Linux the first two RT signals are reserved by
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index f1b2256b21..c2f795b4d8 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -364,8 +364,7 @@ bool socket_address_can_accept(const SocketAddress *a) {
assert(a);
return
- a->type == SOCK_STREAM ||
- a->type == SOCK_SEQPACKET;
+ IN_SET(a->type, SOCK_STREAM, SOCK_SEQPACKET);
}
bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
@@ -1081,7 +1080,7 @@ ssize_t next_datagram_size_fd(int fd) {
l = recv(fd, NULL, 0, MSG_PEEK|MSG_TRUNC);
if (l < 0) {
- if (errno == EOPNOTSUPP || errno == EFAULT)
+ if (IN_SET(errno, EOPNOTSUPP, EFAULT))
goto fallback;
return -errno;
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index 64745e8063..28c8c35fe0 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -476,7 +476,7 @@ int acquire_terminal(
l = read(notify, &buffer, sizeof(buffer));
if (l < 0) {
- if (errno == EINTR || errno == EAGAIN)
+ if (IN_SET(errno, EINTR, EAGAIN))
continue;
r = -errno;
diff --git a/src/basic/util.c b/src/basic/util.c
index daaee99284..687de40993 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -378,7 +378,7 @@ int on_ac_power(void) {
device = openat(dirfd(d), de->d_name, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (device < 0) {
- if (errno == ENOENT || errno == ENOTDIR)
+ if (IN_SET(errno, ENOENT, ENOTDIR))
continue;
return -errno;
diff --git a/src/core/automount.c b/src/core/automount.c
index 0c92616575..ecaa916ce3 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -804,7 +804,7 @@ static int automount_start(Unit *u) {
int r;
assert(a);
- assert(a->state == AUTOMOUNT_DEAD || a->state == AUTOMOUNT_FAILED);
+ assert(IN_SET(a->state, AUTOMOUNT_DEAD, AUTOMOUNT_FAILED));
if (path_is_mount_point(a->where, NULL, 0) > 0) {
log_unit_error(u, "Path %s is already a mount point, refusing start.", a->where);
@@ -836,7 +836,7 @@ static int automount_stop(Unit *u) {
Automount *a = AUTOMOUNT(u);
assert(a);
- assert(a->state == AUTOMOUNT_WAITING || a->state == AUTOMOUNT_RUNNING);
+ assert(IN_SET(a->state, AUTOMOUNT_WAITING, AUTOMOUNT_RUNNING));
automount_enter_dead(a, AUTOMOUNT_SUCCESS);
return 1;
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index 8d2ae964d8..791649e5b5 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -1253,13 +1253,13 @@ int bus_unit_queue_job(
}
if (type == JOB_STOP &&
- (u->load_state == UNIT_NOT_FOUND || u->load_state == UNIT_ERROR) &&
+ (IN_SET(u->load_state, UNIT_NOT_FOUND, UNIT_ERROR)) &&
unit_active_state(u) == UNIT_INACTIVE)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", u->id);
if ((type == JOB_START && u->refuse_manual_start) ||
(type == JOB_STOP && u->refuse_manual_stop) ||
- ((type == JOB_RESTART || type == JOB_TRY_RESTART) && (u->refuse_manual_start || u->refuse_manual_stop)) ||
+ (IN_SET(type, JOB_RESTART, JOB_TRY_RESTART) && (u->refuse_manual_start || u->refuse_manual_stop)) ||
(type == JOB_RELOAD_OR_START && job_type_collapse(type, u) == JOB_START && u->refuse_manual_start))
return sd_bus_error_setf(error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, unit %s may be requested by dependency only (it is configured to refuse manual start/stop).", u->id);
diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c
index 9b0dbaf248..6358fcba02 100644
--- a/src/core/dynamic-user.c
+++ b/src/core/dynamic-user.c
@@ -221,7 +221,7 @@ static int pick_uid(const char *name, uid_t *ret_uid) {
r = flock(lock_fd, LOCK_EX|LOCK_NB); /* Try to get a BSD file lock on the UID lock file */
if (r < 0) {
- if (errno == EBUSY || errno == EAGAIN)
+ if (IN_SET(errno, EBUSY, EAGAIN))
goto next; /* already in use */
return -errno;
diff --git a/src/core/job.c b/src/core/job.c
index f04c8a2168..f962881a12 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -368,19 +368,13 @@ bool job_type_is_redundant(JobType a, UnitActiveState b) {
switch (a) {
case JOB_START:
- return
- b == UNIT_ACTIVE ||
- b == UNIT_RELOADING;
+ return IN_SET(b, UNIT_ACTIVE, UNIT_RELOADING);
case JOB_STOP:
- return
- b == UNIT_INACTIVE ||
- b == UNIT_FAILED;
+ return IN_SET(b, UNIT_INACTIVE, UNIT_FAILED);
case JOB_VERIFY_ACTIVE:
- return
- b == UNIT_ACTIVE ||
- b == UNIT_RELOADING;
+ return IN_SET(b, UNIT_ACTIVE, UNIT_RELOADING);
case JOB_RELOAD:
return
@@ -888,7 +882,7 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive, bool alr
goto finish;
}
- if (result == JOB_FAILED || result == JOB_INVALID)
+ if (IN_SET(result, JOB_FAILED, JOB_INVALID))
j->manager->n_failed_jobs++;
job_uninstall(j);
diff --git a/src/core/manager.c b/src/core/manager.c
index 8ebea8d66b..519473599a 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1442,7 +1442,7 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, sd_bus_e
return -ENOMEM;
r = transaction_add_job_and_dependencies(tr, type, unit, NULL, true, false,
- mode == JOB_IGNORE_DEPENDENCIES || mode == JOB_IGNORE_REQUIREMENTS,
+ IN_SET(mode, JOB_IGNORE_DEPENDENCIES, JOB_IGNORE_REQUIREMENTS),
mode == JOB_IGNORE_DEPENDENCIES, e);
if (r < 0)
goto tr_abort;
@@ -1985,7 +1985,7 @@ static int manager_dispatch_sigchld(Manager *m) {
if (si.si_pid <= 0)
break;
- if (si.si_code == CLD_EXITED || si.si_code == CLD_KILLED || si.si_code == CLD_DUMPED) {
+ if (IN_SET(si.si_code, CLD_EXITED, CLD_KILLED, CLD_DUMPED)) {
_cleanup_free_ char *name = NULL;
Unit *u1, *u2, *u3;
diff --git a/src/core/path.c b/src/core/path.c
index 7092ed13ba..bbf891c462 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -97,7 +97,7 @@ int path_spec_watch(PathSpec *s, sd_event_io_handler_t handler) {
r = inotify_add_watch(s->inotify_fd, s->path, flags);
if (r < 0) {
- if (errno == EACCES || errno == ENOENT) {
+ if (IN_SET(errno, EACCES, ENOENT)) {
if (cut)
*cut = tmp;
break;
@@ -168,14 +168,14 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) {
l = read(s->inotify_fd, &buffer, sizeof(buffer));
if (l < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return 0;
return log_error_errno(errno, "Failed to read inotify event: %m");
}
FOREACH_INOTIFY_EVENT(e, buffer, l) {
- if ((s->type == PATH_CHANGED || s->type == PATH_MODIFIED) &&
+ if (IN_SET(s->type, PATH_CHANGED, PATH_MODIFIED) &&
s->primary_wd == e->wd)
r = 1;
}
@@ -224,7 +224,7 @@ static bool path_spec_check_good(PathSpec *s, bool initial) {
static void path_spec_mkdir(PathSpec *s, mode_t mode) {
int r;
- if (s->type == PATH_EXISTS || s->type == PATH_EXISTS_GLOB)
+ if (IN_SET(s->type, PATH_EXISTS, PATH_EXISTS_GLOB))
return;
r = mkdir_p_label(s->path, mode);
@@ -441,8 +441,7 @@ static int path_coldplug(Unit *u) {
if (p->deserialized_state != p->state) {
- if (p->deserialized_state == PATH_WAITING ||
- p->deserialized_state == PATH_RUNNING)
+ if (IN_SET(p->deserialized_state, PATH_WAITING, PATH_RUNNING))
path_enter_waiting(p, true, true);
else
path_set_state(p, p->deserialized_state);
@@ -566,7 +565,7 @@ static int path_start(Unit *u) {
int r;
assert(p);
- assert(p->state == PATH_DEAD || p->state == PATH_FAILED);
+ assert(IN_SET(p->state, PATH_DEAD, PATH_FAILED));
trigger = UNIT_TRIGGER(u);
if (!trigger || trigger->load_state != UNIT_LOADED) {
@@ -596,7 +595,7 @@ static int path_stop(Unit *u) {
Path *p = PATH(u);
assert(p);
- assert(p->state == PATH_WAITING || p->state == PATH_RUNNING);
+ assert(IN_SET(p->state, PATH_WAITING, PATH_RUNNING));
path_enter_dead(p, PATH_SUCCESS);
return 1;
diff --git a/src/core/scope.c b/src/core/scope.c
index 9670228694..4cd5e3dd2a 100644
--- a/src/core/scope.c
+++ b/src/core/scope.c
@@ -322,8 +322,7 @@ static int scope_start(Unit *u) {
return -EPERM;
/* We can't fulfill this right now, please try again later */
- if (s->state == SCOPE_STOP_SIGTERM ||
- s->state == SCOPE_STOP_SIGKILL)
+ if (IN_SET(s->state, SCOPE_STOP_SIGTERM, SCOPE_STOP_SIGKILL))
return -EAGAIN;
assert(s->state == SCOPE_DEAD);
@@ -357,12 +356,10 @@ static int scope_stop(Unit *u) {
assert(s);
- if (s->state == SCOPE_STOP_SIGTERM ||
- s->state == SCOPE_STOP_SIGKILL)
+ if (IN_SET(s->state, SCOPE_STOP_SIGTERM, SCOPE_STOP_SIGKILL))
return 0;
- assert(s->state == SCOPE_RUNNING ||
- s->state == SCOPE_ABANDONED);
+ assert(IN_SET(s->state, SCOPE_RUNNING, SCOPE_ABANDONED));
scope_enter_signal(s, SCOPE_STOP_SIGTERM, SCOPE_SUCCESS);
return 1;
diff --git a/src/core/service.c b/src/core/service.c
index 1a4455bd22..fb8a970a27 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -529,7 +529,7 @@ static int service_verify(Service *s) {
if (s->bus_name && s->type != SERVICE_DBUS)
log_unit_warning(UNIT(s), "Service has a D-Bus service name specified, but is not of type dbus. Ignoring.");
- if (s->exec_context.pam_name && !(s->kill_context.kill_mode == KILL_CONTROL_GROUP || s->kill_context.kill_mode == KILL_MIXED)) {
+ if (s->exec_context.pam_name && !IN_SET(s->kill_context.kill_mode, KILL_CONTROL_GROUP, KILL_MIXED)) {
log_unit_error(UNIT(s), "Service has PAM enabled. Kill mode must be set to 'control-group' or 'mixed'. Refusing.");
return -EINVAL;
}
@@ -2224,7 +2224,7 @@ static int service_reload(Unit *u) {
assert(s);
- assert(s->state == SERVICE_RUNNING || s->state == SERVICE_EXITED);
+ assert(IN_SET(s->state, SERVICE_RUNNING, SERVICE_EXITED));
service_enter_reload(s);
return 1;
@@ -2755,7 +2755,7 @@ static int service_retry_pid_file(Service *s) {
int r;
assert(s->pid_file);
- assert(s->state == SERVICE_START || s->state == SERVICE_START_POST);
+ assert(IN_SET(s->state, SERVICE_START, SERVICE_START_POST));
r = service_load_pid_file(s, false);
if (r < 0)
@@ -2826,7 +2826,7 @@ static int service_dispatch_io(sd_event_source *source, int fd, uint32_t events,
assert(s);
assert(fd >= 0);
- assert(s->state == SERVICE_START || s->state == SERVICE_START_POST);
+ assert(IN_SET(s->state, SERVICE_START, SERVICE_START_POST));
assert(s->pid_file_pathspec);
assert(path_spec_owns_inotify_fd(s->pid_file_pathspec, fd));
diff --git a/src/core/socket.c b/src/core/socket.c
index e05daaa1dc..d579f341fb 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -2083,7 +2083,7 @@ static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) {
fail:
log_unit_warning_errno(UNIT(s), r, "Failed to kill processes: %m");
- if (state == SOCKET_STOP_PRE_SIGTERM || state == SOCKET_STOP_PRE_SIGKILL)
+ if (IN_SET(state, SOCKET_STOP_PRE_SIGTERM, SOCKET_STOP_PRE_SIGKILL))
socket_enter_stop_post(s, SOCKET_FAILURE_RESOURCES);
else
socket_enter_dead(s, SOCKET_FAILURE_RESOURCES);
@@ -2456,7 +2456,7 @@ static int socket_start(Unit *u) {
}
}
- assert(s->state == SOCKET_DEAD || s->state == SOCKET_FAILED);
+ assert(IN_SET(s->state, SOCKET_DEAD, SOCKET_FAILED));
r = unit_start_limit_test(u);
if (r < 0) {
@@ -2500,7 +2500,7 @@ static int socket_stop(Unit *u) {
return -EAGAIN;
}
- assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
+ assert(IN_SET(s->state, SOCKET_LISTENING, SOCKET_RUNNING));
socket_enter_stop_pre(s, SOCKET_SUCCESS);
return 1;
diff --git a/src/core/timer.c b/src/core/timer.c
index a34bc7b14e..9ea5f322d8 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -589,7 +589,7 @@ static int timer_start(Unit *u) {
int r;
assert(t);
- assert(t->state == TIMER_DEAD || t->state == TIMER_FAILED);
+ assert(IN_SET(t->state, TIMER_DEAD, TIMER_FAILED));
trigger = UNIT_TRIGGER(u);
if (!trigger || trigger->load_state != UNIT_LOADED) {
@@ -649,7 +649,7 @@ static int timer_stop(Unit *u) {
Timer *t = TIMER(u);
assert(t);
- assert(t->state == TIMER_WAITING || t->state == TIMER_RUNNING || t->state == TIMER_ELAPSED);
+ assert(IN_SET(t->state, TIMER_WAITING, TIMER_RUNNING, TIMER_ELAPSED));
timer_enter_dead(t, TIMER_SUCCESS);
return 1;
@@ -754,8 +754,7 @@ static void timer_trigger_notify(Unit *u, Unit *other) {
/* Reenable all timers that depend on unit state */
LIST_FOREACH(value, v, t->values)
- if (v->base == TIMER_UNIT_ACTIVE ||
- v->base == TIMER_UNIT_INACTIVE)
+ if (IN_SET(v->base, TIMER_UNIT_ACTIVE, TIMER_UNIT_INACTIVE))
v->disabled = false;
switch (t->state) {
diff --git a/src/core/transaction.c b/src/core/transaction.c
index 1af4ed9100..46c2fa452e 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -609,7 +609,7 @@ static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) {
/* Moves the transaction jobs to the set of active jobs */
- if (mode == JOB_ISOLATE || mode == JOB_FLUSH) {
+ if (IN_SET(mode, JOB_ISOLATE, JOB_FLUSH)) {
/* When isolating first kill all installed jobs which
* aren't part of the new transaction */
@@ -968,7 +968,7 @@ int transaction_add_job_and_dependencies(
}
/* Finally, recursively add in all dependencies. */
- if (type == JOB_START || type == JOB_RESTART) {
+ if (IN_SET(type, JOB_START, JOB_RESTART)) {
SET_FOREACH(dep, ret->unit->dependencies[UNIT_REQUIRES], i) {
r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, false, false, ignore_order, e);
if (r < 0) {
@@ -1033,7 +1033,7 @@ int transaction_add_job_and_dependencies(
}
- if (type == JOB_STOP || type == JOB_RESTART) {
+ if (IN_SET(type, JOB_STOP, JOB_RESTART)) {
static const UnitDependency propagate_deps[] = {
UNIT_REQUIRED_BY,
UNIT_REQUISITE_OF,
diff --git a/src/core/unit.c b/src/core/unit.c
index 60cf30ea3a..0ef6fcfab5 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -3552,9 +3552,7 @@ bool unit_active_or_pending(Unit *u) {
return true;
if (u->job &&
- (u->job->type == JOB_START ||
- u->job->type == JOB_RELOAD_OR_START ||
- u->job->type == JOB_RESTART))
+ IN_SET(u->job->type, JOB_START, JOB_RELOAD_OR_START, JOB_RESTART))
return true;
return false;
diff --git a/src/core/unit.h b/src/core/unit.h
index 7c6fef27b3..02090ed67d 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -46,19 +46,19 @@ typedef enum KillOperation {
} KillOperation;
static inline bool UNIT_IS_ACTIVE_OR_RELOADING(UnitActiveState t) {
- return t == UNIT_ACTIVE || t == UNIT_RELOADING;
+ return IN_SET(t, UNIT_ACTIVE, UNIT_RELOADING);
}
static inline bool UNIT_IS_ACTIVE_OR_ACTIVATING(UnitActiveState t) {
- return t == UNIT_ACTIVE || t == UNIT_ACTIVATING || t == UNIT_RELOADING;
+ return IN_SET(t, UNIT_ACTIVE, UNIT_ACTIVATING, UNIT_RELOADING);
}
static inline bool UNIT_IS_INACTIVE_OR_DEACTIVATING(UnitActiveState t) {
- return t == UNIT_INACTIVE || t == UNIT_FAILED || t == UNIT_DEACTIVATING;
+ return IN_SET(t, UNIT_INACTIVE, UNIT_FAILED, UNIT_DEACTIVATING);
}
static inline bool UNIT_IS_INACTIVE_OR_FAILED(UnitActiveState t) {
- return t == UNIT_INACTIVE || t == UNIT_FAILED;
+ return IN_SET(t, UNIT_INACTIVE, UNIT_FAILED);
}
#include "job.h"
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index e1e1a9675e..8fc35ad999 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -660,7 +660,7 @@ int main(int argc, char *argv[]) {
crypt_set_log_callback(cd, log_glue, NULL);
status = crypt_status(cd, argv[2]);
- if (status == CRYPT_ACTIVE || status == CRYPT_BUSY) {
+ if (IN_SET(status, CRYPT_ACTIVE, CRYPT_BUSY)) {
log_info("Volume %s already active.", argv[2]);
r = 0;
goto finish;
diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index 2100681e17..434321f806 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -269,7 +269,7 @@ static int fsck_progress_socket(void) {
return log_warning_errno(errno, "socket(): %m");
if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0) {
- r = log_full_errno(errno == ECONNREFUSED || errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
+ r = log_full_errno(IN_SET(errno, ECONNREFUSED, ENOENT) ? LOG_DEBUG : LOG_WARNING,
errno, "Failed to connect to progress socket %s, ignoring: %m", sa.un.sun_path);
safe_close(fd);
return r;
diff --git a/src/import/importd.c b/src/import/importd.c
index 3d379d6de9..bdb9910010 100644
--- a/src/import/importd.c
+++ b/src/import/importd.c
@@ -321,8 +321,7 @@ static int transfer_on_pid(sd_event_source *s, const siginfo_t *si, void *userda
success = true;
}
- } else if (si->si_code == CLD_KILLED ||
- si->si_code == CLD_DUMPED)
+ } else if (IN_SET(si->si_code, CLD_KILLED, CLD_DUMPED))
log_error("Import process terminated by signal %s.", signal_to_string(si->si_status));
else
@@ -585,7 +584,7 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void
n = recvmsg(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
if (n < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return 0;
return -errno;
diff --git a/src/import/pull-job.c b/src/import/pull-job.c
index 320c21305a..3e20905d79 100644
--- a/src/import/pull-job.c
+++ b/src/import/pull-job.c
@@ -58,8 +58,7 @@ PullJob* pull_job_unref(PullJob *j) {
static void pull_job_finish(PullJob *j, int ret) {
assert(j);
- if (j->state == PULL_JOB_DONE ||
- j->state == PULL_JOB_FAILED)
+ if (IN_SET(j->state, PULL_JOB_DONE, PULL_JOB_FAILED))
return;
if (ret == 0) {
@@ -442,7 +441,7 @@ static size_t pull_job_header_callback(void *contents, size_t size, size_t nmemb
assert(contents);
assert(j);
- if (j->state == PULL_JOB_DONE || j->state == PULL_JOB_FAILED) {
+ if (IN_SET(j->state, PULL_JOB_DONE, PULL_JOB_FAILED)) {
r = -ESTALE;
goto fail;
}
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 5c33c435e2..94f0559d64 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -322,8 +322,7 @@ bool journal_file_is_offlining(JournalFile *f) {
__sync_synchronize();
- if (f->offline_state == OFFLINE_DONE ||
- f->offline_state == OFFLINE_JOINED)
+ if (IN_SET(f->offline_state, OFFLINE_DONE, OFFLINE_JOINED))
return false;
return true;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 1bb4d89159..3dcfb0e97a 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -477,11 +477,7 @@ static int parse_argv(int argc, char *argv[]) {
return -EINVAL;
}
- if (arg_output == OUTPUT_EXPORT ||
- arg_output == OUTPUT_JSON ||
- arg_output == OUTPUT_JSON_PRETTY ||
- arg_output == OUTPUT_JSON_SSE ||
- arg_output == OUTPUT_CAT)
+ if (IN_SET(arg_output, OUTPUT_EXPORT, OUTPUT_JSON, OUTPUT_JSON_PRETTY, OUTPUT_JSON_SSE, OUTPUT_CAT))
arg_quiet = true;
break;
diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c
index 869c996aef..b20e7ab129 100644
--- a/src/journal/journald-audit.c
+++ b/src/journal/journald-audit.c
@@ -528,7 +528,7 @@ int server_open_audit(Server *s) {
s->audit_fd = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_AUDIT);
if (s->audit_fd < 0) {
- if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)
+ if (IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT))
log_debug("Audit not supported in the kernel.");
else
log_warning_errno(errno, "Failed to create audit socket, ignoring: %m");
diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c
index 1bad7cb2ee..36f16a1ec8 100644
--- a/src/journal/journald-kmsg.c
+++ b/src/journal/journald-kmsg.c
@@ -335,7 +335,7 @@ static int server_read_dev_kmsg(Server *s) {
return 0;
}
- if (errno == EAGAIN || errno == EINTR || errno == EPIPE)
+ if (IN_SET(errno, EAGAIN, EINTR, EPIPE))
return 0;
return log_error_errno(errno, "Failed to read from kernel: %m");
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 2d51be7c89..de643c9149 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1111,7 +1111,7 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
n = recvmsg(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
if (n < 0) {
- if (errno == EINTR || errno == EAGAIN)
+ if (IN_SET(errno, EINTR, EAGAIN))
return 0;
return log_error_errno(errno, "recvmsg() failed: %m");
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
index fa597e47a2..7d040de893 100644
--- a/src/journal/journald-syslog.c
+++ b/src/journal/journald-syslog.c
@@ -91,7 +91,7 @@ static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned
return;
}
- if (ucred && (errno == ESRCH || errno == EPERM)) {
+ if (ucred && IN_SET(errno, ESRCH, EPERM)) {
struct ucred u;
/* Hmm, presumably the sender process vanished
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 22054835ba..fb7269e510 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -136,7 +136,7 @@ static void reset_location(sd_journal *j) {
static void init_location(Location *l, LocationType type, JournalFile *f, Object *o) {
assert(l);
- assert(type == LOCATION_DISCRETE || type == LOCATION_SEEK);
+ assert(IN_SET(type, LOCATION_DISCRETE, LOCATION_SEEK));
assert(f);
assert(o->object.type == OBJECT_ENTRY);
@@ -2436,7 +2436,7 @@ _public_ int sd_journal_process(sd_journal *j) {
l = read(j->inotify_fd, &buffer, sizeof(buffer));
if (l < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return got_something ? determine_change(j) : SD_JOURNAL_NOP;
return -errno;
diff --git a/src/libsystemd-network/dhcp-packet.c b/src/libsystemd-network/dhcp-packet.c
index 40442b3636..475c5729a0 100644
--- a/src/libsystemd-network/dhcp-packet.c
+++ b/src/libsystemd-network/dhcp-packet.c
@@ -34,8 +34,8 @@ int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid,
size_t offset = 0;
int r;
- assert(op == BOOTREQUEST || op == BOOTREPLY);
- assert(arp_type == ARPHRD_ETHER || arp_type == ARPHRD_INFINIBAND);
+ assert(IN_SET(op, BOOTREQUEST, BOOTREPLY));
+ assert(IN_SET(arp_type, ARPHRD_ETHER, ARPHRD_INFINIBAND));
message->op = op;
message->htype = arp_type;
diff --git a/src/libsystemd-network/icmp6-util.c b/src/libsystemd-network/icmp6-util.c
index 7fbebd6f27..cf69044d6d 100644
--- a/src/libsystemd-network/icmp6-util.c
+++ b/src/libsystemd-network/icmp6-util.c
@@ -191,7 +191,7 @@ int icmp6_receive(int fd, void *buffer, size_t size, struct in6_addr *dst,
len = recvmsg(fd, &msg, MSG_DONTWAIT);
if (len < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return 0;
return -errno;
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 8426f602a9..25cff849e5 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -1164,7 +1164,7 @@ static int client_start_delayed(sd_dhcp_client *client) {
}
client->fd = r;
- if (client->state == DHCP_STATE_INIT || client->state == DHCP_STATE_INIT_REBOOT)
+ if (IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_INIT_REBOOT))
client->start_time = now(clock_boottime_or_monotonic());
return client_initialize_events(client, client_receive_message_raw);
diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c
index 2ebc00f247..909b470251 100644
--- a/src/libsystemd-network/sd-ipv4acd.c
+++ b/src/libsystemd-network/sd-ipv4acd.c
@@ -354,7 +354,7 @@ static int ipv4acd_on_packet(
n = recv(fd, &packet, sizeof(struct ether_arp), 0);
if (n < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return 0;
log_ipv4acd_errno(acd, errno, "Failed to read ARP packet: %m");
diff --git a/src/network/networkd-util.c b/src/network/networkd-util.c
index 555a7c68a1..8856e76269 100644
--- a/src/network/networkd-util.c
+++ b/src/network/networkd-util.c
@@ -25,8 +25,7 @@
#include "util.h"
const char *address_family_boolean_to_string(AddressFamilyBoolean b) {
- if (b == ADDRESS_FAMILY_YES ||
- b == ADDRESS_FAMILY_NO)
+ if (IN_SET(b, ADDRESS_FAMILY_YES, ADDRESS_FAMILY_NO))
return yes_no(b == ADDRESS_FAMILY_YES);
if (b == ADDRESS_FAMILY_IPV4)
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 5ba09a994a..82fd0bd5f4 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1766,8 +1766,7 @@ static int setup_journal(const char *directory) {
r = readlink_and_make_absolute(p, &d);
if (r >= 0) {
- if ((arg_link_journal == LINK_GUEST ||
- arg_link_journal == LINK_AUTO) &&
+ if (IN_SET(arg_link_journal, LINK_GUEST, LINK_AUTO) &&
path_equal(d, q)) {
r = userns_mkdir(directory, p, 0755, 0, 0);
@@ -2882,7 +2881,7 @@ static int nspawn_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t r
n = recvmsg(fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
if (n < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return 0;
return log_warning_errno(errno, "Couldn't read notification socket: %m");
diff --git a/src/resolve/resolved-dns-stub.c b/src/resolve/resolved-dns-stub.c
index 6f7b5ab9e8..292e94daa3 100644
--- a/src/resolve/resolved-dns-stub.c
+++ b/src/resolve/resolved-dns-stub.c
@@ -467,7 +467,7 @@ static int on_dns_stub_stream(sd_event_source *s, int fd, uint32_t revents, void
cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
if (cfd < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return 0;
return -errno;
diff --git a/src/resolve/resolved-dns-synthesize.c b/src/resolve/resolved-dns-synthesize.c
index c454f64049..25d2322453 100644
--- a/src/resolve/resolved-dns-synthesize.c
+++ b/src/resolve/resolved-dns-synthesize.c
@@ -240,21 +240,23 @@ static int synthesize_system_hostname_rr(Manager *m, const DnsResourceKey *key,
/* If we have no local addresses then use ::1
* and 127.0.0.2 as local ones. */
- if (af == AF_INET || af == AF_UNSPEC)
+ if (IN_SET(af, AF_INET, AF_UNSPEC))
buffer[n++] = (struct local_address) {
.family = AF_INET,
.ifindex = dns_synthesize_ifindex(ifindex),
.address.in.s_addr = htobe32(0x7F000002),
};
- if (af == AF_INET6 || af == AF_UNSPEC)
+ if (IN_SET(af, AF_INET6, AF_UNSPEC))
buffer[n++] = (struct local_address) {
.family = AF_INET6,
.ifindex = dns_synthesize_ifindex(ifindex),
.address.in6 = in6addr_loopback,
};
- return answer_add_addresses_rr(answer, dns_resource_key_name(key), buffer, n);
+ return answer_add_addresses_rr(answer,
+ dns_resource_key_name(key),
+ buffer, n);
}
}
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c
index 3075f62b5e..8b23132339 100644
--- a/src/resolve/resolved-dns-transaction.c
+++ b/src/resolve/resolved-dns-transaction.c
@@ -1528,8 +1528,7 @@ int dns_transaction_go(DnsTransaction *t) {
af_to_name_short(t->scope->family));
if (!t->initial_jitter_scheduled &&
- (t->scope->protocol == DNS_PROTOCOL_LLMNR ||
- t->scope->protocol == DNS_PROTOCOL_MDNS)) {
+ IN_SET(t->scope->protocol, DNS_PROTOCOL_LLMNR, DNS_PROTOCOL_MDNS)) {
usec_t jitter, accuracy;
/* RFC 4795 Section 2.7 suggests all queries should be
diff --git a/src/resolve/resolved-link.c b/src/resolve/resolved-link.c
index ea3b061877..95795e4d24 100644
--- a/src/resolve/resolved-link.c
+++ b/src/resolve/resolved-link.c
@@ -314,7 +314,7 @@ void link_set_dnssec_mode(Link *l, DnssecMode mode) {
assert(l);
#ifndef HAVE_GCRYPT
- if (mode == DNSSEC_YES || mode == DNSSEC_ALLOW_DOWNGRADE)
+ if (IN_SET(mode, DNSSEC_YES, DNSSEC_ALLOW_DOWNGRADE))
log_warning("DNSSEC option for the link cannot be enabled or set to allow-downgrade when systemd-resolved is built without gcrypt support. Turning off DNSSEC support.");
return;
#endif
diff --git a/src/resolve/resolved-llmnr.c b/src/resolve/resolved-llmnr.c
index 29396e9973..0cf4583572 100644
--- a/src/resolve/resolved-llmnr.c
+++ b/src/resolve/resolved-llmnr.c
@@ -345,7 +345,7 @@ static int on_llmnr_stream(sd_event_source *s, int fd, uint32_t revents, void *u
cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
if (cfd < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return 0;
return -errno;
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index 0ce8e54573..de3847adfd 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -320,7 +320,7 @@ int ask_password_tty(
n = read(ttyfd >= 0 ? ttyfd : STDIN_FILENO, &c, 1);
if (n < 0) {
- if (errno == EINTR || errno == EAGAIN)
+ if (IN_SET(errno, EINTR, EAGAIN))
continue;
r = -errno;
@@ -613,8 +613,7 @@ int ask_password_agent(
n = recvmsg(socket_fd, &msghdr, 0);
if (n < 0) {
- if (errno == EAGAIN ||
- errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
continue;
r = -errno;
diff --git a/src/shared/clean-ipc.c b/src/shared/clean-ipc.c
index f59f6f23ae..3e246a1dca 100644
--- a/src/shared/clean-ipc.c
+++ b/src/shared/clean-ipc.c
@@ -95,7 +95,7 @@ static int clean_sysvipc_shm(uid_t delete_uid, gid_t delete_gid) {
if (shmctl(shmid, IPC_RMID, NULL) < 0) {
/* Ignore entries that are already deleted */
- if (errno == EIDRM || errno == EINVAL)
+ if (IN_SET(errno, EIDRM, EINVAL))
continue;
ret = log_warning_errno(errno,
@@ -147,7 +147,7 @@ static int clean_sysvipc_sem(uid_t delete_uid, gid_t delete_gid) {
if (semctl(semid, 0, IPC_RMID) < 0) {
/* Ignore entries that are already deleted */
- if (errno == EIDRM || errno == EINVAL)
+ if (IN_SET(errno, EIDRM, EINVAL))
continue;
ret = log_warning_errno(errno,
@@ -200,7 +200,7 @@ static int clean_sysvipc_msg(uid_t delete_uid, gid_t delete_gid) {
if (msgctl(msgid, IPC_RMID, NULL) < 0) {
/* Ignore entries that are already deleted */
- if (errno == EIDRM || errno == EINVAL)
+ if (IN_SET(errno, EIDRM, EINVAL))
continue;
ret = log_warning_errno(errno,
diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c
index 59b541d519..0c92184ba5 100644
--- a/src/shared/ptyfwd.c
+++ b/src/shared/ptyfwd.c
@@ -187,7 +187,7 @@ static int shovel(PTYForward *f) {
if (errno == EAGAIN)
f->stdin_readable = false;
- else if (errno == EIO || errno == EPIPE || errno == ECONNRESET) {
+ else if (IN_SET(errno, EIO, EPIPE, ECONNRESET)) {
f->stdin_readable = false;
f->stdin_hangup = true;
@@ -217,9 +217,9 @@ static int shovel(PTYForward *f) {
k = write(f->master, f->in_buffer, f->in_buffer_full);
if (k < 0) {
- if (errno == EAGAIN || errno == EIO)
+ if (IN_SET(errno, EAGAIN, EIO))
f->master_writable = false;
- else if (errno == EPIPE || errno == ECONNRESET) {
+ else if (IN_SET(errno, EPIPE, ECONNRESET)) {
f->master_writable = f->master_readable = false;
f->master_hangup = true;
@@ -249,7 +249,7 @@ static int shovel(PTYForward *f) {
if (errno == EAGAIN || (errno == EIO && ignore_vhangup(f)))
f->master_readable = false;
- else if (errno == EPIPE || errno == ECONNRESET || errno == EIO) {
+ else if (IN_SET(errno, EPIPE, ECONNRESET, EIO)) {
f->master_readable = f->master_writable = false;
f->master_hangup = true;
@@ -271,7 +271,7 @@ static int shovel(PTYForward *f) {
if (errno == EAGAIN)
f->stdout_writable = false;
- else if (errno == EIO || errno == EPIPE || errno == ECONNRESET) {
+ else if (IN_SET(errno, EIO, EPIPE, ECONNRESET)) {
f->stdout_writable = false;
f->stdout_hangup = true;
f->stdout_event_source = sd_event_source_unref(f->stdout_event_source);
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c
index 9750dcd817..fc8548c5b3 100644
--- a/src/shared/utmp-wtmp.c
+++ b/src/shared/utmp-wtmp.c
@@ -234,7 +234,7 @@ int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line
if (r < 0)
return r;
- if (ut_type == LOGIN_PROCESS || ut_type == USER_PROCESS) {
+ if (IN_SET(ut_type, LOGIN_PROCESS, USER_PROCESS)) {
store.ut_type = LOGIN_PROCESS;
r = write_entry_both(&store);
if (r < 0)
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
index 3f3237d9b3..195f7a0604 100644
--- a/src/sysv-generator/sysv-generator.c
+++ b/src/sysv-generator/sysv-generator.c
@@ -480,7 +480,7 @@ static int load_sysv(SysvStub *s) {
continue;
}
- if ((state == LSB_DESCRIPTION || state == LSB) && streq(t, "### END INIT INFO")) {
+ if (IN_SET(state, LSB_DESCRIPTION, LSB) && streq(t, "### END INIT INFO")) {
state = NORMAL;
continue;
}
@@ -554,7 +554,7 @@ static int load_sysv(SysvStub *s) {
chkconfig_description = d;
}
- } else if (state == LSB || state == LSB_DESCRIPTION) {
+ } else if (IN_SET(state, LSB, LSB_DESCRIPTION)) {
if (startswith_no_case(t, "Provides:")) {
state = LSB;
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 3d3967f271..3f5c1e62ee 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -931,7 +931,7 @@ static int parse_attribute_from_arg(Item *item) {
v = attributes[i].value;
- SET_FLAG(value, v, (mode == MODE_ADD || mode == MODE_SET));
+ SET_FLAG(value, v, IN_SET(mode, MODE_ADD, MODE_SET));
mask |= v;
}
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index a17c006d57..3ea8dae7a9 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -165,7 +165,7 @@ static int ask_password_plymouth(
k = read(fd, buffer + p, sizeof(buffer) - p);
if (k < 0) {
- if (errno == EINTR || errno == EAGAIN)
+ if (IN_SET(errno, EINTR, EAGAIN))
continue;
r = -errno;
@@ -346,8 +346,7 @@ static int parse_password(const char *filename, char **wall) {
} else {
_cleanup_strv_free_erase_ char **passwords = NULL;
- assert(arg_action == ACTION_QUERY ||
- arg_action == ACTION_WATCH);
+ assert(IN_SET(arg_action, ACTION_QUERY, ACTION_WATCH));
if (access(socket_name, W_OK) < 0) {
if (arg_action == ACTION_QUERY)
diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c
index 57dfb016f9..52229d82b5 100644
--- a/src/udev/collect/collect.c
+++ b/src/udev/collect/collect.c
@@ -102,7 +102,7 @@ static int prepare(char *dir, char *filename)
if (lockf(fd,F_TLOCK,0) < 0) {
if (debug)
fprintf(stderr, "Lock taken, wait for %d seconds\n", UDEV_ALARM_TIMEOUT);
- if (errno == EAGAIN || errno == EACCES) {
+ if (IN_SET(errno, EAGAIN, EACCES)) {
alarm(UDEV_ALARM_TIMEOUT);
lockf(fd, F_LOCK, 0);
if (debug)
diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c
index e079e28698..f007cc6001 100644
--- a/src/udev/scsi_id/scsi_serial.c
+++ b/src/udev/scsi_id/scsi_serial.c
@@ -358,7 +358,7 @@ resend:
retval = ioctl(fd, SG_IO, io_buf);
if (retval < 0) {
- if ((errno == EINVAL || errno == ENOSYS) && dev_scsi->use_sg == 4) {
+ if (IN_SET(errno, EINVAL, ENOSYS) && dev_scsi->use_sg == 4) {
dev_scsi->use_sg = 3;
goto resend;
}
diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c
index 94a59186ed..77ae3a9732 100644
--- a/src/udev/udevadm-monitor.c
+++ b/src/udev/udevadm-monitor.c
@@ -33,7 +33,7 @@
static bool udev_exit;
static void sig_handler(int signum) {
- if (signum == SIGINT || signum == SIGTERM)
+ if (IN_SET(signum, SIGINT, SIGTERM))
udev_exit = true;
}
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 0e49e62688..83f846fbc8 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -1134,7 +1134,7 @@ static int on_inotify(sd_event_source *s, int fd, uint32_t revents, void *userda
l = read(fd, &buffer, sizeof(buffer));
if (l < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return 1;
return log_error_errno(errno, "Failed to read inotify fd: %m");
diff --git a/src/veritysetup/veritysetup.c b/src/veritysetup/veritysetup.c
index f809d51638..c6a79541f7 100644
--- a/src/veritysetup/veritysetup.c
+++ b/src/veritysetup/veritysetup.c
@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
crypt_set_log_callback(cd, log_glue, NULL);
status = crypt_status(cd, argv[2]);
- if (status == CRYPT_ACTIVE || status == CRYPT_BUSY) {
+ if (IN_SET(status, CRYPT_ACTIVE, CRYPT_BUSY)) {
log_info("Volume %s already active.", argv[2]);
r = 0;
goto finish;