]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use IN_SET macro (#6977)
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 4 Oct 2017 14:01:32 +0000 (23:01 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 4 Oct 2017 14:01:32 +0000 (16:01 +0200)
92 files changed:
src/basic/calendarspec.c
src/basic/cgroup-util.c
src/basic/env-util.c
src/basic/escape.c
src/basic/extract-word.c
src/basic/fs-util.c
src/basic/hashmap.c
src/basic/hostname-util.c
src/basic/mount-util.c
src/basic/parse-util.c
src/basic/process-util.c
src/basic/rm-rf.c
src/basic/socket-util.c
src/basic/string-util.c
src/basic/time-util.c
src/basic/unit-name.c
src/basic/user-util.c
src/basic/utf8.c
src/basic/xattr-util.c
src/basic/xml.c
src/core/cgroup.c
src/core/dbus-unit.c
src/core/execute.c
src/core/job.c
src/core/main.c
src/core/manager.c
src/core/service.c
src/core/socket.c
src/core/unit.c
src/cryptsetup/cryptsetup-generator.c
src/fsck/fsck.c
src/import/import-common.c
src/import/importd.c
src/import/pull-job.c
src/import/qcow2-util.c
src/journal/catalog.c
src/journal/compress.c
src/journal/journalctl.c
src/journal/journald-audit.c
src/journal/journald-native.c
src/journal/journald-server.c
src/journal/sd-journal.c
src/journal/test-compress.c
src/libsystemd-network/sd-dhcp-client.c
src/libsystemd-network/sd-dhcp-server.c
src/libsystemd-network/sd-dhcp6-client.c
src/libsystemd-network/sd-lldp.c
src/libsystemd-network/test-dhcp-client.c
src/libsystemd/sd-bus/bus-message.c
src/locale/keymap-util.c
src/login/loginctl.c
src/login/logind-seat.c
src/login/logind-user.c
src/machine/machinectl.c
src/network/networkctl.c
src/network/networkd-address.c
src/network/networkd-conf.c
src/network/networkd-route.c
src/nss-resolve/nss-resolve.c
src/resolve/resolved-dns-dnssec.c
src/resolve/resolved-dns-scope.c
src/resolve/resolved-dns-synthesize.c
src/resolve/resolved-dns-transaction.c
src/resolve/resolved-manager.c
src/resolve/resolved-resolv-conf.c
src/shared/ask-password-api.c
src/shared/condition.c
src/shared/dissect-image.c
src/shared/dns-domain.c
src/shared/firewall-util.c
src/shared/logs-show.c
src/shared/machine-image.c
src/shared/path-lookup.c
src/socket-proxy/socket-proxyd.c
src/systemctl/systemctl.c
src/sysusers/sysusers.c
src/test/test-architecture.c
src/test/test-cgroup-mask.c
src/test/test-clock.c
src/test/test-fileio.c
src/test/test-nss.c
src/test/test-unit-file.c
src/tmpfiles/tmpfiles.c
src/tty-ask-password-agent/tty-ask-password-agent.c
src/udev/ata_id/ata_id.c
src/udev/cdrom_id/cdrom_id.c
src/udev/scsi_id/scsi_serial.c
src/udev/udev-builtin-uaccess.c
src/udev/udev-builtin-usb_id.c
src/udev/udev-node.c
src/udev/udev-rules.c
src/update-utmp/update-utmp.c

index be7328af408755d3e94f6fed52764a972f132f76..1fc9e9b1540423b6db0104258257aaf7618a8991 100644 (file)
@@ -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;
index f3f6a21576926e7b082722b9032f94210cc30324..d51c3efd227811f1edd5441dbd847c676e7565ca 100644 (file)
@@ -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");
index d72940acb3858bc34927bfb5c71ee0c4f3f4d2f1..fa42edfa96101abe18703769c158034b2fe4c9bf 100644 (file)
@@ -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;
index 22b8b041568b65bb144ed4e6732cfc14f51d9a37..0a6122c64a78f228580b1d5e93a872463e9cd91c 100644 (file)
@@ -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);
index 804f14c44c48ac02525086ceb289d1aa41177a80..f4ac526eb1b35302f23fa1be8840366e14dbebb4 100644 (file)
@@ -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)) {
index af631710412dd8f76c48506fd653c3f5e8f46c78..b90f343ed392ba02095b2c7ce736819e24d0117e 100644 (file)
@@ -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;
 
index 6ef1b0ba3583678e8df63ed7ff75227854749313..a5ab4570fa1fed604f1458819ca994f85cec018f 100644 (file)
@@ -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.
index b511a36301fc79f004796f0bd7a622d96b625d9b..ea9e77087f86b23fa2aa108a0538bf496738e41b 100644 (file)
@@ -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);
index 8c1d2bc9c968546a5e1dfebaae5366d844d49475..65b488351e8a5aee915880d22a46d088d3ea2247 100644 (file)
@@ -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;
index 89bb667c5fe6b1776cf068365ace06b5c5b6df5e..4ae07b0a8ed9818815dc092c03672befa7bc8457 100644 (file)
@@ -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) {
index ab661a8f1632c322965345508a4ce3023b2228c0..a1b50b6c797644ef4737f964842bf8ac53cb97b8 100644 (file)
@@ -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;
index 77fe88e42c00d574abe2b6426aa7146a47d2950c..0bbafb4cd7232fcd2b58fc2c01f868db4be515c9 100644 (file)
@@ -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 */
index e8d39674cc50fdca99a1b777b420429a50849db9..5942b2df9ba249b58b876f3d192f0f30b61cb756 100644 (file)
@@ -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');
index 5808b1280eb83d6593ef20a8bf5f8ba7d2433078..2eed99d9c001c7a39c4f16f1c1060fca486c7e17 100644 (file)
@@ -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;
index f67467c5bde3251da232bee7a29a0e2c584185ab..46ec722989f07d2b703583eef11985df5eda8b63 100644 (file)
@@ -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 == '/') {
index 5e3f307dcd730ce4f811ee96db9d3b82695be246..f9c034c94b0bf27102dc55c15d24c83f6cb80f29 100644 (file)
@@ -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;
index c619dad52769ecdb5e7f4387860df0b7bcdbffc8..a691a0d3fc4ff1e8c08745f6c8fbcf7be1f1594a 100644 (file)
@@ -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;
         }
 
