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];
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;
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;
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;
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)
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;
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;
}
}
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;
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;
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;
(*q >= 'a' && *q <= 'z') ||
(*q >= 'A' && *q <= 'Z') ||
((!dot || unique) && *q >= '0' && *q <= '9') ||
- *q == '_' || *q == '-';
+ IN_SET(*q, '_', '-');
if (!good)
return false;
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);
}
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);
}
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);
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);
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);
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) {
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);
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);
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");
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;
(*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)
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);
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)
* 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)
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)
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);
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);
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;
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;
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)
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)
#include "macro.h"
#include "missing.h"
#include "parse-util.h"
-#include "process-util.h"
#include "string-util.h"
#include "strv.h"
#include "util.h"
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)
} else
a = *p;
- while (*a != ';' && *a != ',' && *a != 0) {
+ while (!IN_SET(*a, ';', ',', 0)) {
char c;
if (*a == '%') {
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;
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;
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;
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;
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;
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) {
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
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);
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;
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)
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;
}
* 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)
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))
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)
#include "fs-util.h"
#include "parse-util.h"
#include "path-util.h"
-#include "process-util.h"
#include "socket-util.h"
#include "strv.h"
#include "util.h"
if (stat(path, &st_path) < 0) {
- if (errno == ENOENT || errno == ENOTDIR)
+ if (IN_SET(errno, ENOENT, ENOTDIR))
return 0;
return -errno;
if (stat(path, &st_path) < 0) {
- if (errno == ENOENT || errno == ENOTDIR)
+ if (IN_SET(errno, ENOENT, ENOTDIR))
return 0;
return -errno;
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)
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;
}
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
ss = read(fd, &x, sizeof(x));
if (ss < 0) {
- if (errno == EAGAIN || errno == EINTR)
+ if (IN_SET(errno, EAGAIN, EINTR))
return 0;
return -errno;
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
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;
* 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;
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);
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 {
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