1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include "machine-forward.h"
10 #include "time-util.h"
12 typedef enum MachineState
{
13 MACHINE_OPENING
, /* Machine is being registered */
14 MACHINE_RUNNING
, /* Machine is running */
15 MACHINE_CLOSING
, /* Machine is terminating */
17 _MACHINE_STATE_INVALID
= -EINVAL
,
20 typedef enum MachineClass
{
25 _MACHINE_CLASS_INVALID
= -EINVAL
,
28 typedef enum KillWhom
{
32 _KILL_WHOM_INVALID
= -EINVAL
,
35 typedef struct Machine
{
51 sd_event_source
*leader_pidfd_event_source
;
53 dual_timestamp timestamp
;
61 sd_bus_message
*create_message
;
68 char *ssh_private_key_path
;
70 LIST_HEAD(Operation
, operations
);
72 LIST_FIELDS(Machine
, gc_queue
);
75 int machine_new(MachineClass
class, const char *name
, Machine
**ret
);
76 int machine_link(Manager
*manager
, Machine
*machine
);
77 Machine
* machine_free(Machine
*m
);
78 bool machine_may_gc(Machine
*m
, bool drop_not_started
);
79 void machine_add_to_gc_queue(Machine
*m
);
80 int machine_start(Machine
*m
, sd_bus_message
*properties
, sd_bus_error
*error
);
81 int machine_stop(Machine
*m
);
82 int machine_finalize(Machine
*m
);
83 int machine_save(Machine
*m
);
84 int machine_load(Machine
*m
);
85 int machine_kill(Machine
*m
, KillWhom whom
, int signo
);
87 DEFINE_TRIVIAL_CLEANUP_FUNC(Machine
*, machine_free
);
89 void machine_release_unit(Machine
*m
);
91 MachineState
machine_get_state(Machine
*u
);
93 const char* machine_class_to_string(MachineClass t
) _const_
;
94 MachineClass
machine_class_from_string(const char *s
) _pure_
;
96 const char* machine_state_to_string(MachineState t
) _const_
;
97 MachineState
machine_state_from_string(const char *s
) _pure_
;
99 const char* kill_whom_to_string(KillWhom k
) _const_
;
100 KillWhom
kill_whom_from_string(const char *s
) _pure_
;
102 int machine_openpt(Machine
*m
, int flags
, char **ret_peer
);
103 int machine_start_getty(Machine
*m
, const char *ptmx_name
, sd_bus_error
*error
);
104 int machine_start_shell(Machine
*m
, int ptmx_fd
, const char *ptmx_name
, const char *user
, const char *path
, char **args
, char **env
, sd_bus_error
*error
);
105 #define machine_default_shell_path() ("/bin/sh")
106 char** machine_default_shell_args(const char *user
);
108 int machine_copy_from_to_operation(
111 const char *host_path
,
112 const char *container_path
,
113 bool copy_from_container
,
114 CopyFlags copy_flags
,
117 int machine_get_uid_shift(Machine
*m
, uid_t
*ret
);
119 int machine_owns_uid(Machine
*m
, uid_t host_uid
, uid_t
*ret_internal_uid
);
120 int machine_owns_gid(Machine
*m
, gid_t host_gid
, gid_t
*ret_internal_gid
);
122 int machine_translate_uid(Machine
*m
, uid_t internal_uid
, uid_t
*ret_host_uid
);
123 int machine_translate_gid(Machine
*m
, gid_t internal_gid
, gid_t
*ret_host_gid
);
125 int machine_open_root_directory(Machine
*machine
);
127 typedef enum AcquireMetadata
{
129 ACQUIRE_METADATA_YES
,
130 ACQUIRE_METADATA_GRACEFUL
,
131 _ACQUIRE_METADATA_MAX
,
132 _ACQUIRE_METADATA_INVALID
= -EINVAL
,
135 AcquireMetadata
acquire_metadata_from_string(const char *s
) _pure_
;
136 const char* acquire_metadata_to_string(AcquireMetadata am
) _const_
;
137 inline static bool should_acquire_metadata(AcquireMetadata am
) {
138 return am
== ACQUIRE_METADATA_YES
|| am
== ACQUIRE_METADATA_GRACEFUL
;