index 6eae2b983d8dfd7943c479be9918d8539fd538fd..7a52fac62186ff17fc510a22f152a8dd42471486 100644 (file)
@@ -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);
 }
 
index 8256899edae347260027a1495823a9de4c2d1b63..e086376d7c4819bf2e04dc9b40d9fb8437fa7393 100644 (file)
@@ -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;
index 1dbeac7324948975323e2019d20b7b5911d498c6..a4337f48659b311940ac8c6057c373edf6092281 100644 (file)
@@ -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);
index 85f549c4c42d21c7a6a631138c6125dadac49a78..e9f944711886738f2168b1369b10093010c244c8 100644 (file)
@@ -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)
index 791649e5b5f2d0b2de19bf70427480b10fe3d076..a9a68826b4531aa9060fea652c027701e2a18437 100644 (file)
@@ -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;
index e1c2a57cc62842a7589d71875af5b6e8789fdacd..3e264d1dd4457817c4d3d3bf88200071de899d08 100644 (file)
@@ -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);
index f962881a12710ffffca63dbfe17e33423b0b0b29..fb57f193fd42e358ff538135fdc2e25c2a0781f9 100644 (file)
@@ -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];
index 2dfd48005b75012e3a63ca09e59741bfe929093c..962ee28ae57c65287409418a7a91d30cbbf9350b 100644 (file)
@@ -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;
index 5c127e08484394ad58d8dd34225fbfdca96c36a6..02bc8065d8659b589067866d0f805888f196a161 100644 (file)
@@ -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");
index e990d47797297ec6d6cc07aca4b592ce1abed10d..915943aff3a3399613c82884bf2f21413657db86 100644 (file)
@@ -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) {
index 06ceb46eca50451dfa0945eaf6603fd28c83d7ea..c0f4030302f194d9bb727d0aa7bf171e9d47feaa 100644 (file)
@@ -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;
         }
 
