Merge pull request #6941 from andir/use-in_set

use IN_SET where possible
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2017-10-02 15:08:10 +02:00 committed by GitHub
commit b139c95bc4
73 changed files with 334 additions and 191 deletions

35
coccinelle/in_set.cocci Normal file
View file

@ -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)

147
coccinelle/not_in_set.cocci Normal file
View file

@ -0,0 +1,147 @@
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19, n20;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11 && e != n12 && e != n13 && e != n14 && e != n15 && e != n16 && e != n17 && e != n18 && e != n19 && e != n20
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19, n20)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11 && e != n12 && e != n13 && e != n14 && e != n15 && e != n16 && e != n17 && e != n18 && e != n19
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11 && e != n12 && e != n13 && e != n14 && e != n15 && e != n16 && e != n17 && e != n18
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11 && e != n12 && e != n13 && e != n14 && e != n15 && e != n16 && e != n17
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11 && e != n12 && e != n13 && e != n14 && e != n15 && e != n16
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11 && e != n12 && e != n13 && e != n14 && e != n15
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11 && e != n12 && e != n13 && e != n14
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11 && e != n12 && e != n13
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11 && e != n12
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10 && e != n11
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9 && e != n10
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8, n9;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8 && e != n9
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7, n8;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7 && e != n8
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7, n8)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6, n7;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6 && e != n7
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6, n7)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5, n6;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5 && e != n6
+ !IN_SET(e, n0, n1, n2, n3, n4, n5, n6)
@@
expression e;
identifier n0, n1, n2, n3, n4, n5;
statement s;
@@
- e != n0 && e != n1 && e != n2 && e != n3 && e != n4 && e != n5
+ !IN_SET(e, n0, n1, n2, n3, n4, n5)
@@
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, 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)

View file

@ -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);

View file

@ -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) {

View file

@ -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);

View file

@ -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;
}

View file

@ -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);

View file

@ -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;

View file

