summaryrefslogtreecommitdiffstats
path: root/src/shared/varlink-io.systemd.Machine.c
diff options
context:
space:
mode:
authorIvan Kruglov <mail@ikruglov.com>2024-10-23 11:53:22 +0200
committerIvan Kruglov <mail@ikruglov.com>2024-11-06 11:37:51 +0100
commita686bedb888c4cad0bb9095278ae79b2f11bceec (patch)
tree076216b73b62592a6835a057d5c5d1755e0e215f /src/shared/varlink-io.systemd.Machine.c
parentjson: introduce json_dispatch_strv_environment() (diff)
downloadsystemd-a686bedb888c4cad0bb9095278ae79b2f11bceec.tar.xz
systemd-a686bedb888c4cad0bb9095278ae79b2f11bceec.zip
machine: introduce io.systemd.Machine.Open method
Diffstat (limited to '')
-rw-r--r--src/shared/varlink-io.systemd.Machine.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/shared/varlink-io.systemd.Machine.c b/src/shared/varlink-io.systemd.Machine.c
index 3b44f80854..83a20f4f0e 100644
--- a/src/shared/varlink-io.systemd.Machine.c
+++ b/src/shared/varlink-io.systemd.Machine.c
@@ -95,12 +95,41 @@ static SD_VARLINK_DEFINE_METHOD_FULL(
SD_VARLINK_FIELD_COMMENT("Return the base UID/GID of the machine"),
SD_VARLINK_DEFINE_OUTPUT(UIDShift, SD_VARLINK_INT, SD_VARLINK_NULLABLE));
+static SD_VARLINK_DEFINE_ENUM_TYPE(
+ MachineOpenMode,
+ SD_VARLINK_FIELD_COMMENT("This mode allocates a pseudo TTY in the container and returns a file descriptor and its path. This is equivalent to transitioning into the container and invoking posix_openpt(3)."),
+ SD_VARLINK_DEFINE_ENUM_VALUE(tty),
+ SD_VARLINK_FIELD_COMMENT("This mode allocates a pseudo TTY in the container and ensures that a getty login prompt of the container is running on the other end. It returns the file descriptor of the PTY and the PTY path. This is useful for acquiring a pty with a login prompt from the container."),
+ SD_VARLINK_DEFINE_ENUM_VALUE(login),
+ SD_VARLINK_FIELD_COMMENT("This mode allocates a pseudo TTY in the container, as the specified user, and invokes the executable at the specified path with a list of arguments (starting from argv[0]) and an environment block. It then returns the file descriptor of the PTY and the PTY path."),
+ SD_VARLINK_DEFINE_ENUM_VALUE(shell));
+
+static SD_VARLINK_DEFINE_METHOD(
+ Open,
+ VARLINK_DEFINE_MACHINE_LOOKUP_AND_POLKIT_INPUT_FIELDS,
+ SD_VARLINK_FIELD_COMMENT("There are three possible values: 'tty', 'login', and 'shell'. Please see description for each of the modes."),
+ SD_VARLINK_DEFINE_INPUT_BY_TYPE(mode, MachineOpenMode, 0),
+ SD_VARLINK_FIELD_COMMENT("See description of mode='shell'. Valid only when mode='shell'"),
+ SD_VARLINK_DEFINE_INPUT(user, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
+ SD_VARLINK_FIELD_COMMENT("See description of mode='shell'. Valid only when mode='shell'"),
+ SD_VARLINK_DEFINE_INPUT(path, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
+ SD_VARLINK_FIELD_COMMENT("See description of mode='shell'. Valid only when mode='shell'"),
+ SD_VARLINK_DEFINE_INPUT(args, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY),
+ SD_VARLINK_FIELD_COMMENT("See description of mode='shell'. Valid only when mode='shell'"),
+ SD_VARLINK_DEFINE_INPUT(environment, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY),
+ SD_VARLINK_FIELD_COMMENT("File descriptor of the allocated pseudo TTY"),
+ SD_VARLINK_DEFINE_OUTPUT(ptyFileDescriptor, SD_VARLINK_INT, 0),
+ SD_VARLINK_FIELD_COMMENT("Path to the allocated pseudo TTY"),
+ SD_VARLINK_DEFINE_OUTPUT(ptyPath, SD_VARLINK_STRING, 0));
+
static SD_VARLINK_DEFINE_ERROR(NoSuchMachine);
static SD_VARLINK_DEFINE_ERROR(MachineExists);
static SD_VARLINK_DEFINE_ERROR(NoPrivateNetworking);
static SD_VARLINK_DEFINE_ERROR(NoOSReleaseInformation);
static SD_VARLINK_DEFINE_ERROR(NoUIDShift);
static SD_VARLINK_DEFINE_ERROR(NotAvailable);
+static SD_VARLINK_DEFINE_ERROR(NotSupported);
+static SD_VARLINK_DEFINE_ERROR(NoIPC);
SD_VARLINK_DEFINE_INTERFACE(
io_systemd_Machine,
@@ -121,6 +150,10 @@ SD_VARLINK_DEFINE_INTERFACE(
&vl_method_Kill,
SD_VARLINK_SYMBOL_COMMENT("List running machines"),
&vl_method_List,
+ SD_VARLINK_SYMBOL_COMMENT("A enum field which defines way to open TTY for a machine"),
+ &vl_type_MachineOpenMode,
+ SD_VARLINK_SYMBOL_COMMENT("Allocates a pseudo TTY in the container in various modes"),
+ &vl_method_Open,
SD_VARLINK_SYMBOL_COMMENT("No matching machine currently running"),
&vl_error_NoSuchMachine,
&vl_error_MachineExists,
@@ -131,4 +164,8 @@ SD_VARLINK_DEFINE_INTERFACE(
SD_VARLINK_SYMBOL_COMMENT("Machine uses a complex UID/GID mapping, cannot determine shift"),
&vl_error_NoUIDShift,
SD_VARLINK_SYMBOL_COMMENT("Requested information is not available"),
- &vl_error_NotAvailable);
+ &vl_error_NotAvailable,
+ SD_VARLINK_SYMBOL_COMMENT("Requested operation is not supported"),
+ &vl_error_NotSupported,
+ SD_VARLINK_SYMBOL_COMMENT("There is no IPC service (such as system bus or varlink) in the container"),
+ &vl_error_NoIPC);