mirror of
https://github.com/systemd/systemd
synced 2026-03-16 18:14:46 +01:00
Compare commits
No commits in common. "f5e775973a22e10e0813b56cb3e43d5d415979f7" and "e8f99f4e249916e12c09ee5cc9a108cba6a2b5c0" have entirely different histories.
f5e775973a
...
e8f99f4e24
@ -572,9 +572,12 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
|||||||
|
|
||||||
t = strv_env_get_n(env, word+2, e-word-2, flags);
|
t = strv_env_get_n(env, word+2, e-word-2, flags);
|
||||||
|
|
||||||
if (!strextend(&r, t))
|
k = strjoin(r, t);
|
||||||
|
if (!k)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
free_and_replace(r, k);
|
||||||
|
|
||||||
word = e+1;
|
word = e+1;
|
||||||
state = WORD;
|
state = WORD;
|
||||||
} else if (*e == ':') {
|
} else if (*e == ':') {
|
||||||
@ -624,9 +627,12 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
|||||||
else if (!t && state == DEFAULT_VALUE)
|
else if (!t && state == DEFAULT_VALUE)
|
||||||
t = v = replace_env_n(test_value, e-test_value, env, flags);
|
t = v = replace_env_n(test_value, e-test_value, env, flags);
|
||||||
|
|
||||||
if (!strextend(&r, t))
|
k = strjoin(r, t);
|
||||||
|
if (!k)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
free_and_replace(r, k);
|
||||||
|
|
||||||
word = e+1;
|
word = e+1;
|
||||||
state = WORD;
|
state = WORD;
|
||||||
}
|
}
|
||||||
@ -640,9 +646,12 @@ char *replace_env_n(const char *format, size_t n, char **env, unsigned flags) {
|
|||||||
|
|
||||||
t = strv_env_get_n(env, word+1, e-word-1, flags);
|
t = strv_env_get_n(env, word+1, e-word-1, flags);
|
||||||
|
|
||||||
if (!strextend(&r, t))
|
k = strjoin(r, t);
|
||||||
|
if (!k)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
free_and_replace(r, k);
|
||||||
|
|
||||||
word = e--;
|
word = e--;
|
||||||
i--;
|
i--;
|
||||||
state = WORD;
|
state = WORD;
|
||||||
|
|||||||
@ -371,6 +371,8 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents
|
|||||||
int n_retries;
|
int n_retries;
|
||||||
bool truncated = false;
|
bool truncated = false;
|
||||||
|
|
||||||
|
assert(ret_contents);
|
||||||
|
|
||||||
/* Virtual filesystems such as sysfs or procfs use kernfs, and kernfs can work with two sorts of
|
/* Virtual filesystems such as sysfs or procfs use kernfs, and kernfs can work with two sorts of
|
||||||
* virtual files. One sort uses "seq_file", and the results of the first read are buffered for the
|
* virtual files. One sort uses "seq_file", and the results of the first read are buffered for the
|
||||||
* second read. The other sort uses "raw" reads which always go direct to the device. In the latter
|
* second read. The other sort uses "raw" reads which always go direct to the device. In the latter
|
||||||
@ -484,9 +486,7 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents
|
|||||||
return -EBADMSG;
|
return -EBADMSG;
|
||||||
|
|
||||||
buf[n] = 0;
|
buf[n] = 0;
|
||||||
|
*ret_contents = TAKE_PTR(buf);
|
||||||
if (ret_contents)
|
|
||||||
*ret_contents = TAKE_PTR(buf);
|
|
||||||
|
|
||||||
return !truncated;
|
return !truncated;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -236,29 +236,6 @@ int log_emergency_level(void);
|
|||||||
#define log_error_errno(error, ...) log_full_errno(LOG_ERR, error, __VA_ARGS__)
|
#define log_error_errno(error, ...) log_full_errno(LOG_ERR, error, __VA_ARGS__)
|
||||||
#define log_emergency_errno(error, ...) log_full_errno(log_emergency_level(), error, __VA_ARGS__)
|
#define log_emergency_errno(error, ...) log_full_errno(log_emergency_level(), error, __VA_ARGS__)
|
||||||
|
|
||||||
/* This logs at the specified level the first time it is called, and then
|
|
||||||
* logs at debug. If the specified level is debug, this logs only the first
|
|
||||||
* time it is called. */
|
|
||||||
#define log_once(level, ...) \
|
|
||||||
({ \
|
|
||||||
if (ONCE) \
|
|
||||||
log_full(level, __VA_ARGS__); \
|
|
||||||
else if (LOG_PRI(level) != LOG_DEBUG) \
|
|
||||||
log_debug(__VA_ARGS__); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define log_once_errno(level, error, ...) \
|
|
||||||
({ \
|
|
||||||
int _err = (error); \
|
|
||||||
if (ONCE) \
|
|
||||||
_err = log_full_errno(level, _err, __VA_ARGS__); \
|
|
||||||
else if (LOG_PRI(level) != LOG_DEBUG) \
|
|
||||||
_err = log_debug_errno(_err, __VA_ARGS__); \
|
|
||||||
else \
|
|
||||||
_err = -ERRNO_VALUE(_err); \
|
|
||||||
_err; \
|
|
||||||
})
|
|
||||||
|
|
||||||
#if LOG_TRACE
|
#if LOG_TRACE
|
||||||
# define log_trace(...) log_debug(__VA_ARGS__)
|
# define log_trace(...) log_debug(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
|
|||||||
@ -790,8 +790,8 @@ char *strextend_with_separator_internal(char **x, const char *separator, ...) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
int strextendf_with_separator(char **x, const char *separator, const char *format, ...) {
|
int strextendf(char **x, const char *format, ...) {
|
||||||
size_t m, a, l_separator;
|
size_t m, a;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
@ -802,8 +802,6 @@ int strextendf_with_separator(char **x, const char *separator, const char *forma
|
|||||||
assert(x);
|
assert(x);
|
||||||
assert(format);
|
assert(format);
|
||||||
|
|
||||||
l_separator = isempty(*x) ? 0 : strlen_ptr(separator);
|
|
||||||
|
|
||||||
/* Let's try to use the allocated buffer, if there's room at the end still. Otherwise let's extend by 64 chars. */
|
/* Let's try to use the allocated buffer, if there's room at the end still. Otherwise let's extend by 64 chars. */
|
||||||
if (*x) {
|
if (*x) {
|
||||||
m = strlen(*x);
|
m = strlen(*x);
|
||||||
@ -812,15 +810,13 @@ int strextendf_with_separator(char **x, const char *separator, const char *forma
|
|||||||
} else
|
} else
|
||||||
m = a = 0;
|
m = a = 0;
|
||||||
|
|
||||||
if (a - m < 17 + l_separator) { /* if there's less than 16 chars space, then enlarge the buffer first */
|
if (a - m < 17) { /* if there's less than 16 chars space, then enlarge the buffer first */
|
||||||
char *n;
|
char *n;
|
||||||
|
|
||||||
if (_unlikely_(l_separator > SIZE_MAX - 64)) /* overflow check #1 */
|
if (_unlikely_(m > SIZE_MAX - 64)) /* overflow check */
|
||||||
return -ENOMEM;
|
|
||||||
if (_unlikely_(m > SIZE_MAX - 64 - l_separator)) /* overflow check #2 */
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
n = realloc(*x, m + 64 + l_separator);
|
n = realloc(*x, m + 64);
|
||||||
if (!n)
|
if (!n)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -829,20 +825,19 @@ int strextendf_with_separator(char **x, const char *separator, const char *forma
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now, let's try to format the string into it */
|
/* Now, let's try to format the string into it */
|
||||||
memcpy_safe(*x + m, separator, l_separator);
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
l = vsnprintf(*x + m + l_separator, a - m - l_separator, format, ap);
|
l = vsnprintf(*x + m, a - m, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
assert(l >= 0);
|
assert(l >= 0);
|
||||||
|
|
||||||
if ((size_t) l < a - m - l_separator) {
|
if ((size_t) l < a - m) {
|
||||||
char *n;
|
char *n;
|
||||||
|
|
||||||
/* Nice! This worked. We are done. But first, let's return the extra space we don't
|
/* Nice! This worked. We are done. But first, let's return the extra space we don't
|
||||||
* need. This should be a cheap operation, since we only lower the allocation size here,
|
* need. This should be a cheap operation, since we only lower the allocation size here,
|
||||||
* never increase. */
|
* never increase. */
|
||||||
n = realloc(*x, m + (size_t) l + l_separator + 1);
|
n = realloc(*x, m + (size_t) l + 1);
|
||||||
if (n)
|
if (n)
|
||||||
*x = n;
|
*x = n;
|
||||||
} else {
|
} else {
|
||||||
@ -850,22 +845,22 @@ int strextendf_with_separator(char **x, const char *separator, const char *forma
|
|||||||
|
|
||||||
/* Wasn't enough. Then let's allocate exactly what we need. */
|
/* Wasn't enough. Then let's allocate exactly what we need. */
|
||||||
|
|
||||||
if (_unlikely_((size_t) l > SIZE_MAX - (l_separator + 1))) /* overflow check #1 */
|
if (_unlikely_((size_t) l > SIZE_MAX - 1)) /* overflow check #1 */
|
||||||
goto oom;
|
goto oom;
|
||||||
if (_unlikely_(m > SIZE_MAX - ((size_t) l + l_separator + 1))) /* overflow check #2 */
|
if (_unlikely_(m > SIZE_MAX - ((size_t) l + 1))) /* overflow check #2 */
|
||||||
goto oom;
|
goto oom;
|
||||||
|
|
||||||
a = m + (size_t) l + l_separator + 1;
|
a = m + (size_t) l + 1;
|
||||||
n = realloc(*x, a);
|
n = realloc(*x, a);
|
||||||
if (!n)
|
if (!n)
|
||||||
goto oom;
|
goto oom;
|
||||||
*x = n;
|
*x = n;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
l = vsnprintf(*x + m + l_separator, a - m - l_separator, format, ap);
|
l = vsnprintf(*x + m, a - m, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
assert((size_t) l < a - m - l_separator);
|
assert((size_t) l < a - m);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -156,11 +156,11 @@ char *strreplace(const char *text, const char *old_string, const char *new_strin
|
|||||||
char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]);
|
char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]);
|
||||||
|
|
||||||
char *strextend_with_separator_internal(char **x, const char *separator, ...) _sentinel_;
|
char *strextend_with_separator_internal(char **x, const char *separator, ...) _sentinel_;
|
||||||
|
|
||||||
#define strextend_with_separator(x, separator, ...) strextend_with_separator_internal(x, separator, __VA_ARGS__, NULL)
|
#define strextend_with_separator(x, separator, ...) strextend_with_separator_internal(x, separator, __VA_ARGS__, NULL)
|
||||||
#define strextend(x, ...) strextend_with_separator_internal(x, NULL, __VA_ARGS__, NULL)
|
#define strextend(x, ...) strextend_with_separator_internal(x, NULL, __VA_ARGS__, NULL)
|
||||||
|
|
||||||
int strextendf_with_separator(char **x, const char *separator, const char *format, ...) _printf_(3,4);
|
int strextendf(char **x, const char *format, ...) _printf_(2,3);
|
||||||
#define strextendf(x, ...) strextendf_with_separator(x, NULL, __VA_ARGS__)
|
|
||||||
|
|
||||||
char *strrep(const char *s, unsigned n);
|
char *strrep(const char *s, unsigned n);
|
||||||
|
|
||||||
|
|||||||
@ -181,7 +181,7 @@ int bus_read_mount_options(
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
while ((r = sd_bus_message_read(message, "(ss)", &partition, &mount_options)) > 0) {
|
while ((r = sd_bus_message_read(message, "(ss)", &partition, &mount_options)) > 0) {
|
||||||
_cleanup_free_ char *escaped = NULL;
|
_cleanup_free_ char *previous = NULL, *escaped = NULL;
|
||||||
_cleanup_free_ MountOptions *o = NULL;
|
_cleanup_free_ MountOptions *o = NULL;
|
||||||
PartitionDesignator partition_designator;
|
PartitionDesignator partition_designator;
|
||||||
|
|
||||||
@ -198,7 +198,9 @@ int bus_read_mount_options(
|
|||||||
if (!escaped)
|
if (!escaped)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (!strextend_with_separator(&format_str, separator, partition, ":", escaped))
|
previous = TAKE_PTR(format_str);
|
||||||
|
format_str = strjoin(previous, previous ? separator : "", partition, ":", escaped);
|
||||||
|
if (!format_str)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
o = new(MountOptions, 1);
|
o = new(MountOptions, 1);
|
||||||
|
|||||||
@ -188,8 +188,13 @@ static int run(int argc, char *argv[]) {
|
|||||||
|
|
||||||
free_and_replace(e, x);
|
free_and_replace(e, x);
|
||||||
} else if (arg_suffix) {
|
} else if (arg_suffix) {
|
||||||
if (!strextend(&e, ".", arg_suffix))
|
char *x;
|
||||||
|
|
||||||
|
x = strjoin(e, ".", arg_suffix);
|
||||||
|
if (!x)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
|
free_and_replace(e, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -50,17 +50,6 @@
|
|||||||
#define UNIQ_T(x, uniq) CONCATENATE(__unique_prefix_, CONCATENATE(x, uniq))
|
#define UNIQ_T(x, uniq) CONCATENATE(__unique_prefix_, CONCATENATE(x, uniq))
|
||||||
#define UNIQ __COUNTER__
|
#define UNIQ __COUNTER__
|
||||||
|
|
||||||
/* Note that this works differently from pthread_once(): this macro does
|
|
||||||
* not synchronize code execution, i.e. code that is run conditionalized
|
|
||||||
* on this macro will run concurrently to all other code conditionalized
|
|
||||||
* the same way, there's no ordering or completion enforced. */
|
|
||||||
#define ONCE __ONCE(UNIQ_T(_once_, UNIQ))
|
|
||||||
#define __ONCE(o) \
|
|
||||||
({ \
|
|
||||||
static bool (o) = false; \
|
|
||||||
__sync_bool_compare_and_swap(&(o), false, true); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#undef MAX
|
#undef MAX
|
||||||
#define MAX(a, b) __MAX(UNIQ, (a), UNIQ, (b))
|
#define MAX(a, b) __MAX(UNIQ, (a), UNIQ, (b))
|
||||||
#define __MAX(aq, a, bq, b) \
|
#define __MAX(aq, a, bq, b) \
|
||||||
|
|||||||
@ -1574,12 +1574,18 @@ int bus_set_address_machine(sd_bus *b, bool user, const char *machine) {
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
char *k;
|
||||||
|
|
||||||
/* Ideally we'd use the "--user" switch to systemd-stdio-bridge here, but it's only
|
/* Ideally we'd use the "--user" switch to systemd-stdio-bridge here, but it's only
|
||||||
* available in recent systemd versions. Using the "-p" switch with the explicit path
|
* available in recent systemd versions. Using the "-p" switch with the explicit path
|
||||||
* is a working alternative, and is compatible with older versions, hence that's what
|
* is a working alternative, and is compatible with older versions, hence that's what
|
||||||
* we use here. */
|
* we use here. */
|
||||||
if (!strextend(&a, ",argv7=-punix:path%3d%24%7bXDG_RUNTIME_DIR%7d/bus"))
|
|
||||||
|
k = strjoin(a, ",argv7=-punix:path%3d%24%7bXDG_RUNTIME_DIR%7d/bus");
|
||||||
|
if (!k)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
free_and_replace(a, k);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_cleanup_free_ char *e = NULL;
|
_cleanup_free_ char *e = NULL;
|
||||||
|
|||||||
@ -244,103 +244,71 @@ _public_ int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum)
|
|||||||
return sd_device_new_from_syspath(ret, syspath);
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int device_strjoin_new(
|
_public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *subsystem, const char *sysname) {
|
||||||
const char *a,
|
char syspath[PATH_MAX], *name;
|
||||||
const char *b,
|
|
||||||
const char *c,
|
|
||||||
const char *d,
|
|
||||||
sd_device **ret) {
|
|
||||||
|
|
||||||
const char *p;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
p = strjoina(a, b, c, d);
|
|
||||||
if (access(p, F_OK) < 0)
|
|
||||||
return IN_SET(errno, ENOENT, ENAMETOOLONG) ? 0 : -errno; /* If this sysfs is too long then it doesn't exist either */
|
|
||||||
|
|
||||||
r = sd_device_new_from_syspath(ret, p);
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
_public_ int sd_device_new_from_subsystem_sysname(
|
|
||||||
sd_device **ret,
|
|
||||||
const char *subsystem,
|
|
||||||
const char *sysname) {
|
|
||||||
|
|
||||||
const char *s;
|
|
||||||
char *name;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert_return(ret, -EINVAL);
|
assert_return(ret, -EINVAL);
|
||||||
assert_return(path_is_normalized(subsystem), -EINVAL);
|
assert_return(subsystem, -EINVAL);
|
||||||
assert_return(path_is_normalized(sysname), -EINVAL);
|
assert_return(sysname, -EINVAL);
|
||||||
|
assert_return(strlen(sysname) < PATH_MAX - strlen("/sys/bus/"), -ENAMETOOLONG);
|
||||||
|
|
||||||
if (streq(subsystem, "subsystem")) {
|
if (streq(subsystem, "subsystem")) {
|
||||||
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/subsystem/%s", sysname) &&
|
||||||
|
access(syspath, F_OK) >= 0)
|
||||||
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
|
|
||||||
FOREACH_STRING(s, "/sys/subsystem/", "/sys/bus/", "/sys/class/") {
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/bus/%s", sysname) &&
|
||||||
r = device_strjoin_new(s, sysname, NULL, NULL, ret);
|
access(syspath, F_OK) >= 0)
|
||||||
if (r < 0)
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
return r;
|
|
||||||
if (r > 0)
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/class/%s", sysname) &&
|
||||||
return 0;
|
access(syspath, F_OK) >= 0)
|
||||||
}
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
|
|
||||||
} else if (streq(subsystem, "module")) {
|
} else if (streq(subsystem, "module")) {
|
||||||
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/module/%s", sysname) &&
|
||||||
r = device_strjoin_new("/sys/module/", sysname, NULL, NULL, ret);
|
access(syspath, F_OK) >= 0)
|
||||||
if (r < 0)
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
return r;
|
|
||||||
if (r > 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
} else if (streq(subsystem, "drivers")) {
|
} else if (streq(subsystem, "drivers")) {
|
||||||
const char *sep;
|
const char *subsys, *sep;
|
||||||
|
|
||||||
sep = strchr(sysname, ':');
|
sep = strchr(sysname, ':');
|
||||||
if (sep && sep[1] != '\0') { /* Require ":" and something non-empty after that. */
|
if (sep && sep[1] != '\0') { /* Require ":" and something non-empty after that. */
|
||||||
const char *subsys;
|
|
||||||
|
|
||||||
subsys = memdupa_suffix0(sysname, sep - sysname);
|
subsys = memdupa_suffix0(sysname, sep - sysname);
|
||||||
sep++;
|
|
||||||
|
|
||||||
FOREACH_STRING(s, "/sys/subsystem/", "/sys/bus/") {
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/subsystem/%s/drivers/%s", subsys, sep + 1) &&
|
||||||
r = device_strjoin_new(s, subsys, "/drivers/", sep, ret);
|
access(syspath, F_OK) >= 0)
|
||||||
if (r < 0)
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
return r;
|
|
||||||
if (r > 0)
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/bus/%s/drivers/%s", subsys, sep + 1) &&
|
||||||
return 0;
|
access(syspath, F_OK) >= 0)
|
||||||
}
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* translate sysname back to sysfs filename */
|
/* translate sysname back to sysfs filename */
|
||||||
name = strdupa(sysname);
|
name = strdupa(sysname);
|
||||||
|
|
||||||
for (size_t i = 0; name[i]; i++)
|
for (size_t i = 0; name[i]; i++)
|
||||||
if (name[i] == '/')
|
if (name[i] == '/')
|
||||||
name[i] = '!';
|
name[i] = '!';
|
||||||
|
|
||||||
FOREACH_STRING(s, "/sys/subsystem/", "/sys/bus/") {
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/subsystem/%s/devices/%s", subsystem, name) &&
|
||||||
r = device_strjoin_new(s, subsystem, "/devices/", name, ret);
|
access(syspath, F_OK) >= 0)
|
||||||
if (r < 0)
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
return r;
|
|
||||||
if (r > 0)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
r = device_strjoin_new("/sys/class/", subsystem, "/", name, ret);
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/bus/%s/devices/%s", subsystem, name) &&
|
||||||
if (r < 0)
|
access(syspath, F_OK) >= 0)
|
||||||
return r;
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
if (r > 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
r = device_strjoin_new("/sys/firmware/", subsystem, "/", sysname, ret);
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/class/%s/%s", subsystem, name) &&
|
||||||
if (r < 0)
|
access(syspath, F_OK) >= 0)
|
||||||
return r;
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
if (r > 0)
|
|
||||||
return 0;
|
if (snprintf_ok(syspath, sizeof syspath, "/sys/firmware/%s/%s", subsystem, sysname) &&
|
||||||
|
access(syspath, F_OK) >= 0)
|
||||||
|
return sd_device_new_from_syspath(ret, syspath);
|
||||||
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -206,9 +206,6 @@ int journal_directory_vacuum(
|
|||||||
} else if (endswith(de->d_name, ".journal~")) {
|
} else if (endswith(de->d_name, ".journal~")) {
|
||||||
unsigned long long tmp;
|
unsigned long long tmp;
|
||||||
|
|
||||||
/* seqnum_id won't be initialised before use below, so set to 0 */
|
|
||||||
seqnum_id = SD_ID128_NULL;
|
|
||||||
|
|
||||||
/* Vacuum corrupted files */
|
/* Vacuum corrupted files */
|
||||||
|
|
||||||
if (q < 1 + 16 + 1 + 16 + 8 + 1) {
|
if (q < 1 + 16 + 1 + 16 + 8 + 1) {
|
||||||
|
|||||||
@ -1046,25 +1046,26 @@ static int dump_gateways(
|
|||||||
return n;
|
return n;
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
_cleanup_free_ char *gateway = NULL, *description = NULL;
|
_cleanup_free_ char *gateway = NULL, *description = NULL, *with_description = NULL;
|
||||||
char name[IF_NAMESIZE+1];
|
char name[IF_NAMESIZE+1];
|
||||||
|
|
||||||
r = in_addr_to_string(local[i].family, &local[i].address, &gateway);
|
r = in_addr_to_string(local[i].family, &local[i].address, &gateway);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_oom();
|
return r;
|
||||||
|
|
||||||
r = get_gateway_description(rtnl, hwdb, local[i].ifindex, local[i].family, &local[i].address, &description);
|
r = get_gateway_description(rtnl, hwdb, local[i].ifindex, local[i].family, &local[i].address, &description);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_debug_errno(r, "Could not get description of gateway, ignoring: %m");
|
log_debug_errno(r, "Could not get description of gateway, ignoring: %m");
|
||||||
|
|
||||||
if (description) {
|
if (description) {
|
||||||
if (!strextend(&gateway, " (", description, ")"))
|
with_description = strjoin(gateway, " (", description, ")");
|
||||||
|
if (!with_description)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show interface name for the entry if we show entries for all interfaces */
|
/* Show interface name for the entry if we show entries for all interfaces */
|
||||||
r = strv_extendf(&buf, "%s%s%s",
|
r = strv_extendf(&buf, "%s%s%s",
|
||||||
gateway,
|
with_description ?: gateway,
|
||||||
ifindex <= 0 ? " on " : "",
|
ifindex <= 0 ? " on " : "",
|
||||||
ifindex <= 0 ? format_ifname_full(local[i].ifindex, name, FORMAT_IFNAME_IFINDEX_WITH_PERCENT) : "");
|
ifindex <= 0 ? format_ifname_full(local[i].ifindex, name, FORMAT_IFNAME_IFINDEX_WITH_PERCENT) : "");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|||||||
@ -773,17 +773,13 @@ static void log_route_debug(const Route *route, const char *str, const Link *lin
|
|||||||
MultipathRoute *m;
|
MultipathRoute *m;
|
||||||
|
|
||||||
ORDERED_SET_FOREACH(m, route->multipath_routes) {
|
ORDERED_SET_FOREACH(m, route->multipath_routes) {
|
||||||
_cleanup_free_ char *buf = NULL;
|
_cleanup_free_ char *buf = NULL, *joined = NULL;
|
||||||
union in_addr_union a = m->gateway.address;
|
union in_addr_union a = m->gateway.address;
|
||||||
|
|
||||||
(void) in_addr_to_string(m->gateway.family, &a, &buf);
|
(void) in_addr_to_string(m->gateway.family, &a, &buf);
|
||||||
(void) strextend_with_separator(&gw_alloc, ",", strna(buf));
|
joined = strjoin(gw_alloc, gw_alloc ? "," : "", strna(buf), m->ifname ? "@" : "", strempty(m->ifname));
|
||||||
if (m->ifname)
|
if (joined)
|
||||||
(void) strextend(&gw_alloc, "@", m->ifname);
|
free_and_replace(gw_alloc, joined);
|
||||||
else if (m->ifindex > 0)
|
|
||||||
(void) strextendf(&gw_alloc, "@%"PRIu32, m->ifindex);
|
|
||||||
/* See comments in config_parse_multipath_route(). */
|
|
||||||
(void) strextendf(&gw_alloc, ":%"PRIu32, m->weight + 1);
|
|
||||||
}
|
}
|
||||||
gw = gw_alloc;
|
gw = gw_alloc;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -382,28 +382,39 @@ int tmpfs_patch_options(
|
|||||||
const char *selinux_apifs_context,
|
const char *selinux_apifs_context,
|
||||||
char **ret) {
|
char **ret) {
|
||||||
|
|
||||||
_cleanup_free_ char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
|
||||||
assert(ret);
|
if (uid_shift != UID_INVALID) {
|
||||||
|
if (asprintf(&buf, "%s%suid=" UID_FMT ",gid=" UID_FMT,
|
||||||
|
strempty(options), options ? "," : "",
|
||||||
|
uid_shift, uid_shift) < 0)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
if (options) {
|
options = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if HAVE_SELINUX
|
||||||
|
if (selinux_apifs_context) {
|
||||||
|
char *t;
|
||||||
|
|
||||||
|
t = strjoin(strempty(options), options ? "," : "",
|
||||||
|
"context=\"", selinux_apifs_context, "\"");
|
||||||
|
free(buf);
|
||||||
|
if (!t)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
buf = t;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!buf && options) {
|
||||||
buf = strdup(options);
|
buf = strdup(options);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
*ret = buf;
|
||||||
|
|
||||||
if (uid_shift != UID_INVALID)
|
return !!buf;
|
||||||
if (strextendf_with_separator(&buf, ",", "uid=" UID_FMT ",gid=" UID_FMT, uid_shift, uid_shift) < 0)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
#if HAVE_SELINUX
|
|
||||||
if (selinux_apifs_context)
|
|
||||||
if (!strextend_with_separator(&buf, ",", "context=\"", selinux_apifs_context, "\""))
|
|
||||||
return -ENOMEM;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*ret = TAKE_PTR(buf);
|
|
||||||
return !!*ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
|
int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
|
||||||
|
|||||||
@ -333,11 +333,7 @@ int oomd_cgroup_context_acquire(const char *path, OomdCGroupContext **ret) {
|
|||||||
return log_debug_errno(r, "Error getting memory.low from %s: %m", path);
|
return log_debug_errno(r, "Error getting memory.low from %s: %m", path);
|
||||||
|
|
||||||
r = cg_get_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.swap.current", &ctx->swap_usage);
|
r = cg_get_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.swap.current", &ctx->swap_usage);
|
||||||
if (r == -ENODATA)
|
if (r < 0)
|
||||||
/* The kernel can be compiled without support for memory.swap.* files,
|
|
||||||
* or it can be disabled with boot param 'swapaccount=0' */
|
|
||||||
log_once(LOG_WARNING, "No kernel support for memory.swap.current from %s (try boot param swapaccount=1), ignoring.", path);
|
|
||||||
else if (r < 0)
|
|
||||||
return log_debug_errno(r, "Error getting memory.swap.current from %s: %m", path);
|
return log_debug_errno(r, "Error getting memory.swap.current from %s: %m", path);
|
||||||
|
|
||||||
r = cg_get_keyed_attribute(SYSTEMD_CGROUP_CONTROLLER, path, "memory.stat", STRV_MAKE("pgscan"), &val);
|
r = cg_get_keyed_attribute(SYSTEMD_CGROUP_CONTROLLER, path, "memory.stat", STRV_MAKE("pgscan"), &val);
|
||||||
|
|||||||
@ -805,9 +805,7 @@ int dnssec_verify_rrset(
|
|||||||
case DNSSEC_ALGORITHM_ED448:
|
case DNSSEC_ALGORITHM_ED448:
|
||||||
*result = DNSSEC_UNSUPPORTED_ALGORITHM;
|
*result = DNSSEC_UNSUPPORTED_ALGORITHM;
|
||||||
return 0;
|
return 0;
|
||||||
default: {
|
default:
|
||||||
gcry_error_t err;
|
|
||||||
|
|
||||||
/* OK, the RRs are now in canonical order. Let's calculate the digest */
|
/* OK, the RRs are now in canonical order. Let's calculate the digest */
|
||||||
md_algorithm = algorithm_to_gcrypt_md(rrsig->rrsig.algorithm);
|
md_algorithm = algorithm_to_gcrypt_md(rrsig->rrsig.algorithm);
|
||||||
if (md_algorithm == -EOPNOTSUPP) {
|
if (md_algorithm == -EOPNOTSUPP) {
|
||||||
@ -817,8 +815,8 @@ int dnssec_verify_rrset(
|
|||||||
if (md_algorithm < 0)
|
if (md_algorithm < 0)
|
||||||
return md_algorithm;
|
return md_algorithm;
|
||||||
|
|
||||||
err = gcry_md_open(&md, md_algorithm, 0);
|
gcry_md_open(&md, md_algorithm, 0);
|
||||||
if (gcry_err_code(err) != GPG_ERR_NO_ERROR || !md)
|
if (!md)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
hash_size = gcry_md_get_algo_dlen(md_algorithm);
|
hash_size = gcry_md_get_algo_dlen(md_algorithm);
|
||||||
@ -830,7 +828,6 @@ int dnssec_verify_rrset(
|
|||||||
if (!hash)
|
if (!hash)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch (rrsig->rrsig.algorithm) {
|
switch (rrsig->rrsig.algorithm) {
|
||||||
|
|
||||||
|
|||||||
@ -667,8 +667,15 @@ static int transient_cgroup_set_properties(sd_bus_message *m) {
|
|||||||
*end = 0;
|
*end = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isempty(arg_slice) && !strextend_with_separator(&name, "-", arg_slice))
|
if (!isempty(arg_slice)) {
|
||||||
return log_oom();
|
if (name) {
|
||||||
|
char *j = strjoin(name, "-", arg_slice);
|
||||||
|
free_and_replace(name, j);
|
||||||
|
} else
|
||||||
|
name = strdup(arg_slice);
|
||||||
|
if (!name)
|
||||||
|
return log_oom();
|
||||||
|
}
|
||||||
|
|
||||||
if (!name)
|
if (!name)
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "errno-util.h"
|
|
||||||
#include "extract-word.h"
|
#include "extract-word.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
@ -108,18 +107,12 @@ int read_resource_pressure(const char *path, PressureType type, ResourcePressure
|
|||||||
int is_pressure_supported(void) {
|
int is_pressure_supported(void) {
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
/* The pressure files, both under /proc and in cgroups, will exist
|
FOREACH_STRING(p, "/proc/pressure/cpu", "/proc/pressure/io", "/proc/pressure/memory")
|
||||||
* even if the kernel has PSI support disabled; we have to read
|
if (access(p, F_OK) < 0) {
|
||||||
* the file to make sure it doesn't return -EOPNOTSUPP */
|
if (errno == ENOENT)
|
||||||
FOREACH_STRING(p, "/proc/pressure/cpu", "/proc/pressure/io", "/proc/pressure/memory") {
|
return 0;
|
||||||
int r;
|
return -errno;
|
||||||
|
}
|
||||||
r = read_virtual_file(p, 0, NULL, NULL);
|
|
||||||
if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r))
|
|
||||||
return 0;
|
|
||||||
if (r < 0)
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1659,9 +1659,14 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
while ((r = sd_bus_message_read(m, "(ss)", &partition, &mount_options)) > 0)
|
while ((r = sd_bus_message_read(m, "(ss)", &partition, &mount_options)) > 0) {
|
||||||
if (!strextend_with_separator(&str, ":", partition, ":", mount_options))
|
_cleanup_free_ char *previous = NULL;
|
||||||
|
|
||||||
|
previous = TAKE_PTR(str);
|
||||||
|
str = strjoin(strempty(previous), previous ? ":" : "", partition, ":", mount_options);
|
||||||
|
if (!str)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
}
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
|||||||
@ -533,7 +533,7 @@ static int load_sysv(SysvStub *s) {
|
|||||||
* continuation */
|
* continuation */
|
||||||
|
|
||||||
size_t k;
|
size_t k;
|
||||||
const char *j;
|
char *j;
|
||||||
|
|
||||||
k = strlen(t);
|
k = strlen(t);
|
||||||
if (k > 0 && t[k-1] == '\\')
|
if (k > 0 && t[k-1] == '\\')
|
||||||
@ -542,8 +542,19 @@ static int load_sysv(SysvStub *s) {
|
|||||||
state = NORMAL;
|
state = NORMAL;
|
||||||
|
|
||||||
j = strstrip(t);
|
j = strstrip(t);
|
||||||
if (!isempty(j) && !strextend_with_separator(&chkconfig_description, " ", j))
|
if (!isempty(j)) {
|
||||||
return log_oom();
|
char *d = NULL;
|
||||||
|
|
||||||
|
if (chkconfig_description)
|
||||||
|
d = strjoin(chkconfig_description, " ", j);
|
||||||
|
else
|
||||||
|
d = strdup(j);
|
||||||
|
if (!d)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
|
free(chkconfig_description);
|
||||||
|
chkconfig_description = d;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (IN_SET(state, LSB, LSB_DESCRIPTION)) {
|
} else if (IN_SET(state, LSB, LSB_DESCRIPTION)) {
|
||||||
|
|
||||||
@ -593,8 +604,20 @@ static int load_sysv(SysvStub *s) {
|
|||||||
const char *j;
|
const char *j;
|
||||||
|
|
||||||
j = strstrip(t);
|
j = strstrip(t);
|
||||||
if (!isempty(j) && !strextend_with_separator(&long_description, " ", j))
|
if (!isempty(j)) {
|
||||||
return log_oom();
|
char *d = NULL;
|
||||||
|
|
||||||
|
if (long_description)
|
||||||
|
d = strjoin(long_description, " ", t);
|
||||||
|
else
|
||||||
|
d = strdup(j);
|
||||||
|
if (!d)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
|
free(long_description);
|
||||||
|
long_description = d;
|
||||||
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
state = LSB;
|
state = LSB;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -984,20 +984,6 @@ static void test_strextendf(void) {
|
|||||||
|
|
||||||
assert_se(strextendf(&p, "<%08x>", 0x1234) >= 0);
|
assert_se(strextendf(&p, "<%08x>", 0x1234) >= 0);
|
||||||
assert_se(streq(p, "<77><99>< 88><00001234>"));
|
assert_se(streq(p, "<77><99>< 88><00001234>"));
|
||||||
|
|
||||||
p = mfree(p);
|
|
||||||
|
|
||||||
assert_se(strextendf_with_separator(&p, ",", "<%i>", 77) >= 0);
|
|
||||||
assert_se(streq(p, "<77>"));
|
|
||||||
|
|
||||||
assert_se(strextendf_with_separator(&p, ",", "<%i>", 99) >= 0);
|
|
||||||
assert_se(streq(p, "<77>,<99>"));
|
|
||||||
|
|
||||||
assert_se(strextendf_with_separator(&p, ",", "<%80i>", 88) >= 0);
|
|
||||||
assert_se(streq(p, "<77>,<99>,< 88>"));
|
|
||||||
|
|
||||||
assert_se(strextendf_with_separator(&p, ",", "<%08x>", 0x1234) >= 0);
|
|
||||||
assert_se(streq(p, "<77>,<99>,< 88>,<00001234>"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|||||||
@ -252,7 +252,7 @@ static void test_udev_resolve_subsys_kernel(void) {
|
|||||||
test_udev_resolve_subsys_kernel_one("hoge", false, -EINVAL, NULL);
|
test_udev_resolve_subsys_kernel_one("hoge", false, -EINVAL, NULL);
|
||||||
test_udev_resolve_subsys_kernel_one("[hoge", false, -EINVAL, NULL);
|
test_udev_resolve_subsys_kernel_one("[hoge", false, -EINVAL, NULL);
|
||||||
test_udev_resolve_subsys_kernel_one("[hoge/foo", false, -EINVAL, NULL);
|
test_udev_resolve_subsys_kernel_one("[hoge/foo", false, -EINVAL, NULL);
|
||||||
test_udev_resolve_subsys_kernel_one("[hoge/]", false, -EINVAL, NULL);
|
test_udev_resolve_subsys_kernel_one("[hoge/]", false, -ENODEV, NULL);
|
||||||
|
|
||||||
test_udev_resolve_subsys_kernel_one("[net/lo]", false, 0, "/sys/devices/virtual/net/lo");
|
test_udev_resolve_subsys_kernel_one("[net/lo]", false, 0, "/sys/devices/virtual/net/lo");
|
||||||
test_udev_resolve_subsys_kernel_one("[net/lo]/", false, 0, "/sys/devices/virtual/net/lo");
|
test_udev_resolve_subsys_kernel_one("[net/lo]/", false, 0, "/sys/devices/virtual/net/lo");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user