@ -202,7 +202,7 @@ int rm_rf(const char *path, RemoveFlags flags) {
fd = open(path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW|O_NOATIME);
if (fd < 0) {
if (errno != ENOTDIR && errno != ELOOP)
if (!IN_SET(errno, ENOTDIR, ELOOP))
return -errno;
if (!(flags & REMOVE_PHYSICAL)) {

View file

@ -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

View file

@ -268,7 +268,7 @@ int socket_address_verify(const SocketAddress *a) {
if (a->sockaddr.in.sin_port == 0)
return -EINVAL;
if (a->type != SOCK_STREAM && a->type != SOCK_DGRAM)
if (!IN_SET(a->type, SOCK_STREAM, SOCK_DGRAM))
return -EINVAL;
return 0;
@ -280,7 +280,7 @@ int socket_address_verify(const SocketAddress *a) {
if (a->sockaddr.in6.sin6_port == 0)
return -EINVAL;
if (a->type != SOCK_STREAM && a->type != SOCK_DGRAM)
if (!IN_SET(a->type, SOCK_STREAM, SOCK_DGRAM))
return -EINVAL;
return 0;
@ -304,7 +304,7 @@ int socket_address_verify(const SocketAddress *a) {
}
}
if (a->type != SOCK_STREAM && a->type != SOCK_DGRAM && a->type != SOCK_SEQPACKET)
if (!IN_SET(a->type, SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET))
return -EINVAL;
return 0;
@ -314,7 +314,7 @@ int socket_address_verify(const SocketAddress *a) {
if (a->size != sizeof(struct sockaddr_nl))
return -EINVAL;
if (a->type != SOCK_RAW && a->type != SOCK_DGRAM)
if (!IN_SET(a->type, SOCK_RAW, SOCK_DGRAM))
return -EINVAL;
return 0;
@ -323,7 +323,7 @@ int socket_address_verify(const SocketAddress *a) {
if (a->size != sizeof(struct sockaddr_vm))
return -EINVAL;
if (a->type != SOCK_STREAM && a->type != SOCK_DGRAM)
if (!IN_SET(a->type, SOCK_STREAM, SOCK_DGRAM))
return -EINVAL;
return 0;
@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -48,7 +48,7 @@ int get_audit_fd(void) {
audit_fd = audit_open();
if (audit_fd < 0) {
if (errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT)
if (!IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT))
log_error_errno(errno, "Failed to connect to audit log: %m");
audit_fd = errno ? -errno : -EINVAL;

View file

@ -251,8 +251,7 @@ static void automount_set_state(Automount *a, AutomountState state) {
if (state != AUTOMOUNT_RUNNING)
automount_stop_expire(a);
if (state != AUTOMOUNT_WAITING &&
state != AUTOMOUNT_RUNNING)
if (!IN_SET(state, AUTOMOUNT_WAITING, AUTOMOUNT_RUNNING))
unmount_autofs(a);
if (state != old_state)
@ -804,7 +803,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 +835,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;

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -174,8 +174,7 @@ static int killall(int sig, Set *pids, bool send_sighup) {
pid_t pid;
int r;
if (d->d_type != DT_DIR &&
d->d_type != DT_UNKNOWN)
if (!IN_SET(d->d_type, DT_DIR, DT_UNKNOWN))
continue;
if (parse_pid(d->d_name, &pid) < 0)

View file

@ -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;
@ -2513,9 +2513,7 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) {
if (detect_container() > 0)
return;
if (u->type != UNIT_SERVICE &&
u->type != UNIT_MOUNT &&
u->type != UNIT_SWAP)
if (!IN_SET(u->type, UNIT_SERVICE, UNIT_MOUNT, UNIT_SWAP))
return;
/* We set SOCK_NONBLOCK here so that we rather drop the

View file

@ -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;
@ -670,8 +669,7 @@ static int path_dispatch_io(sd_event_source *source, int fd, uint32_t revents, v
p = PATH(s->unit);
if (p->state != PATH_WAITING &&
p->state != PATH_RUNNING)
if (!IN_SET(p->state, PATH_WAITING, PATH_RUNNING))
return 0;
/* log_debug("inotify wakeup on %s.", u->id); */

View file

@ -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;

View file

@ -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;
}
@ -2230,7 +2230,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;
@ -2761,7 +2761,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)
@ -2832,7 +2832,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));

View file

@ -2055,7 +2055,7 @@ static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) {
r = unit_kill_context(
UNIT(s),
&s->kill_context,
(state != SOCKET_STOP_PRE_SIGTERM && state != SOCKET_FINAL_SIGTERM) ?
!IN_SET(state, SOCKET_STOP_PRE_SIGTERM, SOCKET_FINAL_SIGTERM) ?
KILL_KILL : KILL_TERMINATE,
-1,
s->control_pid,
@ -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);
@ -2448,15 +2448,13 @@ static int socket_start(Unit *u) {
/* If the service is already active we cannot start the
* socket */
if (service->state != SERVICE_DEAD &&
service->state != SERVICE_FAILED &&
service->state != SERVICE_AUTO_RESTART) {
if (!IN_SET(service->state, SERVICE_DEAD, SERVICE_FAILED, SERVICE_AUTO_RESTART)) {
log_unit_error(u, "Socket service %s already active, refusing.", UNIT(service)->id);
return -EBUSY;
}
}
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 +2498,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;

View file

@ -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) {

View file

@ -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,

View file

@ -778,8 +778,7 @@ int unit_merge(Unit *u, Unit *other) {
if (!unit_type_may_alias(u->type)) /* Merging only applies to unit names that support aliases */
return -EEXIST;
if (other->load_state != UNIT_STUB &&
other->load_state != UNIT_NOT_FOUND)
if (!IN_SET(other->load_state, UNIT_STUB, UNIT_NOT_FOUND))
return -EEXIST;
if (other->job)
@ -2221,7 +2220,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
if (u->job->state == JOB_RUNNING) {
if (ns == UNIT_ACTIVE)
job_finish_and_invalidate(u->job, reload_success ? JOB_DONE : JOB_FAILED, true, false);
else if (ns != UNIT_ACTIVATING && ns != UNIT_RELOADING) {
else if (!IN_SET(ns, UNIT_ACTIVATING, UNIT_RELOADING)) {
unexpected = true;
if (UNIT_IS_INACTIVE_OR_FAILED(ns))
@ -3552,9 +3551,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;

View file

@ -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"

View file

@ -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;

View file

@ -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;

View file

@ -135,7 +135,7 @@ int import_uncompress(ImportCompress *c, const void *data, size_t size, ImportCo
c->xz.avail_out = sizeof(buffer);
lzr = lzma_code(&c->xz, LZMA_RUN);
if (lzr != LZMA_OK && lzr != LZMA_STREAM_END)
if (!IN_SET(lzr, LZMA_OK, LZMA_STREAM_END))
return -EIO;
r = callback(buffer, sizeof(buffer) - c->xz.avail_out, userdata);
@ -156,7 +156,7 @@ int import_uncompress(ImportCompress *c, const void *data, size_t size, ImportCo
c->gzip.avail_out = sizeof(buffer);
r = inflate(&c->gzip, Z_NO_FLUSH);
if (r != Z_OK && r != Z_STREAM_END)
if (!IN_SET(r, Z_OK, Z_STREAM_END))
return -EIO;
r = callback(buffer, sizeof(buffer) - c->gzip.avail_out, userdata);
@ -177,7 +177,7 @@ int import_uncompress(ImportCompress *c, const void *data, size_t size, ImportCo
c->bzip2.avail_out = sizeof(buffer);
r = BZ2_bzDecompress(&c->bzip2);
if (r != BZ_OK && r != BZ_STREAM_END)
if (!IN_SET(r, BZ_OK, BZ_STREAM_END))
return -EIO;
r = callback(buffer, sizeof(buffer) - c->bzip2.avail_out, userdata);
@ -399,7 +399,7 @@ int import_compress_finish(ImportCompress *c, void **buffer, size_t *buffer_size
c->xz.avail_out = *buffer_allocated - *buffer_size;
lzr = lzma_code(&c->xz, LZMA_FINISH);
if (lzr != LZMA_OK && lzr != LZMA_STREAM_END)
if (!IN_SET(lzr, LZMA_OK, LZMA_STREAM_END))
return -EIO;
*buffer_size += (*buffer_allocated - *buffer_size) - c->xz.avail_out;
@ -420,7 +420,7 @@ int import_compress_finish(ImportCompress *c, void **buffer, size_t *buffer_size
c->gzip.avail_out = *buffer_allocated - *buffer_size;
r = deflate(&c->gzip, Z_FINISH);
if (r != Z_OK && r != Z_STREAM_END)
if (!IN_SET(r, Z_OK, Z_STREAM_END))
return -EIO;
*buffer_size += (*buffer_allocated - *buffer_size) - c->gzip.avail_out;
@ -440,7 +440,7 @@ int import_compress_finish(ImportCompress *c, void **buffer, size_t *buffer_size
c->bzip2.avail_out = *buffer_allocated - *buffer_size;
r = BZ2_bzCompress(&c->bzip2, BZ_FINISH);
if (r != BZ_FINISH_OK && r != BZ_STREAM_END)
if (!IN_SET(r, BZ_FINISH_OK, BZ_STREAM_END))
return -EIO;
*buffer_size += (*buffer_allocated - *buffer_size) - c->bzip2.avail_out;

View file

@ -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
@ -418,7 +417,7 @@ static int transfer_start(Transfer *t) {
}
}
if (pipefd[1] != STDOUT_FILENO && pipefd[1] != STDERR_FILENO)
if (!IN_SET(pipefd[1], STDOUT_FILENO, STDERR_FILENO))
pipefd[1] = safe_close(pipefd[1]);
if (t->stdin_fd >= 0) {
@ -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;

View file

@ -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;
}

View file

@ -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;
@ -1651,8 +1650,7 @@ uint64_t journal_file_entry_array_n_items(Object *o) {
uint64_t journal_file_hash_table_n_items(Object *o) {
assert(o);
if (o->object.type != OBJECT_DATA_HASH_TABLE &&
o->object.type != OBJECT_FIELD_HASH_TABLE)
if (!IN_SET(o->object.type, OBJECT_DATA_HASH_TABLE, OBJECT_FIELD_HASH_TABLE))
return 0;
return (le64toh(o->object.size) - offsetof(Object, hash_table.items)) / sizeof(HashItem);
@ -3242,8 +3240,7 @@ int journal_file_open(
assert(ret);
assert(fd >= 0 || fname);
if ((flags & O_ACCMODE) != O_RDONLY &&
(flags & O_ACCMODE) != O_RDWR)
if (!IN_SET((flags & O_ACCMODE), O_RDONLY, O_RDWR))
return -EINVAL;
if (fname) {

View file

@ -302,7 +302,7 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
if (errno == ENOENT)
return 0;
if (errno != EMSGSIZE && errno != ENOBUFS)
if (!IN_SET(errno, EMSGSIZE, ENOBUFS))
return -errno;
/* Message doesn't fit... Let's dump the data in a memfd or

View file

@ -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;

View file

@ -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");

View file

@ -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");

View file

@ -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");

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -455,9 +455,7 @@ int sd_dhcp_client_set_mtu(sd_dhcp_client *client, uint32_t mtu) {
int sd_dhcp_client_get_lease(sd_dhcp_client *client, sd_dhcp_lease **ret) {
assert_return(client, -EINVAL);
if (client->state != DHCP_STATE_BOUND &&
client->state != DHCP_STATE_RENEWING &&
client->state != DHCP_STATE_REBINDING)
if (!IN_SET(client->state, DHCP_STATE_BOUND, DHCP_STATE_RENEWING, DHCP_STATE_REBINDING))
return -EADDRNOTAVAIL;
if (ret)
@ -1164,7 +1162,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);

View file

@ -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");

View file

@ -354,7 +354,7 @@ static int user_mkdir_runtime_path(User *u) {
r = mount("tmpfs", u->runtime_path, "tmpfs", MS_NODEV|MS_NOSUID, t);
if (r < 0) {
if (errno != EPERM && errno != EACCES) {
if (!IN_SET(errno, EPERM, EACCES)) {
r = log_error_errno(errno, "Failed to mount per-user tmpfs directory %s: %m", u->runtime_path);
goto fail;
}

View file

@ -749,16 +749,16 @@ int config_parse_tunnel(const char *unit,
return 0;
}
if (netdev->kind != NETDEV_KIND_IPIP &&
netdev->kind != NETDEV_KIND_SIT &&
netdev->kind != NETDEV_KIND_GRE &&
netdev->kind != NETDEV_KIND_GRETAP &&
netdev->kind != NETDEV_KIND_IP6GRE &&
netdev->kind != NETDEV_KIND_IP6GRETAP &&
netdev->kind != NETDEV_KIND_VTI &&
netdev->kind != NETDEV_KIND_VTI6 &&
netdev->kind != NETDEV_KIND_IP6TNL
) {
if (!IN_SET(netdev->kind,
NETDEV_KIND_IPIP,
NETDEV_KIND_SIT,
NETDEV_KIND_GRE,
NETDEV_KIND_GRETAP,
NETDEV_KIND_IP6GRE,
NETDEV_KIND_IP6GRETAP,
NETDEV_KIND_VTI,
NETDEV_KIND_VTI6,
NETDEV_KIND_IP6TNL)) {
log_syntax(unit, LOG_ERR, filename, line, 0,
"NetDev is not a tunnel, ignoring assignment: %s", rvalue);
return 0;

View file

@ -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)

View file

@ -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");

View file

@ -337,7 +337,7 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
if (af == AF_UNSPEC)
af = AF_INET;
if (af != AF_INET && af != AF_INET6) {
if (!IN_SET(af, AF_INET, AF_INET6)) {
*errnop = EAFNOSUPPORT;
*h_errnop = NO_DATA;
return NSS_STATUS_UNAVAIL;

View file

@ -221,7 +221,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use
ss = writev(fd, iov, 2);
if (ss < 0) {
if (errno != EINTR && errno != EAGAIN)
if (!IN_SET(errno, EINTR, EAGAIN))
return dns_stream_complete(s, errno);
} else
s->n_written += ss;
@ -243,7 +243,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use
ss = read(fd, (uint8_t*) &s->read_size + s->n_read, sizeof(s->read_size) - s->n_read);
if (ss < 0) {
if (errno != EINTR && errno != EAGAIN)
if (!IN_SET(errno, EINTR, EAGAIN))
return dns_stream_complete(s, errno);
} else if (ss == 0)
return dns_stream_complete(s, ECONNRESET);
@ -293,7 +293,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use
(uint8_t*) DNS_PACKET_DATA(s->read_packet) + s->n_read - sizeof(s->read_size),
sizeof(s->read_size) + be16toh(s->read_size) - s->n_read);
if (ss < 0) {
if (errno != EINTR && errno != EAGAIN)
if (!IN_SET(errno, EINTR, EAGAIN))
return dns_stream_complete(s, errno);
} else if (ss == 0)
return dns_stream_complete(s, ECONNRESET);

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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,

View file

@ -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);

View file

@ -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)

View file

@ -167,7 +167,7 @@ static int connection_shovel(
} else if (z == 0 || errno == EPIPE || errno == ECONNRESET) {
*from_source = sd_event_source_unref(*from_source);
*from = safe_close(*from);
} else if (errno != EAGAIN && errno != EINTR)
} else if (!IN_SET(errno, EAGAIN, EINTR))
return log_error_errno(errno, "Failed to splice: %m");
}
@ -179,7 +179,7 @@ static int connection_shovel(
} else if (z == 0 || errno == EPIPE || errno == ECONNRESET) {
*to_source = sd_event_source_unref(*to_source);
*to = safe_close(*to);
} else if (errno != EAGAIN && errno != EINTR)
} else if (!IN_SET(errno, EAGAIN, EINTR))
return log_error_errno(errno, "Failed to splice: %m");
}
} while (shoveled);

View file

@ -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;

View file

@ -192,8 +192,7 @@ static void test_proc(void) {
pid_t pid;
uid_t uid = UID_INVALID;
if (de->d_type != DT_DIR &&
de->d_type != DT_UNKNOWN)
if (!IN_SET(de->d_type, DT_DIR, DT_UNKNOWN))
continue;
r = parse_pid(de->d_name, &pid);

View file

@ -54,7 +54,7 @@ static void check(Manager *m, Unit *unit, int status_expected, int code_expected
printf("%s\n", unit->id);
exec_context_dump(&service->exec_context, stdout, "\t");
ts = now(CLOCK_MONOTONIC);
while (service->state != SERVICE_DEAD && service->state != SERVICE_FAILED) {
while (!IN_SET(service->state, SERVICE_DEAD, SERVICE_FAILED)) {
int r;
usec_t n;

View file

@ -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;
}

View file

@ -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)

View file

@ -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)

View file

@ -54,7 +54,7 @@ void probe_smart_media(int mtd_fd, mtd_info_t* info)
block_size = info->erasesize;
size_in_megs = info->size / (1024 * 1024);
if (sector_size != SM_SECTOR_SIZE && sector_size != SM_SMALL_PAGE)
if (!IN_SET(sector_size, SM_SECTOR_SIZE, SM_SMALL_PAGE))
goto exit;
switch(size_in_megs) {

View file

@ -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;
}

View file

@ -411,7 +411,7 @@ static struct udev_device *handle_scsi_default(struct udev_device *parent, char
if (dent->d_name[0] == '.')
continue;
if (dent->d_type != DT_DIR && dent->d_type != DT_LNK)
if (!IN_SET(dent->d_type, DT_DIR, DT_LNK))
continue;
if (!startswith(dent->d_name, "host"))
continue;

View file

@ -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;
}

View file

@ -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");

View file

@ -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;