Merge pull request #6933 from yuwata/use_in_set

use IN_SET macro
This commit is contained in:
Lennart Poettering 2017-09-28 19:22:09 +02:00 committed by GitHub
commit aecc6f6b34
19 changed files with 74 additions and 92 deletions

View file

@ -816,7 +816,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
if (!f) {
if (errno == ENOENT)
return -ESRCH;
else if (errno != EPERM && errno != EACCES)
else if (!IN_SET(errno, EPERM, EACCES))
return -errno;
} else {
char line[LINE_MAX];
@ -974,7 +974,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
p = procfs_file_alloca(pid, "attr/current");
r = read_one_line_file(p, &c->label);
if (r < 0) {
if (r != -ENOENT && r != -EINVAL && r != -EPERM && r != -EACCES)
if (!IN_SET(r, -ENOENT, -EINVAL, -EPERM, -EACCES))
return r;
} else
c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
@ -983,7 +983,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
if (missing & SD_BUS_CREDS_COMM) {
r = get_process_comm(pid, &c->comm);
if (r < 0) {
if (r != -EPERM && r != -EACCES)
if (!IN_SET(r, -EPERM, -EACCES))
return r;
} else
c->mask |= SD_BUS_CREDS_COMM;
@ -1002,7 +1002,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
c->exe = NULL;
c->mask |= SD_BUS_CREDS_EXE;
} else if (r < 0) {
if (r != -EPERM && r != -EACCES)
if (!IN_SET(r, -EPERM, -EACCES))
return r;
} else
c->mask |= SD_BUS_CREDS_EXE;
@ -1016,7 +1016,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
if (r == -ENOENT)
return -ESRCH;
if (r < 0) {
if (r != -EPERM && r != -EACCES)
if (!IN_SET(r, -EPERM, -EACCES))
return r;
} else {
if (c->cmdline_size == 0)
@ -1036,7 +1036,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
if (r == -ENOENT)
return -ESRCH;
if (r < 0) {
if (r != -EPERM && r != -EACCES)
if (!IN_SET(r, -EPERM, -EACCES))
return r;
} else
c->mask |= SD_BUS_CREDS_TID_COMM;
@ -1047,7 +1047,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
if (!c->cgroup) {
r = cg_pid_get_path(NULL, pid, &c->cgroup);
if (r < 0) {
if (r != -EPERM && r != -EACCES)
if (!IN_SET(r, -EPERM, -EACCES))
return r;
}
}
@ -1069,7 +1069,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
c->audit_session_id = AUDIT_SESSION_INVALID;
c->mask |= SD_BUS_CREDS_AUDIT_SESSION_ID;
} else if (r < 0) {
if (r != -EOPNOTSUPP && r != -ENOENT && r != -EPERM && r != -EACCES)
if (!IN_SET(r, -EOPNOTSUPP, -ENOENT, -EPERM, -EACCES))
return r;
} else
c->mask |= SD_BUS_CREDS_AUDIT_SESSION_ID;
@ -1082,7 +1082,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
c->audit_login_uid = UID_INVALID;
c->mask |= SD_BUS_CREDS_AUDIT_LOGIN_UID;
} else if (r < 0) {
if (r != -EOPNOTSUPP && r != -ENOENT && r != -EPERM && r != -EACCES)
if (!IN_SET(r, -EOPNOTSUPP, -ENOENT, -EPERM, -EACCES))
return r;
} else
c->mask |= SD_BUS_CREDS_AUDIT_LOGIN_UID;
@ -1095,7 +1095,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
c->tty = NULL;
c->mask |= SD_BUS_CREDS_TTY;
} else if (r < 0) {
if (r != -EPERM && r != -EACCES && r != -ENOENT)
if (!IN_SET(r, -EPERM, -EACCES, -ENOENT))
return r;
} else
c->mask |= SD_BUS_CREDS_TTY;

View file

