machined.c revision 5bb658a1784a0fd4f0f32adb4b1fb636ff503f7d
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2013 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering m->machines = hashmap_new(string_hash_func, string_compare_func);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering m->machine_units = hashmap_new(string_hash_func, string_compare_func);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering m->machine_leaders = hashmap_new(trivial_hash_func, trivial_compare_func);
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering if (!m->machines || !m->machine_units || !m->machine_leaders) {
8730bccfc59fe507bd3e0a3abcf411b497ac4f0eLennart Poettering while ((machine = hashmap_first(m->machines)))
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringint manager_enumerate_machines(Manager *m) {
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering /* Read in machine data stored on disk */
1b4f6e79ec51a57003896a0b605fba427b4a98d2Lennart Poettering log_error("Failed to open /run/systemd/machines: %m");
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering k = manager_add_machine(m, de->d_name, &machine);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Failed to add machine by file name %s: %s", de->d_name, strerror(-k));
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poetteringstatic int manager_connect_bus(Manager *m) {
9c92ce6d67f88beb31dd6555d12ae3f632218a39Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Failed to connect to system bus: %s", strerror(-r));
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek r = sd_bus_add_object_vtable(m->bus, "/org/freedesktop/machine1", "org.freedesktop.machine1.Manager", manager_vtable, m);
c0eb11cfd016381fe02875a4ef29c1ade00c94e7Lennart Poettering log_error("Failed to add manager object vtable: %s", strerror(-r));
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = sd_bus_add_fallback_vtable(m->bus, "/org/freedesktop/machine1/machine", "org.freedesktop.machine1.Machine", machine_vtable, machine_object_find, m);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering log_error("Failed to add machine object vtable: %s", strerror(-r));
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering r = sd_bus_add_node_enumerator(m->bus, "/org/freedesktop/machine1/machine", machine_node_enumerator, m);
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering log_error("Failed to add machine enumerator: %s", strerror(-r));
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering "type='signal',"
7e8e0422aeb16f2a09a40546c61df753d10029b6Lennart Poettering "sender='org.freedesktop.systemd1',"
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek "interface='org.freedesktop.systemd1.Manager',"
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek "member='JobRemoved',"
946c70944ebdf428ffeb9991a7449edbd4011461Zbigniew Jędrzejewski-Szmek "path='/org/freedesktop/systemd1'",
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering log_error("Failed to add match for JobRemoved: %s", strerror(-r));
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek "type='signal',"
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek "sender='org.freedesktop.systemd1',"
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek "interface='org.freedesktop.systemd1.Manager',"
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek "member='UnitRemoved',"
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek "path='/org/freedesktop/systemd1'",
42cc2eebb01056beb7acd3ecfe8e533558237f84Lennart Poettering log_error("Failed to add match for UnitRemoved: %s", strerror(-r));
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek "type='signal',"
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek "sender='org.freedesktop.systemd1',"
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek "interface='org.freedesktop.DBus.Properties',"
f91dc2400dc33e9a0745ecaaef7489af116dca38Lennart Poettering "member='PropertiesChanged'",
8db0d2f5c37e7e8f5bfce016cfdad7947a3ea939Zbigniew Jędrzejewski-Szmek log_error("Failed to add match for PropertiesChanged: %s", strerror(-r));
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek "type='signal',"
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek "sender='org.freedesktop.systemd1',"
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek "interface='org.freedesktop.systemd1.Manager',"
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek "member='Reloading',"
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek "path='/org/freedesktop/systemd1'",
151226ab4bf276d60d51864330a99f886b923697Zbigniew Jędrzejewski-Szmek log_error("Failed to add match for Reloading: %s", strerror(-r));
50f1e641a93cacfc693b0c3d300bee5df0c8c460Tom Gundersen "org.freedesktop.systemd1.Manager",
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering log_error("Failed to enable subscription: %s", bus_error_message(&error, r));
6af47493de0ef2b66d4c3fbcdd4a2e12fec4bfbaLennart Poettering r = sd_bus_request_name(m->bus, "org.freedesktop.machine1", 0);
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen log_error("Failed to register name: %s", strerror(-r));
5d45a8808431987c370706d365fb0cc95cf03d52Tom Gundersen log_error("Failed to attach bus to event loop: %s", strerror(-r));
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringvoid manager_gc(Manager *m, bool drop_not_started) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering while ((machine = m->machine_gc_queue)) {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering LIST_REMOVE(gc_queue, m->machine_gc_queue, machine);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!machine_check_gc(machine, drop_not_started)) {
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* Connect to the bus */
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering /* Deserialize state */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* Remove stale objects before we start them */
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering /* And start everything */
if (r == SD_EVENT_FINISHED)
manager_gc(m, true);
log_open();
r = -EINVAL;
goto finish;
m = manager_new();
r = log_oom();
goto finish;
r = manager_startup(m);
goto finish;
sd_notify(false,
r = manager_run(m);
sd_notify(false,
manager_free(m);