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;
}
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;
}
/* 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") ||
if (s)
p = s;
- if (*p == 0 || *p == '_')
+ if (IN_SET(*p, 0, '_'))
return false;
for (t = p; *t; t++)
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");
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;
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);
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)) {
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;
#include "strv.h"
#include "util.h"
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
#include <pthread.h>
#include "list.h"
#endif
#define DIB_FREE UINT_MAX
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
struct hashmap_debug_info {
LIST_FIELDS(struct hashmap_debug_info, debug_list);
unsigned max_entries; /* high watermark of n_entries */
dibs = dib_raw_ptr(h);
assert(dibs[idx] != DIB_RAW_FREE);
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
h->debug.rem_count++;
h->debug.last_rem_idx = idx;
#endif
/* 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.
assert(e->p.b.key == i->next_key);
}
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
i->prev_idx = idx;
#endif
}
idx = i->idx;
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
i->prev_idx = idx;
#endif
return IDX_NIL;
}
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
if (i->idx == IDX_FIRST) {
i->put_count = h->debug.put_count;
i->rem_count = h->debug.rem_count;
shared_hash_key_initialized= true;
}
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
h->debug.func = func;
h->debug.file = file;
h->debug.line = line;
assert(!h->has_indirect);
assert(!h->n_direct_entries);
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
assert_se(pthread_mutex_lock(&hashmap_debug_list_mutex) == 0);
LIST_REMOVE(debug_list, hashmap_debug_list, &h->debug);
assert_se(pthread_mutex_unlock(&hashmap_debug_list_mutex) == 0);
dib_raw_t raw_dib, *dibs;
unsigned dib, distance;
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
h->debug.put_count++;
#endif
assert_se(hashmap_put_robin_hood(h, idx, swap) == false);
n_entries_inc(h);
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
h->debug.max_entries = MAX(h->debug.max_entries, n_entries(h));
#endif
idx = bucket_scan(h, hash, key);
if (idx != IDX_NIL) {
e = plain_bucket_at(h, idx);
-#if ENABLE_DEBUG_HASHMAP
+#ifdef ENABLE_DEBUG_HASHMAP
/* Although the key is equal, the key pointer may have changed,
* and this would break our assumption for iterating. So count
* this operation as incompatible with iteration. */
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
- c == '-' ||
- c == '_' ||
- c == '.';
+ IN_SET(c, '-', '_', '.');
}
/**
/* 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);
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;
unsigned n_entries, start_pos = 0;
assert(t);
- assert(base == 1000 || base == 1024);
+ assert(IN_SET(base, 1000, 1024));
assert(size);
if (base == 1000) {
#include <sys/wait.h>
#include <syslog.h>
#include <unistd.h>
-#if HAVE_VALGRIND_VALGRIND_H
+#ifdef HAVE_VALGRIND_VALGRIND_H
#include <valgrind/valgrind.h>
#endif
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);
return true;
r = get_process_state(pid);
- if (r == -ESRCH || r == 'Z')
+ if (IN_SET(r, -ESRCH, 'Z'))
return false;
return true;
}
void valgrind_summary_hack(void) {
-#if HAVE_VALGRIND_VALGRIND_H
+#ifdef HAVE_VALGRIND_VALGRIND_H
if (getpid_cached() == 1 && RUNNING_ON_VALGRIND) {
pid_t pid;
pid = raw_clone(SIGCHLD);
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;
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 */
#include "util.h"
#if 0 /// UNNEEDED by elogind
-#if ENABLE_IDN
+#ifdef ENABLE_IDN
# define IDN_FLAGS (NI_IDN|NI_IDN_USE_STD3_ASCII_RULES)
#else
# define IDN_FLAGS 0
if ((unsigned char) *p <= 32U)
return false;
- if (*p == ':' || *p == '/')
+ if (IN_SET(*p, ':', '/'))
return false;
numeric = numeric && (*p >= '0' && *p <= '9');
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;
return 1;
}
-#if !HAVE_EXPLICIT_BZERO
+#if !HAVE_DECL_EXPLICIT_BZERO
/*
* Pointer to memset is volatile so that compiler must de-reference
* the pointer and can't assume that it points to any function in
if (!(*p >= '0' && *p <= '9') &&
!(*p >= 'a' && *p <= 'z') &&
!(*p >= 'A' && *p <= 'Z') &&
- !(*p == '-' || *p == '_' || *p == '+' || *p == '/'))
+ !IN_SET(*p, '-', '_', '+', '/'))
return false;
if (*p == '/') {
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;
if (!(*i >= 'a' && *i <= 'z') &&
!(*i >= 'A' && *i <= 'Z') &&
!(*i >= '0' && *i <= '9') &&
- *i != '_' &&
- *i != '-')
+ !IN_SET(*i, '_', '-'))
return false;
}
'\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);
}
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;
assert(path);
assert(acc);
- assert(type == 'b' || type == 'c');
+ assert(IN_SET(type, 'b', 'c'));
f = fopen("/proc/devices", "re");
if (!f)
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;
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;
(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) {
* 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);
#include <string.h>
#include <unistd.h>
-#if HAVE_AUDIT
+#ifdef HAVE_AUDIT
#include <libaudit.h>
#endif
#include "update-utmp.h"
typedef struct Context {
sd_bus *bus;
-#if HAVE_AUDIT
+#ifdef HAVE_AUDIT
int audit_fd;
#endif
} Context;
/* We finished start-up, so let's write the utmp
* record and send the audit msg */
-#if HAVE_AUDIT
+#ifdef HAVE_AUDIT
if (c->audit_fd >= 0)
if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_BOOT, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
errno != EPERM) {
/* We started shut-down, so let's write the utmp
* record and send the audit msg */
-#if HAVE_AUDIT
+#ifdef HAVE_AUDIT
if (c->audit_fd >= 0)
if (audit_log_user_comm_message(c->audit_fd, AUDIT_SYSTEM_SHUTDOWN, "", "systemd-update-utmp", NULL, NULL, NULL, 1) < 0 &&
errno != EPERM) {
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;
if (previous == runlevel)
return 0;
-#if HAVE_AUDIT
+#ifdef HAVE_AUDIT
if (c->audit_fd >= 0) {
_cleanup_free_ char *s = NULL;
#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;
}
void update_utmp(int argc, char* argv[], sd_bus *bus) {
#endif // 0
Context c = {
-#if HAVE_AUDIT
+#ifdef HAVE_AUDIT
.audit_fd = -1
#endif
};
assert(bus);
#endif // 0
-#if HAVE_AUDIT
+#ifdef HAVE_AUDIT
/* 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
#if 0 /// UNNEEDED by elogind
else if (streq(argv[1], "shutdown"))
(void)on_shutdown(&c);
#endif // 0
-#if HAVE_AUDIT
+#ifdef HAVE_AUDIT
if (c.audit_fd >= 0)
audit_close(c.audit_fd);
#endif