mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
systemctl: allow connecting to capsule instances with --capsule=/-C
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user