index 2b7c7738fe7d056a13c7e4d08647eb7593d3e183..357306dce836c9413b3486a4d2fa949571c600ee 100644 (file)
@@ -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) {
index f882a4f80eefdd588f27e20c0abb7562830e8da9..3752ca2ef2e1fc720383aec1194d9696ecea4fae 100644 (file)
@@ -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);
index 434321f806aaf733ea675085dfe5f7ebf50d1deb..bcb07fe97630bbbf83cace92870cea8d55f1b0cb 100644 (file)
@@ -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);
index 81209cdaf6502d69a6f38276f18508b0055431fd..ae71682988341948d4a3b8a3361a6a9bed8e00bc 100644 (file)
@@ -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
index e20aca0d9efffe195b68c4edd16b7c748eaa44b3..9b3fd06b529e06fcac551665de8b47a337924903 100644 (file)
@@ -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);
index 3e20905d79647162d32e231e06f511bc0d8f04fb..995a652ec339535ba36445c00da053a87d95afd7 100644 (file)
@@ -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) {
index ee2121cc36b7768ecc77cd30f6b9269c0888a70c..00734865b2f841860b346b9d5a96eb5cae6d62ea 100644 (file)
@@ -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)
index f42be0adf945a5dd732a96d0b1e6813459d6b253..bf92da9f905472b058202806a73717220ebfa5d4 100644 (file)
@@ -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;
index 818a720ba888ef85c2193629889eb1ee6fa461a2..7ad7dd519da6370c2599461434df912979f0720f 100644 (file)
@@ -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;
                 }
index 3dcfb0e97a9fa9437fee4dfc66e4a64ecbd2d8bc..641b9afa347d6351b77dd5d529e3c498005ba56f 100644 (file)
@@ -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)) {
index b20e7ab12973c4aee58ac2d178c05d0b5045ddca..3334418f33dc7cee9dbe0e05c74a6c16e74c443a 100644 (file)
@@ -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;
         }
 
index 554f91460d45f0597cb4bfb3682cd5ede236e343..8a2962335ce8ec03d88f39b127de082f2f70acbe 100644 (file)
@@ -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;
index de643c91494c305cbb6ba9248f86aa422dfbdfe3..463a8dd97c2c3cb9b74d8a0fe642f134873fd12a 100644 (file)
@@ -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;
         }
index fb7269e510093a0e2a4be7edd1f1ebdc75f74a01..a47bd122b9b73ac3f44cad25df24501c335d954c 100644 (file)
@@ -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) &&
index 92108a84b3f13af2ed084b934b5b34927c73afe5..bd0ffaffbf3caef7c94dabbb3d533c20110e4111 100644 (file)
@@ -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);
index d0ce7989d8153cf1819deb39867aa6111ebcc83f..29b22eed456cb49e0cb9ea9f18dcf3e07c2bb57a 100644 (file)
@@ -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,
index 727cc16ab569b3e33c689fe8c178ba8fe27f57bd..663fd0e41dc62948faad05ba31103079e91b244d 100644 (file)
@@ -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;
index 6444b0ce94b0999c64f646ade647af23781129d5..eba0c8bcbb7b4035bb20cfa54e53f7798692ca44 100644 (file)
@@ -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");
index 39ddb2461afb421327d19698a17651dcb0275058..0f591a80111110635328bfb8894fc36b35f3eb6e 100644 (file)
@@ -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");
index 5c3ae170ed608102bdd76611c612ffe5315b8a6b..1942199294581333f7193e23bfad40c18091a183 100644 (file)
@@ -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);
 
