X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fmanager.c;h=9667e299f3f299faa195c4443c98af9eb442a6f4;hp=a7e24eb8124bb924ade4a64adca2673c0146a706;hb=eee4b05fab0a26aab7b8dc1e0e11e4a624a15798;hpb=c6c18be35bb1d300d0b62a568783cc1c477f7151 diff --git a/src/manager.c b/src/manager.c index a7e24eb81..9667e299f 100644 --- a/src/manager.c +++ b/src/manager.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "manager.h" #include "hashmap.h" @@ -88,7 +89,7 @@ static int manager_setup_notify(Manager *m) { else strncpy(sa.un.sun_path+1, NOTIFY_SOCKET, sizeof(sa.un.sun_path)-1); - if (bind(m->notify_watch.fd, &sa.sa, sizeof(sa)) < 0) { + if (bind(m->notify_watch.fd, &sa.sa, sizeof(sa_family_t) + 1 + strlen(sa.un.sun_path+1)) < 0) { log_error("bind() failed: %m"); return -errno; } @@ -478,11 +479,71 @@ int manager_coldplug(Manager *m) { return r; } +static void manager_build_unit_path_cache(Manager *m) { + char **i; + DIR *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))) { + log_error("Failed to allocate unit path cache."); + return; + } + + /* This simply builds a list of files we know exist, so that + * we don't always have to go to disk */ + + STRV_FOREACH(i, m->lookup_paths.unit_path) { + struct dirent *de; + + if (!(d = opendir(*i))) { + log_error("Failed to open directory: %m"); + continue; + } + + while ((de = readdir(d))) { + char *p; + + if (ignore_file(de->d_name)) + continue; + + if (asprintf(&p, "%s/%s", streq(*i, "/") ? "" : *i, de->d_name) < 0) { + r = -ENOMEM; + goto fail; + } + + if ((r = set_put(m->unit_path_cache, p)) < 0) { + free(p); + goto fail; + } + } + + closedir(d); + d = NULL; + } + + return; + +fail: + log_error("Failed to build unit path cache: %s", strerror(-r)); + + 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) { int r, q; assert(m); + manager_build_unit_path_cache(m); + /* First, enumerate what we can from all config files */ r = manager_enumerate(m); @@ -1282,20 +1343,26 @@ static int transaction_add_job_and_dependencies( goto fail; SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i) - if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !override, override, e, NULL)) < 0 && r != -EBADR) - log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r)); + if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !override, override, e, NULL)) < 0 && r != -EBADR) { + log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, bus_error(e, r)); + dbus_error_free(e); + } SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_WANTS], i) - if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, false, e, NULL)) < 0) - log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r)); + if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, false, e, NULL)) < 0) { + log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, bus_error(e, r)); + dbus_error_free(e); + } SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE], i) if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR) goto fail; SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUISITE_OVERRIDABLE], i) - if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, !override, override, e, NULL)) < 0 && r != -EBADR) - log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, strerror(-r)); + if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_ACTIVE, dep, ret, !override, override, e, NULL)) < 0 && r != -EBADR) { + log_warning("Cannot add dependency job for unit %s, ignoring: %s", dep->meta.id, bus_error(e, r)); + dbus_error_free(e); + } SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_CONFLICTS], i) if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, override, e, NULL)) < 0 && r != -EBADR) @@ -1880,7 +1947,7 @@ static int manager_process_signal_fd(Manager *m) { static const char * const table[] = { [0] = SPECIAL_DEFAULT_TARGET, [1] = SPECIAL_RESCUE_TARGET, - [2] = SPECIAL_EMERGENCY_SERVICE, + [2] = SPECIAL_EMERGENCY_TARGET, [3] = SPECIAL_HALT_TARGET, [4] = SPECIAL_POWEROFF_TARGET, [5] = SPECIAL_REBOOT_TARGET @@ -1993,6 +2060,10 @@ int manager_loop(Manager *m) { assert(m); m->exit_code = MANAGER_RUNNING; + /* Release the path cache */ + set_free_free(m->unit_path_cache); + m->unit_path_cache = NULL; + /* There might still be some zombies hanging around from * before we were exec()'ed. Leat's reap them */ if ((r = manager_dispatch_sigchld(m)) < 0)