Various preparatory changes from #37344 (#37348)

This commit is contained in:
Daan De Meyer
2025-05-06 11:23:15 +02:00
committed by GitHub
94 changed files with 362 additions and 253 deletions
+1
View File
@@ -8,6 +8,7 @@
#include "log.h"
#include "main-func.h"
#include "pretty-print.h"
#include "string-util.h"
static bool arg_verbose = false;
+1
View File
@@ -7,6 +7,7 @@
#include "sd-device.h"
#include "alloc-util.h"
#include "argv-util.h"
#include "device-util.h"
#include "escape.h"
#include "fileio.h"
+1
View File
@@ -16,6 +16,7 @@
#include "fileio.h"
#include "log.h"
#include "string-table.h"
#include "string-util.h"
#include "utf8.h"
#if defined(__x86_64__)
+3 -2
View File
@@ -2,9 +2,10 @@
#pragma once
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "macro.h"
/*
* MAX_ERRNO is defined as 4095 in linux/err.h
* We use the same value here.
@@ -16,7 +17,7 @@ static inline const char* errno_to_name(int id) {
if (id == 0) /* To stay in line with our own impl */
return NULL;
return strerrorname_np(abs(id));
return strerrorname_np(ABS(id));
}
#else
const char* errno_to_name(int id);
+4 -6
View File
@@ -2,7 +2,6 @@
#pragma once
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include "assert-util.h"
@@ -16,7 +15,7 @@
* https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks
*
* Note that we use the GNU variant of strerror_r() here. */
#define STRERROR(errnum) strerror_r(abs(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
#define STRERROR(errnum) strerror_r(ABS(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
/* A helper to print an error message or message for functions that return 0 on EOF.
* Note that we can't use ({ … }) to define a temporary variable, so errnum is
@@ -41,7 +40,7 @@ static inline void _reset_errno_(int *saved_errno) {
#define LOCAL_ERRNO(value) \
PROTECT_ERRNO; \
errno = abs(value)
errno = ABS(value)
static inline int negative_errno(void) {
/* This helper should be used to shut up gcc if you know 'errno' is
@@ -93,15 +92,14 @@ static inline int errno_or_else(int fallback) {
if (errno > 0)
return -errno;
return -abs(fallback);
return -ABS(fallback);
}
/* abs(3) says: Trying to take the absolute value of the most negative integer is not defined. */
#define _DEFINE_ABS_WRAPPER(name) \
static inline bool ERRNO_IS_##name(intmax_t r) { \
if (r == INTMAX_MIN) \
return false; \
return ERRNO_IS_NEG_##name(-imaxabs(r)); \
return ERRNO_IS_NEG_##name(-ABS(r)); \
}
assert_cc(INT_MAX <= INTMAX_MAX);
+35 -43
View File
@@ -138,11 +138,6 @@ struct hashmap_debug_info {
LIST_FIELDS(struct hashmap_debug_info, debug_list);
unsigned max_entries; /* high watermark of n_entries */
/* who allocated this hashmap */
int line;
const char *file;
const char *func;
/* fields to detect modification while iterating */
unsigned put_count; /* counts puts into the hashmap */
unsigned rem_count; /* counts removals from hashmap */
@@ -778,7 +773,7 @@ static void shared_hash_key_initialize(void) {
random_bytes(shared_hash_key, sizeof(shared_hash_key));
}
static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type) {
HashmapBase *h;
const struct hashmap_type_info *hi = &hashmap_type_info[type];
@@ -803,9 +798,6 @@ static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enu
assert_se(pthread_once(&once, shared_hash_key_initialize) == 0);
#if ENABLE_DEBUG_HASHMAP
h->debug.func = func;
h->debug.file = file;
h->debug.line = line;
assert_se(pthread_mutex_lock(&hashmap_debug_list_mutex) == 0);
LIST_PREPEND(debug_list, hashmap_debug_list, &h->debug);
assert_se(pthread_mutex_unlock(&hashmap_debug_list_mutex) == 0);
@@ -814,20 +806,20 @@ static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enu
return h;
}
Hashmap *_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
return (Hashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS);
Hashmap *hashmap_new(const struct hash_ops *hash_ops) {
return (Hashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_PLAIN);
}
OrderedHashmap *_ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
return (OrderedHashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS);
OrderedHashmap *ordered_hashmap_new(const struct hash_ops *hash_ops) {
return (OrderedHashmap*) hashmap_base_new(hash_ops, HASHMAP_TYPE_ORDERED);
}
Set *_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
return (Set*) hashmap_base_new(hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS);
Set *set_new(const struct hash_ops *hash_ops) {
return (Set*) hashmap_base_new(hash_ops, HASHMAP_TYPE_SET);
}
static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops *hash_ops,
enum HashmapType type HASHMAP_DEBUG_PARAMS) {
enum HashmapType type) {
HashmapBase *q;
assert(h);
@@ -835,7 +827,7 @@ static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops
if (*h)
return 0;
q = hashmap_base_new(hash_ops, type HASHMAP_DEBUG_PASS_ARGS);
q = hashmap_base_new(hash_ops, type);
if (!q)
return -ENOMEM;
@@ -843,52 +835,52 @@ static int hashmap_base_ensure_allocated(HashmapBase **h, const struct hash_ops
return 1;
}
int _hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_PLAIN HASHMAP_DEBUG_PASS_ARGS);
int hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops) {
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_PLAIN);
}
int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_ORDERED HASHMAP_DEBUG_PASS_ARGS);
int ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops) {
return hashmap_base_ensure_allocated((HashmapBase**)h, hash_ops, HASHMAP_TYPE_ORDERED);
}
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS) {
return hashmap_base_ensure_allocated((HashmapBase**)s, hash_ops, HASHMAP_TYPE_SET HASHMAP_DEBUG_PASS_ARGS);
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops) {
return hashmap_base_ensure_allocated((HashmapBase**)s, hash_ops, HASHMAP_TYPE_SET);
}
int _hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) {
int hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) {
int r;
r = _hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
r = hashmap_ensure_allocated(h, hash_ops);
if (r < 0)
return r;
return hashmap_put(*h, key, value);
}
int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) {
int ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) {
int r;
r = _ordered_hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
r = ordered_hashmap_ensure_allocated(h, hash_ops);
if (r < 0)
return r;
return ordered_hashmap_put(*h, key, value);
}
int _ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) {
int ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) {
int r;
r = _ordered_hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
r = ordered_hashmap_ensure_allocated(h, hash_ops);
if (r < 0)
return r;
return ordered_hashmap_replace(*h, key, value);
}
int _hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS) {
int hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value) {
int r;
r = _hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
r = hashmap_ensure_allocated(h, hash_ops);
if (r < 0)
return r;
@@ -1290,20 +1282,20 @@ int set_put(Set *s, const void *key) {
return hashmap_put_boldly(s, hash, &swap, true);
}
int _set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key HASHMAP_DEBUG_PARAMS) {
int set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key) {
int r;
r = _set_ensure_allocated(s, hash_ops HASHMAP_DEBUG_PASS_ARGS);
r = _set_ensure_allocated(s, hash_ops);
if (r < 0)
return r;
return set_put(*s, key);
}
int _set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key HASHMAP_DEBUG_PARAMS) {
int set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key) {
int r;
r = _set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_PASS_ARGS);
r = set_ensure_put(s, hash_ops, key);
if (r <= 0) {
if (hash_ops && hash_ops->free_key)
hash_ops->free_key(key);
@@ -1754,13 +1746,13 @@ int _hashmap_move_one(HashmapBase *h, HashmapBase *other, const void *key) {
return 0;
}
HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) {
HashmapBase* _hashmap_copy(HashmapBase *h) {
HashmapBase *copy;
int r;
assert(h);
copy = hashmap_base_new(h->hash_ops, h->type HASHMAP_DEBUG_PASS_ARGS);
copy = hashmap_base_new(h->hash_ops, h->type);
if (!copy)
return NULL;
@@ -1850,10 +1842,10 @@ int set_consume(Set *s, void *value) {
return r;
}
int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v HASHMAP_DEBUG_PARAMS) {
int hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v) {
int r;
r = _hashmap_ensure_allocated(h, hash_ops HASHMAP_DEBUG_PASS_ARGS);
r = hashmap_ensure_allocated(h, hash_ops);
if (r < 0)
return r;
@@ -1884,14 +1876,14 @@ int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const
return r;
}
int _set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n HASHMAP_DEBUG_PARAMS) {
int set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n) {
char *c;
int r;
assert(s);
assert(p);
r = _set_ensure_allocated(s, hash_ops HASHMAP_DEBUG_PASS_ARGS);
r = _set_ensure_allocated(s, hash_ops);
if (r < 0)
return r;
@@ -1908,13 +1900,13 @@ int _set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *
return set_consume(*s, c);
}
int _set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l HASHMAP_DEBUG_PARAMS) {
int set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l) {
int n = 0, r;
assert(s);
STRV_FOREACH(i, l) {
r = _set_put_strndup_full(s, hash_ops, *i, SIZE_MAX HASHMAP_DEBUG_PASS_ARGS);
r = set_put_strndup_full(s, hash_ops, *i, SIZE_MAX);
if (r < 0)
return r;
+19 -34
View File
@@ -73,20 +73,8 @@ typedef struct {
(Hashmap*)(h), \
(void)0)
#if ENABLE_DEBUG_HASHMAP
# define HASHMAP_DEBUG_PARAMS , const char *func, const char *file, int line
# define HASHMAP_DEBUG_SRC_ARGS , __func__, PROJECT_FILE, __LINE__
# define HASHMAP_DEBUG_PASS_ARGS , func, file, line
#else
# define HASHMAP_DEBUG_PARAMS
# define HASHMAP_DEBUG_SRC_ARGS
# define HASHMAP_DEBUG_PASS_ARGS
#endif
Hashmap* _hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
OrderedHashmap* _ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
#define hashmap_new(ops) _hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS)
#define ordered_hashmap_new(ops) _ordered_hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS)
Hashmap* hashmap_new(const struct hash_ops *hash_ops);
OrderedHashmap* ordered_hashmap_new(const struct hash_ops *hash_ops);
#define hashmap_free_and_replace(a, b) \
free_and_replace_full(a, b, hashmap_free)
@@ -104,25 +92,21 @@ static inline OrderedHashmap* ordered_hashmap_free(OrderedHashmap *h) {
IteratedCache* iterated_cache_free(IteratedCache *cache);
int iterated_cache_get(IteratedCache *cache, const void ***res_keys, const void ***res_values, unsigned *res_n_entries);
HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS);
#define hashmap_copy(h) ((Hashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS))
#define ordered_hashmap_copy(h) ((OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h) HASHMAP_DEBUG_SRC_ARGS))
HashmapBase* _hashmap_copy(HashmapBase *h);
static inline Hashmap* hashmap_copy(Hashmap *h) {
return (Hashmap*) _hashmap_copy(HASHMAP_BASE(h));
}
static inline OrderedHashmap* ordered_hashmap_copy(OrderedHashmap *h) {
return (OrderedHashmap*) _hashmap_copy(HASHMAP_BASE(h));
}
int _hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
int _hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS);
int _ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
int _hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS);
int hashmap_ensure_allocated(Hashmap **h, const struct hash_ops *hash_ops);
int hashmap_ensure_put(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value);
int ordered_hashmap_ensure_allocated(OrderedHashmap **h, const struct hash_ops *hash_ops);
int hashmap_ensure_replace(Hashmap **h, const struct hash_ops *hash_ops, const void *key, void *value);
#define hashmap_ensure_allocated(h, ops) _hashmap_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
#define hashmap_ensure_put(s, ops, key, value) _hashmap_ensure_put(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS)
#define ordered_hashmap_ensure_allocated(h, ops) _ordered_hashmap_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
#define hashmap_ensure_replace(s, ops, key, value) _hashmap_ensure_replace(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS)
int _ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS);
#define ordered_hashmap_ensure_put(s, ops, key, value) _ordered_hashmap_ensure_put(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS)
int _ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value HASHMAP_DEBUG_PARAMS);
#define ordered_hashmap_ensure_replace(s, ops, key, value) _ordered_hashmap_ensure_replace(s, ops, key, value HASHMAP_DEBUG_SRC_ARGS)
int ordered_hashmap_ensure_put(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value);
int ordered_hashmap_ensure_replace(OrderedHashmap **h, const struct hash_ops *hash_ops, const void *key, void *value);
IteratedCache* _hashmap_iterated_cache_new(HashmapBase *h);
static inline IteratedCache* hashmap_iterated_cache_new(Hashmap *h) {
@@ -137,9 +121,10 @@ static inline int ordered_hashmap_put(OrderedHashmap *h, const void *key, void *
return hashmap_put(PLAIN_HASHMAP(h), key, value);
}
int _hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v HASHMAP_DEBUG_PARAMS);
#define hashmap_put_strdup_full(h, hash_ops, k, v) _hashmap_put_strdup_full(h, hash_ops, k, v HASHMAP_DEBUG_SRC_ARGS)
#define hashmap_put_strdup(h, k, v) hashmap_put_strdup_full(h, &string_hash_ops_free_free, k, v)
int hashmap_put_strdup_full(Hashmap **h, const struct hash_ops *hash_ops, const char *k, const char *v);
static inline int hashmap_put_strdup(Hashmap **h, const char *k, const char *v) {
return hashmap_put_strdup_full(h, &string_hash_ops_free_free, k, v);
}
int hashmap_update(Hashmap *h, const void *key, void *value);
static inline int ordered_hashmap_update(OrderedHashmap *h, const void *key, void *value) {
+2 -2
View File
@@ -33,9 +33,9 @@ typedef enum LogTarget{
#define LOG_NULL (LOG_EMERG - 1)
assert_cc(LOG_NULL == -1);
#define SYNTHETIC_ERRNO(num) (abs(num) | (1 << 30))
#define SYNTHETIC_ERRNO(num) (ABS(num) | (1 << 30))
#define IS_SYNTHETIC_ERRNO(val) (((val) >> 30) == 1)
#define ERRNO_VALUE(val) (abs(val) & ~(1 << 30))
#define ERRNO_VALUE(val) (ABS(val) & ~(1 << 30))
/* The callback function to be invoked when syntax warnings are seen
* in the unit files. */
+1 -1
View File
@@ -105,7 +105,7 @@ static inline size_t GREEDY_ALLOC_ROUND_UP(size_t l) {
#define return_with_errno(r, err) \
do { \
errno = abs(err); \
errno = ABS(err); \
return r; \
} while (false)
+7 -1
View File
@@ -244,7 +244,13 @@ filesystem_includes = files(
)
check_filesystems = find_program('check-filesystems.sh')
r = run_command([check_filesystems, cpp, files('filesystems-gperf.gperf')] + filesystem_includes, check: false)
r = run_command(
[
'env', '--chdir', meson.project_build_root(),
check_filesystems, cpp, files('filesystems-gperf.gperf')
] + filesystem_includes,
check: false,
)
if r.returncode() != 0
warning('Unknown filesystems defined in kernel headers:\n\n' + r.stdout())
endif
+8 -8
View File
@@ -4,21 +4,21 @@
#include "ordered-set.h"
#include "strv.h"
int _ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops HASHMAP_DEBUG_PARAMS) {
int ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops) {
if (*s)
return 0;
*s = _ordered_set_new(ops HASHMAP_DEBUG_PASS_ARGS);
*s = ordered_set_new(ops);
if (!*s)
return -ENOMEM;
return 0;
}
int _ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p HASHMAP_DEBUG_PARAMS) {
int ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p) {
int r;
r = _ordered_set_ensure_allocated(s, ops HASHMAP_DEBUG_PASS_ARGS);
r = ordered_set_ensure_allocated(s, ops);
if (r < 0)
return r;
@@ -35,14 +35,14 @@ int ordered_set_consume(OrderedSet *s, void *p) {
return r;
}
int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS) {
int ordered_set_put_strdup(OrderedSet **s, const char *p) {
char *c;
int r;
assert(s);
assert(p);
r = _ordered_set_ensure_allocated(s, &string_hash_ops_free HASHMAP_DEBUG_PASS_ARGS);
r = ordered_set_ensure_allocated(s, &string_hash_ops_free);
if (r < 0)
return r;
@@ -56,11 +56,11 @@ int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS)
return ordered_set_consume(*s, c);
}
int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS) {
int ordered_set_put_strdupv(OrderedSet **s, char **l) {
int n = 0, r;
STRV_FOREACH(i, l) {
r = _ordered_set_put_strdup(s, *i HASHMAP_DEBUG_PASS_ARGS);
r = ordered_set_put_strdup(s, *i);
if (r < 0)
return r;
+6 -11
View File
@@ -7,16 +7,13 @@
typedef struct OrderedSet OrderedSet;
static inline OrderedSet* _ordered_set_new(const struct hash_ops *ops HASHMAP_DEBUG_PARAMS) {
return (OrderedSet*) _ordered_hashmap_new(ops HASHMAP_DEBUG_PASS_ARGS);
static inline OrderedSet* ordered_set_new(const struct hash_ops *ops) {
return (OrderedSet*) ordered_hashmap_new(ops);
}
#define ordered_set_new(ops) _ordered_set_new(ops HASHMAP_DEBUG_SRC_ARGS)
int _ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops HASHMAP_DEBUG_PARAMS);
#define ordered_set_ensure_allocated(s, ops) _ordered_set_ensure_allocated(s, ops HASHMAP_DEBUG_SRC_ARGS)
int ordered_set_ensure_allocated(OrderedSet **s, const struct hash_ops *ops);
int _ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p HASHMAP_DEBUG_PARAMS);
#define ordered_set_ensure_put(s, hash_ops, key) _ordered_set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
int ordered_set_ensure_put(OrderedSet **s, const struct hash_ops *ops, void *p);
static inline void ordered_set_clear(OrderedSet *s) {
return ordered_hashmap_clear((OrderedHashmap*) s);
@@ -71,10 +68,8 @@ static inline int ordered_set_reserve(OrderedSet *s, unsigned entries_add) {
}
int ordered_set_consume(OrderedSet *s, void *p);
int _ordered_set_put_strdup(OrderedSet **s, const char *p HASHMAP_DEBUG_PARAMS);
#define ordered_set_put_strdup(s, p) _ordered_set_put_strdup(s, p HASHMAP_DEBUG_SRC_ARGS)
int _ordered_set_put_strdupv(OrderedSet **s, char **l HASHMAP_DEBUG_PARAMS);
#define ordered_set_put_strdupv(s, l) _ordered_set_put_strdupv(s, l HASHMAP_DEBUG_SRC_ARGS)
int ordered_set_put_strdup(OrderedSet **s, const char *p);
int ordered_set_put_strdupv(OrderedSet **s, char **l);
int ordered_set_put_string_set(OrderedSet **s, OrderedSet *l);
void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
+1
View File
@@ -10,6 +10,7 @@
#include "format-util.h"
#include "log.h"
#include "macro.h"
#include "parse-util.h"
#include "process-util.h"
#include "rlimit-util.h"
#include "string-table.h"
+8 -13
View File
@@ -8,17 +8,16 @@
#define set_free_and_replace(a, b) \
free_and_replace_full(a, b, set_free)
Set* _set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
#define set_new(ops) _set_new(ops HASHMAP_DEBUG_SRC_ARGS)
Set* set_new(const struct hash_ops *hash_ops);
static inline Set* set_free(Set *s) {
return (Set*) _hashmap_free(HASHMAP_BASE(s));
}
#define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(s) HASHMAP_DEBUG_SRC_ARGS))
#define set_copy(s) ((Set*) _hashmap_copy(HASHMAP_BASE(s)))
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
#define set_ensure_allocated(h, ops) _set_ensure_allocated(h, ops HASHMAP_DEBUG_SRC_ARGS)
int _set_ensure_allocated(Set **s, const struct hash_ops *hash_ops);
#define set_ensure_allocated(h, ops) _set_ensure_allocated(h, ops)
int set_put(Set *s, const void *key);
/* no set_update */
@@ -93,22 +92,18 @@ static inline char **set_get_strv(Set *s) {
char** set_to_strv(Set **s);
int _set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key HASHMAP_DEBUG_PARAMS);
#define set_ensure_put(s, hash_ops, key) _set_ensure_put(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
int set_ensure_put(Set **s, const struct hash_ops *hash_ops, const void *key);
int _set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key HASHMAP_DEBUG_PARAMS);
#define set_ensure_consume(s, hash_ops, key) _set_ensure_consume(s, hash_ops, key HASHMAP_DEBUG_SRC_ARGS)
int set_ensure_consume(Set **s, const struct hash_ops *hash_ops, void *key);
int set_consume(Set *s, void *value);
int _set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n HASHMAP_DEBUG_PARAMS);
#define set_put_strndup_full(s, hash_ops, p, n) _set_put_strndup_full(s, hash_ops, p, n HASHMAP_DEBUG_SRC_ARGS)
int set_put_strndup_full(Set **s, const struct hash_ops *hash_ops, const char *p, size_t n);
#define set_put_strdup_full(s, hash_ops, p) set_put_strndup_full(s, hash_ops, p, SIZE_MAX)
#define set_put_strndup(s, p, n) set_put_strndup_full(s, &string_hash_ops_free, p, n)
#define set_put_strdup(s, p) set_put_strndup(s, p, SIZE_MAX)
int _set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l HASHMAP_DEBUG_PARAMS);
#define set_put_strdupv_full(s, hash_ops, l) _set_put_strdupv_full(s, hash_ops, l HASHMAP_DEBUG_SRC_ARGS)
int set_put_strdupv_full(Set **s, const struct hash_ops *hash_ops, char **l );
#define set_put_strdupv(s, l) set_put_strdupv_full(s, &string_hash_ops_free, l)
int set_put_strsplit(Set *s, const char *v, const char *separators, ExtractFlags flags);
+55 -1
View File
@@ -1,9 +1,17 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "parse-util.h"
#include "string-table.h"
#include "string-util.h"
ssize_t string_table_lookup(const char * const *table, size_t len, const char *key) {
const char* string_table_lookup_to_string(const char * const *table, size_t len, ssize_t i) {
if (i < 0 || i >= (ssize_t) len)
return NULL;
return table[i];
}
ssize_t string_table_lookup_from_string(const char * const *table, size_t len, const char *key) {
if (!key)
return -EINVAL;
@@ -13,3 +21,49 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
return -EINVAL;
}
ssize_t string_table_lookup_from_string_with_boolean(const char * const *table, size_t len, const char *key, ssize_t yes) {
if (!key)
return -EINVAL;
int b = parse_boolean(key);
if (b == 0)
return 0;
if (b > 0)
return yes;
return string_table_lookup_from_string(table, len, key);
}
int string_table_lookup_to_string_fallback(const char * const *table, size_t len, ssize_t i, size_t max, char **ret) {
char *s;
if (i < 0 || i > (ssize_t) max)
return -ERANGE;
if (i < (ssize_t) len && table[i]) {
s = strdup(table[i]);
if (!s)
return -ENOMEM;
} else if (asprintf(&s, "%zd", i) < 0)
return -ENOMEM;
*ret = s;
return 0;
}
ssize_t string_table_lookup_from_string_fallback(const char * const *table, size_t len, const char *s, size_t max) {
unsigned u = 0;
if (!s)
return -EINVAL;
ssize_t i = string_table_lookup_from_string(table, len, s);
if (i >= 0)
return i;
if (safe_atou(s, &u) < 0)
return -EINVAL;
if (u > max)
return -EINVAL;
return u;
}
+49 -74
View File
@@ -2,105 +2,80 @@
#pragma once
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/types.h>
#include "macro.h"
#include "parse-util.h"
#include "string-util.h"
ssize_t string_table_lookup(const char * const *table, size_t len, const char *key);
const char* string_table_lookup_to_string(const char * const *table, size_t len, ssize_t i);
ssize_t string_table_lookup_from_string(const char * const *table, size_t len, const char *key);
ssize_t string_table_lookup_from_string_with_boolean(const char * const *table, size_t len, const char *key, ssize_t yes);
int string_table_lookup_to_string_fallback(const char * const *table, size_t len, ssize_t i, size_t max, char **ret);
ssize_t string_table_lookup_from_string_fallback(const char * const *table, size_t len, const char *s, size_t max);
/* For basic lookup tables with strictly enumerated entries */
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
scope const char* name##_to_string(type i) { \
if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \
return NULL; \
return name##_table[i]; \
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \
scope const char* name##_to_string(type i) { \
return string_table_lookup_to_string(name##_table, ELEMENTSOF(name##_table), i); \
}
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \
scope type name##_from_string(const char *s) { \
return (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope) \
scope type name##_from_string(const char *s) { \
return (type) string_table_lookup_from_string(name##_table, ELEMENTSOF(name##_table), s); \
}
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,scope) \
scope type name##_from_string(const char *s) { \
if (!s) \
return -EINVAL; \
int b = parse_boolean(s); \
if (b == 0) \
return (type) 0; \
if (b > 0) \
return yes; \
return (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes, scope) \
scope type name##_from_string(const char *s) { \
return (type) string_table_lookup_from_string_with_boolean(name##_table, ELEMENTSOF(name##_table), s, yes); \
}
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,scope) \
scope int name##_to_string_alloc(type i, char **str) { \
char *s; \
if (i < 0 || i > max) \
return -ERANGE; \
if (i < (type) ELEMENTSOF(name##_table) && name##_table[i]) { \
s = strdup(name##_table[i]); \
if (!s) \
return -ENOMEM; \
} else if (asprintf(&s, "%i", i) < 0) \
return -ENOMEM; \
*str = s; \
return 0; \
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max, scope) \
scope int name##_to_string_alloc(type i, char **ret) { \
return string_table_lookup_to_string_fallback(name##_table, ELEMENTSOF(name##_table), i, max, ret); \
}
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,scope) \
scope type name##_from_string(const char *s) { \
unsigned u = 0; \
type i; \
if (!s) \
return -EINVAL; \
i = (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \
if (i >= 0) \
return i; \
if (safe_atou(s, &u) < 0) \
return -EINVAL; \
if (u > max) \
return -EINVAL; \
return (type) u; \
#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max, scope) \
scope type name##_from_string(const char *s) { \
return (type) string_table_lookup_from_string_fallback(name##_table, ELEMENTSOF(name##_table), s, max); \
}
#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope)
#define _DEFINE_STRING_TABLE_LOOKUP(name, type, scope) \
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope)
#define _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes,scope) \
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,scope)
#define _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes, scope) \
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes, scope)
#define DEFINE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,)
#define DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,)
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,static)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,static)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,static)
#define DEFINE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type,)
#define DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type,)
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type,)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type, static)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, static)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, static)
#define DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes,)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes,static)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,static)
#define DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes,)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes, static)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes, static)
/* For string conversions where numbers are also acceptable */
#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,)
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_FALLBACK(name,type,max) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,)
#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name, type, max) \
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max,) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max,)
#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_FALLBACK(name, type, max) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max,)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max) \
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,static)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,static)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max) \
_DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max, static)
#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max) \
_DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max, static)
#define DUMP_STRING_TABLE(name,type,max) \
#define DUMP_STRING_TABLE(name, type, max) \
({ \
flockfile(stdout); \
for (type _k = 0; _k < (max); _k++) { \
+4 -4
View File
@@ -1126,28 +1126,28 @@ static int string_strv_hashmap_put_internal(Hashmap *h, const char *key, const c
return 1;
}
int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS) {
int string_strv_hashmap_put(Hashmap **h, const char *key, const char *value) {
int r;
assert(h);
assert(key);
assert(value);
r = _hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free HASHMAP_DEBUG_PASS_ARGS);
r = hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free);
if (r < 0)
return r;
return string_strv_hashmap_put_internal(*h, key, value);
}
int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS) {
int string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value) {
int r;
assert(h);
assert(key);
assert(value);
r = _ordered_hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free HASHMAP_DEBUG_PASS_ARGS);
r = ordered_hashmap_ensure_allocated(h, &string_hash_ops_free_strv_free);
if (r < 0)
return r;
+4 -4
View File
@@ -262,10 +262,10 @@ void string_strv_hashmap_remove(Hashmap *h, const char *key, const char *value);
static inline void string_strv_ordered_hashmap_remove(OrderedHashmap *h, const char *key, const char *value) {
string_strv_hashmap_remove(PLAIN_HASHMAP(h), key, value);
}
int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS);
int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value HASHMAP_DEBUG_PARAMS);
#define string_strv_hashmap_put(h, k, v) _string_strv_hashmap_put(h, k, v HASHMAP_DEBUG_SRC_ARGS)
#define string_strv_ordered_hashmap_put(h, k, v) _string_strv_ordered_hashmap_put(h, k, v HASHMAP_DEBUG_SRC_ARGS)
int _string_strv_hashmap_put(Hashmap **h, const char *key, const char *value);
int _string_strv_ordered_hashmap_put(OrderedHashmap **h, const char *key, const char *value);
#define string_strv_hashmap_put(h, k, v) _string_strv_hashmap_put(h, k, v)
#define string_strv_ordered_hashmap_put(h, k, v) _string_strv_ordered_hashmap_put(h, k, v)
int strv_rebreak_lines(char **l, size_t width, char ***ret);
+1 -1
View File
@@ -1785,7 +1785,7 @@ DEFINE_STRING_TABLE_LOOKUP_TO_STRING(timestamp_style, TimestampStyle);
TimestampStyle timestamp_style_from_string(const char *s) {
TimestampStyle t;
t = (TimestampStyle) string_table_lookup(timestamp_style_table, ELEMENTSOF(timestamp_style_table), s);
t = (TimestampStyle) string_table_lookup_from_string(timestamp_style_table, ELEMENTSOF(timestamp_style_table), s);
if (t >= 0)
return t;
if (STRPTR_IN_SET(s, "µs", "μs")) /* accept both µ symbols in unicode, i.e. micro symbol + Greek small letter mu. */
+1
View File
@@ -18,6 +18,7 @@
#include "log.h"
#include "macro.h"
#include "namespace-util.h"
#include "parse-util.h"
#include "process-util.h"
#include "stat-util.h"
#include "string-table.h"
+1
View File
@@ -3,6 +3,7 @@
#include <getopt.h>
#include "sd-bus.h"
#include "sd-daemon.h"
#include "sd-json.h"
#include "alloc-util.h"
+1
View File
@@ -3,6 +3,7 @@
#include "kill.h"
#include "signal-util.h"
#include "string-table.h"
#include "string-util.h"
void kill_context_init(KillContext *c) {
assert(c);
+1
View File
@@ -11,6 +11,7 @@
#include "load-dropin.h"
#include "log.h"
#include "manager.h"
#include "parse-util.h"
#include "process-util.h"
#include "random-util.h"
#include "scope.h"
+2
View File
@@ -23,6 +23,8 @@
#include "missing_magic.h"
#include "pager.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "polkit-agent.h"
#include "pretty-print.h"
#include "process-util.h"
#include "stat-util.h"
@@ -6,6 +6,8 @@
#include <stdbool.h>
#include <stddef.h>
#include "macro.h"
/* crypt_dump() internal indentation magic */
#define CRYPT_DUMP_LINE_SEP "\n\t "
@@ -15,7 +17,7 @@
#define crypt_log(cd, ...) crypt_logf(cd, CRYPT_LOG_NORMAL, __VA_ARGS__)
#define crypt_log_full_errno(cd, e, lvl, ...) ({ \
int _e = abs(e), _s = errno; \
int _e = ABS(e), _s = errno; \
errno = _e; \
crypt_logf(cd, lvl, __VA_ARGS__); \
errno = _s; \
+1
View File
@@ -13,6 +13,7 @@
#include "sd-messages.h"
#include "alloc-util.h"
#include "argv-util.h"
#include "ask-password-api.h"
#include "build.h"
#include "cryptsetup-fido2.h"
+1
View File
@@ -11,6 +11,7 @@
#include "sd-device.h"
#include "architecture.h"
#include "argv-util.h"
#include "blockdev-util.h"
#include "build.h"
#include "chase.h"
+2
View File
@@ -5,9 +5,11 @@
#include <unistd.h>
#include "alloc-util.h"
#include "argv-util.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "chase.h"
#include "creds-util.h"
#include "efi-loader.h"
+7
View File
@@ -176,6 +176,13 @@
UNIQ_T(A, aq) > UNIQ_T(B, bq) ? UNIQ_T(A, aq) : UNIQ_T(B, bq); \
})
#define ABS(a) __ABS(UNIQ, (a))
#define __ABS(aq, a) \
({ \
const typeof(a) UNIQ_T(A, aq) = (a); \
UNIQ_T(A, aq) < 0 ? -UNIQ_T(A, aq) : UNIQ_T(A, aq); \
})
#define IS_UNSIGNED_INTEGER_TYPE(type) \
(__builtin_types_compatible_p(typeof(type), unsigned char) || \
__builtin_types_compatible_p(typeof(type), unsigned short) || \
+1
View File
@@ -11,6 +11,7 @@
#include "blockdev-util.h"
#include "dissect-image.h"
#include "fd-util.h"
#include "log.h"
#include "main-func.h"
#include "mkfs-util.h"
#include "path-util.h"
+1
View File
@@ -28,6 +28,7 @@
#include "missing_magic.h"
#include "missing_mman.h"
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
#include "quota-util.h"
+2
View File
@@ -3,6 +3,8 @@
#include <stddef.h>
#include <sys/mount.h>
#include "sd-daemon.h"
#include "blockdev-util.h"
#include "bus-unit-util.h"
#include "chown-recursive.h"
+1
View File
@@ -15,6 +15,7 @@
#include "bus-get-properties.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "constants.h"
#include "daemon-util.h"
#include "device-private.h"
+1
View File
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "assert-util.h"
#include "import-compress.h"
#include "log.h"
#include "string-table.h"
+1
View File
@@ -12,6 +12,7 @@
#include "bus-get-properties.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "common-signal.h"
#include "constants.h"
#include "daemon-util.h"
+1
View File
@@ -5,6 +5,7 @@
#include <sys/stat.h>
#include "alloc-util.h"
#include "argv-util.h"
#include "cryptsetup-util.h"
#include "fileio.h"
#include "hexdecoct.h"
+1
View File
@@ -20,6 +20,7 @@
#include "microhttpd-util.h"
#include "parse-argument.h"
#include "parse-helpers.h"
#include "parse-util.h"
#include "pretty-print.h"
#include "process-util.h"
#include "rlimit-util.h"
+1
View File
@@ -19,6 +19,7 @@
#include "mount-util.h"
#include "mountpoint-util.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "pretty-print.h"
#include "static-destruct.h"
#include "string-table.h"
+1
View File
@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <sys/utsname.h>
#include "argv-util.h"
#include "boot-entry.h"
#include "build.h"
#include "chase.h"
+1
View File
@@ -30,6 +30,7 @@
#include "lookup3.h"
#include "memory-util.h"
#include "missing_fs.h"
#include "parse-util.h"
#include "path-util.h"
#include "prioq.h"
#include "random-util.h"
+1 -1
View File
@@ -149,7 +149,7 @@ int journal_add_matchf(sd_journal *j, const char *format, ...) _printf_(2, 3);
/* All errors that we might encounter while extracting a field that are not real errors,
* but only mean that the field is too large or we don't support the compression. */
static inline bool JOURNAL_ERRNO_IS_UNAVAILABLE_FIELD(int r) {
return IN_SET(abs(r),
return IN_SET(ABS(r),
ENOBUFS, /* Field or decompressed field too large */
E2BIG, /* Field too large for pointer width */
EPROTONOSUPPORT); /* Unsupported compression */
+1
View File
@@ -30,6 +30,7 @@
#include "memory-util.h"
#include "memstream-util.h"
#include "ordered-set.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
#include "ratelimit.h"
+1
View File
@@ -14,6 +14,7 @@
#include "bus-message.h"
#include "bus-polkit.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "constants.h"
#include "daemon-util.h"
#include "kbd-util.h"
+1
View File
@@ -19,6 +19,7 @@
#include "log.h"
#include "main-func.h"
#include "pager.h"
#include "polkit-agent.h"
#include "pretty-print.h"
#include "process-util.h"
#include "signal-util.h"
+1
View File
@@ -14,6 +14,7 @@
#include "fs-util.h"
#include "label-util.h"
#include "limits-util.h"
#include "log.h"
#include "main-func.h"
#include "missing_magic.h"
#include "missing_syscall.h"
+1
View File
@@ -38,6 +38,7 @@
#include "hostname-util.h"
#include "import-util.h"
#include "in-addr-util.h"
#include "label-util.h"
#include "locale-util.h"
#include "log.h"
#include "logs-show.h"
+1
View File
@@ -11,6 +11,7 @@
#include "bus-locator.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "cgroup-util.h"
#include "common-signal.h"
#include "daemon-util.h"
+1
View File
@@ -16,6 +16,7 @@
#include "main-func.h"
#include "memstream-util.h"
#include "openssl-util.h"
#include "pager.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "pe-binary.h"
+1
View File
@@ -8,6 +8,7 @@
#include "build.h"
#include "conf-files.h"
#include "constants.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "log.h"
+1
View File
@@ -5,6 +5,7 @@
#include "sd-bus.h"
#include "sd-device.h"
#include "argv-util.h"
#include "build.h"
#include "bus-error.h"
#include "bus-locator.h"
+1
View File
@@ -15,6 +15,7 @@
#include "netlink-util.h"
#include "networkd-manager.h"
#include "parse-helpers.h"
#include "parse-util.h"
#include "socket-util.h"
#include "string-table.h"
#include "string-util.h"
+1
View File
@@ -61,6 +61,7 @@
#include "networkd-state-file.h"
#include "networkd-sysctl.h"
#include "networkd-wifi.h"
#include "parse-util.h"
#include "set.h"
#include "socket-util.h"
#include "stdio-util.h"
+1
View File
@@ -24,6 +24,7 @@
#include "parse-util.h"
#include "pretty-print.h"
#include "process-util.h"
#include "signal-util.h"
#include "socket-util.h"
#include "string-util.h"
#include "strv.h"
+4
View File
@@ -16,6 +16,10 @@
#include <termios.h>
#include <unistd.h>
#if HAVE_SELINUX
#include <selinux/selinux.h>
#endif
#include "sd-bus.h"
#include "sd-daemon.h"
#include "sd-id128.h"
+1
View File
@@ -15,6 +15,7 @@
#include "sd-netlink.h"
#include "sd-varlink.h"
#include "argv-util.h"
#include "bus-polkit.h"
#include "env-util.h"
#include "fd-util.h"
+1
View File
@@ -9,6 +9,7 @@
#include "bus-message-util.h"
#include "log.h"
#include "main-func.h"
#include "pager.h"
#include "pretty-print.h"
#include "terminal-util.h"
#include "verbs.h"
+1
View File
@@ -9,6 +9,7 @@
#include "alloc-util.h"
#include "build.h"
#include "errno-util.h"
#include "log.h"
#include "macro.h"
#include "main-func.h"
+1
View File
@@ -8,6 +8,7 @@
#include "alloc-util.h"
#include "bus-log-control-api.h"
#include "bus-polkit.h"
#include "bus-util.h"
#include "common-signal.h"
#include "constants.h"
#include "daemon-util.h"
+1
View File
@@ -12,6 +12,7 @@
#include "pretty-print.h"
#include "process-util.h"
#include "ptyfwd.h"
#include "signal-util.h"
#include "strv.h"
static bool arg_quiet = false;
+1
View File
@@ -62,6 +62,7 @@
#include "openssl-util.h"
#include "parse-argument.h"
#include "parse-helpers.h"
#include "parse-util.h"
#include "pretty-print.h"
#include "proc-cmdline.h"
#include "process-util.h"
+4
View File
@@ -5,18 +5,21 @@
#include <net/if.h>
#include "sd-bus.h"
#include "sd-daemon.h"
#include "sd-json.h"
#include "sd-netlink.h"
#include "sd-varlink.h"
#include "af-list.h"
#include "alloc-util.h"
#include "argv-util.h"
#include "build.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "bus-map-properties.h"
#include "bus-message-util.h"
#include "bus-util.h"
#include "dns-domain.h"
#include "errno-list.h"
#include "escape.h"
@@ -31,6 +34,7 @@
#include "pager.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "polkit-agent.h"
#include "pretty-print.h"
#include "process-util.h"
#include "resolvconf-compat.h"
+1
View File
@@ -12,6 +12,7 @@
#include "alloc-util.h"
#include "device-util.h"
#include "errno-util.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
+2
View File
@@ -7,10 +7,12 @@
#include <sys/types.h>
#include "sd-bus.h"
#include "sd-daemon.h"
#include "sd-event.h"
#include "sd-json.h"
#include "alloc-util.h"
#include "argv-util.h"
#include "ask-password-agent.h"
#include "build.h"
#include "bus-error.h"
+1
View File
@@ -38,6 +38,7 @@
#include "missing_syscall.h"
#include "mkdir-label.h"
#include "nulstr-util.h"
#include "parse-util.h"
#include "path-lookup.h"
#include "plymouth-util.h"
#include "process-util.h"
+1
View File
@@ -15,6 +15,7 @@
#include "fileio.h"
#include "find-esp.h"
#include "log.h"
#include "parse-util.h"
#include "path-util.h"
#include "pe-binary.h"
#include "pretty-print.h"
+1
View File
@@ -12,6 +12,7 @@
#include "fd-util.h"
#include "memory-util.h"
#include "missing_syscall.h"
#include "parse-util.h"
#include "path-util.h"
#include "serialize.h"
#include "string-table.h"
+2
View File
@@ -6,8 +6,10 @@
#include "extract-word.h"
#include "fileio.h"
#include "log.h"
#include "parse-util.h"
#include "stdio-util.h"
#include "string-table.h"
#include "string-util.h"
#include "unaligned.h"
#include "virt.h"
+1
View File
@@ -13,6 +13,7 @@
#include "log.h"
#include "macro-fundamental.h"
#include "memory-util.h"
#include "parse-util.h"
#include "socket-util.h"
#include "string-table.h"
#include "strv.h"
+1 -1
View File
@@ -505,7 +505,7 @@ ExecCommandFlags exec_command_flags_from_string(const char *s) {
if (streq(s, "ambient")) /* Compatibility with ambient hack, removed in v258, map to no bits set */
return 0;
idx = string_table_lookup(exec_command_strings, ELEMENTSOF(exec_command_strings), s);
idx = string_table_lookup_from_string(exec_command_strings, ELEMENTSOF(exec_command_strings), s);
if (idx < 0)
return _EXEC_COMMAND_FLAGS_INVALID;
+1
View File
@@ -22,6 +22,7 @@
#include "macro.h"
#include "netlink-internal.h"
#include "netlink-util.h"
#include "parse-util.h"
#include "socket-util.h"
#include "string-table.h"
#include "time-util.h"
+1
View File
@@ -4,6 +4,7 @@
#include <unistd.h>
#include "alloc-util.h"
#include "argv-util.h"
#include "cgroup-util.h"
#include "dropin.h"
#include "escape.h"
+50
View File
@@ -0,0 +1,50 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#if HAVE_VALGRIND_VALGRIND_H
# include <valgrind/valgrind.h>
#endif
#include "sd-daemon.h"
#include "argv-util.h"
#include "ask-password-agent.h"
#include "hashmap.h"
#include "main-func.h"
#include "pager.h"
#include "polkit-agent.h"
#include "selinux-util.h"
#include "signal-util.h"
void main_prepare(int argc, char *argv[]) {
assert_se(argc > 0 && !isempty(argv[0]));
save_argc_argv(argc, argv);
}
void main_finalize(int r, int exit_status) {
if (r < 0)
(void) sd_notifyf(0, "ERRNO=%i", -r);
(void) sd_notifyf(0, "EXIT_STATUS=%i", exit_status);
ask_password_agent_close();
polkit_agent_close();
pager_close();
mac_selinux_finish();
}
int raise_or_exit_status(int ret) {
if (ret < 0)
return EXIT_FAILURE;
if (ret == 0)
return EXIT_SUCCESS;
if (!SIGNAL_VALID(ret))
return EXIT_FAILURE;
#if HAVE_VALGRIND_VALGRIND_H
/* If raise() below succeeds, the destructor cleanup_pools() in hashmap.c will never called. */
if (RUNNING_ON_VALGRIND)
hashmap_trim_pools();
#endif
(void) raise(ret);
/* exit with failure if raise() does not immediately abort the program. */
return EXIT_FAILURE;
}
+7 -41
View File
@@ -3,36 +3,19 @@
#include <stdlib.h>
#if HAVE_VALGRIND_VALGRIND_H
# include <valgrind/valgrind.h>
#endif
#include "sd-daemon.h"
#include "argv-util.h"
#include "ask-password-agent.h"
#include "hashmap.h"
#include "pager.h"
#include "polkit-agent.h"
#include "selinux-util.h"
#include "signal-util.h"
#include "static-destruct.h"
void main_prepare(int argc, char *argv[]);
void main_finalize(int r, int exit_status);
#define _DEFINE_MAIN_FUNCTION(intro, impl, result_to_exit_status, result_to_return_value) \
int main(int argc, char *argv[]) { \
int r; \
assert_se(argc > 0 && !isempty(argv[0])); \
save_argc_argv(argc, argv); \
main_prepare(argc, argv); \
intro; \
r = impl; \
if (r < 0) \
(void) sd_notifyf(0, "ERRNO=%i", -r); \
(void) sd_notifyf(0, "EXIT_STATUS=%i", \
result_to_exit_status(r)); \
ask_password_agent_close(); \
polkit_agent_close(); \
pager_close(); \
mac_selinux_finish(); \
main_finalize(r, result_to_exit_status(r)); \
static_destruct(); \
return result_to_return_value(r); \
}
@@ -56,24 +39,7 @@ static inline int exit_failure_if_nonzero(int result) {
#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \
_DEFINE_MAIN_FUNCTION(,impl(argc, argv), exit_failure_if_nonzero, exit_failure_if_nonzero)
static inline int raise_or_exit_status(int ret) {
if (ret < 0)
return EXIT_FAILURE;
if (ret == 0)
return EXIT_SUCCESS;
if (!SIGNAL_VALID(ret))
return EXIT_FAILURE;
#if HAVE_VALGRIND_VALGRIND_H
/* If raise() below succeeds, the destructor cleanup_pools() in hashmap.c will never called. */
if (RUNNING_ON_VALGRIND)
hashmap_trim_pools();
#endif
(void) raise(ret);
/* exit with failure if raise() does not immediately abort the program. */
return EXIT_FAILURE;
}
int raise_or_exit_status(int ret);
/* Negative return values from impl are mapped to EXIT_FAILURE, zero is mapped to EXIT_SUCCESS,
* and raise if a positive signal is returned from impl. */
+1
View File
@@ -119,6 +119,7 @@ shared_sources = files(
'machine-id-setup.c',
'machine-pool.c',
'macvlan-util.c',
'main-func.c',
'mkdir-label.c',
'mkfs-util.c',
'module-util.c',
+1
View File
@@ -12,6 +12,7 @@
#include "macro.h"
#include "missing_syscall.h"
#include "numa-util.h"
#include "parse-util.h"
#include "stdio-util.h"
#include "string-table.h"
+1
View File
@@ -3,6 +3,7 @@
#include "format-table.h"
#include "log.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "signal-util.h"
#include "stdio-util.h"
+1 -1
View File
@@ -539,7 +539,7 @@ int uki_hash(int fd,
if (!n)
return log_oom_debug();
i = string_table_lookup(unified_sections, _UNIFIED_SECTION_MAX, n);
i = string_table_lookup_from_string(unified_sections, _UNIFIED_SECTION_MAX, n);
if (i < 0)
continue;
+1 -1
View File
@@ -10,5 +10,5 @@ int plymouth_send_raw(const void *raw, size_t size, int flags);
int plymouth_send_msg(const char *text, bool pause_spinner);
static inline bool ERRNO_IS_NO_PLYMOUTH(int r) {
return IN_SET(abs(r), EAGAIN, ENOENT) || ERRNO_IS_DISCONNECT(r);
return IN_SET(ABS(r), EAGAIN, ENOENT) || ERRNO_IS_DISCONNECT(r);
}
+1 -1
View File
@@ -40,7 +40,7 @@ static inline void log_set_assert_return_is_criticalp(bool *p) {
#define ASSERT_RETURN_EXPECTED_SE(expr) ASSERT_RETURN_EXPECTED(assert_se(expr));
static inline bool manager_errno_skip_test(int r) {
return IN_SET(abs(r),
return IN_SET(ABS(r),
EPERM,
EACCES,
EADDRINUSE,
+1
View File
@@ -11,6 +11,7 @@
#include "sd-bus.h"
#include "sd-varlink.h"
#include "argv-util.h"
#include "blockdev-util.h"
#include "build.h"
#include "bus-error.h"
+2
View File
@@ -6,6 +6,7 @@
#include "sd-daemon.h"
#include "argv-util.h"
#include "build.h"
#include "bus-util.h"
#include "capsule-util.h"
@@ -17,6 +18,7 @@
#include "output-mode.h"
#include "pager.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
#include "process-util.h"
+2
View File
@@ -3,6 +3,8 @@
#include <getopt.h>
#include <unistd.h>
#include "sd-daemon.h"
#include "build.h"
#include "chase.h"
#include "conf-files.h"
+1
View File
@@ -26,6 +26,7 @@
#include "mkdir-label.h"
#include "notify-recv.h"
#include "os-util.h"
#include "parse-util.h"
#include "process-util.h"
#include "service-util.h"
#include "signal-util.h"
+1
View File
@@ -24,6 +24,7 @@
#include "os-util.h"
#include "pager.h"
#include "path-util.h"
#include "polkit-agent.h"
#include "pretty-print.h"
#include "strv.h"
#include "sysupdate-update-set-flags.h"
+1
View File
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "bitfield.h"
#include "errno-util.h"
#include "fd-util.h"
#include "format-util.h"
#include "log.h"
+1
View File
@@ -20,6 +20,7 @@
#include "bus-message-util.h"
#include "bus-polkit.h"
#include "bus-unit-util.h"
#include "bus-util.h"
#include "clock-util.h"
#include "conf-files.h"
#include "constants.h"
+1
View File
@@ -13,6 +13,7 @@
#include "sd-event.h"
#include "errno-util.h"
#include "fd-util.h"
#include "inotify-util.h"
#include "main-func.h"
+1
View File
@@ -6,6 +6,7 @@
#include <stdio.h>
#include "alloc-util.h"
#include "argv-util.h"
#include "main-func.h"
#include "pretty-print.h"
#include "process-util.h"
+2
View File
@@ -6,7 +6,9 @@
#include "sd-daemon.h"
#include "sd-varlink.h"
#include "argv-util.h"
#include "env-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "group-record.h"
#include "io-util.h"
+1
View File
@@ -2,6 +2,7 @@
#include <getopt.h>
#include "sd-daemon.h"
#include "sd-varlink.h"
#include "build.h"
+1
View File
@@ -7,6 +7,7 @@
#include "sd-device.h"
#include "alloc-util.h"
#include "argv-util.h"
#include "cryptsetup-util.h"
#include "fileio.h"
#include "fstab-util.h"
+1
View File
@@ -20,6 +20,7 @@
#include "build.h"
#include "bus-internal.h"
#include "bus-locator.h"
#include "bus-util.h"
#include "bus-wait-for-jobs.h"
#include "capability-util.h"
#include "chase.h"
+1
View File
@@ -7,6 +7,7 @@
#include "chase.h"
#include "devnum-util.h"
#include "escape.h"
#include "log.h"
#include "main-func.h"
#include "mkdir.h"
#include "mount-util.h"
+1 -1
View File
@@ -32,7 +32,7 @@ class sd_dump_hashmaps(gdb.Command):
t = ["plain", "ordered", "set"][int(h["type"])]
print(f'{t}, {h["hash_ops"]}, {bool(h["has_indirect"])}, {n_entries}, {d["max_entries"]}, {n_buckets}, {d["func"].string()}, {d["file"].string()}:{d["line"]}')
print(f'{t}, {h["hash_ops"]}, {bool(h["has_indirect"])}, {n_entries}, {d["max_entries"]}, {n_buckets}')
if arg != "" and n_entries > 0:
dib_raw_addr = storage_ptr + hashmap_type_info[h["type"]]["entry_size"] * n_buckets