summaryrefslogtreecommitdiff
path: root/src/machine/machined.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-08-25 16:46:27 +0200
committerTom Gundersen <teg@jklm.no>2015-08-25 16:46:27 +0200
commit498fb56739a5d18cb85d2ba3523759b1d141d770 (patch)
treed68a7330da711f320063046007cddfbf469fea6f /src/machine/machined.c
parent3ad216b44f4f5cba168f449ae455607a442cfd4c (diff)
parentef3100e9637adda26fa19e7ee8606788320dcde3 (diff)
Merge pull request #1022 from poettering/machinectl-shell
Add new "machinectl shell" command for su(1)-like behaviour
Diffstat (limited to 'src/machine/machined.c')
-rw-r--r--src/machine/machined.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/machine/machined.c b/src/machine/machined.c
index c8ad157326..df3cc9972a 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -30,6 +30,7 @@
#include "label.h"
#include "formats-util.h"
#include "signal-util.h"
+#include "hostname-util.h"
#include "machine-image.h"
#include "machined.h"
@@ -89,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;
@@ -96,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) {
@@ -117,11 +161,12 @@ int manager_enumerate_machines(Manager *m) {
if (startswith(de->d_name, "unit:"))
continue;
+ if (!machine_name_is_valid(de->d_name))
+ continue;
+
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;
}