summaryrefslogtreecommitdiff
path: root/src/machine/machined.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-08-24 21:05:09 +0200
committerLennart Poettering <lennart@poettering.net>2015-08-24 22:46:45 +0200
commitfbe550738d03b178bb004a1390e74115e904118a (patch)
treea4a281a5c7d7fb95ad409ba424eb2a430f1cc664 /src/machine/machined.c
parentb9a8d250810d4803bc9bf6b36932b528cb991d1e (diff)
machined: introduce pseudo-machine ".host" refererring to the host system
Some of the operations machined/machinectl implement are also very useful when applied to the host system (such as machinectl login, machinectl shell or machinectl status), hence introduce a pseudo-machine by the name of ".host" in machined that refers to the host system, and may be used top execute operations on the host system with. This copies the pseudo-image ".host" machined already implements for image related commands. (This commit also adds a PK privilege for opening a PTY in a container, which was previously not accessible for non-root.)
Diffstat (limited to 'src/machine/machined.c')
-rw-r--r--src/machine/machined.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/machine/machined.c b/src/machine/machined.c
index 9b9a334838..df3cc9972a 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -90,6 +90,45 @@ void manager_free(Manager *m) {
free(m);
}
+static int manager_add_host_machine(Manager *m) {
+ _cleanup_free_ char *rd = NULL, *unit = NULL;
+ sd_id128_t mid;
+ Machine *t;
+ int r;
+
+ if (m->host_machine)
+ return 0;
+
+ r = sd_id128_get_machine(&mid);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get machine ID: %m");
+
+ rd = strdup("/");
+ if (!rd)
+ return log_oom();
+
+ unit = strdup("-.slice");
+ if (!unit)
+ return log_oom();
+
+ t = machine_new(m, MACHINE_HOST, ".host");
+ if (!t)
+ return log_oom();
+
+ t->leader = 1;
+ t->id = mid;
+
+ t->root_directory = rd;
+ t->unit = unit;
+ rd = unit = NULL;
+
+ dual_timestamp_from_boottime_or_monotonic(&t->timestamp, 0);
+
+ m->host_machine = t;
+
+ return 0;
+}
+
int manager_enumerate_machines(Manager *m) {
_cleanup_closedir_ DIR *d = NULL;
struct dirent *de;
@@ -97,6 +136,10 @@ int manager_enumerate_machines(Manager *m) {
assert(m);
+ r = manager_add_host_machine(m);
+ if (r < 0)
+ return r;
+
/* Read in machine data stored on disk */
d = opendir("/run/systemd/machines");
if (!d) {
@@ -123,9 +166,7 @@ int manager_enumerate_machines(Manager *m) {
k = manager_add_machine(m, de->d_name, &machine);
if (k < 0) {
- log_error_errno(k, "Failed to add machine by file name %s: %m", de->d_name);
-
- r = k;
+ r = log_error_errno(k, "Failed to add machine by file name %s: %m", de->d_name);
continue;
}