chiark / gitweb /
journal: keep per-JournalFile location info during iteration
[elogind.git] / src / machine / machined.c
index 20e6f7cd63e92c2ae192eefa2d4e5407b3478a0c..ef59497fb212da2beb09a43ad4bbc01cedfd9913 100644 (file)
@@ -35,6 +35,7 @@
 #include "bus-util.h"
 #include "bus-error.h"
 #include "machined.h"
+#include "label.h"
 
 Manager *manager_new(void) {
         Manager *m;
@@ -44,9 +45,9 @@ Manager *manager_new(void) {
         if (!m)
                 return NULL;
 
-        m->machines = hashmap_new(string_hash_func, string_compare_func);
-        m->machine_units = hashmap_new(string_hash_func, string_compare_func);
-        m->machine_leaders = hashmap_new(trivial_hash_func, trivial_compare_func);
+        m->machines = hashmap_new(&string_hash_ops);
+        m->machine_units = hashmap_new(&string_hash_ops);
+        m->machine_leaders = hashmap_new(NULL);
 
         if (!m->machines || !m->machine_units || !m->machine_leaders) {
                 manager_free(m);
@@ -95,7 +96,7 @@ int manager_enumerate_machines(Manager *m) {
                 if (errno == ENOENT)
                         return 0;
 
-                log_error("Failed to open /run/systemd/machines: %m");
+                log_error_errno(errno, "Failed to open /run/systemd/machines: %m");
                 return -errno;
         }
 
@@ -112,7 +113,7 @@ int manager_enumerate_machines(Manager *m) {
 
                 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));
+                        log_error_errno(k, "Failed to add machine by file name %s: %m", de->d_name);
 
                         r = k;
                         continue;
@@ -136,30 +137,23 @@ static int manager_connect_bus(Manager *m) {
         assert(!m->bus);
 
         r = sd_bus_default_system(&m->bus);
-        if (r < 0) {
-                log_error("Failed to connect to system bus: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to connect to system bus: %m");
 
-        r = sd_bus_add_object_vtable(m->bus, "/org/freedesktop/machine1", "org.freedesktop.machine1.Manager", manager_vtable, m);
-        if (r < 0) {
-                log_error("Failed to add manager object vtable: %s", strerror(-r));
-                return r;
-        }
+        r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/machine1", "org.freedesktop.machine1.Manager", manager_vtable, m);
+        if (r < 0)
+                return log_error_errno(r, "Failed to add manager object vtable: %m");
 
-        r = sd_bus_add_fallback_vtable(m->bus, "/org/freedesktop/machine1/machine", "org.freedesktop.machine1.Machine", machine_vtable, machine_object_find, m);
-        if (r < 0) {
-                log_error("Failed to add machine object vtable: %s", strerror(-r));
-                return r;
-        }
+        r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/machine1/machine", "org.freedesktop.machine1.Machine", machine_vtable, machine_object_find, m);
+        if (r < 0)
+                return log_error_errno(r, "Failed to add machine object vtable: %m");
 
-        r = sd_bus_add_node_enumerator(m->bus, "/org/freedesktop/machine1/machine", machine_node_enumerator, m);
-        if (r < 0) {
-                log_error("Failed to add machine enumerator: %s", strerror(-r));
-                return r;
-        }
+        r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/machine1/machine", machine_node_enumerator, m);
+        if (r < 0)
+                return log_error_errno(r, "Failed to add machine enumerator: %m");
 
         r = sd_bus_add_match(m->bus,
+                             NULL,
                              "type='signal',"
                              "sender='org.freedesktop.systemd1',"
                              "interface='org.freedesktop.systemd1.Manager',"
@@ -167,12 +161,11 @@ static int manager_connect_bus(Manager *m) {
                              "path='/org/freedesktop/systemd1'",
                              match_job_removed,
                              m);
-        if (r < 0) {
-                log_error("Failed to add match for JobRemoved: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to add match for JobRemoved: %m");
 
         r = sd_bus_add_match(m->bus,
+                             NULL,
                              "type='signal',"
                              "sender='org.freedesktop.systemd1',"
                              "interface='org.freedesktop.systemd1.Manager',"
@@ -180,24 +173,22 @@ static int manager_connect_bus(Manager *m) {
                              "path='/org/freedesktop/systemd1'",
                              match_unit_removed,
                              m);
-        if (r < 0) {
-                log_error("Failed to add match for UnitRemoved: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to add match for UnitRemoved: %m");
 
         r = sd_bus_add_match(m->bus,
+                             NULL,
                              "type='signal',"
                              "sender='org.freedesktop.systemd1',"
                              "interface='org.freedesktop.DBus.Properties',"
                              "member='PropertiesChanged'",
                              match_properties_changed,
                              m);
-        if (r < 0) {
-                log_error("Failed to add match for PropertiesChanged: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to add match for PropertiesChanged: %m");
 
         r = sd_bus_add_match(m->bus,
+                             NULL,
                              "type='signal',"
                              "sender='org.freedesktop.systemd1',"
                              "interface='org.freedesktop.systemd1.Manager',"
@@ -205,10 +196,8 @@ static int manager_connect_bus(Manager *m) {
                              "path='/org/freedesktop/systemd1'",
                              match_reloading,
                              m);
-        if (r < 0) {
-                log_error("Failed to add match for Reloading: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to add match for Reloading: %m");
 
         r = sd_bus_call_method(
                         m->bus,
@@ -224,16 +213,12 @@ static int manager_connect_bus(Manager *m) {
         }
 
         r = sd_bus_request_name(m->bus, "org.freedesktop.machine1", 0);
-        if (r < 0) {
-                log_error("Failed to register name: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to register name: %m");
 
         r = sd_bus_attach_event(m->bus, m->event, 0);
-        if (r < 0) {
-                log_error("Failed to attach bus to event loop: %s", strerror(-r));
-                return r;
-        }
+        if (r < 0)
+                return log_error_errno(r, "Failed to attach bus to event loop: %m");
 
         return 0;
 }
@@ -330,11 +315,11 @@ int main(int argc, char *argv[]) {
 
         r = manager_startup(m);
         if (r < 0) {
-                log_error("Failed to fully start up daemon: %s", strerror(-r));
+                log_error_errno(r, "Failed to fully start up daemon: %m");
                 goto finish;
         }
 
-        log_debug("systemd-machined running as pid %lu", (unsigned long) getpid());
+        log_debug("systemd-machined running as pid "PID_FMT, getpid());
 
         sd_notify(false,
                   "READY=1\n"
@@ -342,12 +327,9 @@ int main(int argc, char *argv[]) {
 
         r = manager_run(m);
 
-        log_debug("systemd-machined stopped as pid %lu", (unsigned long) getpid());
+        log_debug("systemd-machined stopped as pid "PID_FMT, getpid());
 
 finish:
-        sd_notify(false,
-                  "STATUS=Shutting down...");
-
         if (m)
                 manager_free(m);