chiark / gitweb /
nss-myhostname: copy first result to preallocated buffer
[elogind.git] / src / core / manager.c
index 3a4023f31a914f40adfa25f6cec6cefafb5b2506..c8d7d70dc405e00a8dea0bac251166e6d967a632 100644 (file)
@@ -70,6 +70,7 @@
 #include "cgroup-util.h"
 #include "path-util.h"
 #include "audit-fd.h"
+#include "efivars.h"
 
 /* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
 #define GC_QUEUE_ENTRIES_MAX 16
@@ -80,6 +81,8 @@
 /* Where clients shall send notification messages to */
 #define NOTIFY_SOCKET "@/org/freedesktop/systemd1/notify"
 
+#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
+
 static int manager_setup_notify(Manager *m) {
         union {
                 struct sockaddr sa;
@@ -122,7 +125,7 @@ static int manager_setup_notify(Manager *m) {
         ev.data.ptr = &m->notify_watch;
 
         if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev) < 0) {
-                log_error("Failed to add timer change fd to epoll: %m");
+                log_error("Failed to add notification socket fd to epoll: %m");
                 return -errno;
         }
 
@@ -157,8 +160,8 @@ static int manager_setup_time_change(Manager *m) {
 
         /* We only care for the cancellation event, hence we set the
          * timeout to the latest possible value. */
-        assert_cc(sizeof(time_t) == sizeof(long));
-        its.it_value.tv_sec = LONG_MAX;
+        assert_cc(sizeof(time_t) == sizeof(TIME_T_MAX));
+        its.it_value.tv_sec = TIME_T_MAX;
 
         if (timerfd_settime(m->time_change_watch.fd, TFD_TIMER_ABSTIME|TFD_TIMER_CANCEL_ON_SET, &its, NULL) < 0) {
                 log_debug("Failed to set up TFD_TIMER_CANCEL_ON_SET, ignoring: %m");
@@ -301,6 +304,8 @@ int manager_new(SystemdRunningAs running_as, Manager **_m) {
                 return -ENOMEM;
 
         dual_timestamp_get(&m->userspace_timestamp);
+        dual_timestamp_from_monotonic(&m->kernel_timestamp, 0);
+        efi_get_boot_timestamps(&m->userspace_timestamp, &m->firmware_timestamp, &m->loader_timestamp);
 
         m->running_as = running_as;
         m->name_data_slot = m->conn_data_slot = m->subscribed_data_slot = -1;
@@ -616,14 +621,15 @@ int manager_coldplug(Manager *m) {
 
 static void manager_build_unit_path_cache(Manager *m) {
         char **i;
-        DIR *d = NULL;
+        DIR _cleanup_free_ *d = NULL;
         int r;
 
         assert(m);
 
         set_free_free(m->unit_path_cache);
 
-        if (!(m->unit_path_cache = set_new(string_hash_func, string_compare_func))) {
+        m->unit_path_cache = set_new(string_hash_func, string_compare_func);
+        if (!m->unit_path_cache) {
                 log_error("Failed to allocate unit path cache.");
                 return;
         }
@@ -636,7 +642,8 @@ static void manager_build_unit_path_cache(Manager *m) {
 
                 d = opendir(*i);
                 if (!d) {
-                        log_error("Failed to open directory: %m");
+                        if (errno != ENOENT)
+                                log_error("Failed to open directory %s: %m", *i);
                         continue;
                 }
 
@@ -652,7 +659,8 @@ static void manager_build_unit_path_cache(Manager *m) {
                                 goto fail;
                         }
 
-                        if ((r = set_put(m->unit_path_cache, p)) < 0) {
+                        r = set_put(m->unit_path_cache, p);
+                        if (r < 0) {
                                 free(p);
                                 goto fail;
                         }
@@ -669,9 +677,6 @@ fail:
 
         set_free_free(m->unit_path_cache);
         m->unit_path_cache = NULL;
-
-        if (d)
-                closedir(d);
 }
 
 int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
@@ -2258,7 +2263,8 @@ static int create_generator_dir(Manager *m, char **generator, const char *name)
 
                 r = mkdir_p_label(p, 0755);
                 if (r < 0) {
-                        log_error("Failed to create generator directory: %s", strerror(-r));
+                        log_error("Failed to create generator directory %s: %s",
+                                  p, strerror(-r));
                         free(p);
                         return r;
                 }
@@ -2269,7 +2275,8 @@ static int create_generator_dir(Manager *m, char **generator, const char *name)
 
                 if (!mkdtemp(p)) {
                         free(p);
-                        log_error("Failed to create generator directory: %m");
+                        log_error("Failed to create generator directory %s: %m",
+                                  p);
                         return -errno;
                 }
         }
@@ -2308,7 +2315,8 @@ void manager_run_generators(Manager *m) {
                 if (errno == ENOENT)
                         return;
 
-                log_error("Failed to enumerate generator directory: %m");
+                log_error("Failed to enumerate generator directory %s: %m",
+                          generator_path);
                 return;
         }