summaryrefslogtreecommitdiffstats
path: root/src/systemctl
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-10-26 09:19:32 +0200
committerLennart Poettering <lennart@poettering.net>2024-03-14 11:34:04 +0100
commit56cb74c3cd1358d7d0b3f613feaf2eeab601a6bd (patch)
treed766e8ef463eab7a11a067b7439e6a0395e20206 /src/systemctl
parentbus-util: add ability to connect directly to capsule instances of systemd --user (diff)
downloadsystemd-56cb74c3cd1358d7d0b3f613feaf2eeab601a6bd.tar.xz
systemd-56cb74c3cd1358d7d0b3f613feaf2eeab601a6bd.zip
systemctl: allow connecting to capsule instances with --capsule=/-C
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl-start-unit.c23
-rw-r--r--src/systemctl/systemctl-util.c2
-rw-r--r--src/systemctl/systemctl.c18
3 files changed, 37 insertions, 6 deletions
diff --git a/src/systemctl/systemctl-start-unit.c b/src/systemctl/systemctl-start-unit.c
index c844f7e1e7..de8873caaf 100644
--- a/src/systemctl/systemctl-start-unit.c
+++ b/src/systemctl/systemctl-start-unit.c
@@ -255,14 +255,29 @@ static const char** make_extra_args(const char *extra_args[static 4]) {
if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM)
extra_args[n++] = "--user";
- if (arg_transport == BUS_TRANSPORT_REMOTE) {
+ switch (arg_transport) {
+
+ case BUS_TRANSPORT_REMOTE:
extra_args[n++] = "-H";
extra_args[n++] = arg_host;
- } else if (arg_transport == BUS_TRANSPORT_MACHINE) {
+ break;
+
+ case BUS_TRANSPORT_MACHINE:
extra_args[n++] = "-M";
extra_args[n++] = arg_host;
- } else
- assert(arg_transport == BUS_TRANSPORT_LOCAL);
+ break;
+
+ case BUS_TRANSPORT_CAPSULE:
+ extra_args[n++] = "-C";
+ extra_args[n++] = arg_host;
+ break;
+
+ case BUS_TRANSPORT_LOCAL:
+ break;
+
+ default:
+ assert_not_reached();
+ }
extra_args[n] = NULL;
return extra_args;
diff --git a/src/systemctl/systemctl-util.c b/src/systemctl/systemctl-util.c
index c3da750d64..75c6c547f7 100644
--- a/src/systemctl/systemctl-util.c
+++ b/src/systemctl/systemctl-util.c
@@ -42,7 +42,7 @@ int acquire_bus(BusFocus focus, sd_bus **ret) {
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "--global is not supported for this operation.");
/* We only go directly to the manager, if we are using a local transport */
- if (arg_transport != BUS_TRANSPORT_LOCAL)
+ if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_CAPSULE))
focus = BUS_FULL;
if (getenv_bool("SYSTEMCTL_FORCE_BUS") > 0)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 5241af5bfa..00452cac2c 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -18,6 +18,7 @@
#include "path-util.h"
#include "pretty-print.h"
#include "process-util.h"
+#include "capsule-util.h"
#include "reboot-util.h"
#include "rlimit-util.h"
#include "sigbus.h"
@@ -63,6 +64,7 @@
#include "systemctl.h"
#include "terminal-util.h"
#include "time-util.h"
+#include "user-util.h"
#include "verbs.h"
#include "virt.h"
@@ -262,6 +264,7 @@ static int systemctl_help(void) {
" --version Show package version\n"
" --system Connect to system manager\n"
" --user Connect to user service manager\n"
+ " -C --capsule=NAME Connect to service manager of specified capsule\n"
" -H --host=[USER@]HOST Operate on remote host\n"
" -M --machine=CONTAINER Operate on a local container\n"
" -t --type=TYPE List units of a particular type\n"
@@ -490,6 +493,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
{ "user", no_argument, NULL, ARG_USER },
{ "system", no_argument, NULL, ARG_SYSTEM },
{ "global", no_argument, NULL, ARG_GLOBAL },
+ { "capsule", required_argument, NULL, 'C' },
{ "wait", no_argument, NULL, ARG_WAIT },
{ "no-block", no_argument, NULL, ARG_NO_BLOCK },
{ "legend", required_argument, NULL, ARG_LEGEND },
@@ -544,7 +548,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
/* We default to allowing interactive authorization only in systemctl (not in the legacy commands) */
arg_ask_password = true;
- while ((c = getopt_long(argc, argv, "ht:p:P:alqfs:H:M:n:o:iTr.::", options, NULL)) >= 0)
+ while ((c = getopt_long(argc, argv, "hC:t:p:P:alqfs:H:M:n:o:iTr.::", options, NULL)) >= 0)
switch (c) {
@@ -679,6 +683,18 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
arg_runtime_scope = RUNTIME_SCOPE_GLOBAL;
break;
+ case 'C':
+ r = capsule_name_is_valid(optarg);
+ if (r < 0)
+ return log_error_errno(r, "Unable to validate capsule name '%s': %m", optarg);
+ if (r == 0)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid capsule name: %s", optarg);
+
+ arg_host = optarg;
+ arg_transport = BUS_TRANSPORT_CAPSULE;
+ arg_runtime_scope = RUNTIME_SCOPE_USER;
+ break;
+
case ARG_WAIT:
arg_wait = true;
break;