index 2a509c7d1a1a54668b54e47716f119866cb1d16d..3fc447df3f4afbc35827edfa3c0ef268cc43aab2 100644 (file)
@@ -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;
index 7068603f0fe0c5dbd432b443fae6f2a9fe0a3acf..b71091f706798850b4c324926a3d1cb559801ba6 100644 (file)
@@ -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);
index 1862e8983c5a4664bfea99f4873c8f05a3bfe773..a63174c093f14bd1bbe6bb4c00a1b914ff3794bf 100644 (file)
@@ -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;
 
index 85258737c3209acfbec1c8f5f0e552d5e23157aa..64a622307e354d2f7cb890863d5978346da8b3b9 100644 (file)
@@ -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) {
index d2e5c74fabbffc2529b6c933984c4032970c401a..068bc455b534aa0332adb970f917051da1af90dd 100644 (file)
@@ -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);
index a385e6819bcf5f80b9e238bdfc78023c6d1afb45..2447e734a299ac04269ba3d5a6dbcad564d7e885 100644 (file)
@@ -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;
         }
index 54d54c8fd5939263dbe367e777bc7e9b3a14fca5..e4b95e4195b4d9356e46d30987bad54193240d71 100644 (file)
@@ -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);
 
index 8f625975fbb33aa1826921eccb940982eb366ebd..214192ffe8488e51b6a1703f4c0cbdb03fefb33b 100644 (file)
@@ -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);
index e28e018116044e1cadc7feb79ad5ca03d85f9a65..025662437b8bd0d14aeb3ad21252dc988bf9a2ca 100644 (file)
@@ -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;
                 }
index 5b4874795a7dfd78a1cba054779756fda8c43000..cf420379150cfea11f6a562d54d3051218bc763d 100644 (file)
@@ -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())
index ec059d95865a2970a21dbe5b0405b94b803b1341..17d125c8213d2c072c0059155470b40e05f4d7e6 100644 (file)
@@ -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;
         }
index eddab58a818d32444c9624d8d1c7354d88b2fe49..651c660e96a89f6f9279968fbf07e0bf2a7b670d 100644 (file)
@@ -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)
index ffaefbe3f2b92b3c7d3278e277e8cb39df993418..b01ee6c9ccfdd41f02213954179331c864357c45 100644 (file)
@@ -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");
index ad38c6a5610c28d249524dcfd78b921d9fcb7ba3..e8592a60d863ba5462535c8c58eda7cef1036400 100644 (file)
@@ -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);
index 8b231323392975bf625f4083920633c7e9ebb9dd..3cda429c3cdb36edb37b64a06fc59e21b116889d 100644 (file)
@@ -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);
         }
 
index b6620875eae334001b392be1bcfa42049d54e782..efdf7e5aaa8a1ed4d4c2cf21223a5e976f0a9b92 100644 (file)
@@ -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;
index f4e071ebaad79c94d97bf53ebd797544356806fc..2af77b34074ad2c753e7b00eb925a2e3b21e80a6 100644 (file)
@@ -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");
index de3847adfda5ef5ce2ab47998c77da7220898f7a..e33d8b11cf3d64a6bb5f81819cfdb59613138aaa 100644 (file)
@@ -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) {
 
index 103f8d2e3952944b0643f62494effc01043d99db..74d5e854e1051168852e9cdf201e5f982d5cdbeb 100644 (file)
@@ -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)
index 243a46f2e3c7d4bbbe3cbcfc116db4c43d5b4485..b782b05f8822be0692a0d6a78aa4437adec7be5d 100644 (file)
@@ -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;
         }
