summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-07-02 03:47:23 +0200
committerLennart Poettering <lennart@poettering.net>2013-07-02 03:47:23 +0200
commit1ee306e1248866617c96ed9f4263f375588ad838 (patch)
treeebcb5678d4236ea8a8afc30c6164a4b4f51a03bd /src/login
parent374ec6abf31ada6ca554cc8ea99b282373fac010 (diff)
machined: split out machine registration stuff from logind
Embedded folks don't need the machine registration stuff, hence it's nice to make this optional. Also, I'd expect that machinectl will grow additional commands quickly, for example to join existing containers and suchlike, hence it's better keeping that separate from loginctl.
Diffstat (limited to 'src/login')
-rw-r--r--src/login/loginctl.c309
-rw-r--r--src/login/logind-dbus.c378
-rw-r--r--src/login/logind-machine-dbus.c360
-rw-r--r--src/login/logind-machine.c403
-rw-r--r--src/login/logind-machine.h99
-rw-r--r--src/login/logind-user.c12
-rw-r--r--src/login/logind.c117
-rw-r--r--src/login/logind.h7
8 files changed, 12 insertions, 1673 deletions
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 3637a408dc..e118deffda 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -261,69 +261,6 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) {
return 0;
}
-static int list_machines(DBusConnection *bus, char **args, unsigned n) {
- _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
- DBusMessageIter iter, sub, sub2;
- unsigned k = 0;
- int r;
-
- pager_open_if_enabled();
-
- r = bus_method_call_with_reply (
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "ListMachines",
- &reply,
- NULL,
- DBUS_TYPE_INVALID);
- if (r)
- return r;
-
- if (!dbus_message_iter_init(reply, &iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
- dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT) {
- log_error("Failed to parse reply.");
- return -EIO;
- }
-
- dbus_message_iter_recurse(&iter, &sub);
-
- if (on_tty())
- printf("%-32s %-9s %-16s\n", "MACHINE", "CONTAINER", "SERVICE");
-
- while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
- const char *name, *class, *service, *object;
-
- if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
- log_error("Failed to parse reply.");
- return -EIO;
- }
-
- dbus_message_iter_recurse(&sub, &sub2);
-
- if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &name, true) < 0 ||
- bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &class, true) < 0 ||
- bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &service, true) < 0 ||
- bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &object, false) < 0) {
- log_error("Failed to parse reply.");
- return -EIO;
- }
-
- printf("%-32s %-9s %-16s\n", name, class, service);
-
- k++;
-
- dbus_message_iter_next(&sub);
- }
-
- if (on_tty())
- printf("\n%u machines listed.\n", k);
-
- return 0;
-}
-
typedef struct SessionStatusInfo {
const char *id;
uid_t uid;
@@ -362,18 +299,6 @@ typedef struct SeatStatusInfo {
char **sessions;
} SeatStatusInfo;
-typedef struct MachineStatusInfo {
- const char *name;
- sd_id128_t id;
- const char *default_control_group;
- const char *class;
- const char *service;
- const char *slice;
- const char *root_directory;
- pid_t leader;
- usec_t timestamp;
-} MachineStatusInfo;
-
static void print_session_status_info(SessionStatusInfo *i) {
char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
char since2[FORMAT_TIMESTAMP_MAX], *s2;
@@ -569,76 +494,6 @@ static void print_seat_status_info(SeatStatusInfo *i) {
}
}
-static void print_machine_status_info(MachineStatusInfo *i) {
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
- char since2[FORMAT_TIMESTAMP_MAX], *s2;
- assert(i);
-
- fputs(strna(i->name), stdout);
-
- if (!sd_id128_equal(i->id, SD_ID128_NULL))
- printf("(" SD_ID128_FORMAT_STR ")\n", SD_ID128_FORMAT_VAL(i->id));
- else
- putchar('\n');
-
- s1 = format_timestamp_relative(since1, sizeof(since1), i->timestamp);
- s2 = format_timestamp(since2, sizeof(since2), i->timestamp);
-
- if (s1)
- printf("\t Since: %s; %s\n", s2, s1);
- else if (s2)
- printf("\t Since: %s\n", s2);
-
- if (i->leader > 0) {
- _cleanup_free_ char *t = NULL;
-
- printf("\t Leader: %u", (unsigned) i->leader);
-
- get_process_comm(i->leader, &t);
- if (t)
- printf(" (%s)", t);
-
- putchar('\n');
- }
-
- if (i->service) {
- printf("\t Service: %s", i->service);
-
- if (i->class)
- printf("; class %s", i->class);
-
- putchar('\n');
- } else if (i->class)
- printf("\t Class: %s\n", i->class);
-
- if (i->slice)
- printf("\t Slice: %s\n", i->slice);
- if (i->root_directory)
- printf("\t Root: %s\n", i->root_directory);
-
- if (i->default_control_group) {
- unsigned c;
- int output_flags =
- arg_all * OUTPUT_SHOW_ALL |
- arg_full * OUTPUT_FULL_WIDTH;
-
- printf("\t CGroup: %s\n", i->default_control_group);
-
- if (arg_transport != TRANSPORT_SSH) {
- c = columns();
- if (c > 18)
- c -= 18;
- else
- c = 0;
-
- show_cgroup_and_extra_by_spec(i->default_control_group,
- "\t\t ", c, false, &i->leader,
- i->leader > 0 ? 1 : 0,
- output_flags);
- }
- }
-}
-
static int status_property_session(const char *name, DBusMessageIter *iter, SessionStatusInfo *i) {
assert(name);
assert(iter);
@@ -912,80 +767,6 @@ static int status_property_seat(const char *name, DBusMessageIter *iter, SeatSta
return 0;
}
-static int status_property_machine(const char *name, DBusMessageIter *iter, MachineStatusInfo *i) {
- assert(name);
- assert(iter);
- assert(i);
-
- switch (dbus_message_iter_get_arg_type(iter)) {
-
- case DBUS_TYPE_STRING: {
- const char *s;
-
- dbus_message_iter_get_basic(iter, &s);
-
- if (!isempty(s)) {
- if (streq(name, "Name"))
- i->name = s;
- else if (streq(name, "DefaultControlGroup"))
- i->default_control_group = s;
- else if (streq(name, "Class"))
- i->class = s;
- else if (streq(name, "Service"))
- i->service = s;
- else if (streq(name, "Slice"))
- i->slice = s;
- else if (streq(name, "RootDirectory"))
- i->root_directory = s;
- }
- break;
- }
-
- case DBUS_TYPE_UINT32: {
- uint32_t u;
-
- dbus_message_iter_get_basic(iter, &u);
-
- if (streq(name, "Leader"))
- i->leader = (pid_t) u;
-
- break;
- }
-
- case DBUS_TYPE_UINT64: {
- uint64_t u;
-
- dbus_message_iter_get_basic(iter, &u);
-
- if (streq(name, "Timestamp"))
- i->timestamp = (usec_t) u;
-
- break;
- }
-
- case DBUS_TYPE_ARRAY: {
- DBusMessageIter sub;
-
- dbus_message_iter_recurse(iter, &sub);
-
- if (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_BYTE && streq(name, "Id")) {
- void *v;
- int n;
-
- dbus_message_iter_get_fixed_array(&sub, &v, &n);
- if (n == 0)
- i->id = SD_ID128_NULL;
- else if (n == 16)
- memcpy(&i->id, v, n);
- }
-
- break;
- }
- }
-
- return 0;
-}
-
static int print_property(const char *name, DBusMessageIter *iter) {
assert(name);
assert(iter);
@@ -1067,7 +848,6 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
SessionStatusInfo session_info = {};
UserStatusInfo user_info = {};
SeatStatusInfo seat_info = {};
- MachineStatusInfo machine_info = {};
assert(path);
assert(new_line);
@@ -1131,10 +911,8 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
r = status_property_session(name, &sub3, &session_info);
else if (strstr(verb, "user"))
r = status_property_user(name, &sub3, &user_info);
- else if (strstr(verb, "seat"))
- r = status_property_seat(name, &sub3, &seat_info);
else
- r = status_property_machine(name, &sub3, &machine_info);
+ r = status_property_seat(name, &sub3, &seat_info);
if (r < 0) {
log_error("Failed to parse reply.");
@@ -1149,10 +927,8 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
print_session_status_info(&session_info);
else if (strstr(verb, "user"))
print_user_status_info(&user_info);
- else if (strstr(verb, "seat"))
- print_seat_status_info(&seat_info);
else
- print_machine_status_info(&machine_info);
+ print_seat_status_info(&seat_info);
}
r = 0;
@@ -1226,7 +1002,7 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
DBUS_TYPE_UINT32, &u,
DBUS_TYPE_INVALID);
- } else if (strstr(args[0], "seat")) {
+ } else {
ret = bus_method_call_with_reply(
bus,
@@ -1239,18 +1015,6 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
DBUS_TYPE_STRING, &args[i],
DBUS_TYPE_INVALID);
- } else {
-
- ret = bus_method_call_with_reply(
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "GetMachine",
- &reply,
- NULL,
- DBUS_TYPE_STRING, &args[i],
- DBUS_TYPE_INVALID);
}
if (ret < 0)
@@ -1334,36 +1098,6 @@ static int kill_session(DBusConnection *bus, char **args, unsigned n) {
return 0;
}
-static int kill_machine(DBusConnection *bus, char **args, unsigned n) {
- unsigned i;
-
- assert(args);
-
- if (!arg_kill_who)
- arg_kill_who = "all";
-
- for (i = 1; i < n; i++) {
- int r;
-
- r = bus_method_call_with_reply (
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "KillMachine",
- NULL,
- NULL,
- DBUS_TYPE_STRING, &args[i],
- DBUS_TYPE_STRING, &arg_kill_who,
- DBUS_TYPE_INT32, &arg_signal,
- DBUS_TYPE_INVALID);
- if (r)
- return r;
- }
-
- return 0;
-}
-
static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
unsigned i;
dbus_bool_t b, interactive = true;
@@ -1567,31 +1301,6 @@ static int terminate_seat(DBusConnection *bus, char **args, unsigned n) {
return 0;
}
-static int terminate_machine(DBusConnection *bus, char **args, unsigned n) {
- unsigned i;
-
- assert(args);
-
- for (i = 1; i < n; i++) {
- int r;
-
- r = bus_method_call_with_reply (
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "TerminateMachine",
- NULL,
- NULL,
- DBUS_TYPE_STRING, &args[i],
- DBUS_TYPE_INVALID);
- if (r)
- return r;
- }
-
- return 0;
-}
-
static int help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
@@ -1630,12 +1339,7 @@ static int help(void) {
" show-seat [NAME...] Show properties of one or more seats\n"
" attach [NAME] [DEVICE...] Attach one or more devices to a seat\n"
" flush-devices Flush all device associations\n"
- " terminate-seat [NAME...] Terminate all sessions on one or more seats\n"
- " list-machines List running VMs and containers\n"
- " machine-status [NAME...] Show VM/container status\n"
- " show-machine [NAME...] Show properties of one or more VMs/containers\n"
- " terminate-machine [NAME...] Terminate one or more VMs/containers\n"
- " kill-machine [NAME...] Send signal to processes of a VM/container\n",
+ " terminate-seat [NAME...] Terminate all sessions on one or more seats\n",
program_invocation_short_name);
return 0;
@@ -1784,11 +1488,6 @@ static int loginctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
{ "attach", MORE, 3, attach },
{ "flush-devices", EQUAL, 1, flush_devices },
{ "terminate-seat", MORE, 2, terminate_seat },
- { "list-machines", EQUAL, 1, list_machines },
- { "machine-status", MORE, 2, show },
- { "show-machine", MORE, 1, show },
- { "terminate-machine", MORE, 2, terminate_machine },
- { "kill-machine", MORE, 2, kill_machine },
};
int left;
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index d8d25b0041..9a19932af4 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -63,14 +63,6 @@
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"seat\" type=\"o\" direction=\"out\"/>\n" \
" </method>\n" \
- " <method name=\"GetMachine\">\n" \
- " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
- " <arg name=\"machine\" type=\"o\" direction=\"out\"/>\n" \
- " </method>\n" \
- " <method name=\"GetMachineByPID\">\n" \
- " <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n" \
- " <arg name=\"machine\" type=\"o\" direction=\"out\"/>\n" \
- " </method>\n" \
" <method name=\"ListSessions\">\n" \
" <arg name=\"sessions\" type=\"a(susso)\" direction=\"out\"/>\n" \
" </method>\n" \
@@ -80,9 +72,6 @@
" <method name=\"ListSeats\">\n" \
" <arg name=\"seats\" type=\"a(so)\" direction=\"out\"/>\n" \
" </method>\n" \
- " <method name=\"ListMachines\">\n" \
- " <arg name=\"machines\" type=\"a(ssso)\" direction=\"out\"/>\n" \
- " </method>\n" \
" <method name=\"CreateSession\">\n" \
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"leader\" type=\"u\" direction=\"in\"/>\n" \
@@ -108,16 +97,6 @@
" <method name=\"ReleaseSession\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
- " <method name=\"CreateMachine\">\n" \
- " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \
- " <arg name=\"id\" type=\"ay\" direction=\"in\"/>\n" \
- " <arg name=\"service\" type=\"s\" direction=\"in\"/>\n" \
- " <arg name=\"class\" type=\"s\" direction=\"in\"/>\n" \
- " <arg name=\"leader\" type=\"u\" direction=\"in\"/>\n" \
- " <arg name=\"root_directory\" type=\"s\" direction=\"in\"/>\n" \
- " <arg name=\"scope_properties\" type=\"a(sv)\" direction=\"in\"/>\n" \
- " <arg name=\"path\" type=\"o\" direction=\"out\"/>\n" \
- " </method>\n" \
" <method name=\"ActivateSession\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
@@ -151,9 +130,6 @@
" <method name=\"TerminateSeat\">\n" \
" <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
" </method>\n" \
- " <method name=\"TerminateMachine\">\n" \
- " <arg name=\"id\" type=\"s\" direction=\"in\"/>\n" \
- " </method>\n" \
" <method name=\"SetUserLinger\">\n" \
" <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n" \
" <arg name=\"b\" type=\"b\" direction=\"in\"/>\n" \
@@ -231,22 +207,12 @@
" <arg name=\"id\" type=\"s\"/>\n" \
" <arg name=\"path\" type=\"o\"/>\n" \
" </signal>\n" \
- " <signal name=\"MachineNew\">\n" \
- " <arg name=\"machine\" type=\"s\"/>\n" \
- " <arg name=\"path\" type=\"o\"/>\n" \
- " </signal>\n" \
- " <signal name=\"MachineRemoved\">\n" \
- " <arg name=\"machine\" type=\"s\"/>\n" \
- " <arg name=\"path\" type=\"o\"/>\n" \
- " </signal>\n" \
" <signal name=\"PrepareForShutdown\">\n" \
" <arg name=\"active\" type=\"b\"/>\n" \
" </signal>\n" \
" <signal name=\"PrepareForSleep\">\n" \
" <arg name=\"active\" type=\"b\"/>\n" \
" </signal>\n" \
- " <property name=\"Controllers\" type=\"as\" access=\"read\"/>\n" \
- " <property name=\"ResetControllers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"NAutoVTs\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"KillOnlyUsers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"KillExcludeUsers\" type=\"as\" access=\"read\"/>\n" \
@@ -689,148 +655,6 @@ fail:
return r;
}
-static bool valid_machine_name(const char *p) {
- size_t l;
-
- if (!filename_is_safe(p))
- return false;
-
- if (!ascii_is_valid(p))
- return false;
-
- l = strlen(p);
-
- if (l < 1 || l> 64)
- return false;
-
- return true;
-}
-
-static int bus_manager_create_machine(Manager *manager, DBusMessage *message) {
-
- const char *name, *service, *class, *slice, *root_directory;
- _cleanup_free_ char *p = NULL;
- DBusMessageIter iter, sub;
- MachineClass c;
- uint32_t leader;
- sd_id128_t id;
- Machine *m;
- int n, r;
- void *v;
-
- assert(manager);
- assert(message);
-
- if (!dbus_message_iter_init(message, &iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(&iter, &name);
-
- if (!valid_machine_name(name) ||
- !dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
- dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE)
- return -EINVAL;
-
- dbus_message_iter_recurse(&iter, &sub);
- dbus_message_iter_get_fixed_array(&sub, &v, &n);
-
- if (n == 0)
- id = SD_ID128_NULL;
- else if (n == 16)
- memcpy(&id, v, n);
- else
- return -EINVAL;
-
- if (!dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(&iter, &service);
-
- if (!dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(&iter, &class);
-
- if (isempty(class))
- c = _MACHINE_CLASS_INVALID;
- else {
- c = machine_class_from_string(class);
- if (c < 0)
- return -EINVAL;
- }
-
- if (!dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
- return -EINVAL;
-
- dbus_message_iter_get_basic(&iter, &leader);
- if (!dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(&iter, &slice);
- if (!(isempty(slice) || (unit_name_is_valid(slice, false) && endswith(slice, ".slice"))) ||
- !dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return -EINVAL;
-
- dbus_message_iter_get_basic(&iter, &root_directory);
-
- if (!(isempty(root_directory) || path_is_absolute(root_directory)))
- return -EINVAL;
-
- if (hashmap_get(manager->machines, name))
- return -EEXIST;
-
- if (leader <= 0) {
- leader = bus_get_unix_process_id(manager->bus, dbus_message_get_sender(message), NULL);
- if (leader == 0)
- return -EINVAL;
- }
-
- r = manager_add_machine(manager, name, &m);
- if (r < 0)
- goto fail;
-
- m->leader = leader;
- m->class = c;
- m->id = id;
-
- if (!isempty(service)) {
- m->service = strdup(service);
- if (!m->service) {
- r = -ENOMEM;
- goto fail;
- }
- }
-
- if (!isempty(root_directory)) {
- m->root_directory = strdup(root_directory);
- if (!m->root_directory) {
- r = -ENOMEM;
- goto fail;
- }
- }
-
- r = machine_start(m);
- if (r < 0)
- goto fail;
-
- m->create_message = dbus_message_ref(message);
-
- return 0;
-
-fail:
- if (m)
- machine_add_to_gc_queue(m);
-
- return r;
-}
-
static int bus_manager_inhibit(
Manager *m,
DBusConnection *connection,
@@ -1673,73 +1497,6 @@ static DBusHandlerResult manager_message_handler(
if (!b)
goto oom;
- } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetMachine")) {
- Machine *machine;
- const char *name;
- char *p;
- bool b;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(connection, message, &error, -EINVAL);
-
- machine = hashmap_get(m->machines, name);
- if (!machine)
- return bus_send_error_reply(connection, message, &error, -ENOENT);
-
- reply = dbus_message_new_method_return(message);
- if (!reply)
- goto oom;
-
- p = machine_bus_path(machine);
- if (!p)
- goto oom;
-
- b = dbus_message_append_args(
- reply,
- DBUS_TYPE_OBJECT_PATH, &p,
- DBUS_TYPE_INVALID);
- free(p);
-
- if (!b)
- goto oom;
-
- } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetMachineByPID")) {
- uint32_t pid;
- char *p;
- Machine *machine;
- bool b;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_UINT32, &pid,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(connection, message, &error, -EINVAL);
-
- r = manager_get_machine_by_pid(m, pid, &machine);
- if (r <= 0)
- return bus_send_error_reply(connection, message, NULL, r < 0 ? r : -ENOENT);
-
- reply = dbus_message_new_method_return(message);
- if (!reply)
- goto oom;
-
- p = machine_bus_path(machine);
- if (!p)
- goto oom;
-
- b = dbus_message_append_args(
- reply,
- DBUS_TYPE_OBJECT_PATH, &p,
- DBUS_TYPE_INVALID);
- free(p);
-
- if (!b)
- goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSeat")) {
const char *name;
@@ -1946,48 +1703,6 @@ static DBusHandlerResult manager_message_handler(
if (!dbus_message_iter_close_container(&iter, &sub))
goto oom;
- } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ListMachines")) {
- Machine *machine;
- Iterator i;
- DBusMessageIter iter, sub;
-
- reply = dbus_message_new_method_return(message);
- if (!reply)
- goto oom;
-
- dbus_message_iter_init_append(reply, &iter);
-
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssso)", &sub))
- goto oom;
-
- HASHMAP_FOREACH(machine, m->machines, i) {
- _cleanup_free_ char *p = NULL;
- DBusMessageIter sub2;
- const char *class;
-
- if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
- goto oom;
-
- p = machine_bus_path(machine);
- if (!p)
- goto oom;
-
- class = strempty(machine_class_to_string(machine->class));
-
- if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &machine->name) ||
- !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &class) ||
- !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &machine->service) ||
- !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) {
- free(p);
- goto oom;
- }
-
- if (!dbus_message_iter_close_container(&sub, &sub2))
- goto oom;
- }
-
- if (!dbus_message_iter_close_container(&iter, &sub))
- goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "Inhibit")) {
@@ -2009,12 +1724,6 @@ static DBusHandlerResult manager_message_handler(
if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
- } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CreateMachine")) {
-
- r = bus_manager_create_machine(m, message);
- if (r < 0)
- return bus_send_error_reply(connection, message, NULL, r);
-
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "ReleaseSession")) {
const char *name;
Session *session;
@@ -2201,45 +1910,6 @@ static DBusHandlerResult manager_message_handler(
if (!reply)
goto oom;
- } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "KillMachine")) {
- const char *swho;
- int32_t signo;
- KillWho who;
- const char *name;
- Machine *machine;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_STRING, &swho,
- DBUS_TYPE_INT32, &signo,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(connection, message, &error, -EINVAL);
-
- if (isempty(swho))
- who = KILL_ALL;
- else {
- who = kill_who_from_string(swho);
- if (who < 0)
- return bus_send_error_reply(connection, message, &error, -EINVAL);
- }
-
- if (signo <= 0 || signo >= _NSIG)
- return bus_send_error_reply(connection, message, &error, -EINVAL);
-
- machine = hashmap_get(m->machines, name);
- if (!machine)
- return bus_send_error_reply(connection, message, &error, -ENOENT);
-
- r = machine_kill(machine, who, signo);
- if (r < 0)
- return bus_send_error_reply(connection, message, NULL, r);
-
- reply = dbus_message_new_method_return(message);
- if (!reply)
- goto oom;
-
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateSession")) {
const char *name;
Session *session;
@@ -2309,29 +1979,6 @@ static DBusHandlerResult manager_message_handler(
if (!reply)
goto oom;
- } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "TerminateMachine")) {
- const char *name;
- Machine *machine;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(connection, message, &error, -EINVAL);
-
- machine = hashmap_get(m->machines, name);
- if (!machine)
- return bus_send_error_reply(connection, message, &error, -ENOENT);
-
- r = machine_stop(machine);
- if (r < 0)
- return bus_send_error_reply(connection, message, NULL, r);
-
- reply = dbus_message_new_method_return(message);
- if (!reply)
- goto oom;
-
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "SetUserLinger")) {
uint32_t uid;
struct passwd *pw;
@@ -2701,7 +2348,6 @@ DBusHandlerResult bus_message_filter(
m->action_what = 0;
} else {
- Machine *mm;
Session *s;
User *u;
@@ -2738,25 +2384,6 @@ DBusHandlerResult bus_message_filter(
user_add_to_gc_queue(u);
}
-
- mm = hashmap_get(m->machine_units, unit);
- if (mm) {
- if (streq_ptr(path, mm->scope_job)) {
- free(mm->scope_job);
- mm->scope_job = NULL;
-
- if (mm->started) {
- if (streq(result, "done"))
- machine_send_create_reply(mm, NULL);
- else {
- dbus_set_error(&error, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
- machine_send_create_reply(mm, &error);
- }
- }
- }
-
- machine_add_to_gc_queue(mm);
- }
}
} else if (dbus_message_is_signal(message, "org.freedesktop.DBus.Properties", "PropertiesChanged")) {
@@ -2771,7 +2398,6 @@ DBusHandlerResult bus_message_filter(
unit_name_from_dbus_path(path, &unit);
if (unit) {
- Machine *mm;
Session *s;
User *u;
@@ -2782,10 +2408,6 @@ DBusHandlerResult bus_message_filter(
u = hashmap_get(m->user_units, unit);
if (u)
user_add_to_gc_queue(u);
-
- mm = hashmap_get(m->machine_units, unit);
- if (mm)
- machine_add_to_gc_queue(mm);
}
}
diff --git a/src/login/logind-machine-dbus.c b/src/login/logind-machine-dbus.c
deleted file mode 100644
index ae8c5d720a..0000000000
--- a/src/login/logind-machine-dbus.c
+++ /dev/null
@@ -1,360 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2011 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include <errno.h>
-#include <string.h>
-
-#include "logind.h"
-#include "logind-machine.h"
-#include "dbus-common.h"
-
-#define BUS_MACHINE_INTERFACE \
- " <interface name=\"org.freedesktop.login1.Machine\">\n" \
- " <method name=\"Terminate\"/>\n" \
- " <method name=\"Kill\">\n" \
- " <arg name=\"who\" type=\"s\"/>\n" \
- " <arg name=\"signal\" type=\"s\"/>\n" \
- " </method>\n" \
- " <property name=\"Name\" type=\"s\" access=\"read\"/>\n" \
- " <property name=\"Id\" type=\"ay\" access=\"read\"/>\n" \
- " <property name=\"Timestamp\" type=\"t\" access=\"read\"/>\n" \
- " <property name=\"TimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
- " <property name=\"Service\" type=\"s\" access=\"read\"/>\n" \
- " <property name=\"Scope\" type=\"s\" access=\"read\"/>\n" \
- " <property name=\"Leader\" type=\"u\" access=\"read\"/>\n" \
- " <property name=\"Class\" type=\"s\" access=\"read\"/>\n" \
- " <property name=\"State\" type=\"s\" access=\"read\"/>\n" \
- " <property name=\"RootDirectory\" type=\"s\" access=\"read\"/>\n" \
- " </interface>\n"
-
-#define INTROSPECTION \
- DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
- "<node>\n" \
- BUS_MACHINE_INTERFACE \
- BUS_PROPERTIES_INTERFACE \
- BUS_PEER_INTERFACE \
- BUS_INTROSPECTABLE_INTERFACE \
- "</node>\n"
-
-#define INTERFACES_LIST \
- BUS_GENERIC_INTERFACES_LIST \
- "org.freedesktop.login1.Machine\0"
-
-static int bus_machine_append_id(DBusMessageIter *i, const char *property, void *data) {
- DBusMessageIter sub;
- Machine *m = data;
- dbus_bool_t b;
- void *p;
-
- assert(i);
- assert(property);
- assert(m);
-
- if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "y", &sub))
- return -ENOMEM;
-
- p = &m->id;
- b = dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &p, 16);
- if (!b)
- return -ENOMEM;
-
- if (!dbus_message_iter_close_container(i, &sub))
- return -ENOMEM;
-
- return 0;
-}
-
-static int bus_machine_append_state(DBusMessageIter *i, const char *property, void *data) {
- Machine *m = data;
- const char *state;
-
- assert(i);
- assert(property);
- assert(m);
-
- state = machine_state_to_string(machine_get_state(m));
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state))
- return -ENOMEM;
-
- return 0;
-}
-
-static int get_machine_for_path(Manager *m, const char *path, Machine **_machine) {
- _cleanup_free_ char *e = NULL;
- Machine *machine;
-
- assert(m);
- assert(path);
- assert(_machine);
-
- if (!startswith(path, "/org/freedesktop/login1/machine/"))
- return -EINVAL;
-
- e = bus_path_unescape(path + 32);
- if (!e)
- return -ENOMEM;
-
- machine = hashmap_get(m->machines, e);
- if (!machine)
- return -ENOENT;
-
- *_machine = machine;
- return 0;
-}
-
-static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_machine_append_class, machine_class, MachineClass);
-
-static const BusProperty bus_login_machine_properties[] = {
- { "Name", bus_property_append_string, "s", offsetof(Machine, name), true },
- { "Id", bus_machine_append_id, "ay", 0 },
- { "Timestamp", bus_property_append_usec, "t", offsetof(Machine, timestamp.realtime) },
- { "TimestampMonotonic", bus_property_append_usec, "t", offsetof(Machine, timestamp.monotonic) },
- { "Service", bus_property_append_string, "s", offsetof(Machine, service), true },
- { "Scope", bus_property_append_string, "s", offsetof(Machine, scope), true },
- { "Leader", bus_property_append_pid, "u", offsetof(Session, leader) },
- { "Class", bus_machine_append_class, "s", offsetof(Machine, class) },
- { "State", bus_machine_append_state, "s", 0 },
- { "RootDirectory", bus_property_append_string, "s", offsetof(Machine, root_directory), true },
- { NULL, }
-};
-
-static DBusHandlerResult machine_message_dispatch(
- Machine *m,
- DBusConnection *connection,
- DBusMessage *message) {
-
- DBusError error;
- _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
- int r;
-
- assert(m);
- assert(connection);
- assert(message);
-
- if (dbus_message_is_method_call(message, "org.freedesktop.login1.Machine", "Terminate")) {
-
- r = machine_stop(m);
- if (r < 0)
- return bus_send_error_reply(connection, message, NULL, r);
-
- reply = dbus_message_new_method_return(message);
- if (!reply)
- goto oom;
-
- } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Machine", "Kill")) {
- const char *swho;
- int32_t signo;
- KillWho who;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_STRING, &swho,
- DBUS_TYPE_INT32, &signo,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(connection, message, &error, -EINVAL);
-
- if (isempty(swho))
- who = KILL_ALL;
- else {
- who = kill_who_from_string(swho);
- if (who < 0)
- return bus_send_error_reply(connection, message, &error, -EINVAL);
- }
-
- if (signo <= 0 || signo >= _NSIG)
- return bus_send_error_reply(connection, message, &error, -EINVAL);
-
- r = machine_kill(m, who, signo);
- if (r < 0)
- return bus_send_error_reply(connection, message, NULL, r);
-
- reply = dbus_message_new_method_return(message);
- if (!reply)
- goto oom;
-
- } else {
- const BusBoundProperties bps[] = {
- { "org.freedesktop.login1.Machine", bus_login_machine_properties, m },
- { NULL, }
- };
-
- return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, bps);
- }
-
- if (reply) {
- if (!bus_maybe_send_reply(connection, message, reply))
- goto oom;
- }
-
- return DBUS_HANDLER_RESULT_HANDLED;
-
-oom:
- dbus_error_free(&error);
-
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-}
-
-static DBusHandlerResult machine_message_handler(
- DBusConnection *connection,
- DBusMessage *message,
- void *userdata) {
-
- Manager *manager = userdata;
- Machine *m;
- int r;
-
- r = get_machine_for_path(manager, dbus_message_get_path(message), &m);
- if (r < 0) {
-
- if (r == -ENOMEM)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-
- if (r == -ENOENT) {
- DBusError e;
-
- dbus_error_init(&e);
- dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown machine");
- return bus_send_error_reply(connection, message, &e, r);
- }
-
- return bus_send_error_reply(connection, message, NULL, r);
- }
-
- return machine_message_dispatch(m, connection, message);
-}
-
-const DBusObjectPathVTable bus_machine_vtable = {
- .message_function = machine_message_handler
-};
-
-char *machine_bus_path(Machine *m) {
- _cleanup_free_ char *e = NULL;
-
- assert(m);
-
- e = bus_path_escape(m->name);
- if (!e)
- return NULL;
-
- return strappend("/org/freedesktop/login1/machine/", e);
-}
-
-int machine_send_signal(Machine *m, bool new_machine) {
- _cleanup_dbus_message_unref_ DBusMessage *msg = NULL;
- _cleanup_free_ char *p = NULL;
-
- assert(m);
-
- msg = dbus_message_new_signal("/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- new_machine ? "MachineNew" : "MachineRemoved");
-
- if (!m)
- return -ENOMEM;
-
- p = machine_bus_path(m);
- if (!p)
- return -ENOMEM;
-
- if (!dbus_message_append_args(
- msg,
- DBUS_TYPE_STRING, &m->name,
- DBUS_TYPE_OBJECT_PATH, &p,
- DBUS_TYPE_INVALID))
- return -ENOMEM;
-
- if (!dbus_connection_send(m->manager->bus, msg, NULL))
- return -ENOMEM;
-
- return 0;
-}
-
-int machine_send_changed(Machine *m, const char *properties) {
- _cleanup_dbus_message_unref_ DBusMessage *msg = NULL;
- _cleanup_free_ char *p = NULL;
-
- assert(m);
-
- if (!m->started)
- return 0;
-
- p = machine_bus_path(m);
- if (!p)
- return -ENOMEM;
-
- msg = bus_properties_changed_new(p, "org.freedesktop.login1.Machine", properties);
- if (!msg)
- return -ENOMEM;
-
- if (!dbus_connection_send(m->manager->bus, msg, NULL))
- return -ENOMEM;
-
- return 0;
-}
-
-int machine_send_create_reply(Machine *m, DBusError *error) {
- _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-
- assert(m);
-
- if (!m->create_message)
- return 0;
-
- if (error) {
- DBusError buffer;
-
- dbus_error_init(&buffer);
-
- if (!error || !dbus_error_is_set(error)) {
- dbus_set_error_const(&buffer, DBUS_ERROR_INVALID_ARGS, "Invalid Arguments");
- error = &buffer;
- }
-
- reply = dbus_message_new_error(m->create_message, error->name, error->message);
- dbus_error_free(&buffer);
-
- if (!reply)
- return log_oom();
- } else {
- _cleanup_free_ char *p = NULL;
-
- p = machine_bus_path(m);
- if (!p)
- return log_oom();
-
- reply = dbus_message_new_method_return(m->create_message);
- if (!reply)
- return log_oom();
-
- if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &p, DBUS_TYPE_INVALID))
- return log_oom();
- }
-
- if (!dbus_connection_send(m->manager->bus, reply, NULL))
- return log_oom();
-
- dbus_message_unref(m->create_message);
- m->create_message = NULL;
-
- return 0;
-}
diff --git a/src/login/logind-machine.c b/src/login/logind-machine.c
deleted file mode 100644
index a1342c155e..0000000000
--- a/src/login/logind-machine.c
+++ /dev/null
@@ -1,403 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2011 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <systemd/sd-messages.h>
-
-#include "util.h"
-#include "mkdir.h"
-#include "cgroup-util.h"
-#include "hashmap.h"
-#include "strv.h"
-#include "fileio.h"
-#include "special.h"
-#include "unit-name.h"
-#include "dbus-common.h"
-#include "logind-machine.h"
-
-Machine* machine_new(Manager *manager, const char *name) {
- Machine *m;
-
- assert(manager);
- assert(name);
-
- m = new0(Machine, 1);
- if (!m)
- return NULL;
-
- m->name = strdup(name);
- if (!m->name)
- goto fail;
-
- m->state_file = strappend("/run/systemd/machines/", m->name);
- if (!m->state_file)
- goto fail;
-
- if (hashmap_put(manager->machines, m->name, m) < 0)
- goto fail;
-
- m->class = _MACHINE_CLASS_INVALID;
- m->manager = manager;
-
- return m;
-
-fail:
- free(m->state_file);
- free(m->name);
- free(m);
-
- return NULL;
-}
-
-void machine_free(Machine *m) {
- assert(m);
-
- if (m->in_gc_queue)
- LIST_REMOVE(Machine, gc_queue, m->manager->machine_gc_queue, m);
-
- if (m->scope) {
- hashmap_remove(m->manager->machine_units, m->scope);
- free(m->scope);
- }
-
- free(m->scope_job);
-
- hashmap_remove(m->manager->machines, m->name);
-
- if (m->create_message)
- dbus_message_unref(m->create_message);
-
- free(m->name);
- free(m->state_file);
- free(m->service);
- free(m->root_directory);
- free(m);
-}
-
-int machine_save(Machine *m) {
- _cleanup_free_ char *temp_path = NULL;
- _cleanup_fclose_ FILE *f = NULL;
- int r;
-
- assert(m);
- assert(m->state_file);
-
- if (!m->started)
- return 0;
-
- r = mkdir_safe_label("/run/systemd/machines", 0755, 0, 0);
- if (r < 0)
- goto finish;
-
- r = fopen_temporary(m->state_file, &f, &temp_path);
- if (r < 0)
- goto finish;
-
- fchmod(fileno(f), 0644);
-
- fprintf(f,
- "# This is private data. Do not parse.\n"
- "NAME=%s\n",
- m->name);
-
- if (m->scope)
- fprintf(f, "SCOPE=%s\n", m->scope);
-
- if (m->scope_job)
- fprintf(f, "SCOPE_JOB=%s\n", m->scope_job);
-
- if (m->service)
- fprintf(f, "SERVICE=%s\n", m->service);
-
- if (m->root_directory)
- fprintf(f, "ROOT=%s\n", m->root_directory);
-
- if (!sd_id128_equal(m->id, SD_ID128_NULL))
- fprintf(f, "ID=" SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(m->id));
-
- if (m->leader != 0)
- fprintf(f, "LEADER=%lu\n", (unsigned long) m->leader);
-
- if (m->class != _MACHINE_CLASS_INVALID)
- fprintf(f, "CLASS=%s\n", machine_class_to_string(m->class));
-
- if (dual_timestamp_is_set(&m->timestamp))
- fprintf(f,
- "REALTIME=%llu\n"
- "MONOTONIC=%llu\n",
- (unsigned long long) m->timestamp.realtime,
- (unsigned long long) m->timestamp.monotonic);
-
- fflush(f);
-
- if (ferror(f) || rename(temp_path, m->state_file) < 0) {
- r = -errno;
- unlink(m->state_file);
- unlink(temp_path);
- }
-
-finish:
- if (r < 0)
- log_error("Failed to save machine data for %s: %s", m->name, strerror(-r));
-
- return r;
-}
-
-int machine_load(Machine *m) {
- _cleanup_free_ char *realtime = NULL, *monotonic = NULL, *id = NULL, *leader = NULL, *class = NULL;
- int r;
-
- assert(m);
-
- r = parse_env_file(m->state_file, NEWLINE,
- "SCOPE", &m->scope,
- "SCOPE_JOB", &m->scope_job,
- "SERVICE", &m->service,
- "ROOT", &m->root_directory,
- "ID", &id,
- "LEADER", &leader,
- "CLASS", &class,
- "REALTIME", &realtime,
- "MONOTONIC", &monotonic,
- NULL);
- if (r < 0) {
- if (r == -ENOENT)
- return 0;
-
- log_error("Failed to read %s: %s", m->state_file, strerror(-r));
- return r;
- }
-
- if (id)
- sd_id128_from_string(id, &m->id);
-
- if (leader)
- parse_pid(leader, &m->leader);
-
- if (class) {
- MachineClass c;
-
- c = machine_class_from_string(class);
- if (c >= 0)
- m->class = c;
- }
-
- if (realtime) {
- unsigned long long l;
- if (sscanf(realtime, "%llu", &l) > 0)
- m->timestamp.realtime = l;
- }
-
- if (monotonic) {
- unsigned long long l;
- if (sscanf(monotonic, "%llu", &l) > 0)
- m->timestamp.monotonic = l;
- }
-
- return r;
-}
-
-static int machine_start_scope(Machine *m) {
- _cleanup_free_ char *description = NULL;
- DBusError error;
- char *job;
- int r;
-
- assert(m);
-
- dbus_error_init(&error);
-
- if (!m->scope) {
- _cleanup_free_ char *escaped = NULL;
-
- escaped = unit_name_escape(m->name);
- if (!escaped)
- return log_oom();
-
- m->scope = strjoin("machine-", m->name, ".scope", NULL);
- if (!m->scope)
- return log_oom();
-
- r = hashmap_put(m->manager->machine_units, m->scope, m);
- if (r < 0)
- log_warning("Failed to create mapping between unit and machine");
- }
-
- description = strappend(m->class == MACHINE_VM ? "Virtual Machine " : "Container ", m->name);
-
- r = manager_start_scope(m->manager, m->scope, m->leader, SPECIAL_MACHINE_SLICE, description, &error, &job);
- if (r < 0) {
- log_error("Failed to start machine scope: %s", bus_error(&error, r));
- dbus_error_free(&error);
- }
-
- free(m->scope_job);
- m->scope_job = job;
-
- return r;
-}
-
-int machine_start(Machine *m) {
- int r;
-
- assert(m);
-
- if (m->started)
- return 0;
-
- /* Create cgroup */
- r = machine_start_scope(m);
- if (r < 0)
- return r;
-
- log_struct(LOG_INFO,
- MESSAGE_ID(SD_MESSAGE_MACHINE_START),
- "NAME=%s", m->name,
- "LEADER=%lu", (unsigned long) m->leader,
- "MESSAGE=New machine %s.", m->name,
- NULL);
-
- if (!dual_timestamp_is_set(&m->timestamp))
- dual_timestamp_get(&m->timestamp);
-
- m->started = true;
-
- /* Save new machine data */
- machine_save(m);
-
- machine_send_signal(m, true);
-
- return 0;
-}
-
-static int machine_stop_scope(Machine *m) {
- DBusError error;
- char *job;
- int r;
-
- assert(m);
-
- dbus_error_init(&error);
-
- if (!m->scope)
- return 0;
-
- r = manager_stop_unit(m->manager, m->scope, &error, &job);
- if (r < 0) {
- log_error("Failed to stop machine scope: %s", bus_error(&error, r));
- dbus_error_free(&error);
- return r;
- }
-
- free(m->scope_job);
- m->scope_job = job;
-
- return r;
-}
-
-int machine_stop(Machine *m) {
- int r = 0, k;
- assert(m);
-
- if (m->started)
- log_struct(LOG_INFO,
- MESSAGE_ID(SD_MESSAGE_MACHINE_STOP),
- "NAME=%s", m->name,
- "LEADER=%lu", (unsigned long) m->leader,
- "MESSAGE=Machine %s terminated.", m->name,
- NULL);
-
- /* Kill cgroup */
- k = machine_stop_scope(m);
- if (k < 0)
- r = k;
-
- unlink(m->state_file);
- machine_add_to_gc_queue(m);
-
- if (m->started)
- machine_send_signal(m, false);
-
- m->started = false;
-
- return r;
-}
-
-int machine_check_gc(Machine *m, bool drop_not_started) {
- assert(m);
-
- if (drop_not_started && !m->started)
- return 0;
-
- if (m->scope_job)
- return 1;
-
- if (m->scope)
- return manager_unit_is_active(m->manager, m->scope) != 0;
-
- return 0;
-}
-
-void machine_add_to_gc_queue(Machine *m) {
- assert(m);
-
- if (m->in_gc_queue)
- return;
-
- LIST_PREPEND(Machine, gc_queue, m->manager->machine_gc_queue, m);
- m->in_gc_queue = true;
-}
-
-MachineState machine_get_state(Machine *s) {
- assert(s);
-
- if (s->scope_job)
- return s->started ? MACHINE_OPENING : MACHINE_CLOSING;
-
- return MACHINE_RUNNING;
-}
-
-int machine_kill(Machine *m, KillWho who, int signo) {
- assert(m);
-
- if (!m->scope)
- return -ESRCH;
-
- return manager_kill_unit(m->manager, m->scope, who, signo, NULL);
-}
-
-static const char* const machine_class_table[_MACHINE_CLASS_MAX] = {
- [MACHINE_CONTAINER] = "container",
- [MACHINE_VM] = "vm"
-};
-
-DEFINE_STRING_TABLE_LOOKUP(machine_class, MachineClass);
-
-static const char* const machine_state_table[_MACHINE_STATE_MAX] = {
- [MACHINE_OPENING] = "opening",
- [MACHINE_RUNNING] = "running",
- [MACHINE_CLOSING] = "closing"
-};
-
-DEFINE_STRING_TABLE_LOOKUP(machine_state, MachineState);
diff --git a/src/login/logind-machine.h b/src/login/logind-machine.h
deleted file mode 100644
index a09f07195a..0000000000
--- a/src/login/logind-machine.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-/***
- This file is part of systemd.
-
- Copyright 2013 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-typedef struct Machine Machine;
-
-#include "list.h"
-#include "util.h"
-#include "logind.h"
-#include "logind-session.h"
-
-typedef enum MachineState {
- MACHINE_OPENING, /* Machine is being registered */
- MACHINE_RUNNING, /* Machine is running */
- MACHINE_CLOSING, /* Machine is terminating */
- _MACHINE_STATE_MAX,
- _MACHINE_STATE_INVALID = -1
-} MachineState;
-
-typedef enum MachineClass {
- MACHINE_CONTAINER,
- MACHINE_VM,
- _MACHINE_CLASS_MAX,
- _MACHINE_CLASS_INVALID = -1
-} MachineClass;
-
-struct Machine {
- Manager *manager;
-
- char *name;
- sd_id128_t id;
-
- MachineState state;
- MachineClass class;
-
- char *state_file;
- char *service;
- char *root_directory;
-
- char *scope;
- char *scope_job;
-
- pid_t leader;
-
- dual_timestamp timestamp;
-
- bool in_gc_queue:1;
- bool started:1;
-
- DBusMessage *create_message;
-
- LIST_FIELDS(Machine, gc_queue);
-};
-
-Machine* machine_new(Manager *manager, const char *name);
-void machine_free(Machine *m);
-int machine_check_gc(Machine *m, bool drop_not_started);
-void machine_add_to_gc_queue(Machine *m);
-int machine_start(Machine *m);
-int machine_stop(Machine *m);
-int machine_save(Machine *m);
-int machine_load(Machine *m);
-int machine_kill(Machine *m, KillWho who, int signo);
-
-char *machine_bus_path(Machine *s);
-
-MachineState machine_get_state(Machine *u);
-
-extern const DBusObjectPathVTable bus_machine_vtable;
-
-int machine_send_signal(Machine *m, bool new_machine);
-int machine_send_changed(Machine *m, const char *properties);
-
-int machine_send_create_reply(Machine *m, DBusError *error);
-
-const char* machine_class_to_string(MachineClass t) _const_;
-MachineClass machine_class_from_string(const char *s) _pure_;
-
-const char* machine_state_to_string(MachineState t) _const_;
-MachineState machine_state_from_string(const char *s) _pure_;
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 316c4cd095..fb961bf64b 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -354,11 +354,11 @@ static int user_start_slice(User *u) {
if (r < 0) {
log_error("Failed to start user slice: %s", bus_error(&error, r));
dbus_error_free(&error);
+ } else {
+ free(u->slice_job);
+ u->slice_job = job;
}
- free(u->slice_job);
- u->slice_job = job;
-
return 0;
}
@@ -388,11 +388,11 @@ static int user_start_service(User *u) {
if (r < 0) {
log_error("Failed to start user service: %s", bus_error(&error, r));
dbus_error_free(&error);
+ } else {
+ free(u->service_job);
+ u->service_job = job;
}
- free(u->service_job);
- u->service_job = job;
-
return 0;
}
diff --git a/src/login/logind.c b/src/login/logind.c
index 7040ac9e8a..e37a1071a2 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -74,18 +74,16 @@ Manager *manager_new(void) {
m->users = hashmap_new(trivial_hash_func, trivial_compare_func);
m->inhibitors = hashmap_new(string_hash_func, string_compare_func);
m->buttons = hashmap_new(string_hash_func, string_compare_func);
- m->machines = hashmap_new(string_hash_func, string_compare_func);
m->user_units = hashmap_new(string_hash_func, string_compare_func);
m->session_units = hashmap_new(string_hash_func, string_compare_func);
- m->machine_units = hashmap_new(string_hash_func, string_compare_func);
m->session_fds = hashmap_new(trivial_hash_func, trivial_compare_func);
m->inhibitor_fds = hashmap_new(trivial_hash_func, trivial_compare_func);
m->button_fds = hashmap_new(trivial_hash_func, trivial_compare_func);
- if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->machines ||
- !m->user_units || !m->session_units || !m->machine_units ||
+ if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons ||
+ !m->user_units || !m->session_units ||
!m->session_fds || !m->inhibitor_fds || !m->button_fds) {
manager_free(m);
return NULL;
@@ -113,7 +111,6 @@ void manager_free(Manager *m) {
Seat *s;
Inhibitor *i;
Button *b;
- Machine *machine;
assert(m);
@@ -135,20 +132,15 @@ void manager_free(Manager *m) {
while ((b = hashmap_first(m->buttons)))
button_free(b);
- while ((machine = hashmap_first(m->machines)))
- machine_free(machine);
-
hashmap_free(m->devices);
hashmap_free(m->seats);
hashmap_free(m->sessions);
hashmap_free(m->users);
hashmap_free(m->inhibitors);
hashmap_free(m->buttons);
- hashmap_free(m->machines);
hashmap_free(m->user_units);
hashmap_free(m->session_units);
- hashmap_free(m->machine_units);
hashmap_free(m->session_fds);
hashmap_free(m->inhibitor_fds);
@@ -364,30 +356,6 @@ int manager_add_button(Manager *m, const char *name, Button **_button) {
return 0;
}
-int manager_add_machine(Manager *m, const char *name, Machine **_machine) {
- Machine *machine;
-
- assert(m);
- assert(name);
-
- machine = hashmap_get(m->machines, name);
- if (machine) {
- if (_machine)
- *_machine = machine;
-
- return 0;
- }
-
- machine = machine_new(m, name);
- if (!m)
- return -ENOMEM;
-
- if (_machine)
- *_machine = machine;
-
- return 0;
-}
-
int manager_process_seat_device(Manager *m, struct udev_device *d) {
Device *device;
int r;
@@ -772,48 +740,6 @@ int manager_enumerate_inhibitors(Manager *m) {
return r;
}
-int manager_enumerate_machines(Manager *m) {
- _cleanup_closedir_ DIR *d = NULL;
- struct dirent *de;
- int r = 0;
-
- assert(m);
-
- /* Read in machine data stored on disk */
- d = opendir("/run/systemd/machines");
- if (!d) {
- if (errno == ENOENT)
- return 0;
-
- log_error("Failed to open /run/systemd/machines: %m");
- return -errno;
- }
-
- FOREACH_DIRENT(de, d, return -errno) {
- struct Machine *machine;
- int k;
-
- if (!dirent_is_file(de))
- continue;
-
- k = manager_add_machine(m, de->d_name, &machine);
- if (k < 0) {
- log_error("Failed to add machine by file name %s: %s", de->d_name, strerror(-k));
-
- r = k;
- continue;
- }
-
- machine_add_to_gc_queue(machine);
-
- k = machine_load(machine);
- if (k < 0)
- r = k;
- }
-
- return r;
-}
-
int manager_dispatch_seat_udev(Manager *m) {
struct udev_device *d;
int r;
@@ -1018,27 +944,6 @@ int manager_get_user_by_pid(Manager *m, pid_t pid, User **user) {
return 1;
}
-int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) {
- _cleanup_free_ char *unit = NULL;
- Machine *mm;
- int r;
-
- assert(m);
- assert(pid >= 1);
- assert(machine);
-
- r = cg_pid_get_unit(pid, &unit);
- if (r < 0)
- return r;
-
- mm = hashmap_get(m->machine_units, unit);
- if (!mm)
- return 0;
-
- *machine = mm;
- return 1;
-}
-
static void manager_dispatch_other(Manager *m, int fd) {
Session *s;
Inhibitor *i;
@@ -1098,7 +1003,6 @@ static int manager_connect_bus(Manager *m) {
!dbus_connection_register_fallback(m->bus, "/org/freedesktop/login1/seat", &bus_seat_vtable, m) ||
!dbus_connection_register_fallback(m->bus, "/org/freedesktop/login1/session", &bus_session_vtable, m) ||
!dbus_connection_register_fallback(m->bus, "/org/freedesktop/login1/user", &bus_user_vtable, m) ||
- !dbus_connection_register_fallback(m->bus, "/org/freedesktop/login1/machine", &bus_machine_vtable, m) ||
!dbus_connection_add_filter(m->bus, bus_message_filter, m, NULL)) {
r = log_oom();
goto fail;
@@ -1298,7 +1202,6 @@ void manager_gc(Manager *m, bool drop_not_started) {
Seat *seat;
Session *session;
User *user;
- Machine *machine;
assert(m);
@@ -1331,16 +1234,6 @@ void manager_gc(Manager *m, bool drop_not_started) {
user_free(user);
}
}
-
- while ((machine = m->machine_gc_queue)) {
- LIST_REMOVE(Machine, gc_queue, m->machine_gc_queue, machine);
- machine->in_gc_queue = false;
-
- if (machine_check_gc(machine, drop_not_started) == 0) {
- machine_stop(machine);
- machine_free(machine);
- }
- }
}
int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
@@ -1459,7 +1352,6 @@ int manager_startup(Manager *m) {
Session *session;
User *user;
Inhibitor *inhibitor;
- Machine *machine;
Iterator i;
assert(m);
@@ -1496,7 +1388,6 @@ int manager_startup(Manager *m) {
manager_enumerate_sessions(m);
manager_enumerate_inhibitors(m);
manager_enumerate_buttons(m);
- manager_enumerate_machines(m);
/* Remove stale objects before we start them */
manager_gc(m, false);
@@ -1517,9 +1408,6 @@ int manager_startup(Manager *m) {
HASHMAP_FOREACH(inhibitor, m->inhibitors, i)
inhibitor_start(inhibitor);
- HASHMAP_FOREACH(machine, m->machines, i)
- machine_start(machine);
-
manager_dispatch_idle_action(m);
return 0;
@@ -1671,7 +1559,6 @@ int main(int argc, char *argv[]) {
mkdir_label("/run/systemd/seats", 0755);
mkdir_label("/run/systemd/users", 0755);
mkdir_label("/run/systemd/sessions", 0755);
- mkdir_label("/run/systemd/machines", 0755);
m = manager_new();
if (!m) {
diff --git a/src/login/logind.h b/src/login/logind.h
index b7277af73d..f7457c0537 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -41,7 +41,6 @@ typedef struct Manager Manager;
#include "logind-inhibit.h"
#include "logind-button.h"
#include "logind-action.h"
-#include "logind-machine.h"
struct Manager {
DBusConnection *bus;
@@ -52,12 +51,10 @@ struct Manager {
Hashmap *users;
Hashmap *inhibitors;
Hashmap *buttons;
- Hashmap *machines;
LIST_HEAD(Seat, seat_gc_queue);
LIST_HEAD(Session, session_gc_queue);
LIST_HEAD(User, user_gc_queue);
- LIST_HEAD(Machine, machine_gc_queue);
struct udev *udev;
struct udev_monitor *udev_seat_monitor, *udev_vcsa_monitor, *udev_button_monitor;
@@ -85,7 +82,6 @@ struct Manager {
Hashmap *session_units;
Hashmap *user_units;
- Hashmap *machine_units;
Hashmap *session_fds;
Hashmap *inhibitor_fds;
@@ -144,7 +140,6 @@ int manager_add_user(Manager *m, uid_t uid, gid_t gid, const char *name, User **
int manager_add_user_by_name(Manager *m, const char *name, User **_user);
int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user);
int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor);
-int manager_add_machine(Manager *m, const char *name, Machine **_machine);
int manager_process_seat_device(Manager *m, struct udev_device *d);
int manager_process_button_device(Manager *m, struct udev_device *d);
@@ -161,7 +156,6 @@ int manager_enumerate_seats(Manager *m);
int manager_enumerate_sessions(Manager *m);
int manager_enumerate_users(Manager *m);
int manager_enumerate_inhibitors(Manager *m);
-int manager_enumerate_machines(Manager *m);
int manager_startup(Manager *m);
int manager_run(Manager *m);
@@ -173,7 +167,6 @@ int manager_get_idle_hint(Manager *m, dual_timestamp *t);
int manager_get_user_by_pid(Manager *m, pid_t pid, User **user);
int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
-int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine);
extern const DBusObjectPathVTable bus_manager_vtable;