1
0
mirror of https://github.com/systemd/systemd synced 2025-11-17 15:54:45 +01:00

Compare commits

..

11 Commits

Author SHA1 Message Date
dependabot[bot]
25a507d290 build(deps): bump softprops/action-gh-release from 2.2.2 to 2.4.1
Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 2.2.2 to 2.4.1.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](da05d55257...6da8fa9354)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-version: 2.4.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-01 18:12:26 +09:00
dependabot[bot]
61f7ec3fc5 build(deps): bump redhat-plumbers-in-action/advanced-issue-labeler
Bumps [redhat-plumbers-in-action/advanced-issue-labeler](https://github.com/redhat-plumbers-in-action/advanced-issue-labeler) from 3.2.2 to 3.2.3.
- [Release notes](https://github.com/redhat-plumbers-in-action/advanced-issue-labeler/releases)
- [Commits](0db433d412...e38e6809c5)

---
updated-dependencies:
- dependency-name: redhat-plumbers-in-action/advanced-issue-labeler
  dependency-version: 3.2.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-01 18:12:00 +09:00
Yu Watanabe
7829c9cc48 discover-image: introduce bus_property_get_image_is_read_only() with BUS_DEFINE_PROPERTY_GET() macro
This also makes image_is_read_only() return bool.

Follow-up for ee327e086e0534645d1c8cb9daa49cd8d7d68d51.
2025-11-01 18:11:18 +09:00
Yu Watanabe
cbd8a12bce
Several cleanups around strv_extendf() (#39508) 2025-11-01 18:10:42 +09:00
Yu Watanabe
154de15bdf vmspawn: replace strv_extendf() with strv_extend_joined() when concatenating strings 2025-11-01 00:59:41 +09:00
Yu Watanabe
323fafbb55 vmspawn: use strv_extendf() at one more place 2025-11-01 00:59:41 +09:00
Yu Watanabe
2b2b04d6d0 dns-rr: use strv_extendf() at one more place 2025-11-01 00:59:41 +09:00
Yu Watanabe
bafbcd3b27 core/exec-invoke: use heap allocation to build environment variables
We sometimes forget to increase the size N_ENV_VARS. Let's use heap
allocation.
2025-11-01 00:59:41 +09:00
Yu Watanabe
19bbcd35d7 strv: introduce strv_extend_joined() and strv_extend_joined_with_size() 2025-11-01 00:59:36 +09:00
Yu Watanabe
69350ee3e3 string-util: introduce strextendv_with_separator() 2025-11-01 00:58:42 +09:00
Yu Watanabe
3c66f40262 strv: introduce strv_extendf_with_size() 2025-11-01 00:58:39 +09:00
14 changed files with 180 additions and 176 deletions

View File

@ -29,7 +29,7 @@ jobs:
template-path: .github/ISSUE_TEMPLATE/${{ matrix.template }} template-path: .github/ISSUE_TEMPLATE/${{ matrix.template }}
- name: Set labels based on component field - name: Set labels based on component field
uses: redhat-plumbers-in-action/advanced-issue-labeler@0db433d412193574252480b4fc22f2e4319a4ea3 uses: redhat-plumbers-in-action/advanced-issue-labeler@e38e6809c5420d038eed380d49ee9a6ca7c92dbf
with: with:
issue-form: ${{ steps.issue-parser.outputs.jsonString }} issue-form: ${{ steps.issue-parser.outputs.jsonString }}
template: ${{ matrix.template }} template: ${{ matrix.template }}

View File

@ -18,7 +18,7 @@ jobs:
steps: steps:
- name: Release - name: Release
uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631 uses: softprops/action-gh-release@6da8fa9354ddfdc4aeace5fc48d7f679b5214090
with: with:
prerelease: ${{ contains(github.ref_name, '-rc') }} prerelease: ${{ contains(github.ref_name, '-rc') }}
draft: ${{ github.repository == 'systemd/systemd' }} draft: ${{ github.repository == 'systemd/systemd' }}

View File

@ -793,12 +793,11 @@ char* strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
return *ibuf; return *ibuf;
} }
char* strextend_with_separator_internal(char **x, const char *separator, ...) { char* strextendv_with_separator(char **x, const char *separator, va_list ap) {
_cleanup_free_ char *buffer = NULL; _cleanup_free_ char *buffer = NULL;
size_t f, l, l_separator; size_t f, l, l_separator;
bool need_separator; bool need_separator;
char *nr, *p; char *nr, *p;
va_list ap;
if (!x) if (!x)
x = &buffer; x = &buffer;
@ -808,11 +807,12 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) {
need_separator = !isempty(*x); need_separator = !isempty(*x);
l_separator = strlen_ptr(separator); l_separator = strlen_ptr(separator);
va_start(ap, separator); va_list aq;
va_copy(aq, ap);
for (const char *t;;) { for (const char *t;;) {
size_t n; size_t n;
t = va_arg(ap, const char *); t = va_arg(aq, const char *);
if (!t) if (!t)
break; break;
if (t == POINTER_MAX) if (t == POINTER_MAX)
@ -824,14 +824,14 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) {
n += l_separator; n += l_separator;
if (n >= SIZE_MAX - l) { if (n >= SIZE_MAX - l) {
va_end(ap); va_end(aq);
return NULL; return NULL;
} }
l += n; l += n;
need_separator = true; need_separator = true;
} }
va_end(ap); va_end(aq);
need_separator = !isempty(*x); need_separator = !isempty(*x);
@ -842,7 +842,6 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) {
*x = nr; *x = nr;
p = nr + f; p = nr + f;
va_start(ap, separator);
for (;;) { for (;;) {
const char *t; const char *t;
@ -859,7 +858,6 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) {
need_separator = true; need_separator = true;
} }
va_end(ap);
assert(p == nr + l); assert(p == nr + l);
*p = 0; *p = 0;
@ -872,6 +870,17 @@ char* strextend_with_separator_internal(char **x, const char *separator, ...) {
return p; return p;
} }
char* strextend_with_separator_internal(char **x, const char *separator, ...) {
va_list ap;
char *ret;
va_start(ap, separator);
ret = strextendv_with_separator(x, separator, ap);
va_end(ap);
return ret;
}
int strextendf_with_separator(char **x, const char *separator, const char *format, ...) { int strextendf_with_separator(char **x, const char *separator, const char *format, ...) {
size_t m, a, l_separator; size_t m, a, l_separator;
va_list ap; va_list ap;

View File

@ -169,6 +169,7 @@ 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* strextendv_with_separator(char **x, const char *separator, va_list ap);
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)

View File

@ -906,7 +906,7 @@ void strv_print_full(char * const *l, const char *prefix) {
printf("%s%s\n", strempty(prefix), *s); printf("%s%s\n", strempty(prefix), *s);
} }
int strv_extendf(char ***l, const char *format, ...) { int strv_extendf_with_size(char ***l, size_t *n, const char *format, ...) {
va_list ap; va_list ap;
char *x; char *x;
int r; int r;
@ -918,7 +918,19 @@ int strv_extendf(char ***l, const char *format, ...) {
if (r < 0) if (r < 0)
return -ENOMEM; return -ENOMEM;
return strv_consume(l, x); return strv_consume_with_size(l, n, x);
}
int strv_extend_joined_with_size_sentinel(char ***l, size_t *n, ...) {
va_list ap;
va_start(ap, n);
char *x = strextendv_with_separator(/* x= */ NULL, /* separator=*/ NULL, ap);
va_end(ap);
if (!x)
return -ENOMEM;
return strv_consume_with_size(l, n, x);
} }
char* startswith_strv(const char *s, char * const *l) { char* startswith_strv(const char *s, char * const *l) {

View File

@ -56,7 +56,12 @@ static inline int strv_extend(char ***l, const char *value) {
int strv_extend_many_internal(char ***l, const char *value, ...); int strv_extend_many_internal(char ***l, const char *value, ...);
#define strv_extend_many(l, ...) strv_extend_many_internal(l, __VA_ARGS__, POINTER_MAX) #define strv_extend_many(l, ...) strv_extend_many_internal(l, __VA_ARGS__, POINTER_MAX)
int strv_extendf(char ***l, const char *format, ...) _printf_(2,3); int strv_extendf_with_size(char ***l, size_t *n, const char *format, ...) _printf_(3,4);
#define strv_extendf(l, ...) strv_extendf_with_size(l, NULL, __VA_ARGS__)
int strv_extend_joined_with_size_sentinel(char ***l, size_t *n, ...) _sentinel_;
#define strv_extend_joined_with_size(l, n, ...) strv_extend_joined_with_size_sentinel(l, n, __VA_ARGS__, NULL)
#define strv_extend_joined(l, ...) strv_extend_joined_with_size(l, NULL, __VA_ARGS__)
int strv_push_with_size(char ***l, size_t *n, char *value); int strv_push_with_size(char ***l, size_t *n, char *value);
static inline int strv_push(char ***l, char *value) { static inline int strv_push(char ***l, char *value) {

View File

@ -1999,9 +1999,8 @@ static int build_environment(
bool needs_sandboxing, bool needs_sandboxing,
char ***ret) { char ***ret) {
_cleanup_strv_free_ char **our_env = NULL; _cleanup_strv_free_ char **e = NULL;
size_t n_env = 0; size_t n = 0;
char *x;
int r; int r;
assert(c); assert(c);
@ -2009,57 +2008,50 @@ static int build_environment(
assert(cgroup_context); assert(cgroup_context);
assert(ret); assert(ret);
#define N_ENV_VARS 20
our_env = new0(char*, N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX + 1);
if (!our_env)
return -ENOMEM;
if (p->n_socket_fds + p->n_stashed_fds > 0) { if (p->n_socket_fds + p->n_stashed_fds > 0) {
_cleanup_free_ char *joined = NULL; _cleanup_free_ char *joined = NULL;
if (asprintf(&x, "LISTEN_PID="PID_FMT, getpid_cached()) < 0) r = strv_extendf_with_size(&e, &n, "LISTEN_PID="PID_FMT, getpid_cached());
return -ENOMEM; if (r < 0)
our_env[n_env++] = x; return r;
uint64_t pidfdid; uint64_t pidfdid;
if (pidfd_get_inode_id_self_cached(&pidfdid) >= 0) { if (pidfd_get_inode_id_self_cached(&pidfdid) >= 0) {
if (asprintf(&x, "LISTEN_PIDFDID=%"PRIu64, pidfdid) < 0) r = strv_extendf_with_size(&e, &n, "LISTEN_PIDFDID=%"PRIu64, pidfdid);
return -ENOMEM; if (r < 0)
our_env[n_env++] = x; return r;
} }
if (asprintf(&x, "LISTEN_FDS=%zu", p->n_socket_fds + p->n_stashed_fds) < 0) r = strv_extendf_with_size(&e, &n, "LISTEN_FDS=%zu", p->n_socket_fds + p->n_stashed_fds);
return -ENOMEM; if (r < 0)
our_env[n_env++] = x; return r;
joined = strv_join(p->fd_names, ":"); joined = strv_join(p->fd_names, ":");
if (!joined) if (!joined)
return -ENOMEM; return -ENOMEM;
x = strjoin("LISTEN_FDNAMES=", joined); r = strv_extend_joined_with_size(&e, &n, "LISTEN_FDNAMES=", joined);
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
} }
if ((p->flags & EXEC_SET_WATCHDOG) && p->watchdog_usec > 0) { if ((p->flags & EXEC_SET_WATCHDOG) && p->watchdog_usec > 0) {
if (asprintf(&x, "WATCHDOG_PID="PID_FMT, getpid_cached()) < 0) r = strv_extendf_with_size(&e, &n, "WATCHDOG_PID="PID_FMT, getpid_cached());
return -ENOMEM; if (r < 0)
our_env[n_env++] = x; return r;
if (asprintf(&x, "WATCHDOG_USEC="USEC_FMT, p->watchdog_usec) < 0) r = strv_extendf_with_size(&e, &n, "WATCHDOG_USEC="USEC_FMT, p->watchdog_usec);
return -ENOMEM; if (r < 0)
our_env[n_env++] = x; return r;
} }
/* If this is D-Bus, tell the nss-systemd module, since it relies on being able to use blocking /* If this is D-Bus, tell the nss-systemd module, since it relies on being able to use blocking
* Varlink calls back to us for look up dynamic users in PID 1. Break the deadlock between D-Bus and * Varlink calls back to us for look up dynamic users in PID 1. Break the deadlock between D-Bus and
* PID 1 by disabling use of PID1' NSS interface for looking up dynamic users. */ * PID 1 by disabling use of PID1' NSS interface for looking up dynamic users. */
if (p->flags & EXEC_NSS_DYNAMIC_BYPASS) { if (p->flags & EXEC_NSS_DYNAMIC_BYPASS) {
x = strdup("SYSTEMD_NSS_DYNAMIC_BYPASS=1"); r = strv_extend_with_size(&e, &n, "SYSTEMD_NSS_DYNAMIC_BYPASS=1");
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
} }
/* We query "root" if this is a system unit and User= is not specified. $USER is always set. $HOME /* We query "root" if this is a system unit and User= is not specified. $USER is always set. $HOME
@ -2077,16 +2069,14 @@ static int build_environment(
bool set_user_login_env = exec_context_get_set_login_environment(c); bool set_user_login_env = exec_context_get_set_login_environment(c);
if (username) { if (username) {
x = strjoin("USER=", username); r = strv_extend_joined_with_size(&e, &n, "USER=", username);
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
if (set_user_login_env) { if (set_user_login_env) {
x = strjoin("LOGNAME=", username); r = strv_extend_joined_with_size(&e, &n, "LOGNAME=", username);
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
} }
} }
@ -2094,51 +2084,51 @@ static int build_environment(
* (i.e. are "/" or "/bin/nologin"). */ * (i.e. are "/" or "/bin/nologin"). */
if (home && set_user_login_env && !empty_or_root(home)) { if (home && set_user_login_env && !empty_or_root(home)) {
x = strjoin("HOME=", home); _cleanup_free_ char *x = NULL;
if (!x)
return -ENOMEM;
path_simplify(x + 5); r = path_simplify_alloc(home, &x);
our_env[n_env++] = x; if (r < 0)
return r;
r = strv_extend_joined_with_size(&e, &n, "HOME=", x);
if (r < 0)
return r;
} }
if (shell && set_user_login_env && !shell_is_placeholder(shell)) { if (shell && set_user_login_env && !shell_is_placeholder(shell)) {
x = strjoin("SHELL=", shell); _cleanup_free_ char *x = NULL;
if (!x)
return -ENOMEM;
path_simplify(x + 6); r = path_simplify_alloc(shell, &x);
our_env[n_env++] = x; if (r < 0)
return r;
r = strv_extend_joined_with_size(&e, &n, "SHELL=", x);
if (r < 0)
return r;
} }
if (!sd_id128_is_null(p->invocation_id)) { if (!sd_id128_is_null(p->invocation_id)) {
assert(p->invocation_id_string); assert(p->invocation_id_string);
x = strjoin("INVOCATION_ID=", p->invocation_id_string); r = strv_extend_joined_with_size(&e, &n, "INVOCATION_ID=", p->invocation_id_string);
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
} }
if (journal_stream_dev != 0 && journal_stream_ino != 0) { if (journal_stream_dev != 0 && journal_stream_ino != 0) {
if (asprintf(&x, "JOURNAL_STREAM=" DEV_FMT ":" INO_FMT, journal_stream_dev, journal_stream_ino) < 0) r = strv_extendf_with_size(&e, &n, "JOURNAL_STREAM=" DEV_FMT ":" INO_FMT, journal_stream_dev, journal_stream_ino);
return -ENOMEM; if (r < 0)
return r;
our_env[n_env++] = x;
} }
if (c->log_namespace) { if (c->log_namespace) {
x = strjoin("LOG_NAMESPACE=", c->log_namespace); r = strv_extend_joined_with_size(&e, &n, "LOG_NAMESPACE=", c->log_namespace);
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
} }
for (ExecDirectoryType t = 0; t < _EXEC_DIRECTORY_TYPE_MAX; t++) { for (ExecDirectoryType t = 0; t < _EXEC_DIRECTORY_TYPE_MAX; t++) {
_cleanup_free_ char *joined = NULL; _cleanup_free_ char *joined = NULL;
const char *n;
if (!p->prefix[t]) if (!p->prefix[t])
continue; continue;
@ -2146,8 +2136,8 @@ static int build_environment(
if (c->directories[t].n_items == 0) if (c->directories[t].n_items == 0)
continue; continue;
n = exec_directory_env_name_to_string(t); const char *name = exec_directory_env_name_to_string(t);
if (!n) if (!name)
continue; continue;
for (size_t i = 0; i < c->directories[t].n_items; i++) { for (size_t i = 0; i < c->directories[t].n_items; i++) {
@ -2161,11 +2151,9 @@ static int build_environment(
return -ENOMEM; return -ENOMEM;
} }
x = strjoin(n, "=", joined); r = strv_extend_joined_with_size(&e, &n, name, "=", joined);
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
} }
_cleanup_free_ char *creds_dir = NULL; _cleanup_free_ char *creds_dir = NULL;
@ -2173,27 +2161,22 @@ static int build_environment(
if (r < 0) if (r < 0)
return r; return r;
if (r > 0) { if (r > 0) {
x = strjoin("CREDENTIALS_DIRECTORY=", creds_dir); r = strv_extend_joined_with_size(&e, &n, "CREDENTIALS_DIRECTORY=", creds_dir);
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
} }
if (asprintf(&x, "SYSTEMD_EXEC_PID=" PID_FMT, getpid_cached()) < 0) r = strv_extendf_with_size(&e, &n, "SYSTEMD_EXEC_PID=" PID_FMT, getpid_cached());
return -ENOMEM; if (r < 0)
return r;
our_env[n_env++] = x;
if (memory_pressure_path) { if (memory_pressure_path) {
x = strjoin("MEMORY_PRESSURE_WATCH=", memory_pressure_path); r = strv_extend_joined_with_size(&e, &n, "MEMORY_PRESSURE_WATCH=", memory_pressure_path);
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
if (!path_equal(memory_pressure_path, "/dev/null")) { if (!path_equal(memory_pressure_path, "/dev/null")) {
_cleanup_free_ char *b = NULL, *e = NULL; _cleanup_free_ char *b = NULL, *x = NULL;
if (asprintf(&b, "%s " USEC_FMT " " USEC_FMT, if (asprintf(&b, "%s " USEC_FMT " " USEC_FMT,
MEMORY_PRESSURE_DEFAULT_TYPE, MEMORY_PRESSURE_DEFAULT_TYPE,
@ -2202,23 +2185,21 @@ static int build_environment(
MEMORY_PRESSURE_DEFAULT_WINDOW_USEC) < 0) MEMORY_PRESSURE_DEFAULT_WINDOW_USEC) < 0)
return -ENOMEM; return -ENOMEM;
if (base64mem(b, strlen(b) + 1, &e) < 0) if (base64mem(b, strlen(b) + 1, &x) < 0)
return -ENOMEM; return -ENOMEM;
x = strjoin("MEMORY_PRESSURE_WRITE=", e); r = strv_extend_joined_with_size(&e, &n, "MEMORY_PRESSURE_WRITE=", x);
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
} }
} }
if (p->notify_socket) { if (p->notify_socket) {
x = strjoin("NOTIFY_SOCKET=", exec_get_private_notify_socket_path(c, p, needs_sandboxing) ?: p->notify_socket); r = strv_extend_joined_with_size(
if (!x) &e, &n, "NOTIFY_SOCKET=",
return -ENOMEM; exec_get_private_notify_socket_path(c, p, needs_sandboxing) ?: p->notify_socket);
if (r < 0)
our_env[n_env++] = x; return r;
} }
assert(c->private_var_tmp >= 0 && c->private_var_tmp < _PRIVATE_TMP_MAX); assert(c->private_var_tmp >= 0 && c->private_var_tmp < _PRIVATE_TMP_MAX);
@ -2229,18 +2210,12 @@ static int build_environment(
/* When private tmpfs is enabled only on /tmp/, then explicitly set $TMPDIR to suggest the /* When private tmpfs is enabled only on /tmp/, then explicitly set $TMPDIR to suggest the
* service to use /tmp/. */ * service to use /tmp/. */
x = strdup("TMPDIR=/tmp"); r = strv_extend_with_size(&e, &n, "TMPDIR=/tmp");
if (!x) if (r < 0)
return -ENOMEM; return r;
our_env[n_env++] = x;
} }
assert(n_env <= N_ENV_VARS + _EXEC_DIRECTORY_TYPE_MAX); *ret = TAKE_PTR(e);
#undef N_ENV_VARS
*ret = TAKE_PTR(our_env);
return 0; return 0;
} }

View File

@ -24,20 +24,6 @@
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, image_type, ImageType); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, image_type, ImageType);
static int property_get_read_only(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
Image *image = ASSERT_PTR(userdata);
return sd_bus_message_append(ASSERT_PTR(reply), "b", image_is_read_only(image));
}
int bus_image_method_remove( int bus_image_method_remove(
sd_bus_message *message, sd_bus_message *message,
void *userdata, void *userdata,
@ -462,7 +448,7 @@ const sd_bus_vtable image_vtable[] = {
SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Image, name), 0), SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Image, name), 0),
SD_BUS_PROPERTY("Path", "s", NULL, offsetof(Image, path), 0), SD_BUS_PROPERTY("Path", "s", NULL, offsetof(Image, path), 0),
SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Image, type), 0), SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Image, type), 0),
SD_BUS_PROPERTY("ReadOnly", "b", property_get_read_only, 0, 0), SD_BUS_PROPERTY("ReadOnly", "b", bus_property_get_image_is_read_only, 0, 0),
SD_BUS_PROPERTY("CreationTimestamp", "t", NULL, offsetof(Image, crtime), 0), SD_BUS_PROPERTY("CreationTimestamp", "t", NULL, offsetof(Image, crtime), 0),
SD_BUS_PROPERTY("ModificationTimestamp", "t", NULL, offsetof(Image, mtime), 0), SD_BUS_PROPERTY("ModificationTimestamp", "t", NULL, offsetof(Image, mtime), 0),
SD_BUS_PROPERTY("Usage", "t", NULL, offsetof(Image, usage), 0), SD_BUS_PROPERTY("Usage", "t", NULL, offsetof(Image, usage), 0),

View File

@ -30,20 +30,6 @@
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, image_type, ImageType); static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_type, image_type, ImageType);
static int property_get_read_only(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
Image *image = ASSERT_PTR(userdata);
return sd_bus_message_append(ASSERT_PTR(reply), "b", image_is_read_only(image));
}
int bus_image_common_get_os_release( int bus_image_common_get_os_release(
Manager *m, Manager *m,
sd_bus_message *message, sd_bus_message *message,
@ -879,7 +865,7 @@ const sd_bus_vtable image_vtable[] = {
SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Image, name), 0), SD_BUS_PROPERTY("Name", "s", NULL, offsetof(Image, name), 0),
SD_BUS_PROPERTY("Path", "s", NULL, offsetof(Image, path), 0), SD_BUS_PROPERTY("Path", "s", NULL, offsetof(Image, path), 0),
SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Image, type), 0), SD_BUS_PROPERTY("Type", "s", property_get_type, offsetof(Image, type), 0),
SD_BUS_PROPERTY("ReadOnly", "b", property_get_read_only, 0, 0), SD_BUS_PROPERTY("ReadOnly", "b", bus_property_get_image_is_read_only, 0, 0),
SD_BUS_PROPERTY("CreationTimestamp", "t", NULL, offsetof(Image, crtime), 0), SD_BUS_PROPERTY("CreationTimestamp", "t", NULL, offsetof(Image, crtime), 0),
SD_BUS_PROPERTY("ModificationTimestamp", "t", NULL, offsetof(Image, mtime), 0), SD_BUS_PROPERTY("ModificationTimestamp", "t", NULL, offsetof(Image, mtime), 0),
SD_BUS_PROPERTY("Usage", "t", NULL, offsetof(Image, usage), 0), SD_BUS_PROPERTY("Usage", "t", NULL, offsetof(Image, usage), 0),

View File

@ -16,6 +16,7 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "blockdev-util.h" #include "blockdev-util.h"
#include "btrfs-util.h" #include "btrfs-util.h"
#include "bus-get-properties.h"
#include "chase.h" #include "chase.h"
#include "chattr-util.h" #include "chattr-util.h"
#include "copy.h" #include "copy.h"
@ -2220,3 +2221,5 @@ int image_root_pick(
*ret = TAKE_PTR(s); *ret = TAKE_PTR(s);
return 0; return 0;
} }
BUS_DEFINE_PROPERTY_GET(bus_property_get_image_is_read_only, "b", Image, (int) image_is_read_only);