index 139d286af8d3b2a8a31aea74e9b2df1fc5ca8af3..d75abd8121b6cce6771a23276d55ed4cd6706438 100644 (file)
@@ -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')) {
index 3a6e987ee18b94e522235472415ef7e21f7b6497..6d295ea65b8c41d7f71a9193817840ccb1df4d8d 100644 (file)
@@ -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)
index 54516cfb9617afab210e5ea1cd99439c3da0c9b0..0626d80b199ea8c36e46928902560b864de26c85 100644 (file)
@@ -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')
index 32a4c67590e5de1738cb7bdfdb9d46dd5abe04d8..859e5ffc1a3b43b12135d588a5ed049b4acc510f 100644 (file)
@@ -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;
index bf10acda94480671f1f54b81c90698ca3d1b9cd7..e7a878ab50a7e17da1347240bd00887bc08e06ff 100644 (file)
@@ -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 */
index bf8c2f86a3460df9ab9d301f07a8deb48238d231..34c938438cb235ca5ac6fb17ce989bb411c2fde4 100644 (file)
@@ -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))
index 897fc48b9895e06242fc01378aa645f2daf93c2a..782924d95add910610454abf51603c1d2c3f5473 100644 (file)
@@ -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)
index e9e6dae10c7293920e765341eb23d5a3977ef16a..50fce6b29f758871e731eac7b9cf3513a8318371 100644 (file)
@@ -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);
index f41e488d9950a7b33ec25ce216d9b6fed8801b8f..68975b790a24279938178a45fc592f6e924eac4a 100644 (file)
@@ -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);
index 15d76bddda2b90d000b383f93c03d6b122bd56fe..02aae84152daab11a23be13ba775345e222eade6 100644 (file)
@@ -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;
         }
index f246ae838552c911a2463ccaf8ffcc8d579e59fe..94f8b50f41452011f27efdd406773fde20f8b434 100644 (file)
@@ -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);
index b5b6391cdd81e191d7deac7f91fe14714b43c3df..27495fa5be469f003e647fc32a661eeb88f33fba 100644 (file)
@@ -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);
 }
 
index 44570caa6c09c93455d26f78e3972baca7b4474d..be8b9d71bafaaa4b8c705b2fd133e7a6c75fcefb 100644 (file)
@@ -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)));
 
index 578e09447f79e85aa9bbe4a28bcdcc299595c538..07f21d0d3db1161a06523436b958985dcae57a44 100644 (file)
@@ -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;
         }
index 3f5c1e62ee66f631382c4abe1eb2bdfd9d4a0a06..17fce9332846936e1d14f5119942055d4cbacd55 100644 (file)
@@ -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);
index 3ea8dae7a9caed4bc9bce051e4f978b8a9c3e752..495ae464b475d9233f003e6fe289a55fed877bc2 100644 (file)
@@ -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;
 
index ad152b9d316413272b132c7f377d689e514d33b1..1dc62b69d5e175fea42a761265b01ecd29e69a14 100644 (file)
@@ -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 {
index 1f906a85258f511dc36830d9a96d14e2dbfbd212..b9cf3bdf687181bac73cb4333b0304d00eb171b7 100644 (file)
@@ -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);
index f007cc6001b8a1c03cace1d7aa93a80baed6d52c..b56a541f7813d64097db97561550959528c6e872 100644 (file)
@@ -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];
index 3ebe36f0433c7b1737b10d35fc6643890183f0ce..d92a10e1c5b272a2766ba90e0fe304a9cc09067f 100644 (file)
@@ -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;
index 587649eff0aa6d15e5f306cd1c53875ec60db787..3ce075f07929d0e63c9fe8227592fdb683c65e91 100644 (file)
@@ -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;
index 53cfd9c053f9c90956586d2aca43d15b796deb3d..01e56cac366e1abce4acab34b34d0658b514ec2c 100644 (file)
@@ -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)
index 5ab697e3994f623b0c6b5bed82bb3b0467ac712f..9aaec72baf5888c45e42b8f14867469ab2530d99 100644 (file)
@@ -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),
index f68d60a134a0c13c0069d47b14afa8a09f39e1d1..679471e2179c6f7972e1811729abbfba49714906 100644 (file)
@@ -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);