@ -148,7 +148,7 @@ bool service_name_is_valid(const char *p) {
(*q >= 'a' && *q <= 'z') ||
(*q >= 'A' && *q <= 'Z') ||
((!dot || unique) && *q >= '0' && *q <= '9') ||
*q == '_' || *q == '-';
IN_SET(*q, '_', '-');
if (!good)
return false;

View file

@ -81,7 +81,7 @@ static void introspect_write_flags(struct introspect *i, int type, int flags) {
if (type == _SD_BUS_VTABLE_METHOD && (flags & SD_BUS_VTABLE_METHOD_NO_REPLY))
fputs_unlocked(" <annotation name=\"org.freedesktop.DBus.Method.NoReply\" value=\"true\"/>\n", i->f);
if (type == _SD_BUS_VTABLE_PROPERTY || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) {
if (IN_SET(type, _SD_BUS_VTABLE_PROPERTY, _SD_BUS_VTABLE_WRITABLE_PROPERTY)) {
if (flags & SD_BUS_VTABLE_PROPERTY_EXPLICIT)
fputs_unlocked(" <annotation name=\"org.freedesktop.systemd1.Explicit\" value=\"true\"/>\n", i->f);
@ -94,7 +94,7 @@ static void introspect_write_flags(struct introspect *i, int type, int flags) {
}
if (!i->trusted &&
(type == _SD_BUS_VTABLE_METHOD || type == _SD_BUS_VTABLE_WRITABLE_PROPERTY) &&
IN_SET(type, _SD_BUS_VTABLE_METHOD, _SD_BUS_VTABLE_WRITABLE_PROPERTY) &&
!(flags & SD_BUS_VTABLE_UNPRIVILEGED))
fputs_unlocked(" <annotation name=\"org.freedesktop.systemd1.Privileged\" value=\"true\"/>\n", i->f);
}

View file

@ -453,7 +453,7 @@ static int bus_match_add_compare_value(
int r;
assert(where);
assert(where->type == BUS_MATCH_ROOT || where->type == BUS_MATCH_VALUE);
assert(IN_SET(where->type, BUS_MATCH_ROOT, BUS_MATCH_VALUE));
assert(BUS_MATCH_IS_COMPARE(t));
assert(ret);
@ -567,7 +567,7 @@ static int bus_match_find_compare_value(
struct bus_match_node *c, *n;
assert(where);
assert(where->type == BUS_MATCH_ROOT || where->type == BUS_MATCH_VALUE);
assert(IN_SET(where->type, BUS_MATCH_ROOT, BUS_MATCH_VALUE));
assert(BUS_MATCH_IS_COMPARE(t));
assert(ret);
@ -601,7 +601,7 @@ static int bus_match_add_leaf(
struct bus_match_node *n;
assert(where);
assert(where->type == BUS_MATCH_ROOT || where->type == BUS_MATCH_VALUE);
assert(IN_SET(where->type, BUS_MATCH_ROOT, BUS_MATCH_VALUE));
assert(callback);
n = new0(struct bus_match_node, 1);
@ -631,7 +631,7 @@ static int bus_match_find_leaf(
struct bus_match_node *c;
assert(where);
assert(where->type == BUS_MATCH_ROOT || where->type == BUS_MATCH_VALUE);
assert(IN_SET(where->type, BUS_MATCH_ROOT, BUS_MATCH_VALUE));
assert(ret);
for (c = where->child; c; c = c->next) {

View file

@ -587,7 +587,7 @@ static sd_bus_message *message_new(sd_bus *bus, uint8_t type) {
m->header->endian = BUS_NATIVE_ENDIAN;
m->header->type = type;
m->header->version = bus->message_version;
m->allow_fds = bus->can_fds || (bus->state != BUS_HELLO && bus->state != BUS_RUNNING);
m->allow_fds = bus->can_fds || !IN_SET(bus->state, BUS_HELLO, BUS_RUNNING);
m->root_container.need_offsets = BUS_MESSAGE_IS_GVARIANT(m);
m->bus = sd_bus_ref(bus);
@ -1550,7 +1550,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
if (!a)
return -ENOMEM;
if (type == SD_BUS_TYPE_STRING || type == SD_BUS_TYPE_OBJECT_PATH) {
if (IN_SET(type, SD_BUS_TYPE_STRING, SD_BUS_TYPE_OBJECT_PATH)) {
*(uint32_t*) a = sz - 5;
memcpy((uint8_t*) a + 4, p, sz - 4);
@ -2229,7 +2229,7 @@ _public_ int sd_bus_message_close_container(sd_bus_message *m) {
r = bus_message_close_array(m, c);
else if (c->enclosing == SD_BUS_TYPE_VARIANT)
r = bus_message_close_variant(m, c);
else if (c->enclosing == SD_BUS_TYPE_STRUCT || c->enclosing == SD_BUS_TYPE_DICT_ENTRY)
else if (IN_SET(c->enclosing, SD_BUS_TYPE_STRUCT, SD_BUS_TYPE_DICT_ENTRY))
r = bus_message_close_struct(m, c, true);
else
assert_not_reached("Unknown container type");
@ -3171,9 +3171,7 @@ static int container_next_item(sd_bus_message *m, struct bus_container *c, size_
c->offset_index++;
} else if (c->enclosing == 0 ||
c->enclosing == SD_BUS_TYPE_STRUCT ||
c->enclosing == SD_BUS_TYPE_DICT_ENTRY) {
} else if (IN_SET(c->enclosing, 0, SD_BUS_TYPE_STRUCT, SD_BUS_TYPE_DICT_ENTRY)) {
int alignment;
size_t n, j;
@ -5060,8 +5058,7 @@ static int message_skip_fields(
(*signature)++;
} else if (t == SD_BUS_TYPE_STRUCT ||
t == SD_BUS_TYPE_DICT_ENTRY) {
} else if (IN_SET(t, SD_BUS_TYPE_STRUCT, SD_BUS_TYPE_DICT_ENTRY)) {
r = signature_element_length(*signature, &l);
if (r < 0)
@ -5719,9 +5716,7 @@ _public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int
assert(r > 0);
if (type == SD_BUS_TYPE_OBJECT_PATH ||
type == SD_BUS_TYPE_SIGNATURE ||
type == SD_BUS_TYPE_STRING)
if (IN_SET(type, SD_BUS_TYPE_OBJECT_PATH, SD_BUS_TYPE_SIGNATURE, SD_BUS_TYPE_STRING))
r = sd_bus_message_append_basic(m, type, basic.string);
else
r = sd_bus_message_append_basic(m, type, &basic);

View file

@ -753,7 +753,7 @@ static int vtable_append_all_properties(
return 1;
for (v = c->vtable+1; v->type != _SD_BUS_VTABLE_END; v++) {
if (v->type != _SD_BUS_VTABLE_PROPERTY && v->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY)
if (!IN_SET(v->type, _SD_BUS_VTABLE_PROPERTY, _SD_BUS_VTABLE_WRITABLE_PROPERTY))
continue;
if (v->flags & SD_BUS_VTABLE_HIDDEN)
@ -2000,7 +2000,7 @@ static int emit_properties_changed_on_interface(
* as changing in the message. */
for (v = c->vtable+1; v->type != _SD_BUS_VTABLE_END; v++) {
if (v->type != _SD_BUS_VTABLE_PROPERTY && v->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY)
if (!IN_SET(v->type, _SD_BUS_VTABLE_PROPERTY, _SD_BUS_VTABLE_WRITABLE_PROPERTY))
continue;
if (v->flags & SD_BUS_VTABLE_HIDDEN)
@ -2071,7 +2071,7 @@ static int emit_properties_changed_on_interface(
const sd_bus_vtable *v;
for (v = c->vtable+1; v->type != _SD_BUS_VTABLE_END; v++) {
if (v->type != _SD_BUS_VTABLE_PROPERTY && v->type != _SD_BUS_VTABLE_WRITABLE_PROPERTY)
if (!IN_SET(v->type, _SD_BUS_VTABLE_PROPERTY, _SD_BUS_VTABLE_WRITABLE_PROPERTY))
continue;
if (v->flags & SD_BUS_VTABLE_HIDDEN)

View file

@ -343,7 +343,7 @@ static int bus_socket_auth_write(sd_bus *b, const char *t) {
assert(t);
/* We only make use of the first iovec */
assert(b->auth_index == 0 || b->auth_index == 1);
assert(IN_SET(b->auth_index, 0, 1));
l = strlen(t);
p = malloc(b->auth_iovec[0].iov_len + l);
@ -731,7 +731,7 @@ int bus_socket_exec(sd_bus *b) {
assert_se(dup3(s[1], STDIN_FILENO, 0) == STDIN_FILENO);
assert_se(dup3(s[1], STDOUT_FILENO, 0) == STDOUT_FILENO);
if (s[1] != STDIN_FILENO && s[1] != STDOUT_FILENO)
if (!IN_SET(s[1], STDIN_FILENO, STDOUT_FILENO))
safe_close(s[1]);
fd_cloexec(STDIN_FILENO, false);
@ -775,7 +775,7 @@ int bus_socket_write_message(sd_bus *bus, sd_bus_message *m, size_t *idx) {
assert(bus);
assert(m);
assert(idx);
assert(bus->state == BUS_RUNNING || bus->state == BUS_HELLO);
assert(IN_SET(bus->state, BUS_RUNNING, BUS_HELLO));
if (*idx >= BUS_MESSAGE_SIZE(m))
return 0;
@ -830,7 +830,7 @@ static int bus_socket_read_message_need(sd_bus *bus, size_t *need) {
assert(bus);
assert(need);
assert(bus->state == BUS_RUNNING || bus->state == BUS_HELLO);
assert(IN_SET(bus->state, BUS_RUNNING, BUS_HELLO));
if (bus->rbuffer_size < sizeof(struct bus_header)) {
*need = sizeof(struct bus_header) + 8;
@ -882,7 +882,7 @@ static int bus_socket_make_message(sd_bus *bus, size_t size) {
assert(bus);
assert(bus->rbuffer_size >= size);
assert(bus->state == BUS_RUNNING || bus->state == BUS_HELLO);
assert(IN_SET(bus->state, BUS_RUNNING, BUS_HELLO));
r = bus_rqueue_make_room(bus);
if (r < 0)
@ -931,7 +931,7 @@ int bus_socket_read_message(sd_bus *bus) {
bool handle_cmsg = false;
assert(bus);
assert(bus->state == BUS_RUNNING || bus->state == BUS_HELLO);
assert(IN_SET(bus->state, BUS_RUNNING, BUS_HELLO));
r = bus_socket_read_message_need(bus, &need);
if (r < 0)

View file

@ -382,7 +382,7 @@ static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *e
assert(reply);
bus = reply->bus;
assert(bus);
assert(bus->state == BUS_HELLO || bus->state == BUS_CLOSING);
assert(IN_SET(bus->state, BUS_HELLO, BUS_CLOSING));
r = sd_bus_message_get_errno(reply);
if (r > 0)
@ -463,7 +463,7 @@ static int parse_address_key(const char **p, const char *key, char **value) {
} else
a = *p;
while (*a != ';' && *a != ',' && *a != 0) {
while (!IN_SET(*a, ';', ',', 0)) {
char c;
if (*a == '%') {
@ -532,7 +532,7 @@ static int parse_unix_address(sd_bus *b, const char **p, char **guid) {
assert(*p);
assert(guid);
while (**p != 0 && **p != ';') {
while (!IN_SET(**p, 0, ';')) {
r = parse_address_key(p, "guid", guid);
if (r < 0)
return r;
@ -597,7 +597,7 @@ static int parse_tcp_address(sd_bus *b, const char **p, char **guid) {
assert(*p);
assert(guid);
while (**p != 0 && **p != ';') {
while (!IN_SET(**p, 0, ';')) {
r = parse_address_key(p, "guid", guid);
if (r < 0)
return r;
@ -665,7 +665,7 @@ static int parse_exec_address(sd_bus *b, const char **p, char **guid) {
assert(*p);
assert(guid);
while (**p != 0 && **p != ';') {
while (!IN_SET(**p, 0, ';')) {
r = parse_address_key(p, "guid", guid);
if (r < 0)
goto fail;
@ -755,7 +755,7 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid)
assert(*p);
assert(guid);
while (**p != 0 && **p != ';') {
while (!IN_SET(**p, 0, ';')) {
r = parse_address_key(p, "guid", guid);
if (r < 0)
return r;
@ -1319,10 +1319,7 @@ _public_ sd_bus* sd_bus_flush_close_unref(sd_bus *bus) {
static void bus_enter_closing(sd_bus *bus) {
assert(bus);
if (bus->state != BUS_OPENING &&
bus->state != BUS_AUTHENTICATING &&
bus->state != BUS_HELLO &&
bus->state != BUS_RUNNING)
if (!IN_SET(bus->state, BUS_OPENING, BUS_AUTHENTICATING, BUS_HELLO, BUS_RUNNING))
return;
bus->state = BUS_CLOSING;
@ -1486,7 +1483,7 @@ static int dispatch_wqueue(sd_bus *bus) {
int r, ret = 0;
assert(bus);
assert(bus->state == BUS_RUNNING || bus->state == BUS_HELLO);
assert(IN_SET(bus->state, BUS_RUNNING, BUS_HELLO));
while (bus->wqueue_size > 0) {
@ -1542,7 +1539,7 @@ static int dispatch_rqueue(sd_bus *bus, bool hint_priority, int64_t priority, sd
assert(bus);
assert(m);
assert(bus->state == BUS_RUNNING || bus->state == BUS_HELLO);
assert(IN_SET(bus->state, BUS_RUNNING, BUS_HELLO));
/* Note that the priority logic is only available on kdbus,
* where the rqueue is unused. We check the rqueue here
@ -1611,7 +1608,7 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie,
if (m->dont_send)
goto finish;
if ((bus->state == BUS_RUNNING || bus->state == BUS_HELLO) && bus->wqueue_size <= 0) {
if (IN_SET(bus->state, BUS_RUNNING, BUS_HELLO) && bus->wqueue_size <= 0) {
size_t idx = 0;
r = bus_write_message(bus, m, hint_sync_call, &idx);
@ -1788,7 +1785,7 @@ int bus_ensure_running(sd_bus *bus) {
assert(bus);
if (bus->state == BUS_UNSET || bus->state == BUS_CLOSED || bus->state == BUS_CLOSING)
if (IN_SET(bus->state, BUS_UNSET, BUS_CLOSED, BUS_CLOSING))
return -ENOTCONN;
if (bus->state == BUS_RUNNING)
return 1;
@ -1992,7 +1989,7 @@ _public_ int sd_bus_get_events(sd_bus *bus) {
flags |= POLLIN;
} else if (bus->state == BUS_RUNNING || bus->state == BUS_HELLO) {
} else if (IN_SET(bus->state, BUS_RUNNING, BUS_HELLO)) {
if (bus->rqueue_size <= 0)
flags |= POLLIN;
if (bus->wqueue_size > 0)
@ -2027,7 +2024,7 @@ _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) {
return 1;
}
if (bus->state != BUS_RUNNING && bus->state != BUS_HELLO) {
if (!IN_SET(bus->state, BUS_RUNNING, BUS_HELLO)) {
*timeout_usec = (uint64_t) -1;
return 0;
}
@ -2124,8 +2121,7 @@ static int process_hello(sd_bus *bus, sd_bus_message *m) {
* here (we leave that to the usual handling), we just verify
* we don't let any earlier msg through. */
if (m->header->type != SD_BUS_MESSAGE_METHOD_RETURN &&
m->header->type != SD_BUS_MESSAGE_METHOD_ERROR)
if (!IN_SET(m->header->type, SD_BUS_MESSAGE_METHOD_RETURN, SD_BUS_MESSAGE_METHOD_ERROR))
return -EIO;
if (m->reply_cookie != 1)
@ -2144,8 +2140,7 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
assert(bus);
assert(m);
if (m->header->type != SD_BUS_MESSAGE_METHOD_RETURN &&
m->header->type != SD_BUS_MESSAGE_METHOD_ERROR)
if (!IN_SET(m->header->type, SD_BUS_MESSAGE_METHOD_RETURN, SD_BUS_MESSAGE_METHOD_ERROR))
return 0;
if (m->destination && bus->unique_name && !streq_ptr(m->destination, bus->unique_name))
@ -2414,7 +2409,7 @@ static int process_running(sd_bus *bus, bool hint_priority, int64_t priority, sd
int r;
assert(bus);
assert(bus->state == BUS_RUNNING || bus->state == BUS_HELLO);
assert(IN_SET(bus->state, BUS_RUNNING, BUS_HELLO));
r = process_timeout(bus);
if (r != 0)

View file

@ -38,7 +38,7 @@ static int test_bus_open(void) {
int r;
r = sd_bus_open_user(&bus);
if (r == -ECONNREFUSED || r == -ENOENT)
if (IN_SET(r, -ECONNREFUSED, -ENOENT))
return r;
assert_se(r >= 0);

View file

@ -161,7 +161,7 @@ _public_ int sd_is_fifo(int fd, const char *path) {
if (stat(path, &st_path) < 0) {
if (errno == ENOENT || errno == ENOTDIR)
if (IN_SET(errno, ENOENT, ENOTDIR))
return 0;
return -errno;
@ -191,7 +191,7 @@ _public_ int sd_is_special(int fd, const char *path) {
if (stat(path, &st_path) < 0) {
if (errno == ENOENT || errno == ENOTDIR)
if (IN_SET(errno, ENOENT, ENOTDIR))
return 0;
return -errno;
@ -297,8 +297,7 @@ _public_ int sd_is_socket_inet(int fd, int family, int type, int listening, uint
if (l < sizeof(sa_family_t))
return -EINVAL;
if (sockaddr.sa.sa_family != AF_INET &&
sockaddr.sa.sa_family != AF_INET6)
if (!IN_SET(sockaddr.sa.sa_family, AF_INET, AF_INET6))
return 0;
if (family != 0)
@ -492,7 +491,7 @@ _public_ int sd_pid_notify_with_fds(pid_t pid, int unset_environment, const char
return 0;
/* Must be an abstract socket, or an absolute path */
if ((e[0] != '@' && e[0] != '/') || e[1] == 0) {
if (!IN_SET(e[0], '@', '/') || e[1] == 0) {
r = -EINVAL;
goto finish;
}

View file

@ -249,7 +249,7 @@ _public_ int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum)
char id[DECIMAL_STR_MAX(unsigned) * 2 + 1];
assert_return(ret, -EINVAL);
assert_return(type == 'b' || type == 'c', -EINVAL);
assert_return(IN_SET(type, 'b', 'c'), -EINVAL);
/* use /sys/dev/{block,char}/<maj>:<min> link */
snprintf(id, sizeof(id), "%u:%u", major(devnum), minor(devnum));
@ -1636,7 +1636,7 @@ static int device_sysattrs_read_all(sd_device *device) {
struct stat statbuf;
/* only handle symlinks and regular files */
if (dent->d_type != DT_LNK && dent->d_type != DT_REG)
if (!IN_SET(dent->d_type, DT_LNK, DT_REG))
continue;
path = strjoina(syspath, "/", dent->d_name);

View file

@ -1597,7 +1597,7 @@ _public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {
int r;
assert_return(s, -EINVAL);
assert_return(m == SD_EVENT_OFF || m == SD_EVENT_ON || m == SD_EVENT_ONESHOT, -EINVAL);
assert_return(IN_SET(m, SD_EVENT_OFF, SD_EVENT_ON, SD_EVENT_ONESHOT), -EINVAL);
assert_return(!event_pid_changed(s->event), -ECHILD);
/* If we are dead anyway, we are fine with turning off
@ -2050,7 +2050,7 @@ static int flush_timer(sd_event *e, int fd, uint32_t events, usec_t *next) {
ss = read(fd, &x, sizeof(x));
if (ss < 0) {
if (errno == EAGAIN || errno == EINTR)
if (IN_SET(errno, EAGAIN, EINTR))
return 0;
return -errno;
@ -2139,10 +2139,7 @@ static int process_child(sd_event *e) {
return -errno;
if (s->child.siginfo.si_pid != 0) {
bool zombie =
s->child.siginfo.si_code == CLD_EXITED ||
s->child.siginfo.si_code == CLD_KILLED ||
s->child.siginfo.si_code == CLD_DUMPED;
bool zombie = IN_SET(s->child.siginfo.si_code, CLD_EXITED, CLD_KILLED, CLD_DUMPED);
if (!zombie && (s->child.options & WEXITED)) {
/* If the child isn't dead then let's
@ -2193,7 +2190,7 @@ static int process_signal(sd_event *e, struct signal_data *d, uint32_t events) {
n = read(d->fd, &si, sizeof(si));
if (n < 0) {
if (errno == EAGAIN || errno == EINTR)
if (IN_SET(errno, EAGAIN, EINTR))
return read_one;
return -errno;
@ -2235,7 +2232,7 @@ static int source_dispatch(sd_event_source *s) {
* the event. */
saved_type = s->type;
if (s->type != SOURCE_DEFER && s->type != SOURCE_EXIT) {
if (!IN_SET(s->type, SOURCE_DEFER, SOURCE_EXIT)) {
r = source_set_pending(s, false);
if (r < 0)
return r;
@ -2287,9 +2284,7 @@ static int source_dispatch(sd_event_source *s) {
case SOURCE_CHILD: {
bool zombie;
zombie = s->child.siginfo.si_code == CLD_EXITED ||
s->child.siginfo.si_code == CLD_KILLED ||
s->child.siginfo.si_code == CLD_DUMPED;
zombie = IN_SET(s->child.siginfo.si_code, CLD_EXITED, CLD_KILLED, CLD_DUMPED);
r = s->child.callback(s, &s->child.siginfo, s->userdata);

View file

@ -75,7 +75,7 @@ bool id128_is_valid(const char *s) {
for (i = 0; i < l; i++) {
char c = s[i];
if ((i == 8 || i == 13 || i == 18 || i == 23)) {
if (IN_SET(i, 8, 13, 18, 23)) {
if (c != '-')
return false;
} else {

View file

@ -66,7 +66,7 @@ _public_ int sd_id128_from_string(const char s[], sd_id128_t *ret) {
if (i == 8)
is_guid = true;
else if (i == 13 || i == 18 || i == 23) {
else if (IN_SET(i, 13, 18, 23)) {
if (!is_guid)
return -EINVAL;
} else

View file

@ -122,7 +122,7 @@ int local_addresses(sd_netlink *context, int ifindex, int af, struct local_addre
if (r < 0)
return r;
if (ifindex == 0 && (a->scope == RT_SCOPE_HOST || a->scope == RT_SCOPE_NOWHERE))
if (ifindex == 0 && IN_SET(a->scope, RT_SCOPE_HOST, RT_SCOPE_NOWHERE))
continue;
switch (family) {

View file

@ -282,7 +282,7 @@ int sd_rtnl_message_new_route(sd_netlink *rtnl, sd_netlink_message **ret,
assert_return(rtnl_message_type_is_route(nlmsg_type), -EINVAL);
assert_return((nlmsg_type == RTM_GETROUTE && rtm_family == AF_UNSPEC) ||
rtm_family == AF_INET || rtm_family == AF_INET6, -EINVAL);
IN_SET(rtm_family, AF_INET, AF_INET6), -EINVAL);
assert_return(ret, -EINVAL);
r = message_new(rtnl, ret, nlmsg_type);
@ -390,9 +390,7 @@ int sd_rtnl_message_new_neigh(sd_netlink *rtnl, sd_netlink_message **ret, uint16
int r;
assert_return(rtnl_message_type_is_neigh(nlmsg_type), -EINVAL);
assert_return(ndm_family == AF_INET ||
ndm_family == AF_INET6 ||
ndm_family == PF_BRIDGE, -EINVAL);
assert_return(IN_SET(ndm_family, AF_INET, AF_INET6, PF_BRIDGE), -EINVAL);
assert_return(ret, -EINVAL);
r = message_new(rtnl, ret, nlmsg_type);
@ -608,7 +606,7 @@ int sd_rtnl_message_new_addr(sd_netlink *rtnl, sd_netlink_message **ret,
assert_return((nlmsg_type == RTM_GETADDR && index == 0) ||
index > 0, -EINVAL);
assert_return((nlmsg_type == RTM_GETADDR && family == AF_UNSPEC) ||
family == AF_INET || family == AF_INET6, -EINVAL);
IN_SET(family, AF_INET, AF_INET6), -EINVAL);
assert_return(ret, -EINVAL);
r = message_new(rtnl, ret, nlmsg_type);

View file

@ -362,7 +362,7 @@ static void test_get_addresses(sd_netlink *rtnl) {
assert_se(sd_rtnl_message_addr_get_flags(m, &flags) >= 0);
assert_se(ifindex > 0);
assert_se(family == AF_INET || family == AF_INET6);
assert_se(IN_SET(family, AF_INET, AF_INET6));
log_info("got IPv%u address on ifindex %i", family == AF_INET ? 4: 6, ifindex);
}

View file

@ -342,7 +342,7 @@ _public_ int sd_network_monitor_flush(sd_network_monitor *m) {
l = read(fd, &buffer, sizeof(buffer));
if (l < 0) {
if (errno == EAGAIN || errno == EINTR)
if (IN_SET(errno, EAGAIN, EINTR))
return 0;
return -errno;

View file

@ -319,7 +319,7 @@ int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, vo
if (r < 0) {
log_warning_errno(r, "rtnl: could not get message type: %m");
return 0;
} else if (type != RTM_NEWROUTE && type != RTM_DELROUTE) {
} else if (!IN_SET(type, RTM_NEWROUTE, RTM_DELROUTE)) {
log_warning("rtnl: received unexpected message type when processing route");
return 0;
}
@ -413,7 +413,7 @@ int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, vo
break;
default:
log_link_debug(link, "rtnl: ignoring unsupported address family: %d", family);
assert_not_reached("Received unsupported address family");
return 0;
}
@ -516,7 +516,7 @@ int manager_rtnl_process_address(sd_netlink *rtnl, sd_netlink_message *message,
if (r < 0) {
log_warning_errno(r, "rtnl: could not get message type: %m");
return 0;
} else if (type != RTM_NEWADDR && type != RTM_DELADDR) {
} else if (!IN_SET(type, RTM_NEWADDR, RTM_DELADDR)) {
log_warning("rtnl: received unexpected message type when processing address");
return 0;
}
@ -663,7 +663,7 @@ static int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *messa
if (r < 0) {
log_warning_errno(r, "rtnl: Could not get message type: %m");
return 0;
} else if (type != RTM_NEWLINK && type != RTM_DELLINK) {
} else if (!IN_SET(type, RTM_NEWLINK, RTM_DELLINK)) {
log_warning("rtnl: Received unexpected message type when processing link");
return 0;
}
@ -801,7 +801,7 @@ int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, voi
break;
default:
assert_not_reached("Received unsupported rule family");
assert_not_reached("Received unsupported address family");
}
if (from_prefixlen == 0 && to_prefixlen == 0)