mirror of
https://github.com/systemd/systemd
synced 2026-03-28 09:44:50 +01:00
Compare commits
4 Commits
53405835a2
...
940e26c19c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
940e26c19c | ||
|
|
381d3cdca0 | ||
|
|
5830250991 | ||
|
|
1a2e23b887 |
@ -23,7 +23,7 @@
|
|||||||
#include "virt.h"
|
#include "virt.h"
|
||||||
|
|
||||||
static int parse_chid_type(const char *s, size_t *ret) {
|
static int parse_chid_type(const char *s, size_t *ret) {
|
||||||
char *e;
|
const char *e;
|
||||||
unsigned u;
|
unsigned u;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
|||||||
@ -163,9 +163,7 @@ int proc_cmdline_strv(char ***ret) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *mangle_word(const char *word, ProcCmdlineFlags flags) {
|
static char *mangle_word(const char *word, ProcCmdlineFlags flags) {
|
||||||
char *c;
|
char *c = (char*) startswith(word, "rd.");
|
||||||
|
|
||||||
c = startswith(word, "rd.");
|
|
||||||
if (c) {
|
if (c) {
|
||||||
/* Filter out arguments that are intended only for the initrd */
|
/* Filter out arguments that are intended only for the initrd */
|
||||||
|
|
||||||
@ -182,6 +180,8 @@ static char *mangle_word(const char *word, ProcCmdlineFlags flags) {
|
|||||||
return (char*) word;
|
return (char*) word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define mangle_word(word, flags) const_generic(word, mangle_word(word, flags))
|
||||||
|
|
||||||
static int proc_cmdline_parse_strv(char **args, proc_cmdline_parse_t parse_item, void *data, ProcCmdlineFlags flags) {
|
static int proc_cmdline_parse_strv(char **args, proc_cmdline_parse_t parse_item, void *data, ProcCmdlineFlags flags) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
|||||||
@ -1869,7 +1869,7 @@ int vsock_parse_cid(const char *s, unsigned *ret) {
|
|||||||
int socket_address_parse_vsock(SocketAddress *ret_address, const char *s) {
|
int socket_address_parse_vsock(SocketAddress *ret_address, const char *s) {
|
||||||
/* AF_VSOCK socket in vsock:cid:port notation */
|
/* AF_VSOCK socket in vsock:cid:port notation */
|
||||||
_cleanup_free_ char *n = NULL;
|
_cleanup_free_ char *n = NULL;
|
||||||
char *e, *cid_start;
|
const char *e, *cid_start;
|
||||||
unsigned port, cid;
|
unsigned port, cid;
|
||||||
int type, r;
|
int type, r;
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* bsearch_safe(const void *key, const void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
|
void* bsearch_safe_internal(const void *key, const void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
|
||||||
/**
|
/**
|
||||||
* Normal bsearch requires base to be nonnull. Here were require
|
* Normal bsearch requires base to be nonnull. Here were require
|
||||||
* that only if nmemb > 0.
|
* that only if nmemb > 0.
|
||||||
@ -40,7 +40,7 @@ void* bsearch_safe(const void *key, const void *base, size_t nmemb, size_t size,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
assert(base);
|
assert(base);
|
||||||
return bsearch(key, base, nmemb, size, compar);
|
return (void*) bsearch(key, base, nmemb, size, compar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
|
void qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
|
||||||
|
|||||||
@ -13,7 +13,9 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
|
|||||||
(typeof((b)[0])*) xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \
|
(typeof((b)[0])*) xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \
|
||||||
})
|
})
|
||||||
|
|
||||||
void* bsearch_safe(const void *key, const void *base, size_t nmemb, size_t size, comparison_fn_t compar);
|
void* bsearch_safe_internal(const void *key, const void *base, size_t nmemb, size_t size, comparison_fn_t compar);
|
||||||
|
#define bsearch_safe(key, base, nmemb, size, compar) \
|
||||||
|
const_generic((base), bsearch_safe_internal(key, base, nmemb, size, compar))
|
||||||
|
|
||||||
#define typesafe_bsearch(k, b, n, func) \
|
#define typesafe_bsearch(k, b, n, func) \
|
||||||
({ \
|
({ \
|
||||||
|
|||||||
@ -1339,16 +1339,14 @@ char* strdupcspn(const char *a, const char *reject) {
|
|||||||
return strndup(a, strcspn(a, reject));
|
return strndup(a, strcspn(a, reject));
|
||||||
}
|
}
|
||||||
|
|
||||||
char* find_line_startswith(const char *haystack, const char *needle) {
|
char* find_line_startswith_internal(const char *haystack, const char *needle) {
|
||||||
char *p;
|
|
||||||
|
|
||||||
assert(haystack);
|
assert(haystack);
|
||||||
assert(needle);
|
assert(needle);
|
||||||
|
|
||||||
/* Finds the first line in 'haystack' that starts with the specified string. Returns a pointer to the
|
/* Finds the first line in 'haystack' that starts with the specified string. Returns a pointer to the
|
||||||
* first character after it */
|
* first character after it */
|
||||||
|
|
||||||
p = strstr(haystack, needle);
|
char *p = (char*) strstr(haystack, needle);
|
||||||
if (!p)
|
if (!p)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -1362,16 +1360,14 @@ char* find_line_startswith(const char *haystack, const char *needle) {
|
|||||||
return p + strlen(needle);
|
return p + strlen(needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* find_line(const char *haystack, const char *needle) {
|
char* find_line_internal(const char *haystack, const char *needle) {
|
||||||
char *p;
|
|
||||||
|
|
||||||
assert(haystack);
|
assert(haystack);
|
||||||
assert(needle);
|
assert(needle);
|
||||||
|
|
||||||
/* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the
|
/* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the
|
||||||
* beginning of the line */
|
* beginning of the line */
|
||||||
|
|
||||||
p = find_line_startswith(haystack, needle);
|
char *p = (char*) find_line_startswith(haystack, needle);
|
||||||
if (!p)
|
if (!p)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -1381,16 +1377,14 @@ char* find_line(const char *haystack, const char *needle) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* find_line_after(const char *haystack, const char *needle) {
|
char* find_line_after_internal(const char *haystack, const char *needle) {
|
||||||
char *p;
|
|
||||||
|
|
||||||
assert(haystack);
|
assert(haystack);
|
||||||
assert(needle);
|
assert(needle);
|
||||||
|
|
||||||
/* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the
|
/* Finds the first line in 'haystack' that match the specified string. Returns a pointer to the
|
||||||
* next line after it */
|
* next line after it */
|
||||||
|
|
||||||
p = find_line_startswith(haystack, needle);
|
char *p = (char*) find_line_startswith(haystack, needle);
|
||||||
if (!p)
|
if (!p)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -1490,7 +1484,7 @@ ssize_t strlevenshtein(const char *x, const char *y) {
|
|||||||
return t1[yl];
|
return t1[yl];
|
||||||
}
|
}
|
||||||
|
|
||||||
char* strrstr(const char *haystack, const char *needle) {
|
char* strrstr_internal(const char *haystack, const char *needle) {
|
||||||
/* Like strstr() but returns the last rather than the first occurrence of "needle" in "haystack". */
|
/* Like strstr() but returns the last rather than the first occurrence of "needle" in "haystack". */
|
||||||
|
|
||||||
if (!haystack || !needle)
|
if (!haystack || !needle)
|
||||||
@ -1499,7 +1493,7 @@ char* strrstr(const char *haystack, const char *needle) {
|
|||||||
/* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the
|
/* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the
|
||||||
* last char, not before. */
|
* last char, not before. */
|
||||||
if (*needle == 0)
|
if (*needle == 0)
|
||||||
return strchr(haystack, 0);
|
return (char*) strchr(haystack, 0);
|
||||||
|
|
||||||
for (const char *p = strstr(haystack, needle), *q; p; p = q) {
|
for (const char *p = strstr(haystack, needle), *q; p; p = q) {
|
||||||
q = strstr(p + 1, needle);
|
q = strstr(p + 1, needle);
|
||||||
|
|||||||
@ -7,24 +7,28 @@
|
|||||||
#include "forward.h"
|
#include "forward.h"
|
||||||
#include "string-util-fundamental.h" /* IWYU pragma: export */
|
#include "string-util-fundamental.h" /* IWYU pragma: export */
|
||||||
|
|
||||||
static inline char* strstr_ptr(const char *haystack, const char *needle) {
|
static inline char* strstr_ptr_internal(const char *haystack, const char *needle) {
|
||||||
if (!haystack || !needle)
|
if (!haystack || !needle)
|
||||||
return NULL;
|
return NULL;
|
||||||
return strstr(haystack, needle);
|
return (char*) strstr(haystack, needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char* strstrafter(const char *haystack, const char *needle) {
|
#define strstr_ptr(haystack, needle) \
|
||||||
char *p;
|
const_generic(haystack, strstr_ptr_internal(haystack, needle))
|
||||||
|
|
||||||
|
static inline char* strstrafter_internal(const char *haystack, const char *needle) {
|
||||||
/* Returns NULL if not found, or pointer to first character after needle if found */
|
/* Returns NULL if not found, or pointer to first character after needle if found */
|
||||||
|
|
||||||
p = strstr_ptr(haystack, needle);
|
char *p = (char*) strstr_ptr(haystack, needle);
|
||||||
if (!p)
|
if (!p)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return p + strlen(needle);
|
return p + strlen(needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define strstrafter(haystack, needle) \
|
||||||
|
const_generic(haystack, strstrafter_internal(haystack, needle))
|
||||||
|
|
||||||
static inline const char* strnull(const char *s) {
|
static inline const char* strnull(const char *s) {
|
||||||
return s ?: "(null)";
|
return s ?: "(null)";
|
||||||
}
|
}
|
||||||
@ -286,15 +290,25 @@ char* strdupcspn(const char *a, const char *reject);
|
|||||||
(char*) memdupa_suffix0(_t, strnlen(_t, n)); \
|
(char*) memdupa_suffix0(_t, strnlen(_t, n)); \
|
||||||
})
|
})
|
||||||
|
|
||||||
char* find_line_startswith(const char *haystack, const char *needle);
|
char* find_line_startswith_internal(const char *haystack, const char *needle);
|
||||||
char* find_line(const char *haystack, const char *needle);
|
#define find_line_startswith(haystack, needle) \
|
||||||
char* find_line_after(const char *haystack, const char *needle);
|
const_generic(haystack, find_line_startswith_internal(haystack, needle))
|
||||||
|
|
||||||
|
char* find_line_internal(const char *haystack, const char *needle);
|
||||||
|
#define find_line(haystack, needle) \
|
||||||
|
const_generic(haystack, find_line_internal(haystack, needle))
|
||||||
|
|
||||||
|
char* find_line_after_internal(const char *haystack, const char *needle);
|
||||||
|
#define find_line_after(haystack, needle) \
|
||||||
|
const_generic(haystack, find_line_after_internal(haystack, needle))
|
||||||
|
|
||||||
bool version_is_valid(const char *s) _pure_;
|
bool version_is_valid(const char *s) _pure_;
|
||||||
bool version_is_valid_versionspec(const char *s) _pure_;
|
bool version_is_valid_versionspec(const char *s) _pure_;
|
||||||
|
|
||||||
ssize_t strlevenshtein(const char *x, const char *y);
|
ssize_t strlevenshtein(const char *x, const char *y);
|
||||||
|
|
||||||
char* strrstr(const char *haystack, const char *needle) _pure_;
|
char* strrstr_internal(const char *haystack, const char *needle) _pure_;
|
||||||
|
#define strrstr(haystack, needle) \
|
||||||
|
const_generic(haystack, strrstr_internal(haystack, needle))
|
||||||
|
|
||||||
size_t str_common_prefix(const char *a, const char *b) _pure_;
|
size_t str_common_prefix(const char *a, const char *b) _pure_;
|
||||||
|
|||||||
@ -921,9 +921,9 @@ int strv_extendf(char ***l, const char *format, ...) {
|
|||||||
return strv_consume(l, x);
|
return strv_consume(l, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* startswith_strv(const char *s, char * const *l) {
|
char* startswith_strv_internal(const char *s, char * const *l) {
|
||||||
STRV_FOREACH(i, l) {
|
STRV_FOREACH(i, l) {
|
||||||
char *found = startswith(s, *i);
|
char *found = (char*) startswith(s, *i);
|
||||||
if (found)
|
if (found)
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
@ -931,9 +931,9 @@ char* startswith_strv(const char *s, char * const *l) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* endswith_strv(const char *s, char * const *l) {
|
char* endswith_strv_internal(const char *s, char * const *l) {
|
||||||
STRV_FOREACH(i, l) {
|
STRV_FOREACH(i, l) {
|
||||||
char *found = endswith(s, *i);
|
char *found = (char*) endswith(s, *i);
|
||||||
if (found)
|
if (found)
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -150,12 +150,14 @@ static inline void strv_print(char * const *l) {
|
|||||||
strv_print_full(l, NULL);
|
strv_print_full(l, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* startswith_strv(const char *s, char * const *l);
|
char* startswith_strv_internal(const char *s, char * const *l);
|
||||||
|
#define startswith_strv(s, l) const_generic(s, startswith_strv_internal(s, l))
|
||||||
|
|
||||||
#define STARTSWITH_SET(p, ...) \
|
#define STARTSWITH_SET(p, ...) \
|
||||||
startswith_strv(p, STRV_MAKE(__VA_ARGS__))
|
startswith_strv(p, STRV_MAKE(__VA_ARGS__))
|
||||||
|
|
||||||
char* endswith_strv(const char *s, char * const *l);
|
char* endswith_strv_internal(const char *s, char * const *l);
|
||||||
|
#define endswith_strv(s, l) const_generic(s, endswith_strv_internal(s, l))
|
||||||
|
|
||||||
#define ENDSWITH_SET(p, ...) \
|
#define ENDSWITH_SET(p, ...) \
|
||||||
endswith_strv(p, STRV_MAKE(__VA_ARGS__))
|
endswith_strv(p, STRV_MAKE(__VA_ARGS__))
|
||||||
|
|||||||
@ -1119,9 +1119,7 @@ static const char* extract_multiplier(const char *p, usec_t *ret) {
|
|||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
FOREACH_ELEMENT(i, table) {
|
FOREACH_ELEMENT(i, table) {
|
||||||
char *e;
|
const char *e = startswith(p, i->suffix);
|
||||||
|
|
||||||
e = startswith(p, i->suffix);
|
|
||||||
if (e) {
|
if (e) {
|
||||||
*ret = i->usec;
|
*ret = i->usec;
|
||||||
return e;
|
return e;
|
||||||
@ -1297,9 +1295,7 @@ static const char* extract_nsec_multiplier(const char *p, nsec_t *ret) {
|
|||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
FOREACH_ELEMENT(i, table) {
|
FOREACH_ELEMENT(i, table) {
|
||||||
char *e;
|
const char *e = startswith(p, i->suffix);
|
||||||
|
|
||||||
e = startswith(p, i->suffix);
|
|
||||||
if (e) {
|
if (e) {
|
||||||
*ret = i->nsec;
|
*ret = i->nsec;
|
||||||
return e;
|
return e;
|
||||||
|
|||||||
@ -213,7 +213,7 @@ UnitType unit_name_to_type(const char *n) {
|
|||||||
int unit_name_change_suffix(const char *n, const char *suffix, char **ret) {
|
int unit_name_change_suffix(const char *n, const char *suffix, char **ret) {
|
||||||
_cleanup_free_ char *s = NULL;
|
_cleanup_free_ char *s = NULL;
|
||||||
size_t a, b;
|
size_t a, b;
|
||||||
char *e;
|
const char *e;
|
||||||
|
|
||||||
assert(n);
|
assert(n);
|
||||||
assert(suffix);
|
assert(suffix);
|
||||||
@ -521,7 +521,7 @@ int unit_name_template(const char *f, char **ret) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool unit_name_is_hashed(const char *name) {
|
bool unit_name_is_hashed(const char *name) {
|
||||||
char *s;
|
const char *s;
|
||||||
|
|
||||||
if (!unit_name_is_valid(name, UNIT_NAME_PLAIN))
|
if (!unit_name_is_valid(name, UNIT_NAME_PLAIN))
|
||||||
return false;
|
return false;
|
||||||
@ -544,7 +544,7 @@ bool unit_name_is_hashed(const char *name) {
|
|||||||
|
|
||||||
int unit_name_hash_long(const char *name, char **ret) {
|
int unit_name_hash_long(const char *name, char **ret) {
|
||||||
_cleanup_free_ char *n = NULL, *hash = NULL;
|
_cleanup_free_ char *n = NULL, *hash = NULL;
|
||||||
char *suffix;
|
const char *suffix;
|
||||||
le64_t h;
|
le64_t h;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
@ -834,7 +834,7 @@ int slice_build_subslice(const char *slice, const char *name, char **ret) {
|
|||||||
if (streq(slice, SPECIAL_ROOT_SLICE))
|
if (streq(slice, SPECIAL_ROOT_SLICE))
|
||||||
subslice = strjoin(name, ".slice");
|
subslice = strjoin(name, ".slice");
|
||||||
else {
|
else {
|
||||||
char *e;
|
const char *e;
|
||||||
|
|
||||||
assert_se(e = endswith(slice, ".slice"));
|
assert_se(e = endswith(slice, ".slice"));
|
||||||
|
|
||||||
|
|||||||
@ -1024,6 +1024,7 @@ _used_ void *memcpy(void * restrict dest, const void * restrict src, size_t n);
|
|||||||
_used_ void *memset(void *p, int c, size_t n);
|
_used_ void *memset(void *p, int c, size_t n);
|
||||||
#else
|
#else
|
||||||
/* And for userspace unit testing we need to give them an efi_ prefix. */
|
/* And for userspace unit testing we need to give them an efi_ prefix. */
|
||||||
|
# undef memchr
|
||||||
# define memchr efi_memchr
|
# define memchr efi_memchr
|
||||||
# define memcmp efi_memcmp
|
# define memcmp efi_memcmp
|
||||||
# define memcpy efi_memcpy
|
# define memcpy efi_memcpy
|
||||||
|
|||||||
@ -2116,7 +2116,7 @@ static int build_environment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sd_id128_is_null(p->invocation_id)) {
|
if (!sd_id128_is_null(p->invocation_id)) {
|
||||||
assert(p->invocation_id_string);
|
assert(!isempty(p->invocation_id_string));
|
||||||
|
|
||||||
x = strjoin("INVOCATION_ID=", p->invocation_id_string);
|
x = strjoin("INVOCATION_ID=", p->invocation_id_string);
|
||||||
if (!x)
|
if (!x)
|
||||||
|
|||||||
@ -1778,7 +1778,7 @@ int config_parse_exec_root_hash_sig(
|
|||||||
void *userdata) {
|
void *userdata) {
|
||||||
|
|
||||||
_cleanup_free_ void *roothash_sig_decoded = NULL;
|
_cleanup_free_ void *roothash_sig_decoded = NULL;
|
||||||
char *value;
|
const char *value;
|
||||||
ExecContext *c = ASSERT_PTR(data);
|
ExecContext *c = ASSERT_PTR(data);
|
||||||
size_t roothash_sig_decoded_size = 0;
|
size_t roothash_sig_decoded_size = 0;
|
||||||
int r;
|
int r;
|
||||||
|
|||||||
@ -798,10 +798,9 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
|
|||||||
static int add_crypttab_device(const char *name, const char *device, const char *keyspec, const char *options) {
|
static int add_crypttab_device(const char *name, const char *device, const char *keyspec, const char *options) {
|
||||||
_cleanup_free_ char *keyfile = NULL, *keydev = NULL, *headerdev = NULL, *filtered_header = NULL;
|
_cleanup_free_ char *keyfile = NULL, *keydev = NULL, *headerdev = NULL, *filtered_header = NULL;
|
||||||
crypto_device *d = NULL;
|
crypto_device *d = NULL;
|
||||||
char *uuid;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
uuid = startswith(device, "UUID=");
|
const char *uuid = startswith(device, "UUID=");
|
||||||
if (!uuid)
|
if (!uuid)
|
||||||
uuid = path_startswith(device, "/dev/disk/by-uuid/");
|
uuid = path_startswith(device, "/dev/disk/by-uuid/");
|
||||||
if (!uuid)
|
if (!uuid)
|
||||||
|
|||||||
@ -482,3 +482,10 @@ assert_cc(STRLEN(__FILE__) > STRLEN(RELATIVE_SOURCE_PATH) + 1);
|
|||||||
#else
|
#else
|
||||||
# define ENUM_TYPE_S64(id) id
|
# define ENUM_TYPE_S64(id) id
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* This macro is used to have a const-returning and non-const returning version of a function based on
|
||||||
|
* whether its first argument is const or not (e.g. strstr()). */
|
||||||
|
#define const_generic(ptr, call) \
|
||||||
|
_Generic(0 ? (ptr) : (void*) 1, \
|
||||||
|
const void*: (const typeof(*call)*) (call), \
|
||||||
|
void*: (call))
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include "macro-fundamental.h"
|
#include "macro-fundamental.h"
|
||||||
#include "string-util-fundamental.h"
|
#include "string-util-fundamental.h"
|
||||||
|
|
||||||
sd_char *startswith(const sd_char *s, const sd_char *prefix) {
|
sd_char *startswith_internal(const sd_char *s, const sd_char *prefix) {
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
@ -16,7 +16,7 @@ sd_char *startswith(const sd_char *s, const sd_char *prefix) {
|
|||||||
return (sd_char*) s + l;
|
return (sd_char*) s + l;
|
||||||
}
|
}
|
||||||
|
|
||||||
sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) {
|
sd_char *startswith_no_case_internal(const sd_char *s, const sd_char *prefix) {
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
@ -29,7 +29,7 @@ sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) {
|
|||||||
return (sd_char*) s + l;
|
return (sd_char*) s + l;
|
||||||
}
|
}
|
||||||
|
|
||||||
sd_char* endswith(const sd_char *s, const sd_char *suffix) {
|
sd_char* endswith_internal(const sd_char *s, const sd_char *suffix) {
|
||||||
size_t sl, pl;
|
size_t sl, pl;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
@ -50,7 +50,7 @@ sd_char* endswith(const sd_char *s, const sd_char *suffix) {
|
|||||||
return (sd_char*) s + sl - pl;
|
return (sd_char*) s + sl - pl;
|
||||||
}
|
}
|
||||||
|
|
||||||
sd_char* endswith_no_case(const sd_char *s, const sd_char *suffix) {
|
sd_char* endswith_no_case_internal(const sd_char *s, const sd_char *suffix) {
|
||||||
size_t sl, pl;
|
size_t sl, pl;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
|
|||||||
@ -77,10 +77,17 @@ static inline size_t strlen_ptr(const sd_char *s) {
|
|||||||
return strlen(s);
|
return strlen(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
sd_char *startswith(const sd_char *s, const sd_char *prefix) _pure_;
|
sd_char *startswith_internal(const sd_char *s, const sd_char *prefix) _pure_;
|
||||||
sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_;
|
#define startswith(s, prefix) const_generic(s, startswith_internal(s, prefix))
|
||||||
sd_char *endswith(const sd_char *s, const sd_char *suffix) _pure_;
|
|
||||||
sd_char *endswith_no_case(const sd_char *s, const sd_char *suffix) _pure_;
|
sd_char *startswith_no_case_internal(const sd_char *s, const sd_char *prefix) _pure_;
|
||||||
|
#define startswith_no_case(s, prefix) const_generic(s, startswith_no_case_internal(s, prefix))
|
||||||
|
|
||||||
|
sd_char *endswith_internal(const sd_char *s, const sd_char *suffix) _pure_;
|
||||||
|
#define endswith(s, suffix) const_generic(s, endswith_internal(s, suffix))
|
||||||
|
|
||||||
|
sd_char *endswith_no_case_internal(const sd_char *s, const sd_char *suffix) _pure_;
|
||||||
|
#define endswith_no_case(s, suffix) const_generic(s, endswith_no_case_internal(s, suffix))
|
||||||
|
|
||||||
static inline bool isempty(const sd_char *a) {
|
static inline bool isempty(const sd_char *a) {
|
||||||
return !a || a[0] == '\0';
|
return !a || a[0] == '\0';
|
||||||
|
|||||||
@ -861,7 +861,7 @@ static int manager_assess_image(
|
|||||||
const char *dir_path,
|
const char *dir_path,
|
||||||
const char *dentry_name) {
|
const char *dentry_name) {
|
||||||
|
|
||||||
char *luks_suffix, *directory_suffix;
|
const char *luks_suffix, *directory_suffix;
|
||||||
_cleanup_free_ char *path = NULL;
|
_cleanup_free_ char *path = NULL;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int r;
|
int r;
|
||||||
|
|||||||
@ -151,9 +151,8 @@ int get_possible_units(
|
|||||||
|
|
||||||
SD_JOURNAL_FOREACH_UNIQUE(j, data, size) {
|
SD_JOURNAL_FOREACH_UNIQUE(j, data, size) {
|
||||||
_cleanup_free_ char *u = NULL;
|
_cleanup_free_ char *u = NULL;
|
||||||
char *eq;
|
|
||||||
|
|
||||||
eq = memchr(data, '=', size);
|
const char *eq = memchr(data, '=', size);
|
||||||
if (eq) {
|
if (eq) {
|
||||||
size -= eq - (char*) data + 1;
|
size -= eq - (char*) data + 1;
|
||||||
data = ++eq;
|
data = ++eq;
|
||||||
|
|||||||
@ -1437,7 +1437,7 @@ _public_ int sd_bus_open_user(sd_bus **ret) {
|
|||||||
|
|
||||||
int bus_set_address_system_remote(sd_bus *b, const char *host) {
|
int bus_set_address_system_remote(sd_bus *b, const char *host) {
|
||||||
_cleanup_free_ char *e = NULL;
|
_cleanup_free_ char *e = NULL;
|
||||||
char *m = NULL, *c = NULL, *a, *rbracket = NULL, *p = NULL;
|
const char *m = NULL, *c = NULL, *a, *rbracket = NULL, *p = NULL;
|
||||||
|
|
||||||
assert(b);
|
assert(b);
|
||||||
assert(host);
|
assert(host);
|
||||||
@ -1475,7 +1475,7 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) {
|
|||||||
/* Let's see if a port was given */
|
/* Let's see if a port was given */
|
||||||
m = strchr(rbracket ? rbracket + 1 : host, ':');
|
m = strchr(rbracket ? rbracket + 1 : host, ':');
|
||||||
if (m) {
|
if (m) {
|
||||||
char *t;
|
const char *t;
|
||||||
bool got_forward_slash = false;
|
bool got_forward_slash = false;
|
||||||
|
|
||||||
p = m + 1;
|
p = m + 1;
|
||||||
@ -1521,14 +1521,15 @@ interpret_port_as_machine_old_syntax:
|
|||||||
if (!ssh_escaped)
|
if (!ssh_escaped)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
a = strjoin("unixexec:path=", ssh_escaped, ",argv1=-xT",
|
char *address = strjoin(
|
||||||
p ? ",argv2=-p,argv3=" : "", strempty(p),
|
"unixexec:path=", ssh_escaped, ",argv1=-xT",
|
||||||
",argv", p ? "4" : "2", "=--,argv", p ? "5" : "3", "=", e,
|
p ? ",argv2=-p,argv3=" : "", strempty(p),
|
||||||
",argv", p ? "6" : "4", "=systemd-stdio-bridge", c);
|
",argv", p ? "4" : "2", "=--,argv", p ? "5" : "3", "=", e,
|
||||||
if (!a)
|
",argv", p ? "6" : "4", "=systemd-stdio-bridge", c);
|
||||||
|
if (!address)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
return free_and_replace(b->address, a);
|
return free_and_replace(b->address, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
_public_ int sd_bus_open_system_remote(sd_bus **ret, const char *host) {
|
_public_ int sd_bus_open_system_remote(sd_bus **ret, const char *host) {
|
||||||
|
|||||||
@ -95,7 +95,7 @@ static int trie_children_cmp_f(const void *v1, const void *v2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct trie_node_f *node_lookup_f(sd_hwdb *hwdb, const struct trie_node_f *node, uint8_t c) {
|
static const struct trie_node_f *node_lookup_f(sd_hwdb *hwdb, const struct trie_node_f *node, uint8_t c) {
|
||||||
struct trie_child_entry_f *child;
|
const struct trie_child_entry_f *child;
|
||||||
struct trie_child_entry_f search;
|
struct trie_child_entry_f search;
|
||||||
|
|
||||||
search.c = c;
|
search.c = c;
|
||||||
|
|||||||
@ -210,23 +210,21 @@ static int finish_item(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int catalog_file_lang(const char *filename, char **ret) {
|
int catalog_file_lang(const char *filename, char **ret) {
|
||||||
char *beg, *end, *lang;
|
|
||||||
|
|
||||||
assert(filename);
|
assert(filename);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
end = endswith(filename, ".catalog");
|
const char *end = endswith(filename, ".catalog");
|
||||||
if (!end)
|
if (!end)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
beg = end - 1;
|
const char *beg = end - 1;
|
||||||
while (beg > filename && !IN_SET(*beg, '.', '/') && end - beg < 32)
|
while (beg > filename && !IN_SET(*beg, '.', '/') && end - beg < 32)
|
||||||
beg--;
|
beg--;
|
||||||
|
|
||||||
if (*beg != '.' || end <= beg + 1)
|
if (*beg != '.' || end <= beg + 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
lang = strndup(beg + 1, end - beg - 1);
|
char *lang = strndup(beg + 1, end - beg - 1);
|
||||||
if (!lang)
|
if (!lang)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -553,7 +551,8 @@ static int open_mmap(const char *database, int *ret_fd, struct stat *ret_st, voi
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char* find_id(const void *p, sd_id128_t id) {
|
static const char* find_id(const void *p, sd_id128_t id) {
|
||||||
CatalogItem *f = NULL, key = { .id = id };
|
CatalogItem key = { .id = id };
|
||||||
|
const CatalogItem *f = NULL;
|
||||||
const CatalogHeader *h = ASSERT_PTR(p);
|
const CatalogHeader *h = ASSERT_PTR(p);
|
||||||
const char *loc;
|
const char *loc;
|
||||||
|
|
||||||
|
|||||||
@ -786,7 +786,6 @@ int config_parse_dhcp_server_relay_agent_suboption(
|
|||||||
void *userdata) {
|
void *userdata) {
|
||||||
|
|
||||||
char **suboption_value = data;
|
char **suboption_value = data;
|
||||||
char* p;
|
|
||||||
|
|
||||||
assert(filename);
|
assert(filename);
|
||||||
assert(lvalue);
|
assert(lvalue);
|
||||||
@ -797,7 +796,7 @@ int config_parse_dhcp_server_relay_agent_suboption(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = startswith(rvalue, "string:");
|
const char *p = startswith(rvalue, "string:");
|
||||||
if (!p) {
|
if (!p) {
|
||||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||||
"Failed to parse %s=%s'. Invalid format, ignoring.", lvalue, rvalue);
|
"Failed to parse %s=%s'. Invalid format, ignoring.", lvalue, rvalue);
|
||||||
|
|||||||
@ -1639,7 +1639,6 @@ static int bus_append_root_hash(sd_bus_message *m, const char *field, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int bus_append_root_hash_signature(sd_bus_message *m, const char *field, const char *eq) {
|
static int bus_append_root_hash_signature(sd_bus_message *m, const char *field, const char *eq) {
|
||||||
char *value;
|
|
||||||
_cleanup_free_ void *roothash_sig_decoded = NULL;
|
_cleanup_free_ void *roothash_sig_decoded = NULL;
|
||||||
size_t roothash_sig_decoded_size = 0;
|
size_t roothash_sig_decoded_size = 0;
|
||||||
int r;
|
int r;
|
||||||
@ -1648,7 +1647,8 @@ static int bus_append_root_hash_signature(sd_bus_message *m, const char *field,
|
|||||||
if (path_is_absolute(eq))
|
if (path_is_absolute(eq))
|
||||||
return bus_append_string(m, "RootHashSignaturePath", eq);
|
return bus_append_string(m, "RootHashSignaturePath", eq);
|
||||||
|
|
||||||
if (!(value = startswith(eq, "base64:")))
|
const char *value = startswith(eq, "base64:");
|
||||||
|
if (!value)
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
"Failed to decode %s value '%s': neither a path nor starts with 'base64:'.",
|
"Failed to decode %s value '%s': neither a path nor starts with 'base64:'.",
|
||||||
field, eq);
|
field, eq);
|
||||||
|
|||||||
@ -298,7 +298,7 @@ bool pager_have(void) {
|
|||||||
|
|
||||||
int show_man_page(const char *desc, bool null_stdio) {
|
int show_man_page(const char *desc, bool null_stdio) {
|
||||||
const char *args[4] = { "man", NULL, NULL, NULL };
|
const char *args[4] = { "man", NULL, NULL, NULL };
|
||||||
char *e = NULL;
|
const char *e = NULL;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
size_t k;
|
size_t k;
|
||||||
int r;
|
int r;
|
||||||
|
|||||||
@ -2391,7 +2391,7 @@ uint32_t scmp_act_kill_process(void) {
|
|||||||
|
|
||||||
int parse_syscall_and_errno(const char *in, char **name, int *error) {
|
int parse_syscall_and_errno(const char *in, char **name, int *error) {
|
||||||
_cleanup_free_ char *n = NULL;
|
_cleanup_free_ char *n = NULL;
|
||||||
char *p;
|
const char *p;
|
||||||
int e = -1;
|
int e = -1;
|
||||||
|
|
||||||
assert(in);
|
assert(in);
|
||||||
|
|||||||
@ -343,7 +343,7 @@ static int make_choice(
|
|||||||
unsigned found_tries_done = UINT_MAX, found_tries_left = UINT_MAX;
|
unsigned found_tries_done = UINT_MAX, found_tries_left = UINT_MAX;
|
||||||
_cleanup_free_ char *dname = NULL;
|
_cleanup_free_ char *dname = NULL;
|
||||||
size_t found_architecture_index = SIZE_MAX;
|
size_t found_architecture_index = SIZE_MAX;
|
||||||
const char *e;
|
char *e;
|
||||||
|
|
||||||
dname = strdup((*entry)->d_name);
|
dname = strdup((*entry)->d_name);
|
||||||
if (!dname)
|
if (!dname)
|
||||||
|
|||||||
@ -922,7 +922,7 @@ static int names_pci(UdevEvent *event, const char *prefix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int get_usb_specifier(sd_device *dev, char **ret) {
|
static int get_usb_specifier(sd_device *dev, char **ret) {
|
||||||
char *ports, *config, *interf, *s, *buf;
|
char *ports, *config, *interf, *buf;
|
||||||
const char *sysname;
|
const char *sysname;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -934,26 +934,26 @@ static int get_usb_specifier(sd_device *dev, char **ret) {
|
|||||||
return log_device_debug_errno(dev, r, "Failed to get sysname: %m");
|
return log_device_debug_errno(dev, r, "Failed to get sysname: %m");
|
||||||
|
|
||||||
/* get USB port number chain, configuration, interface */
|
/* get USB port number chain, configuration, interface */
|
||||||
s = strchr(sysname, '-');
|
const char *s = strchr(sysname, '-');
|
||||||
if (!s)
|
if (!s)
|
||||||
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
|
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
|
||||||
"sysname \"%s\" does not have '-' in the expected place.", sysname);
|
"sysname \"%s\" does not have '-' in the expected place.", sysname);
|
||||||
|
|
||||||
ports = strdupa_safe(s + 1);
|
ports = strdupa_safe(s + 1);
|
||||||
s = strchr(ports, ':');
|
char *t = strchr(ports, ':');
|
||||||
if (!s)
|
if (!s)
|
||||||
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
|
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
|
||||||
"sysname \"%s\" does not have ':' in the expected place.", sysname);
|
"sysname \"%s\" does not have ':' in the expected place.", sysname);
|
||||||
|
|
||||||
*s = '\0';
|
*t = '\0';
|
||||||
config = s + 1;
|
config = t + 1;
|
||||||
s = strchr(config, '.');
|
s = strchr(config, '.');
|
||||||
if (!s)
|
if (!s)
|
||||||
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
|
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
|
||||||
"sysname \"%s\" does not have '.' in the expected place.", sysname);
|
"sysname \"%s\" does not have '.' in the expected place.", sysname);
|
||||||
|
|
||||||
*s = '\0';
|
*t = '\0';
|
||||||
interf = s + 1;
|
interf = t + 1;
|
||||||
|
|
||||||
/* prefix every port number in the chain with "u" */
|
/* prefix every port number in the chain with "u" */
|
||||||
string_replace_char(ports, '.', 'u');
|
string_replace_char(ports, '.', 'u');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user