X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fmanager.c;h=58848356ea9aec577068650514cfe5b4df30b766;hb=3dda9fc3a738241e42df43dbebf9e479e5ad1da8;hp=5125db2e9a4f1af68d1e7fd5ea30d01fa260884c;hpb=fe51822e7120e89566cf76278d0b78ec7db4b43a;p=elogind.git diff --git a/src/manager.c b/src/manager.c index 5125db2e9..58848356e 100644 --- a/src/manager.c +++ b/src/manager.c @@ -89,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; } @@ -544,6 +544,12 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { manager_build_unit_path_cache(m); + /* If we will deserialize make sure that during enumeration + * this is already known, so we increase the counter here + * already */ + if (serialization) + m->n_deserializing ++; + /* First, enumerate what we can from all config files */ r = manager_enumerate(m); @@ -556,6 +562,11 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { if ((q = manager_coldplug(m)) < 0) r = q; + if (serialization) { + assert(m->n_deserializing > 0); + m->n_deserializing --; + } + /* Now that the initial devices are available, let's see if we * can write the utmp file */ manager_write_utmp_reboot(m); @@ -1317,7 +1328,8 @@ static int transaction_add_job_and_dependencies( assert(type < _JOB_TYPE_MAX); assert(unit); - if (unit->meta.load_state != UNIT_LOADED) { + if (type != JOB_STOP && + unit->meta.load_state != UNIT_LOADED) { dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s failed to load. See logs for details.", unit->meta.id); return -EINVAL; } @@ -1343,20 +1355,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) @@ -1941,7 +1959,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 @@ -2328,7 +2346,7 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) { log_debug("Deserializing state..."); - m->deserializing = true; + m->n_deserializing ++; for (;;) { Unit *u; @@ -2360,7 +2378,8 @@ int manager_deserialize(Manager *m, FILE *f, FDSet *fds) { r = 0; finish: - m->deserializing = false; + assert(m->n_deserializing > 0); + m->n_deserializing --; return r; } @@ -2396,6 +2415,8 @@ int manager_reload(Manager *m) { if ((q = lookup_paths_init(&m->lookup_paths, m->running_as)) < 0) r = q; + m->n_deserializing ++; + /* First, enumerate what we can from all config files */ if ((q = manager_enumerate(m)) < 0) r = q; @@ -2411,6 +2432,9 @@ int manager_reload(Manager *m) { if ((q = manager_coldplug(m)) < 0) r = q; + assert(m->n_deserializing > 0); + m->n_deserializing ++; + finish: if (f) fclose(f);