diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2017-10-04 23:01:32 +0900 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-10-04 16:01:32 +0200 |
commit | 4c701096002fff540d9ddb3b21398c551ac3af78 (patch) | |
tree | 537e654dc92baa5eed5b6ff69867114384ecfa47 | |
parent | 6d0aa4db7b33c9ce71b820c76428a1cfd24fb56f (diff) | |
download | systemd-4c701096002fff540d9ddb3b21398c551ac3af78.tar.gz |
tree-wide: use IN_SET macro (#6977)
92 files changed, 168 insertions, 191 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index be7328af40..1fc9e9b154 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -421,11 +421,7 @@ static int parse_weekdays(const char **p, CalendarSpec *c) { skip = strlen(day_nr[i].name); - if ((*p)[skip] != '-' && - (*p)[skip] != '.' && - (*p)[skip] != ',' && - (*p)[skip] != ' ' && - (*p)[skip] != 0) + if (!IN_SET((*p)[skip], 0, '-', '.', ',', ' ')) return -EINVAL; c->weekdays_bits |= 1 << day_nr[i].nr; @@ -484,7 +480,7 @@ static int parse_weekdays(const char **p, CalendarSpec *c) { } /* Allow a trailing comma but not an open range */ - if (**p == 0 || **p == ' ') { + if (IN_SET(**p, 0, ' ')) { *p += strspn(*p, " "); return l < 0 ? 0 : -EINVAL; } @@ -644,7 +640,7 @@ static int prepend_component(const char **p, bool usec, CalendarComponent **c) { return -ERANGE; } - if (*e != 0 && *e != ' ' && *e != ',' && *e != '-' && *e != '~' && *e != ':') + if (!IN_SET(*e, 0, ' ', ',', '-', '~', ':')) return -EINVAL; cc = new0(CalendarComponent, 1); @@ -741,7 +737,7 @@ static int parse_date(const char **p, CalendarSpec *c) { return r; /* Already the end? A ':' as separator? In that case this was a time, not a date */ - if (*t == 0 || *t == ':') { + if (IN_SET(*t, 0, ':')) { free_chain(first); return 0; } @@ -761,7 +757,7 @@ static int parse_date(const char **p, CalendarSpec *c) { } /* Got two parts, hence it's month and day */ - if (*t == ' ' || *t == 0) { + if (IN_SET(*t, 0, ' ')) { *p = t + strspn(t, " "); c->month = first; c->day = second; @@ -789,7 +785,7 @@ static int parse_date(const char **p, CalendarSpec *c) { } /* Got three parts, hence it is year, month and day */ - if (*t == ' ' || *t == 0) { + if (IN_SET(*t, 0, ' ')) { *p = t + strspn(t, " "); c->year = first; c->month = second; diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index f3f6a21576..d51c3efd22 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -374,7 +374,7 @@ int cg_kill_recursive( if (flags & CGROUP_REMOVE) { r = cg_rmdir(controller, path); - if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY) + if (r < 0 && ret >= 0 && !IN_SET(r, -ENOENT, -EBUSY)) return r; } @@ -509,7 +509,7 @@ int cg_migrate_recursive( if (flags & CGROUP_REMOVE) { r = cg_rmdir(cfrom, pfrom); - if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY) + if (r < 0 && ret >= 0 && !IN_SET(r, -ENOENT, -EBUSY)) return r; } @@ -1883,9 +1883,7 @@ char *cg_escape(const char *p) { /* The return value of this function (unlike cg_unescape()) * needs free()! */ - if (p[0] == 0 || - p[0] == '_' || - p[0] == '.' || + if (IN_SET(p[0], 0, '_', '.') || streq(p, "notify_on_release") || streq(p, "release_agent") || streq(p, "tasks") || @@ -1951,7 +1949,7 @@ bool cg_controller_is_valid(const char *p) { if (s) p = s; - if (*p == 0 || *p == '_') + if (IN_SET(*p, 0, '_')) return false; for (t = p; *t; t++) @@ -2003,7 +2001,7 @@ int cg_slice_to_path(const char *unit, char **ret) { char n[dash - p + sizeof(".slice")]; /* Don't allow trailing or double dashes */ - if (dash[1] == 0 || dash[1] == '-') + if (IN_SET(dash[1], 0, '-')) return -EINVAL; strcpy(stpncpy(n, p, dash - p), ".slice"); diff --git a/src/basic/env-util.c b/src/basic/env-util.c index d72940acb3..fa42edfa96 100644 --- a/src/basic/env-util.c +++ b/src/basic/env-util.c @@ -707,7 +707,7 @@ char **replace_env_argv(char **argv, char **env) { STRV_FOREACH(i, argv) { /* If $FOO appears as single word, replace it by the split up variable */ - if ((*i)[0] == '$' && (*i)[1] != '{' && (*i)[1] != '$') { + if ((*i)[0] == '$' && !IN_SET((*i)[1], '{', '$')) { char *e; char **w, **m = NULL; unsigned q; diff --git a/src/basic/escape.c b/src/basic/escape.c index 22b8b04156..0a6122c64a 100644 --- a/src/basic/escape.c +++ b/src/basic/escape.c @@ -426,7 +426,7 @@ char *octescape(const char *s, size_t len) { for (f = s, t = r; f < s + len; f++) { - if (*f < ' ' || *f >= 127 || *f == '\\' || *f == '"') { + if (*f < ' ' || *f >= 127 || IN_SET(*f, '\\', '"')) { *(t++) = '\\'; *(t++) = '0' + (*f >> 6); *(t++) = '0' + ((*f >> 3) & 8); diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c index 804f14c44c..f4ac526eb1 100644 --- a/src/basic/extract-word.c +++ b/src/basic/extract-word.c @@ -152,7 +152,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra for (;; (*p)++, c = **p) { if (c == 0) goto finish_force_terminate; - else if ((c == '\'' || c == '"') && (flags & EXTRACT_QUOTES)) { + else if (IN_SET(c, '\'', '"') && (flags & EXTRACT_QUOTES)) { quote = c; break; } else if (c == '\\' && !(flags & EXTRACT_RETAIN_ESCAPE)) { diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index af63171041..b90f343ed3 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -324,7 +324,7 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi mkdir_parents(path, 0755); fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, - (mode == 0 || mode == MODE_INVALID) ? 0644 : mode); + IN_SET(mode, 0, MODE_INVALID) ? 0644 : mode); if (fd < 0) return -errno; diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 6ef1b0ba35..a5ab4570fa 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -508,7 +508,7 @@ static void base_remove_entry(HashmapBase *h, unsigned idx) { /* Find the stop bucket ("right"). It is either free or has DIB == 0. */ for (right = next_idx(h, left); ; right = next_idx(h, right)) { raw_dib = dibs[right]; - if (raw_dib == 0 || raw_dib == DIB_RAW_FREE) + if (IN_SET(raw_dib, 0, DIB_RAW_FREE)) break; /* The buckets are not supposed to be all occupied and with DIB > 0. diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c index b511a36301..ea9e77087f 100644 --- a/src/basic/hostname-util.c +++ b/src/basic/hostname-util.c @@ -90,9 +90,7 @@ static bool hostname_valid_char(char c) { (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || - c == '-' || - c == '_' || - c == '.'; + IN_SET(c, '-', '_', '.'); } /** @@ -235,7 +233,7 @@ int read_hostname_config(const char *path, char **hostname) { /* may have comments, ignore them */ FOREACH_LINE(l, f, return -errno) { truncate_nl(l); - if (l[0] != '\0' && l[0] != '#') { + if (!IN_SET(l[0], '\0', '#')) { /* found line with value */ name = hostname_cleanup(l); name = strdup(name); diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c index 8c1d2bc9c9..65b488351e 100644 --- a/src/basic/mount-util.c +++ b/src/basic/mount-util.c @@ -472,14 +472,14 @@ int bind_remount_recursive_with_mountinfo(const char *prefix, bool ro, char **bl while ((x = set_steal_first(todo))) { r = set_consume(done, x); - if (r == -EEXIST || r == 0) + if (IN_SET(r, 0, -EEXIST)) continue; if (r < 0) return r; /* Deal with mount points that are obstructed by a later mount */ r = path_is_mount_point(x, NULL, 0); - if (r == -ENOENT || r == 0) + if (IN_SET(r, 0, -ENOENT)) continue; if (r < 0) return r; diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 89bb667c5f..4ae07b0a8e 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -152,7 +152,7 @@ int parse_size(const char *t, uint64_t base, uint64_t *size) { unsigned n_entries, start_pos = 0; assert(t); - assert(base == 1000 || base == 1024); + assert(IN_SET(base, 1000, 1024)); assert(size); if (base == 1000) { diff --git a/src/basic/process-util.c b/src/basic/process-util.c index ab661a8f16..a1b50b6c79 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -392,7 +392,7 @@ int is_kernel_thread(pid_t pid) { bool eof; FILE *f; - if (pid == 0 || pid == 1 || pid == getpid_cached()) /* pid 1, and we ourselves certainly aren't a kernel thread */ + if (IN_SET(pid, 0, 1) || pid == getpid_cached()) /* pid 1, and we ourselves certainly aren't a kernel thread */ return 0; assert(pid > 1); @@ -817,7 +817,7 @@ bool pid_is_alive(pid_t pid) { return true; r = get_process_state(pid); - if (r == -ESRCH || r == 'Z') + if (IN_SET(r, -ESRCH, 'Z')) return false; return true; diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c index 77fe88e42c..0bbafb4cd7 100644 --- a/src/basic/rm-rf.c +++ b/src/basic/rm-rf.c @@ -132,7 +132,7 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) { r = btrfs_subvol_remove_fd(fd, de->d_name, BTRFS_REMOVE_RECURSIVE|BTRFS_REMOVE_QUOTA); if (r < 0) { - if (r != -ENOTTY && r != -EINVAL) { + if (!IN_SET(r, -ENOTTY, -EINVAL)) { if (ret == 0) ret = r; @@ -193,7 +193,7 @@ int rm_rf(const char *path, RemoveFlags flags) { if (r >= 0) return r; - if (r != -ENOTTY && r != -EINVAL && r != -ENOTDIR) + if (!IN_SET(r, -ENOTTY, -EINVAL, -ENOTDIR)) return r; /* Not btrfs or not a subvolume */ diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index e8d39674cc..5942b2df9b 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -892,7 +892,7 @@ bool ifname_valid(const char *p) { if ((unsigned char) *p <= 32U) return false; - if (*p == ':' || *p == '/') + if (IN_SET(*p, ':', '/')) return false; numeric = numeric && (*p >= '0' && *p <= '9'); diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 5808b1280e..2eed99d9c0 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -673,7 +673,7 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz) { case STATE_BRACKET: if (i >= *ibuf + isz || /* EOT */ - (!(*i >= '0' && *i <= '9') && *i != ';' && *i != 'm')) { + (!(*i >= '0' && *i <= '9') && !IN_SET(*i, ';', 'm'))) { fputc_unlocked('\x1B', f); fputc_unlocked('[', f); state = STATE_OTHER; diff --git a/src/basic/time-util.c b/src/basic/time-util.c index f67467c5bd..46ec722989 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -1308,7 +1308,7 @@ bool timezone_is_valid(const char *name) { if (!(*p >= '0' && *p <= '9') && !(*p >= 'a' && *p <= 'z') && !(*p >= 'A' && *p <= 'Z') && - !(*p == '-' || *p == '_' || *p == '+' || *p == '/')) + !IN_SET(*p, '-', '_', '+', '/')) return false; if (*p == '/') { diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c index 5e3f307dcd..f9c034c94b 100644 --- a/src/basic/unit-name.c +++ b/src/basic/unit-name.c @@ -305,7 +305,7 @@ static char *do_escape(const char *f, char *t) { for (; *f; f++) { if (*f == '/') *(t++) = '-'; - else if (*f == '-' || *f == '\\' || !strchr(VALID_CHARS, *f)) + else if (IN_SET(*f, '-', '\\') || !strchr(VALID_CHARS, *f)) t = do_escape_char(*f, t); else *(t++) = *f; diff --git a/src/basic/user-util.c b/src/basic/user-util.c index c619dad527..a691a0d3fc 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -543,8 +543,7 @@ bool valid_user_group_name(const char *u) { if (!(*i >= 'a' && *i <= 'z') && !(*i >= 'A' && *i <= 'Z') && !(*i >= '0' && *i <= '9') && - *i != '_' && - *i != '-') + !IN_SET(*i, '_', '-')) return false; } diff --git a/src/basic/utf8.c b/src/basic/utf8.c index 6eae2b983d..7a52fac621 100644 --- a/src/basic/utf8.c +++ b/src/basic/utf8.c @@ -73,7 +73,7 @@ static bool unichar_is_control(char32_t ch) { '\t' is in C0 range, but more or less harmless and commonly used. */ - return (ch < ' ' && ch != '\t' && ch != '\n') || + return (ch < ' ' && !IN_SET(ch, '\t', '\n')) || (0x7F <= ch && ch <= 0x9F); } diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index 8256899eda..e086376d7c 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -129,7 +129,7 @@ static int parse_crtime(le64_t le, usec_t *usec) { assert(usec); u = le64toh(le); - if (u == 0 || u == (uint64_t) -1) + if (IN_SET(u, 0, (uint64_t) -1)) return -EIO; *usec = (usec_t) u; diff --git a/src/basic/xml.c b/src/basic/xml.c index 1dbeac7324..a4337f4865 100644 --- a/src/basic/xml.c +++ b/src/basic/xml.c @@ -208,7 +208,7 @@ int xml_tokenize(const char **p, char **name, void **state, unsigned *line) { if (*c == '=') { c++; - if (*c == '\'' || *c == '\"') { + if (IN_SET(*c, '\'', '\"')) { /* Tag with a quoted value */ e = strchr(c+1, *c); diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 85f549c4c4..e9f9447118 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -355,7 +355,7 @@ static int whitelist_major(const char *path, const char *name, char type, const assert(path); assert(acc); - assert(type == 'b' || type == 'c'); + assert(IN_SET(type, 'b', 'c')); f = fopen("/proc/devices", "re"); if (!f) diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index 791649e5b5..a9a68826b4 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -917,7 +917,7 @@ static int append_process(sd_bus_message *reply, const char *p, pid_t pid, Set * assert(pid > 0); r = set_put(pids, PID_TO_PTR(pid)); - if (r == -EEXIST || r == 0) + if (IN_SET(r, 0, -EEXIST)) return 0; if (r < 0) return r; diff --git a/src/core/execute.c b/src/core/execute.c index e1c2a57cc6..3e264d1dd4 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2062,7 +2062,7 @@ static int setup_smack( _cleanup_free_ char *exec_label = NULL; r = mac_smack_read(command->path, SMACK_ATTR_EXEC, &exec_label); - if (r < 0 && r != -ENODATA && r != -EOPNOTSUPP) + if (r < 0 && !IN_SET(r, -ENODATA, -EOPNOTSUPP)) return r; r = mac_smack_apply_pid(0, exec_label ? : SMACK_DEFAULT_PROCESS_LABEL); diff --git a/src/core/job.c b/src/core/job.c index f962881a12..fb57f193fd 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -681,7 +681,7 @@ _pure_ static const char *job_get_status_message_format(Unit *u, JobType t, JobR /* Return generic strings */ if (t == JOB_START) return generic_finished_start_job[result]; - else if (t == JOB_STOP || t == JOB_RESTART) + else if (IN_SET(t, JOB_STOP, JOB_RESTART)) return generic_finished_stop_job[result]; else if (t == JOB_RELOAD) return generic_finished_reload_job[result]; diff --git a/src/core/main.c b/src/core/main.c index 2dfd48005b..962ee28ae5 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1672,7 +1672,7 @@ int main(int argc, char *argv[]) { goto finish; } - if (arg_action == ACTION_TEST || arg_action == ACTION_HELP) { + if (IN_SET(arg_action, ACTION_TEST, ACTION_HELP)) { pager_open(arg_no_pager, false); skip_setup = true; } @@ -1696,7 +1696,7 @@ int main(int argc, char *argv[]) { goto finish; } - assert_se(arg_action == ACTION_RUN || arg_action == ACTION_TEST); + assert_se(IN_SET(arg_action, ACTION_RUN, ACTION_TEST)); /* Close logging fds, in order not to confuse fdset below */ log_close(); @@ -1892,7 +1892,7 @@ int main(int argc, char *argv[]) { r = manager_load_unit(m, arg_default_unit, NULL, &error, &target); if (r < 0) log_error("Failed to load default target: %s", bus_error_message(&error, r)); - else if (target->load_state == UNIT_ERROR || target->load_state == UNIT_NOT_FOUND) + else if (IN_SET(target->load_state, UNIT_ERROR, UNIT_NOT_FOUND)) log_error_errno(target->load_error, "Failed to load default target: %m"); else if (target->load_state == UNIT_MASKED) log_error("Default target masked."); @@ -1905,7 +1905,7 @@ int main(int argc, char *argv[]) { log_emergency("Failed to load rescue target: %s", bus_error_message(&error, r)); error_message = "Failed to load rescue target"; goto finish; - } else if (target->load_state == UNIT_ERROR || target->load_state == UNIT_NOT_FOUND) { + } else if (IN_SET(target->load_state, UNIT_ERROR, UNIT_NOT_FOUND)) { log_emergency_errno(target->load_error, "Failed to load rescue target: %m"); error_message = "Failed to load rescue target"; goto finish; diff --git a/src/core/manager.c b/src/core/manager.c index 5c127e0848..02bc8065d8 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -396,7 +396,7 @@ static int enable_special_signals(Manager *m) { /* Enable that we get SIGINT on control-alt-del. In containers * this will fail with EPERM (older) or EINVAL (newer), so * ignore that. */ - if (reboot(RB_DISABLE_CAD) < 0 && errno != EPERM && errno != EINVAL) + if (reboot(RB_DISABLE_CAD) < 0 && !IN_SET(errno, EPERM, EINVAL)) log_warning_errno(errno, "Failed to enable ctrl-alt-del handling: %m"); fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC); @@ -985,10 +985,8 @@ static void unit_gc_sweep(Unit *u, unsigned gc_marker) { assert(u); - if (u->gc_marker == gc_marker + GC_OFFSET_GOOD || - u->gc_marker == gc_marker + GC_OFFSET_BAD || - u->gc_marker == gc_marker + GC_OFFSET_UNSURE || - u->gc_marker == gc_marker + GC_OFFSET_IN_PATH) + if (IN_SET(u->gc_marker - gc_marker, + GC_OFFSET_GOOD, GC_OFFSET_BAD, GC_OFFSET_UNSURE, GC_OFFSET_IN_PATH)) return; if (u->in_cleanup_queue) @@ -1055,8 +1053,8 @@ static unsigned manager_dispatch_gc_unit_queue(Manager *m) { n++; - if (u->gc_marker == gc_marker + GC_OFFSET_BAD || - u->gc_marker == gc_marker + GC_OFFSET_UNSURE) { + if (IN_SET(u->gc_marker - gc_marker, + GC_OFFSET_BAD, GC_OFFSET_UNSURE)) { if (u->id) log_unit_debug(u, "Collecting."); u->gc_marker = gc_marker + GC_OFFSET_BAD; @@ -3747,7 +3745,7 @@ int manager_dispatch_user_lookup_fd(sd_event_source *source, int fd, uint32_t re l = recv(fd, &buffer, sizeof(buffer), MSG_DONTWAIT); if (l < 0) { - if (errno == EINTR || errno == EAGAIN) + if (IN_SET(errno, EINTR, EAGAIN)) return 0; return log_error_errno(errno, "Failed to read from user lookup fd: %m"); diff --git a/src/core/service.c b/src/core/service.c index e990d47797..915943aff3 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -218,7 +218,7 @@ static void service_start_watchdog(Service *s) { assert(s); watchdog_usec = service_get_watchdog_usec(s); - if (watchdog_usec == 0 || watchdog_usec == USEC_INFINITY) + if (IN_SET(watchdog_usec, 0, USEC_INFINITY)) return; if (s->watchdog_event_source) { diff --git a/src/core/socket.c b/src/core/socket.c index 06ceb46eca..c0f4030302 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1444,7 +1444,7 @@ static int socket_determine_selinux_label(Socket *s, char **ret) { goto no_label; r = mac_selinux_get_create_label_from_exe(c->path, ret); - if (r == -EPERM || r == -EOPNOTSUPP) + if (IN_SET(r, -EPERM, -EOPNOTSUPP)) goto no_label; } diff --git a/src/core/unit.c b/src/core/unit.c index 2b7c7738fe..357306dce8 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -3647,7 +3647,7 @@ int unit_kill_common( return -ENOMEM; q = cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, signo, 0, pid_set, NULL, NULL); - if (q < 0 && q != -EAGAIN && q != -ESRCH && q != -ENOENT) + if (q < 0 && !IN_SET(q, -EAGAIN, -ESRCH, -ENOENT)) r = q; else killed = true; @@ -4179,7 +4179,7 @@ int unit_kill_context( pid_set, log_func, u); if (r < 0) { - if (r != -EAGAIN && r != -ESRCH && r != -ENOENT) + if (!IN_SET(r, -EAGAIN, -ESRCH, -ENOENT)) log_unit_warning_errno(u, r, "Failed to kill control group %s, ignoring: %m", u->cgroup_path); } else if (r > 0) { diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index f882a4f80e..3752ca2ef2 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -378,7 +378,7 @@ static int add_crypttab_devices(void) { crypttab_line++; l = strstrip(line); - if (*l == '#' || *l == 0) + if (IN_SET(*l, 0, '#')) continue; k = sscanf(l, "%ms %ms %ms %ms", &name, &device, &keyfile, &options); diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 434321f806..bcb07fe976 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -462,7 +462,7 @@ int main(int argc, char *argv[]) { if (status.si_code != CLD_EXITED || (status.si_status & ~1)) { - if (status.si_code == CLD_KILLED || status.si_code == CLD_DUMPED) + if (IN_SET(status.si_code, CLD_KILLED, CLD_DUMPED)) log_error("fsck terminated by signal %s.", signal_to_string(status.si_status)); else if (status.si_code == CLD_EXITED) log_error("fsck failed with error code %i.", status.si_status); diff --git a/src/import/import-common.c b/src/import/import-common.c index 81209cdaf6..ae71682988 100644 --- a/src/import/import-common.c +++ b/src/import/import-common.c @@ -37,7 +37,7 @@ int import_make_read_only_fd(int fd) { /* First, let's make this a read-only subvolume if it refers * to a subvolume */ r = btrfs_subvol_set_read_only_fd(fd, true); - if (r == -ENOTTY || r == -ENOTDIR || r == -EINVAL) { + if (IN_SET(r, -ENOTTY, -ENOTDIR, -EINVAL)) { struct stat st; /* This doesn't refer to a subvolume, or the file diff --git a/src/import/importd.c b/src/import/importd.c index e20aca0d9e..9b3fd06b52 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -250,7 +250,7 @@ static void transfer_send_logs(Transfer *t, bool flush) { n = strndup(t->log_message, e - t->log_message); /* Skip over NUL and newlines */ - while ((e < t->log_message + t->log_message_size) && (*e == 0 || *e == '\n')) + while ((e < t->log_message + t->log_message_size) && IN_SET(*e, 0, '\n')) e++; memmove(t->log_message, e, t->log_message + sizeof(t->log_message) - e); diff --git a/src/import/pull-job.c b/src/import/pull-job.c index 3e20905d79..995a652ec3 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -108,7 +108,7 @@ void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result) { if (curl_easy_getinfo(curl, CURLINFO_PRIVATE, (char **)&j) != CURLE_OK) return; - if (!j || j->state == PULL_JOB_DONE || j->state == PULL_JOB_FAILED) + if (!j || IN_SET(j->state, PULL_JOB_DONE, PULL_JOB_FAILED)) return; if (result != CURLE_OK) { diff --git a/src/import/qcow2-util.c b/src/import/qcow2-util.c index ee2121cc36..00734865b2 100644 --- a/src/import/qcow2-util.c +++ b/src/import/qcow2-util.c @@ -213,8 +213,7 @@ static int verify_header(const Header *header) { if (HEADER_MAGIC(header) != QCOW2_MAGIC) return -EBADMSG; - if (HEADER_VERSION(header) != 2 && - HEADER_VERSION(header) != 3) + if (!IN_SET(HEADER_VERSION(header), 2, 3)) return -EOPNOTSUPP; if (HEADER_CRYPT_METHOD(header) != 0) diff --git a/src/journal/catalog.c b/src/journal/catalog.c index f42be0adf9..bf92da9f90 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -216,7 +216,7 @@ int catalog_file_lang(const char* filename, char **lang) { return 0; beg = end - 1; - while (beg > filename && *beg != '.' && *beg != '/' && end - beg < 32) + while (beg > filename && !IN_SET(*beg, '.', '/') && end - beg < 32) beg--; if (*beg != '.' || end <= beg + 1) @@ -312,7 +312,7 @@ int catalog_import_file(Hashmap *h, const char *path) { line[0] == '-' && line[1] == '-' && line[2] == ' ' && - (line[2+1+32] == ' ' || line[2+1+32] == '\0')) { + IN_SET(line[2+1+32], ' ', '\0')) { bool with_language; sd_id128_t jd; diff --git a/src/journal/compress.c b/src/journal/compress.c index 818a720ba8..7ad7dd519d 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -280,7 +280,7 @@ int decompress_startswith_xz(const void *src, uint64_t src_size, for (;;) { ret = lzma_code(&s, LZMA_FINISH); - if (ret != LZMA_STREAM_END && ret != LZMA_OK) + if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END)) return -EBADMSG; if (*buffer_size - s.avail_out >= prefix_len + 1) @@ -417,7 +417,7 @@ int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes) { } ret = lzma_code(&s, action); - if (ret != LZMA_OK && ret != LZMA_STREAM_END) { + if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END)) { log_error("Compression failed: code %u", ret); return -EBADMSG; } @@ -579,7 +579,7 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) { } ret = lzma_code(&s, action); - if (ret != LZMA_OK && ret != LZMA_STREAM_END) { + if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END)) { log_debug("Decompression failed: code %u", ret); return -EBADMSG; } diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 3dcfb0e97a..641b9afa34 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -248,7 +248,7 @@ static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset if (r >= 0) x += 32; - if (*x != '-' && *x != '+' && *x != 0) + if (!IN_SET(*x, 0, '-', '+')) return -EINVAL; if (*x != 0) { @@ -1572,7 +1572,7 @@ static int setup_keys(void) { struct stat st; r = stat("/var/log/journal", &st); - if (r < 0 && errno != ENOENT && errno != ENOTDIR) + if (r < 0 && !IN_SET(errno, ENOENT, ENOTDIR)) return log_error_errno(errno, "stat(\"%s\") failed: %m", "/var/log/journal"); if (r < 0 || !S_ISDIR(st.st_mode)) { diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c index b20e7ab129..3334418f33 100644 --- a/src/journal/journald-audit.c +++ b/src/journal/journald-audit.c @@ -49,7 +49,7 @@ static int map_simple_field(const char *field, const char **p, struct iovec **io return -ENOMEM; memcpy(c, field, l); - for (e = *p; *e != ' ' && *e != 0; e++) { + for (e = *p; !IN_SET(*e, 0, ' '); e++) { if (!GREEDY_REALLOC(c, allocated, l+2)) return -ENOMEM; @@ -110,7 +110,7 @@ static int map_string_field_internal(const char *field, const char **p, struct i return -ENOMEM; memcpy(c, field, l); - for (e = *p; *e != ' ' && *e != 0; e += 2) { + for (e = *p; !IN_SET(*e, 0, ' '); e += 2) { int a, b; uint8_t x; @@ -167,7 +167,7 @@ static int map_generic_field(const char *prefix, const char **p, struct iovec ** for (e = *p; e < *p + 16; e++) { - if (*e == 0 || *e == ' ') + if (IN_SET(*e, 0, ' ')) return 0; if (*e == '=') @@ -176,7 +176,7 @@ static int map_generic_field(const char *prefix, const char **p, struct iovec ** if (!((*e >= 'a' && *e <= 'z') || (*e >= 'A' && *e <= 'Z') || (*e >= '0' && *e <= '9') || - *e == '_' || *e == '-')) + IN_SET(*e, '_', '-'))) return 0; } diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c index 554f91460d..8a2962335c 100644 --- a/src/journal/journald-native.c +++ b/src/journal/journald-native.c @@ -183,7 +183,7 @@ static int server_process_entry( break; } - if (*p == '.' || *p == '#') { + if (IN_SET(*p, '.', '#')) { /* Ignore control commands for now, and * comments too. */ *remaining -= (e - p) + 1; diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index de643c9149..463a8dd97c 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -317,7 +317,7 @@ static int system_journal_open(Server *s, bool flush_requested) { (void) cache_space_refresh(s, &s->system_storage); patch_min_use(&s->system_storage); } else if (r < 0) { - if (r != -ENOENT && r != -EROFS) + if (!IN_SET(r, -ENOENT, -EROFS)) log_warning_errno(r, "Failed to open system journal: %m"); r = 0; @@ -1620,7 +1620,7 @@ static int server_connect_notify(Server *s) { if (!e) return 0; - if ((e[0] != '@' && e[0] != '/') || e[1] == 0) { + if (!IN_SET(e[0], '@', '/') || e[1] == 0) { log_error("NOTIFY_SOCKET set to an invalid value: %s", e); return -EINVAL; } diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index fb7269e510..a47bd122b9 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -450,7 +450,7 @@ _pure_ static int compare_with_location(JournalFile *f, Location *l) { assert(f); assert(l); assert(f->location_type == LOCATION_SEEK); - assert(l->type == LOCATION_DISCRETE || l->type == LOCATION_SEEK); + assert(IN_SET(l->type, LOCATION_DISCRETE, LOCATION_SEEK)); if (l->monotonic_set && sd_id128_equal(f->current_boot_id, l->boot_id) && diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c index 92108a84b3..bd0ffaffbf 100644 --- a/src/journal/test-compress.c +++ b/src/journal/test-compress.c @@ -194,7 +194,7 @@ static void test_compress_stream(int compression, assert_se(lseek(dst, 1, SEEK_SET) == 1); r = decompress(dst, dst2, st.st_size); - assert_se(r == -EBADMSG || r == 0); + assert_se(IN_SET(r, 0, -EBADMSG)); assert_se(lseek(dst, 0, SEEK_SET) == 0); assert_se(lseek(dst2, 0, SEEK_SET) == 0); diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index d0ce7989d8..29b22eed45 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -528,7 +528,7 @@ static int client_message_init( assert(ret); assert(_optlen); assert(_optoffset); - assert(type == DHCP_DISCOVER || type == DHCP_REQUEST); + assert(IN_SET(type, DHCP_DISCOVER, DHCP_REQUEST)); optlen = DHCP_MIN_OPTIONS_SIZE; size = sizeof(DHCPPacket) + optlen; @@ -707,8 +707,7 @@ static int client_send_discover(sd_dhcp_client *client) { int r; assert(client); - assert(client->state == DHCP_STATE_INIT || - client->state == DHCP_STATE_SELECTING); + assert(IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_SELECTING)); r = client_message_init(client, &discover, DHCP_DISCOVER, &optlen, &optoffset); @@ -1688,7 +1687,7 @@ static int client_receive_message_udp( len = recv(fd, message, buflen, 0); if (len < 0) { - if (errno == EAGAIN || errno == EINTR) + if (IN_SET(errno, EAGAIN, EINTR)) return 0; return log_dhcp_client_errno(client, errno, @@ -1782,7 +1781,7 @@ static int client_receive_message_raw( len = recvmsg(fd, &msg, 0); if (len < 0) { - if (errno == EAGAIN || errno == EINTR) + if (IN_SET(errno, EAGAIN, EINTR)) return 0; return log_dhcp_client_errno(client, errno, diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 727cc16ab5..663fd0e41d 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -993,7 +993,7 @@ static int server_receive_message(sd_event_source *s, int fd, len = recvmsg(fd, &msg, 0); 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-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index 6444b0ce94..eba0c8bcbb 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -940,7 +940,7 @@ static int client_receive_message( len = recv(fd, message, buflen, 0); if (len < 0) { - if (errno == EAGAIN || errno == EINTR) + if (IN_SET(errno, EAGAIN, EINTR)) return 0; return log_dhcp6_client_errno(client, errno, "Could not receive message from UDP socket: %m"); diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c index 39ddb2461a..0f591a8011 100644 --- a/src/libsystemd-network/sd-lldp.c +++ b/src/libsystemd-network/sd-lldp.c @@ -218,7 +218,7 @@ static int lldp_receive_datagram(sd_event_source *s, int fd, uint32_t revents, v length = recv(fd, LLDP_NEIGHBOR_RAW(n), n->raw_size, MSG_DONTWAIT); if (length < 0) { - if (errno == EAGAIN || errno == EINTR) + if (IN_SET(errno, EAGAIN, EINTR)) return 0; return log_lldp_errno(errno, "Failed to read LLDP datagram: %m"); diff --git a/src/libsystemd-network/test-dhcp-client.c b/src/libsystemd-network/test-dhcp-client.c index 5c3ae170ed..1942199294 100644 --- a/src/libsystemd-network/test-dhcp-client.c +++ b/src/libsystemd-network/test-dhcp-client.c @@ -294,7 +294,7 @@ static void test_discover_message(sd_event *e) { res = sd_dhcp_client_start(client); - assert_se(res == 0 || res == -EINPROGRESS); + assert_se(IN_SET(res, 0, -EINPROGRESS)); sd_event_run(e, (uint64_t) -1); @@ -513,7 +513,7 @@ static void test_addr_acq(sd_event *e) { test_dhcp_hangcheck, NULL) >= 0); res = sd_dhcp_client_start(client); - assert_se(res == 0 || res == -EINPROGRESS); + assert_se(IN_SET(res, 0, -EINPROGRESS)); assert_se(sd_event_loop(e) >= 0); diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 2a509c7d1a..3fc447df3f 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -4219,8 +4219,7 @@ _public_ int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char return 1; } - if (c->signature[c->index] == SD_BUS_TYPE_STRUCT_BEGIN || - c->signature[c->index] == SD_BUS_TYPE_DICT_ENTRY_BEGIN) { + if (IN_SET(c->signature[c->index], SD_BUS_TYPE_STRUCT_BEGIN, SD_BUS_TYPE_DICT_ENTRY_BEGIN)) { if (contents) { size_t l; diff --git a/src/locale/keymap-util.c b/src/locale/keymap-util.c index 7068603f0f..b71091f706 100644 --- a/src/locale/keymap-util.c +++ b/src/locale/keymap-util.c @@ -39,7 +39,7 @@ static bool startswith_comma(const char *s, const char *prefix) { if (!s) return false; - return *s == ',' || *s == '\0'; + return IN_SET(*s, ',', '\0'); } static const char* strnulldash(const char *s) { @@ -177,7 +177,7 @@ static int x11_read_data(Context *c) { char_array_0(line); l = strstrip(line); - if (l[0] == 0 || l[0] == '#') + if (IN_SET(l[0], 0, '#')) continue; if (in_section && first_word(l, "Option")) { @@ -425,7 +425,7 @@ static int read_next_mapping(const char* filename, (*n)++; l = strstrip(line); - if (l[0] == 0 || l[0] == '#') + if (IN_SET(l[0], 0, '#')) continue; r = strv_split_extract(&b, l, WHITESPACE, EXTRACT_QUOTES); diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 1862e8983c..a63174c093 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -407,7 +407,7 @@ static int prop_map_first_of_struct(sd_bus *bus, const char *member, sd_bus_mess if (r < 0) return r; - if (contents[0] == 's' || contents[0] == 'o') { + if (IN_SET(contents[0], 's', 'o')) { const char *s; char **p = (char **) userdata; diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 85258737c3..64a622307e 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -663,8 +663,7 @@ static bool seat_name_valid_char(char c) { (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || - c == '-' || - c == '_'; + IN_SET(c, '-', '_'); } bool seat_name_is_valid(const char *name) { diff --git a/src/login/logind-user.c b/src/login/logind-user.c index d2e5c74fab..068bc455b5 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -547,7 +547,7 @@ static int user_remove_runtime_path(User *u) { * quite possible, if we lacked the permissions to mount * something */ r = umount2(u->runtime_path, MNT_DETACH); - if (r < 0 && errno != EINVAL && errno != ENOENT) + if (r < 0 && !IN_SET(errno, EINVAL, ENOENT)) log_error_errno(errno, "Failed to unmount user runtime directory %s: %m", u->runtime_path); r = rm_rf(u->runtime_path, REMOVE_ROOT); diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index a385e6819b..2447e734a2 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -1458,8 +1458,7 @@ static int login_machine(int argc, char *argv[], void *userdata) { return -EINVAL; } - if (arg_transport != BUS_TRANSPORT_LOCAL && - arg_transport != BUS_TRANSPORT_MACHINE) { + if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE)) { log_error("Login only supported on local machines."); return -EOPNOTSUPP; } @@ -1521,8 +1520,7 @@ static int shell_machine(int argc, char *argv[], void *userdata) { assert(bus); - if (arg_transport != BUS_TRANSPORT_LOCAL && - arg_transport != BUS_TRANSPORT_MACHINE) { + if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE)) { log_error("Shell only supported on local machines."); return -EOPNOTSUPP; } diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 54d54c8fd5..e4b95e4195 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -383,7 +383,7 @@ static int get_gateway_description( assert(rtnl); assert(ifindex >= 0); - assert(family == AF_INET || family == AF_INET6); + assert(IN_SET(family, AF_INET, AF_INET6)); assert(gateway); assert(gateway_description); diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 8f625975fb..214192ffe8 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -453,7 +453,7 @@ int address_remove( int r; assert(address); - assert(address->family == AF_INET || address->family == AF_INET6); + assert(IN_SET(address->family, AF_INET, AF_INET6)); assert(link); assert(link->ifindex > 0); assert(link->manager); @@ -553,7 +553,7 @@ int address_configure( int r; assert(address); - assert(address->family == AF_INET || address->family == AF_INET6); + assert(IN_SET(address->family, AF_INET, AF_INET6)); assert(link); assert(link->ifindex > 0); assert(link->manager); diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c index e28e018116..025662437b 100644 --- a/src/network/networkd-conf.c +++ b/src/network/networkd-conf.c @@ -87,7 +87,7 @@ int config_parse_duid_rawdata( } len = strlen(cbyte); - if (len != 1 && len != 2) { + if (!IN_SET(len, 1, 2)) { log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue); return 0; } diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 5b4874795a..cf42037915 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -401,7 +401,7 @@ int route_remove(Route *route, Link *link, assert(link->manager); assert(link->manager->rtnl); assert(link->ifindex > 0); - assert(route->family == AF_INET || route->family == AF_INET6); + assert(IN_SET(route->family, AF_INET, AF_INET6)); r = sd_rtnl_message_new_route(link->manager->rtnl, &req, RTM_DELROUTE, route->family, @@ -528,7 +528,7 @@ int route_configure( assert(link->manager); assert(link->manager->rtnl); assert(link->ifindex > 0); - assert(route->family == AF_INET || route->family == AF_INET6); + assert(IN_SET(route->family, AF_INET, AF_INET6)); if (route_get(link, route->family, &route->dst, route->dst_prefixlen, route->tos, route->priority, route->table, NULL) <= 0 && set_size(link->routes) >= routes_max()) diff --git a/src/nss-resolve/nss-resolve.c b/src/nss-resolve/nss-resolve.c index ec059d9586..17d125c821 100644 --- a/src/nss-resolve/nss-resolve.c +++ b/src/nss-resolve/nss-resolve.c @@ -307,7 +307,7 @@ enum nss_status _nss_resolve_gethostbyname3_r( if (af == AF_UNSPEC) af = AF_INET; - if (af != AF_INET && af != AF_INET6) { + if (!IN_SET(af, AF_INET, AF_INET6)) { r = -EAFNOSUPPORT; goto fail; } diff --git a/src/resolve/resolved-dns-dnssec.c b/src/resolve/resolved-dns-dnssec.c index eddab58a81..651c660e96 100644 --- a/src/resolve/resolved-dns-dnssec.c +++ b/src/resolve/resolved-dns-dnssec.c @@ -1247,10 +1247,10 @@ static int nsec3_is_good(DnsResourceRecord *rr, DnsResourceRecord *nsec3) { /* Ignore NSEC3 RRs generated from wildcards. If these NSEC3 RRs weren't correctly signed we can't make this * check (since rr->n_skip_labels_source is -1), but that's OK, as we won't trust them anyway in that case. */ - if (rr->n_skip_labels_source != 0 && rr->n_skip_labels_source != (unsigned) -1) + if (!IN_SET(rr->n_skip_labels_source, 0, (unsigned) -1)) return 0; /* Ignore NSEC3 RRs that are located anywhere else than one label below the zone */ - if (rr->n_skip_labels_signer != 1 && rr->n_skip_labels_signer != (unsigned) -1) + if (!IN_SET(rr->n_skip_labels_signer, 1, (unsigned) -1)) return 0; if (!nsec3) diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index ffaefbe3f2..b01ee6c9cc 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -904,7 +904,7 @@ int dns_scope_notify_conflict(DnsScope *scope, DnsResourceRecord *rr) { * messages, not all of them. That should be enough to * indicate where there might be a conflict */ r = ordered_hashmap_put(scope->conflict_queue, rr->key, rr); - if (r == -EEXIST || r == 0) + if (IN_SET(r, 0, -EEXIST)) return 0; if (r < 0) return log_debug_errno(r, "Failed to queue conflicting RR: %m"); diff --git a/src/resolve/resolved-dns-synthesize.c b/src/resolve/resolved-dns-synthesize.c index ad38c6a561..e8592a60d8 100644 --- a/src/resolve/resolved-dns-synthesize.c +++ b/src/resolve/resolved-dns-synthesize.c @@ -383,8 +383,7 @@ int dns_synthesize_answer( const char *name; int af; - if (key->class != DNS_CLASS_IN && - key->class != DNS_CLASS_ANY) + if (!IN_SET(key->class, DNS_CLASS_IN, DNS_CLASS_ANY)) continue; name = dns_resource_key_name(key); diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 8b23132339..3cda429c3c 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -190,7 +190,7 @@ int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key) return -EOPNOTSUPP; /* We only support the IN class */ - if (key->class != DNS_CLASS_IN && key->class != DNS_CLASS_ANY) + if (!IN_SET(key->class, DNS_CLASS_IN, DNS_CLASS_ANY)) return -EOPNOTSUPP; if (hashmap_size(s->manager->dns_transactions) >= TRANSACTIONS_MAX) @@ -1593,7 +1593,7 @@ int dns_transaction_go(DnsTransaction *t) { log_debug("Sending query via TCP since it is too large."); else if (r == -EAGAIN) log_debug("Sending query via TCP since server doesn't support UDP."); - if (r == -EMSGSIZE || r == -EAGAIN) + if (IN_SET(r, -EMSGSIZE, -EAGAIN)) r = dns_transaction_open_tcp(t); } diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index b6620875ea..efdf7e5aaa 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -741,7 +741,7 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) { if (l == 0) return 0; if (l < 0) { - if (errno == EAGAIN || errno == EINTR) + if (IN_SET(errno, EAGAIN, EINTR)) return 0; return -errno; diff --git a/src/resolve/resolved-resolv-conf.c b/src/resolve/resolved-resolv-conf.c index f4e071ebaa..2af77b3407 100644 --- a/src/resolve/resolved-resolv-conf.c +++ b/src/resolve/resolved-resolv-conf.c @@ -87,7 +87,7 @@ int manager_read_resolv_conf(Manager *m) { char *l; l = strstrip(line); - if (*l == '#' || *l == ';') + if (IN_SET(*l, '#', ';')) continue; a = first_word(l, "nameserver"); diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index de3847adfd..e33d8b11cf 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -337,7 +337,7 @@ int ask_password_tty( backspace_chars(ttyfd, p); p = 0; - } else if (c == '\b' || c == 127) { + } else if (IN_SET(c, '\b', 127)) { if (p > 0) { diff --git a/src/shared/condition.c b/src/shared/condition.c index 103f8d2e39..74d5e854e1 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -131,7 +131,7 @@ static int condition_test_kernel_command_line(Condition *c) { const char *f; f = startswith(word, c->parameter); - found = f && (*f == '=' || *f == 0); + found = f && IN_SET(*f, 0, '='); } if (found) diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 243a46f2e3..b782b05f88 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -57,7 +57,7 @@ _unused_ static int probe_filesystem(const char *node, char **ret_fstype) { errno = 0; r = blkid_do_safeprobe(b); - if (r == -2 || r == 1) { + if (IN_SET(r, -2, 1)) { log_debug("Failed to identify any partition type on partition %s", node); goto not_found; } @@ -156,7 +156,7 @@ int dissect_image(int fd, const void *root_hash, size_t root_hash_size, DissectI errno = 0; r = blkid_do_safeprobe(b); - if (r == -2 || r == 1) { + if (IN_SET(r, -2, 1)) { log_debug("Failed to identify any partition table."); return -ENOPKG; } diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index 139d286af8..d75abd8121 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -76,7 +76,7 @@ int dns_label_unescape(const char **name, char *dest, size_t sz) { /* Ending NUL */ return -EINVAL; - else if (*n == '\\' || *n == '.') { + else if (IN_SET(*n, '\\', '.')) { /* Escaped backslash or dot */ if (d) @@ -164,7 +164,7 @@ int dns_label_unescape_suffix(const char *name, const char **label_terminal, cha } terminal = *label_terminal; - assert(*terminal == '.' || *terminal == 0); + assert(IN_SET(*terminal, 0, '.')); /* Skip current terminal character (and accept domain names ending it ".") */ if (*terminal == 0) @@ -228,7 +228,7 @@ int dns_label_escape(const char *p, size_t l, char *dest, size_t sz) { q = dest; while (l > 0) { - if (*p == '.' || *p == '\\') { + if (IN_SET(*p, '.', '\\')) { /* Dot or backslash */ @@ -240,8 +240,7 @@ int dns_label_escape(const char *p, size_t l, char *dest, size_t sz) { sz -= 2; - } else if (*p == '_' || - *p == '-' || + } else if (IN_SET(*p, '_', '-') || (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z')) { diff --git a/src/shared/firewall-util.c b/src/shared/firewall-util.c index 3a6e987ee1..6d295ea65b 100644 --- a/src/shared/firewall-util.c +++ b/src/shared/firewall-util.c @@ -110,7 +110,7 @@ int fw_add_masquerade( if (af != AF_INET) return -EOPNOTSUPP; - if (protocol != 0 && protocol != IPPROTO_TCP && protocol != IPPROTO_UDP) + if (!IN_SET(protocol, 0, IPPROTO_TCP, IPPROTO_UDP)) return -EOPNOTSUPP; h = iptc_init("nat"); @@ -194,7 +194,7 @@ int fw_add_local_dnat( if (af != AF_INET) return -EOPNOTSUPP; - if (protocol != IPPROTO_TCP && protocol != IPPROTO_UDP) + if (!IN_SET(protocol, IPPROTO_TCP, IPPROTO_UDP)) return -EOPNOTSUPP; if (local_port <= 0) diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 54516cfb96..0626d80b19 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -683,7 +683,7 @@ void json_escape( fputc('\"', f); while (l > 0) { - if (*p == '"' || *p == '\\') { + if (IN_SET(*p, '"', '\\')) { fputc('\\', f); fputc(*p, f); } else if (*p == '\n') diff --git a/src/shared/machine-image.c b/src/shared/machine-image.c index 32a4c67590..859e5ffc1a 100644 --- a/src/shared/machine-image.c +++ b/src/shared/machine-image.c @@ -313,7 +313,7 @@ int image_find(const char *name, Image **ret) { } r = image_make(NULL, dirfd(d), path, name, ret); - if (r == 0 || r == -ENOENT) { + if (IN_SET(r, 0, -ENOENT)) { _cleanup_free_ char *raw = NULL; raw = strappend(name, ".raw"); @@ -321,7 +321,7 @@ int image_find(const char *name, Image **ret) { return -ENOMEM; r = image_make(NULL, dirfd(d), path, raw, ret); - if (r == 0 || r == -ENOENT) + if (IN_SET(r, 0, -ENOENT)) continue; } if (r < 0) @@ -364,7 +364,7 @@ int image_discover(Hashmap *h) { continue; r = image_make(NULL, dirfd(d), path, de->d_name, &image); - if (r == 0 || r == -ENOENT) + if (IN_SET(r, 0, -ENOENT)) continue; if (r < 0) return r; diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index bf10acda94..e7a878ab50 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -514,13 +514,13 @@ int lookup_paths_init( /* Note: if XDG_RUNTIME_DIR is not set, this will fail completely with ENXIO */ r = acquire_generator_dirs(scope, tempdir, &generator, &generator_early, &generator_late); - if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO) + if (r < 0 && !IN_SET(r, -EOPNOTSUPP, -ENXIO)) return r; } /* Note: if XDG_RUNTIME_DIR is not set, this will fail completely with ENXIO */ r = acquire_transient_dir(scope, tempdir, &transient); - if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO) + if (r < 0 && !IN_SET(r, -EOPNOTSUPP, -ENXIO)) return r; /* Note: when XDG_RUNTIME_DIR is not set this will not return -ENXIO, but simply set runtime_control to NULL */ diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index bf8c2f86a3..34c938438c 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -164,7 +164,7 @@ static int connection_shovel( if (z > 0) { *full += z; shoveled = true; - } else if (z == 0 || errno == EPIPE || errno == ECONNRESET) { + } else if (z == 0 || IN_SET(errno, EPIPE, ECONNRESET)) { *from_source = sd_event_source_unref(*from_source); *from = safe_close(*from); } else if (!IN_SET(errno, EAGAIN, EINTR)) @@ -176,7 +176,7 @@ static int connection_shovel( if (z > 0) { *full -= z; shoveled = true; - } else if (z == 0 || errno == EPIPE || errno == ECONNRESET) { + } else if (z == 0 || IN_SET(errno, EPIPE, ECONNRESET)) { *to_source = sd_event_source_unref(*to_source); *to = safe_close(*to); } else if (!IN_SET(errno, EAGAIN, EINTR)) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 897fc48b98..782924d95a 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -7815,7 +7815,7 @@ static int halt_parse_argv(int argc, char *argv[]) { assert(argv); if (utmp_get_runlevel(&runlevel, NULL) >= 0) - if (runlevel == '0' || runlevel == '6') + if (IN_SET(runlevel, '0', '6')) arg_force = 2; while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0) diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index e9e6dae10c..50fce6b29f 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -1669,7 +1669,7 @@ static int read_config_file(const char *fn, bool ignore_enoent) { v++; l = strstrip(line); - if (*l == '#' || *l == 0) + if (IN_SET(*l, 0, '#')) continue; k = parse_line(fn, v, l); diff --git a/src/test/test-architecture.c b/src/test/test-architecture.c index f41e488d99..68975b790a 100644 --- a/src/test/test-architecture.c +++ b/src/test/test-architecture.c @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) { int a, v; v = detect_virtualization(); - if (v == -EPERM || v == -EACCES) + if (IN_SET(v, -EPERM, -EACCES)) return EXIT_TEST_SKIP; assert_se(v >= 0); diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c index 15d76bddda..02aae84152 100644 --- a/src/test/test-cgroup-mask.c +++ b/src/test/test-cgroup-mask.c @@ -40,7 +40,7 @@ static int test_cgroup_mask(void) { assert_se(set_unit_path(get_testdata_dir("")) >= 0); assert_se(runtime_dir = setup_fake_runtime_dir()); r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_MINIMAL, &m); - if (r == -EPERM || r == -EACCES) { + if (IN_SET(r, -EPERM, -EACCES)) { puts("manager_new: Permission denied. Skipping test."); return EXIT_TEST_SKIP; } diff --git a/src/test/test-clock.c b/src/test/test-clock.c index f246ae8385..94f8b50f41 100644 --- a/src/test/test-clock.c +++ b/src/test/test-clock.c @@ -82,7 +82,7 @@ static void test_clock_is_localtime_system(void) { log_info("/etc/adjtime exists, clock_is_localtime() == %i", r); /* if /etc/adjtime exists we expect some answer, no error or * crash */ - assert_se(r == 0 || r == 1); + assert_se(IN_SET(r, 0, 1)); } else /* default is UTC if there is no /etc/adjtime */ assert_se(r == 0); diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index b5b6391cdd..27495fa5be 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -393,7 +393,7 @@ static void test_capeff(void) { r = get_process_capeff(0, &capeff); log_info("capeff: '%s' (r=%d)", capeff, r); - if (r == -ENOENT || r == -EPERM) + if (IN_SET(r, -ENOENT, -EPERM)) return; assert_se(r == 0); @@ -479,15 +479,15 @@ static void test_write_string_file_verify(void) { assert_se((buf2 = strjoin(buf, "\n"))); r = write_string_file("/proc/cmdline", buf, 0); - assert_se(r == -EACCES || r == -EIO); + assert_se(IN_SET(r, -EACCES, -EIO)); r = write_string_file("/proc/cmdline", buf2, 0); - assert_se(r == -EACCES || r == -EIO); + assert_se(IN_SET(r, -EACCES, -EIO)); assert_se(write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0); assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0); r = write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE); - assert_se(r == -EACCES || r == -EIO); + assert_se(IN_SET(r, -EACCES, -EIO)); assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0); } diff --git a/src/test/test-nss.c b/src/test/test-nss.c index 44570caa6c..be8b9d71ba 100644 --- a/src/test/test-nss.c +++ b/src/test/test-nss.c @@ -97,7 +97,7 @@ static int print_gaih_addrtuples(const struct gaih_addrtuple *tuples) { memcpy(&u, it->addr, 16); r = in_addr_to_string(it->family, &u, &a); - assert_se(r == 0 || r == -EAFNOSUPPORT); + assert_se(IN_SET(r, 0, -EAFNOSUPPORT)); if (r == -EAFNOSUPPORT) assert_se((a = hexmem(it->addr, 16))); diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index 578e09447f..07f21d0d3d 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -55,7 +55,7 @@ static int test_unit_file_get_set(void) { r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h, NULL, NULL); - if (r == -EPERM || r == -EACCES) { + if (IN_SET(r, -EPERM, -EACCES)) { log_notice_errno(r, "Skipping test: unit_file_get_list: %m"); return EXIT_TEST_SKIP; } diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 3f5c1e62ee..17fce93328 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -333,7 +333,7 @@ static int dir_is_mount_point(DIR *d, const char *subdir) { /* got only one handle; assume different mount points if one * of both queries was not supported by the filesystem */ - if (r_p == -ENOSYS || r_p == -EOPNOTSUPP || r == -ENOSYS || r == -EOPNOTSUPP) + if (IN_SET(r_p, -ENOSYS, -EOPNOTSUPP) || IN_SET(r, -ENOSYS, -EOPNOTSUPP)) return true; /* return error */ @@ -501,7 +501,7 @@ static int dir_cleanup( log_debug("Removing directory \"%s\".", sub_path); if (unlinkat(dirfd(d), dent->d_name, AT_REMOVEDIR) < 0) - if (errno != ENOENT && errno != ENOTEMPTY) { + if (!IN_SET(errno, ENOENT, ENOTEMPTY)) { log_error_errno(errno, "rmdir(%s): %m", sub_path); r = -errno; } @@ -984,7 +984,7 @@ static int path_set_attribute(Item *item, const char *path) { r = chattr_fd(fd, f, item->attribute_mask); if (r < 0) - log_full_errno(r == -ENOTTY || r == -EOPNOTSUPP ? LOG_DEBUG : LOG_WARNING, + log_full_errno(IN_SET(r, -ENOTTY, -EOPNOTSUPP) ? LOG_DEBUG : LOG_WARNING, r, "Cannot set file attribute for '%s', value=0x%08x, mask=0x%08x: %m", path, item->attribute_value, item->attribute_mask); @@ -1075,7 +1075,7 @@ static int item_do_children(Item *i, const char *path, action_t action) { d = opendir_nomod(path); if (!d) - return errno == ENOENT || errno == ENOTDIR ? 0 : -errno; + return IN_SET(errno, ENOENT, ENOTDIR) ? 0 : -errno; FOREACH_DIRENT_ALL(de, d, r = -errno) { _cleanup_free_ char *p = NULL; @@ -1253,7 +1253,7 @@ static int create_item(Item *i) { if (r < 0) { int k; - if (r != -EEXIST && r != -EROFS) + if (!IN_SET(r, -EEXIST, -EROFS)) return log_error_errno(r, "Failed to create directory or subvolume \"%s\": %m", i->path); k = is_dir(i->path, false); @@ -2215,7 +2215,7 @@ static int read_config_file(const char *fn, bool ignore_enoent) { v++; l = strstrip(line); - if (*l == '#' || *l == 0) + if (IN_SET(*l, 0, '#')) continue; k = parse_line(fn, v, l); 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 3ea8dae7a9..495ae464b4 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -206,7 +206,7 @@ static int ask_password_plymouth( r = -ENOENT; goto finish; - } else if (buffer[0] == 2 || buffer[0] == 9) { + } else if (IN_SET(buffer[0], 2, 9)) { uint32_t size; char **l; diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index ad152b9d31..1dc62b69d5 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -617,7 +617,7 @@ int main(int argc, char *argv[]) */ word = identify.wyde[76]; - if (word != 0x0000 && word != 0xffff) { + if (!IN_SET(word, 0x0000, 0xffff)) { printf("ID_ATA_SATA=1\n"); /* * If bit 2 of word 76 is set to one, then the device supports the Gen2 @@ -661,8 +661,7 @@ int main(int argc, char *argv[]) } /* from Linux's include/linux/ata.h */ - if (identify.wyde[0] == 0x848a || - identify.wyde[0] == 0x844a || + if (IN_SET(identify.wyde[0], 0x848a, 0x844a) || (identify.wyde[83] & 0xc004) == 0x4004) printf("ID_ATA_CFA=1\n"); } else { diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 1f906a8525..b9cf3bdf68 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -544,7 +544,7 @@ static int cd_profiles(struct udev *udev, int fd) if ((err != 0)) { info_scsi_cmd_err(udev, "GET CONFIGURATION", err); /* handle pre-MMC2 drives which do not support GET CONFIGURATION */ - if (SK(err) == 0x5 && (ASC(err) == 0x20 || ASC(err) == 0x24)) { + if (SK(err) == 0x5 && IN_SET(ASC(err), 0x20, 0x24)) { log_debug("drive is pre-MMC2 and does not support 46h get configuration command"); log_debug("trying to work around the problem"); ret = cd_profiles_old_mmc(udev, fd); diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c index f007cc6001..b56a541f78 100644 --- a/src/udev/scsi_id/scsi_serial.c +++ b/src/udev/scsi_id/scsi_serial.c @@ -115,9 +115,8 @@ static int sg_err_category_new(struct udev *udev, if (!scsi_status && !host_status && !driver_status) return SG_ERR_CAT_CLEAN; - if ((scsi_status == SCSI_CHECK_CONDITION) || - (scsi_status == SCSI_COMMAND_TERMINATED) || - ((driver_status & 0xf) == DRIVER_SENSE)) { + if (IN_SET(scsi_status, SCSI_CHECK_CONDITION, SCSI_COMMAND_TERMINATED) || + (driver_status & 0xf) == DRIVER_SENSE) { if (sense_buffer && (sb_len > 2)) { int sense_key; unsigned char asc; @@ -143,9 +142,7 @@ static int sg_err_category_new(struct udev *udev, return SG_ERR_CAT_SENSE; } if (host_status) { - if ((host_status == DID_NO_CONNECT) || - (host_status == DID_BUS_BUSY) || - (host_status == DID_TIME_OUT)) + if (IN_SET(host_status, DID_NO_CONNECT, DID_BUS_BUSY, DID_TIME_OUT)) return SG_ERR_CAT_TIMEOUT; } if (driver_status) { @@ -215,7 +212,7 @@ static int scsi_dump_sense(struct udev *udev, dev_scsi->kernel, sb_len, s - sb_len); return -1; } - if ((code == 0x0) || (code == 0x1)) { + if (IN_SET(code, 0x0, 0x1)) { sense_key = sense_buffer[2] & 0xf; if (s < 14) { /* @@ -227,7 +224,7 @@ static int scsi_dump_sense(struct udev *udev, } asc = sense_buffer[12]; ascq = sense_buffer[13]; - } else if ((code == 0x2) || (code == 0x3)) { + } else if (IN_SET(code, 0x2, 0x3)) { sense_key = sense_buffer[1] & 0xf; asc = sense_buffer[2]; ascq = sense_buffer[3]; diff --git a/src/udev/udev-builtin-uaccess.c b/src/udev/udev-builtin-uaccess.c index 3ebe36f043..d92a10e1c5 100644 --- a/src/udev/udev-builtin-uaccess.c +++ b/src/udev/udev-builtin-uaccess.c @@ -47,7 +47,7 @@ static int builtin_uaccess(struct udev_device *dev, int argc, char *argv[], bool seat = "seat0"; r = sd_seat_get_active(seat, NULL, &uid); - if (r == -ENXIO || r == -ENODATA) { + if (IN_SET(r, -ENXIO, -ENODATA)) { /* No active session on this seat */ r = 0; goto finish; diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index 587649eff0..3ce075f079 100644 --- a/src/udev/udev-builtin-usb_id.c +++ b/src/udev/udev-builtin-usb_id.c @@ -307,7 +307,7 @@ static int builtin_usb_id(struct udev_device *dev, int argc, char *argv[], bool dev_if_packed_info(dev_usb, packed_if_str, sizeof(packed_if_str)); /* mass storage : SCSI or ATAPI */ - if (protocol == 6 || protocol == 2) { + if (IN_SET(protocol, 6, 2)) { struct udev_device *dev_scsi; const char *scsi_model, *scsi_vendor, *scsi_type, *scsi_rev; int host, bus, target, lun; diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 53cfd9c053..01e56cac36 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -87,7 +87,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s log_debug("creating symlink '%s' to '%s'", slink, target); do { err = mkdir_parents_label(slink, 0755); - if (err != 0 && err != -ENOENT) + if (!IN_SET(err, 0, -ENOENT)) break; mac_selinux_create_file_prepare(slink, S_IFLNK); err = symlink(target, slink); @@ -104,7 +104,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s unlink(slink_tmp); do { err = mkdir_parents_label(slink_tmp, 0755); - if (err != 0 && err != -ENOENT) + if (!IN_SET(err, 0, -ENOENT)) break; mac_selinux_create_file_prepare(slink_tmp, S_IFLNK); err = symlink(target, slink_tmp); @@ -209,7 +209,7 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) { int fd; err = mkdir_parents(filename, 0755); - if (err != 0 && err != -ENOENT) + if (!IN_SET(err, 0, -ENOENT)) break; fd = open(filename, O_WRONLY|O_CREAT|O_CLOEXEC|O_TRUNC|O_NOFOLLOW, 0444); if (fd >= 0) diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 5ab697e399..9aaec72baf 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -579,7 +579,7 @@ static int import_property_from_string(struct udev_device *dev, char *line) { key++; /* comment or empty line */ - if (key[0] == '#' || key[0] == '\0') + if (IN_SET(key[0], '#', '\0')) return -1; /* split key/value */ @@ -613,7 +613,7 @@ static int import_property_from_string(struct udev_device *dev, char *line) { return -1; /* unquote */ - if (val[0] == '"' || val[0] == '\'') { + if (IN_SET(val[0], '"', '\'')) { if (len == 1 || val[len-1] != val[0]) { log_debug("inconsistent quoting: '%s', skip", line); return -1; @@ -741,7 +741,7 @@ static int get_key(struct udev *udev, char **line, char **key, enum operation_ty break; if (linepos[0] == '=') break; - if ((linepos[0] == '+') || (linepos[0] == '-') || (linepos[0] == '!') || (linepos[0] == ':')) + if (IN_SET(linepos[0], '+', '-', '!', ':')) if (linepos[1] == '=') break; } @@ -1968,7 +1968,7 @@ void udev_rules_apply_to_event(struct udev_rules *rules, int count; util_remove_trailing_chars(result, '\n'); - if (esc == ESCAPE_UNSET || esc == ESCAPE_REPLACE) { + if (IN_SET(esc, ESCAPE_UNSET, ESCAPE_REPLACE)) { count = util_replace_chars(result, UDEV_ALLOWED_CHARS_INPUT); if (count > 0) log_debug("%i character(s) replaced" , count); @@ -2219,7 +2219,7 @@ void udev_rules_apply_to_event(struct udev_rules *rules, else label = rules_str(rules, cur->key.value_off); - if (cur->key.op == OP_ASSIGN || cur->key.op == OP_ASSIGN_FINAL) + if (IN_SET(cur->key.op, OP_ASSIGN, OP_ASSIGN_FINAL)) udev_list_cleanup(&event->seclabel_list); udev_list_entry_add(&event->seclabel_list, name, label); log_debug("SECLABEL{%s}='%s' %s:%u", @@ -2260,13 +2260,13 @@ void udev_rules_apply_to_event(struct udev_rules *rules, const char *p; udev_event_apply_format(event, rules_str(rules, cur->key.value_off), tag, sizeof(tag), false); - if (cur->key.op == OP_ASSIGN || cur->key.op == OP_ASSIGN_FINAL) + if (IN_SET(cur->key.op, OP_ASSIGN, OP_ASSIGN_FINAL)) udev_device_cleanup_tags_list(event->dev); for (p = tag; *p != '\0'; p++) { if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || (*p >= '0' && *p <= '9') || - *p == '-' || *p == '_') + IN_SET(*p, '-', '_')) continue; log_error("ignoring invalid tag name '%s'", tag); break; @@ -2288,7 +2288,7 @@ void udev_rules_apply_to_event(struct udev_rules *rules, if (cur->key.op == OP_ASSIGN_FINAL) event->name_final = true; udev_event_apply_format(event, name, name_str, sizeof(name_str), false); - if (esc == ESCAPE_UNSET || esc == ESCAPE_REPLACE) { + if (IN_SET(esc, ESCAPE_UNSET, ESCAPE_REPLACE)) { count = util_replace_chars(name_str, "/"); if (count > 0) log_debug("%i character(s) replaced", count); @@ -2323,7 +2323,7 @@ void udev_rules_apply_to_event(struct udev_rules *rules, break; if (cur->key.op == OP_ASSIGN_FINAL) event->devlink_final = true; - if (cur->key.op == OP_ASSIGN || cur->key.op == OP_ASSIGN_FINAL) + if (IN_SET(cur->key.op, OP_ASSIGN, OP_ASSIGN_FINAL)) udev_device_cleanup_devlinks_list(event->dev); /* allow multiple symlinks separated by spaces */ @@ -2396,7 +2396,7 @@ void udev_rules_apply_to_event(struct udev_rules *rules, case TK_A_RUN_PROGRAM: { struct udev_list_entry *entry; - if (cur->key.op == OP_ASSIGN || cur->key.op == OP_ASSIGN_FINAL) + if (IN_SET(cur->key.op, OP_ASSIGN, OP_ASSIGN_FINAL)) udev_list_cleanup(&event->run_list); log_debug("RUN '%s' %s:%u", rules_str(rules, cur->key.value_off), diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index f68d60a134..679471e217 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -183,7 +183,7 @@ static int on_runlevel(Context *c) { q = utmp_get_runlevel(&previous, NULL); if (q < 0) { - if (q != -ESRCH && q != -ENOENT) + if (!IN_SET(q, -ESRCH, -ENOENT)) return log_error_errno(q, "Failed to get current runlevel: %m"); previous = 0; @@ -213,7 +213,7 @@ static int on_runlevel(Context *c) { #endif q = utmp_put_runlevel(runlevel, previous); - if (q < 0 && q != -ESRCH && q != -ENOENT) { + if (q < 0 && !IN_SET(q, -ESRCH, -ENOENT)) { log_error_errno(q, "Failed to write utmp record: %m"); r = q; } @@ -249,7 +249,7 @@ int main(int argc, char *argv[]) { /* If the kernel lacks netlink or audit support, * don't worry about it. */ c.audit_fd = audit_open(); - if (c.audit_fd < 0 && errno != EAFNOSUPPORT && errno != EPROTONOSUPPORT) + if (c.audit_fd < 0 && !IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT)) log_error_errno(errno, "Failed to connect to audit log: %m"); #endif r = bus_connect_system_systemd(&c.bus); |