View File

@ -91,7 +91,7 @@ static inline bool image_is_hidden(const Image *i) {
return i->name && i->name[0] == '.'; return i->name && i->name[0] == '.';
} }
static inline int image_is_read_only(const Image *i) { static inline bool image_is_read_only(const Image *i) {
assert(i); assert(i);
/* We enforce the rule that hidden images are always read-only too. If people want to change hidden /* We enforce the rule that hidden images are always read-only too. If people want to change hidden
@ -102,6 +102,7 @@ static inline int image_is_read_only(const Image *i) {
return i->read_only; return i->read_only;
} }
int bus_property_get_image_is_read_only(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *reterr_error);
bool image_is_vendor(const Image *i); bool image_is_vendor(const Image *i);
bool image_is_host(const Image *i); bool image_is_host(const Image *i);

View File

@ -819,21 +819,12 @@ static char *format_types(Bitmap *types) {
int r; int r;
BITMAP_FOREACH(type, types) { BITMAP_FOREACH(type, types) {
if (dns_type_to_string(type)) { if (dns_type_to_string(type))
r = strv_extend(&strv, dns_type_to_string(type)); r = strv_extend(&strv, dns_type_to_string(type));
else
r = strv_extendf(&strv, "TYPE%u", type);
if (r < 0) if (r < 0)
return NULL; return NULL;
} else {
char *t;
r = asprintf(&t, "TYPE%u", type);
if (r < 0)
return NULL;
r = strv_consume(&strv, t);
if (r < 0)
return NULL;
}
} }
str = strv_join(strv, " "); str = strv_join(strv, " ");

View File

@ -749,6 +749,43 @@ TEST(strv_extendf) {
ASSERT_STREQ(b[0], "test3 bar foo 128"); ASSERT_STREQ(b[0], "test3 bar foo 128");
} }
TEST(strv_extendf_with_size) {
_cleanup_strv_free_ char **a = NULL;
size_t n = 0;
ASSERT_OK(strv_extendf_with_size(&a, &n, "test2 %s %d %s", "foo", 128, "bar"));
ASSERT_OK(strv_extendf_with_size(&a, &n, "test3 %s %s %d", "bar", "foo", 128));
ASSERT_EQ(n, 2u);
ASSERT_EQ(strv_length(a), n);
ASSERT_STREQ(a[0], "test2 foo 128 bar");
ASSERT_STREQ(a[1], "test3 bar foo 128");
}
TEST(strv_extend_joined) {
_cleanup_strv_free_ char **a = NULL;
ASSERT_OK(strv_extend_joined(&a, "hoge"));
ASSERT_OK(strv_extend_joined(&a, "aaa", "bbb", "ccc"));
ASSERT_EQ(strv_length(a), 2u);
ASSERT_STREQ(a[0], "hoge");
ASSERT_STREQ(a[1], "aaabbbccc");
}
TEST(strv_extend_joined_with_size) {
_cleanup_strv_free_ char **a = NULL;
size_t n = 0;
ASSERT_OK(strv_extend_joined_with_size(&a, &n, "hoge"));
ASSERT_OK(strv_extend_joined_with_size(&a, &n, "aaa", "bbb", "ccc"));
ASSERT_EQ(n, 2u);
ASSERT_EQ(strv_length(a), n);
ASSERT_STREQ(a[0], "hoge");
ASSERT_STREQ(a[1], "aaabbbccc");
}
TEST(strv_foreach) { TEST(strv_foreach) {
_cleanup_strv_free_ char **a; _cleanup_strv_free_ char **a;
unsigned i = 0; unsigned i = 0;

View File

@ -1154,7 +1154,7 @@ static int cmdline_add_kernel_cmdline(char ***cmdline, const char *kernel, const
if (strv_extend(cmdline, "-smbios") < 0) if (strv_extend(cmdline, "-smbios") < 0)
return log_oom(); return log_oom();
if (strv_extendf(cmdline, "type=11,path=%s", p) < 0) if (strv_extend_joined(cmdline, "type=11,path=", p) < 0)
return log_oom(); return log_oom();
} }
} }
@ -1191,7 +1191,7 @@ static int cmdline_add_smbios11(char ***cmdline, const char* smbios_dir) {
if (strv_extend(cmdline, "-smbios") < 0) if (strv_extend(cmdline, "-smbios") < 0)
return log_oom(); return log_oom();
if (strv_extendf(cmdline, "type=11,path=%s", p) < 0) if (strv_extend_joined(cmdline, "type=11,path=", p) < 0)
return log_oom(); return log_oom();
p = mfree(p); p = mfree(p);
@ -1289,7 +1289,7 @@ static int start_tpm(
if (!argv) if (!argv)
return log_oom(); return log_oom();
r = strv_extendf(&argv, "dir=%s", state_dir); r = strv_extend_joined(&argv, "dir=", state_dir);
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
@ -1933,11 +1933,10 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
return log_error_errno(r, "Failed to make up randomized vmgenid: %m"); return log_error_errno(r, "Failed to make up randomized vmgenid: %m");
} }
_cleanup_free_ char *vmgenid_device = NULL; if (strv_extend(&cmdline, "-device") < 0)
if (asprintf(&vmgenid_device, "vmgenid,guid=" SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(vmgenid)) < 0)
return log_oom(); return log_oom();
if (strv_extend_many(&cmdline, "-device", vmgenid_device) < 0) if (strv_extendf(&cmdline, "vmgenid,guid=" SD_ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(vmgenid)) < 0)
return log_oom(); return log_oom();
} }
@ -2151,8 +2150,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
"-chardev") < 0) "-chardev") < 0)
return log_oom(); return log_oom();
if (strv_extendf(&cmdline, if (strv_extend_joined(&cmdline, "serial,id=console,path=", pty_path) < 0)
"serial,id=console,path=%s", pty_path) < 0)
return log_oom(); return log_oom();
r = strv_extend_many( r = strv_extend_many(
@ -2282,7 +2280,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
if (strv_extend(&cmdline, "-device") < 0) if (strv_extend(&cmdline, "-device") < 0)
return log_oom(); return log_oom();
if (strv_extendf(&cmdline, "virtio-blk-pci,drive=vmspawn,bootindex=1,serial=%s", escaped_image_fn) < 0) if (strv_extend_joined(&cmdline, "virtio-blk-pci,drive=vmspawn,bootindex=1,serial=", escaped_image_fn) < 0)
return log_oom(); return log_oom();
r = grow_image(arg_image, arg_grow_image); r = grow_image(arg_image, arg_grow_image);
@ -2552,7 +2550,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
if (strv_extend(&cmdline, "-chardev") < 0) if (strv_extend(&cmdline, "-chardev") < 0)
return log_oom(); return log_oom();
if (strv_extendf(&cmdline, "socket,id=chrtpm,path=%s", tpm_socket_address) < 0) if (strv_extend_joined(&cmdline, "socket,id=chrtpm,path=", tpm_socket_address) < 0)
return log_oom(); return log_oom();
if (strv_extend_many(&cmdline, "-tpmdev", "emulator,id=tpm0,chardev=chrtpm") < 0) if (strv_extend_many(&cmdline, "-tpmdev", "emulator,id=tpm0,chardev=chrtpm") < 0)
@ -2687,7 +2685,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
r = strv_extendf(&cmdline, "type=11,path=%s", p); r = strv_extend_joined(&cmdline, "type=11,path=", p);
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
} }