X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fmanager.c;h=4bebb2996fcaaa8c06c280795a7b5334bcd3c261;hb=8b55b8c4e7fce5e05dcfd783a37fb843d1bf1868;hp=ec3541418d99c52ef64e174e90de95da889cc328;hpb=bd0af84999e6270af3dc9401382be21b76fb0311;p=elogind.git diff --git a/src/core/manager.c b/src/core/manager.c index ec3541418..4bebb2996 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -70,6 +70,8 @@ #include "cgroup-util.h" #include "path-util.h" #include "audit-fd.h" +#include "efivars.h" +#include "env-util.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 +82,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 +126,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 +161,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"); @@ -286,6 +290,9 @@ static void manager_strip_environment(Manager *m) { * the initrd interface: * http://www.freedesktop.org/wiki/Software/systemd/InitrdInterface */ strv_remove_prefix(m->environment, "RD_"); + + /* Drop invalid entries */ + strv_env_clean(m->environment); } int manager_new(SystemdRunningAs running_as, Manager **_m) { @@ -301,6 +308,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; @@ -487,7 +496,7 @@ static unsigned manager_dispatch_gc_queue(Manager *m) { if (u->gc_marker == gc_marker + GC_OFFSET_BAD || u->gc_marker == gc_marker + GC_OFFSET_UNSURE) { - log_debug("Collecting %s", u->id); + log_debug_unit(u->id, "Collecting %s", u->id); u->gc_marker = gc_marker + GC_OFFSET_BAD; unit_add_to_cleanup_queue(u); } @@ -616,14 +625,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 +646,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 +663,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 +681,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) { @@ -749,7 +758,9 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove return -EPERM; } - log_debug("Trying to enqueue job %s/%s/%s", unit->id, job_type_to_string(type), job_mode_to_string(mode)); + log_debug_unit(unit->id, + "Trying to enqueue job %s/%s/%s", unit->id, + job_type_to_string(type), job_mode_to_string(mode)); job_type_collapse(&type, unit); @@ -773,7 +784,9 @@ int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool ove if (r < 0) goto tr_abort; - log_debug("Enqueued job %s/%s as %u", unit->id, job_type_to_string(type), (unsigned) tr->anchor_job->id); + log_debug_unit(unit->id, + "Enqueued job %s/%s as %u", unit->id, + job_type_to_string(type), (unsigned) tr->anchor_job->id); if (_ret) *_ret = tr->anchor_job; @@ -1070,7 +1083,7 @@ static int manager_process_notify_fd(Manager *m) { if (!tags) return log_oom(); - log_debug("Got notification message for unit %s", u->id); + log_debug_unit(u->id, "Got notification message for unit %s", u->id); if (UNIT_VTABLE(u)->notify_message) UNIT_VTABLE(u)->notify_message(u, ucred->pid, tags); @@ -1150,7 +1163,8 @@ static int manager_dispatch_sigchld(Manager *m) { if (!u) continue; - log_debug("Child %lu belongs to %s", (long unsigned) si.si_pid, u->id); + log_debug_unit(u->id, + "Child %lu belongs to %s", (long unsigned) si.si_pid, u->id); hashmap_remove(m->watch_pids, LONG_TO_PTR(si.si_pid)); UNIT_VTABLE(u)->sigchld_event(u, si.si_pid, si.si_code, si.si_status); @@ -1165,11 +1179,12 @@ static int manager_start_target(Manager *m, const char *name, JobMode mode) { dbus_error_init(&error); - log_debug("Activating special unit %s", name); + log_debug_unit(name, "Activating special unit %s", name); r = manager_add_job_by_name(m, JOB_START, name, mode, true, &error, NULL); if (r < 0) - log_error("Failed to enqueue %s job: %s", name, bus_error(&error, r)); + log_error_unit(name, + "Failed to enqueue %s job: %s", name, bus_error(&error, r)); dbus_error_free(&error); @@ -1677,7 +1692,8 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) { p = unit_name_to_prefix_and_instance(u->id); if (!p) { - log_error("Failed to allocate unit name for audit message: %s", strerror(ENOMEM)); + log_error_unit(u->id, + "Failed to allocate unit name for audit message: %s", strerror(ENOMEM)); return; } @@ -2251,7 +2267,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; } @@ -2262,7 +2279,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; } } @@ -2301,7 +2319,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; }