]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | #pragma once | |
3 | ||
4 | #include "sd-id128.h" | |
5 | ||
6 | #include "copy.h" | |
7 | #include "list.h" | |
8 | #include "machine-forward.h" | |
9 | #include "pidref.h" | |
10 | #include "time-util.h" | |
11 | ||
12 | typedef enum MachineState { | |
13 | MACHINE_OPENING, /* Machine is being registered */ | |
14 | MACHINE_RUNNING, /* Machine is running */ | |
15 | MACHINE_CLOSING, /* Machine is terminating */ | |
16 | _MACHINE_STATE_MAX, | |
17 | _MACHINE_STATE_INVALID = -EINVAL, | |
18 | } MachineState; | |
19 | ||
20 | typedef enum MachineClass { | |
21 | MACHINE_CONTAINER, | |
22 | MACHINE_VM, | |
23 | MACHINE_HOST, | |
24 | _MACHINE_CLASS_MAX, | |
25 | _MACHINE_CLASS_INVALID = -EINVAL, | |
26 | } MachineClass; | |
27 | ||
28 | typedef enum KillWhom { | |
29 | KILL_LEADER, | |
30 | KILL_ALL, | |
31 | _KILL_WHOM_MAX, | |
32 | _KILL_WHOM_INVALID = -EINVAL, | |
33 | } KillWhom; | |
34 | ||
35 | typedef struct Machine { | |
36 | Manager *manager; | |
37 | ||
38 | char *name; | |
39 | sd_id128_t id; | |
40 | ||
41 | MachineClass class; | |
42 | ||
43 | char *state_file; | |
44 | char *service; | |
45 | char *root_directory; | |
46 | ||
47 | char *unit; | |
48 | char *scope_job; | |
49 | ||
50 | PidRef leader; | |
51 | sd_event_source *leader_pidfd_event_source; | |
52 | ||
53 | dual_timestamp timestamp; | |
54 | ||
55 | bool in_gc_queue:1; | |
56 | bool started:1; | |
57 | bool stopping:1; | |
58 | bool referenced:1; | |
59 | bool allocate_unit; | |
60 | ||
61 | sd_bus_message *create_message; | |
62 | ||
63 | int *netif; | |
64 | size_t n_netif; | |
65 | ||
66 | unsigned vsock_cid; | |
67 | char *ssh_address; | |
68 | char *ssh_private_key_path; | |
69 | ||
70 | LIST_HEAD(Operation, operations); | |
71 | ||
72 | LIST_FIELDS(Machine, gc_queue); | |
73 | } Machine; | |
74 | ||
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); | |
86 | ||
87 | DEFINE_TRIVIAL_CLEANUP_FUNC(Machine*, machine_free); | |
88 | ||
89 | void machine_release_unit(Machine *m); | |
90 | ||
91 | MachineState machine_get_state(Machine *u); | |
92 | ||
93 | const char* machine_class_to_string(MachineClass t) _const_; | |
94 | MachineClass machine_class_from_string(const char *s) _pure_; | |
95 | ||
96 | const char* machine_state_to_string(MachineState t) _const_; | |
97 | MachineState machine_state_from_string(const char *s) _pure_; | |
98 | ||
99 | const char* kill_whom_to_string(KillWhom k) _const_; | |
100 | KillWhom kill_whom_from_string(const char *s) _pure_; | |
101 | ||
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); | |
107 | ||
108 | int machine_copy_from_to_operation( | |
109 | Manager *manager, | |
110 | Machine *machine, | |
111 | const char *host_path, | |
112 | const char *container_path, | |
113 | bool copy_from_container, | |
114 | CopyFlags copy_flags, | |
115 | Operation **ret); | |
116 | ||
117 | int machine_get_uid_shift(Machine *m, uid_t *ret); | |
118 | ||
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); | |
121 | ||
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); | |
124 | ||
125 | int machine_open_root_directory(Machine *machine); | |
126 | ||
127 | typedef enum AcquireMetadata { | |
128 | ACQUIRE_METADATA_NO, | |
129 | ACQUIRE_METADATA_YES, | |
130 | ACQUIRE_METADATA_GRACEFUL, | |
131 | _ACQUIRE_METADATA_MAX, | |
132 | _ACQUIRE_METADATA_INVALID = -EINVAL, | |
133 | } AcquireMetadata; | |
134 | ||
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; | |
139 | } |