]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
9444b1f2 LP |
2 | #pragma once |
3 | ||
ff43267c | 4 | #include "sd-id128.h" |
9444b1f2 | 5 | |
9af9d661 | 6 | #include "copy.h" |
9444b1f2 | 7 | #include "list.h" |
64943cac | 8 | #include "machine-forward.h" |
d8854ff1 | 9 | #include "pidref.h" |
ca78ad1d | 10 | #include "time-util.h" |
9444b1f2 | 11 | |
fb6becb4 LP |
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, | |
2d93c20e | 17 | _MACHINE_STATE_INVALID = -EINVAL, |
fb6becb4 LP |
18 | } MachineState; |
19 | ||
9444b1f2 LP |
20 | typedef enum MachineClass { |
21 | MACHINE_CONTAINER, | |
22 | MACHINE_VM, | |
fbe55073 | 23 | MACHINE_HOST, |
9444b1f2 | 24 | _MACHINE_CLASS_MAX, |
2d93c20e | 25 | _MACHINE_CLASS_INVALID = -EINVAL, |
9444b1f2 LP |
26 | } MachineClass; |
27 | ||
ff43267c | 28 | typedef enum KillWhom { |
1ee306e1 LP |
29 | KILL_LEADER, |
30 | KILL_ALL, | |
cd2fb049 ZJS |
31 | _KILL_WHOM_MAX, |
32 | _KILL_WHOM_INVALID = -EINVAL, | |
ff43267c | 33 | } KillWhom; |
1ee306e1 | 34 | |
64943cac | 35 | typedef struct Machine { |
9444b1f2 LP |
36 | Manager *manager; |
37 | ||
38 | char *name; | |
39 | sd_id128_t id; | |
40 | ||
41 | MachineClass class; | |
42 | ||
43 | char *state_file; | |
44 | char *service; | |
9444b1f2 LP |
45 | char *root_directory; |
46 | ||
89f7c846 | 47 | char *unit; |
fb6becb4 LP |
48 | char *scope_job; |
49 | ||
d8854ff1 | 50 | PidRef leader; |
1762c2c0 | 51 | sd_event_source *leader_pidfd_event_source; |
9444b1f2 LP |
52 | |
53 | dual_timestamp timestamp; | |
54 | ||
55 | bool in_gc_queue:1; | |
56 | bool started:1; | |
49f3fffd | 57 | bool stopping:1; |
2798430e | 58 | bool referenced:1; |
f98e821c | 59 | bool allocate_unit; |
9444b1f2 | 60 | |
c3350683 | 61 | sd_bus_message *create_message; |
fb6becb4 | 62 | |
9b5ed6fe | 63 | int *netif; |
68e16e9c | 64 | size_t n_netif; |
9b5ed6fe | 65 | |
1f815bf1 SL |
66 | unsigned vsock_cid; |
67 | char *ssh_address; | |
68 | char *ssh_private_key_path; | |
69 | ||
795c5d31 | 70 | LIST_HEAD(Operation, operations); |
0370612e | 71 | |
795c5d31 | 72 | LIST_FIELDS(Machine, gc_queue); |
64943cac | 73 | } Machine; |
9444b1f2 | 74 | |
885317f1 SL |
75 | int machine_new(MachineClass class, const char *name, Machine **ret); |
76 | int machine_link(Manager *manager, Machine *machine); | |
bb1a05d6 | 77 | Machine* machine_free(Machine *m); |
554ce41f | 78 | bool machine_may_gc(Machine *m, bool drop_not_started); |
9444b1f2 | 79 | void machine_add_to_gc_queue(Machine *m); |
c3350683 | 80 | int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error); |
9444b1f2 | 81 | int machine_stop(Machine *m); |
49f3fffd | 82 | int machine_finalize(Machine *m); |
9444b1f2 LP |
83 | int machine_save(Machine *m); |
84 | int machine_load(Machine *m); | |
cd2fb049 | 85 | int machine_kill(Machine *m, KillWhom whom, int signo); |
9444b1f2 | 86 | |
71a15f37 SL |
87 | DEFINE_TRIVIAL_CLEANUP_FUNC(Machine*, machine_free); |
88 | ||
9b420b3c LP |
89 | void machine_release_unit(Machine *m); |
90 | ||
fb6becb4 LP |
91 | MachineState machine_get_state(Machine *u); |
92 | ||
9444b1f2 LP |
93 | const char* machine_class_to_string(MachineClass t) _const_; |
94 | MachineClass machine_class_from_string(const char *s) _pure_; | |
fb6becb4 LP |
95 | |
96 | const char* machine_state_to_string(MachineState t) _const_; | |
97 | MachineState machine_state_from_string(const char *s) _pure_; | |
1ee306e1 | 98 | |
bfd5a068 | 99 | const char* kill_whom_to_string(KillWhom k) _const_; |
cd2fb049 | 100 | KillWhom kill_whom_from_string(const char *s) _pure_; |
fbe55073 | 101 | |
9fbecf12 | 102 | int machine_openpt(Machine *m, int flags, char **ret_peer); |
41f1f283 IK |
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); | |
b0eca6de IK |
105 | #define machine_default_shell_path() ("/bin/sh") |
106 | char** machine_default_shell_args(const char *user); | |
3401419b | 107 | |
2694549d | 108 | int machine_copy_from_to_operation( |
9af9d661 IK |
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 | ||
3401419b | 117 | int machine_get_uid_shift(Machine *m, uid_t *ret); |
74d1b7d2 LP |
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); | |
16b1b304 | 124 | |
65275cfb IK |
125 | int machine_open_root_directory(Machine *machine); |
126 | ||
16b1b304 IK |
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 | } |