X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=unit.c;h=1757af317ddbf60c7ac869ca4bdc992ca94e3aee;hb=129126f3792c452c871c0a096dcb1020c4d8096b;hp=5c19b3b2da32626b5da0ce15a7850db35e723420;hpb=701cc384c283206a29b21e4e7302e5cf5f2d9433;p=elogind.git diff --git a/unit.c b/unit.c index 5c19b3b2d..1757af317 100644 --- a/unit.c +++ b/unit.c @@ -47,7 +47,8 @@ const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = { [UNIT_DEVICE] = &device_vtable, [UNIT_MOUNT] = &mount_vtable, [UNIT_AUTOMOUNT] = &automount_vtable, - [UNIT_SNAPSHOT] = &snapshot_vtable + [UNIT_SNAPSHOT] = &snapshot_vtable, + [UNIT_SWAP] = &swap_vtable }; Unit *unit_new(Manager *m) { @@ -125,6 +126,11 @@ int unit_add_name(Unit *u, const char *text) { goto fail; } + if (hashmap_size(u->meta.manager->units) >= MANAGER_MAX_NAMES) { + r = -E2BIG; + goto fail; + } + if ((r = set_put(u->meta.names, s)) < 0) { if (r == -EEXIST) r = 0; @@ -552,7 +558,11 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) { char *p2; const char *prefix2; CGroupBonding *b; - char timestamp1[FORMAT_TIMESTAMP_MAX], timestamp2[FORMAT_TIMESTAMP_MAX]; + char + timestamp1[FORMAT_TIMESTAMP_MAX], + timestamp2[FORMAT_TIMESTAMP_MAX], + timestamp3[FORMAT_TIMESTAMP_MAX], + timestamp4[FORMAT_TIMESTAMP_MAX]; assert(u); assert(u->meta.type >= 0); @@ -563,21 +573,25 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) { prefix2 = p2 ? p2 : prefix; fprintf(f, - "%s→ Unit %s:\n" + "%s-> Unit %s:\n" "%s\tDescription: %s\n" "%s\tInstance: %s\n" "%s\tUnit Load State: %s\n" "%s\tUnit Active State: %s\n" + "%s\tInactive Exit Timestamp: %s\n" "%s\tActive Enter Timestamp: %s\n" "%s\tActive Exit Timestamp: %s\n" + "%s\tInactive Enter Timestamp: %s\n" "%s\tGC Check Good: %s\n", prefix, u->meta.id, prefix, unit_description(u), prefix, strna(u->meta.instance), prefix, unit_load_state_to_string(u->meta.load_state), prefix, unit_active_state_to_string(unit_active_state(u)), - prefix, strna(format_timestamp(timestamp1, sizeof(timestamp1), u->meta.active_enter_timestamp)), - prefix, strna(format_timestamp(timestamp2, sizeof(timestamp2), u->meta.active_exit_timestamp)), + prefix, strna(format_timestamp(timestamp1, sizeof(timestamp1), u->meta.inactive_exit_timestamp)), + prefix, strna(format_timestamp(timestamp2, sizeof(timestamp2), u->meta.active_enter_timestamp)), + prefix, strna(format_timestamp(timestamp3, sizeof(timestamp3), u->meta.active_exit_timestamp)), + prefix, strna(format_timestamp(timestamp4, sizeof(timestamp4), u->meta.inactive_enter_timestamp)), prefix, yes_no(unit_check_gc(u))); SET_FOREACH(t, u->meta.names, i) @@ -707,7 +721,7 @@ fail: u->meta.load_state = UNIT_FAILED; unit_add_to_dbus_queue(u); - log_error("Failed to load configuration for %s: %s", u->meta.id, strerror(-r)); + log_debug("Failed to load configuration for %s: %s", u->meta.id, strerror(-r)); return r; } @@ -902,6 +916,7 @@ static void retroactively_stop_dependencies(Unit *u) { void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { bool unexpected = false; + usec_t ts; assert(u); assert(os < _UNIT_ACTIVE_STATE_MAX); @@ -914,10 +929,17 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { * this function will be called too and the utmp code below * relies on that! */ + ts = now(CLOCK_REALTIME); + + if (os == UNIT_INACTIVE && ns != UNIT_INACTIVE) + u->meta.inactive_exit_timestamp = ts; + else if (os != UNIT_INACTIVE && ns == UNIT_INACTIVE) + u->meta.inactive_enter_timestamp = ts; + if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns)) - u->meta.active_enter_timestamp = now(CLOCK_REALTIME); + u->meta.active_enter_timestamp = ts; else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns)) - u->meta.active_exit_timestamp = now(CLOCK_REALTIME); + u->meta.active_exit_timestamp = ts; if (u->meta.job) { @@ -1005,7 +1027,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { /* The syslog daemon just might have become * available, hence try to connect to it, if * we aren't yet connected. */ - log_open_syslog(); + log_open(); if (u->meta.type == UNIT_MOUNT) /* Another directory became available, let's @@ -1825,6 +1847,42 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) { } } +int unit_add_node_link(Unit *u, const char *what, bool wants) { + Unit *device; + char *e; + int r; + + assert(u); + + if (!what) + return 0; + + /* Adds in links to the device node that this unit is based on */ + + if (!path_startswith(what, "/dev/") && !path_startswith(what, "/sys/")) + return 0; + + if (!(e = unit_name_build_escape(what+1, NULL, ".device"))) + return -ENOMEM; + + r = manager_load_unit(u->meta.manager, e, NULL, &device); + free(e); + + if (r < 0) + return r; + + if ((r = unit_add_dependency(u, UNIT_AFTER, device, true)) < 0) + return r; + + if ((r = unit_add_dependency(u, UNIT_REQUIRES, device, true)) < 0) + return r; + + if (wants) + if ((r = unit_add_dependency(device, UNIT_WANTS, u, false)) < 0) + return r; + + return 0; +} static const char* const unit_type_table[_UNIT_TYPE_MAX] = { [UNIT_SERVICE] = "service", @@ -1834,7 +1892,8 @@ static const char* const unit_type_table[_UNIT_TYPE_MAX] = { [UNIT_DEVICE] = "device", [UNIT_MOUNT] = "mount", [UNIT_AUTOMOUNT] = "automount", - [UNIT_SNAPSHOT] = "snapshot" + [UNIT_SNAPSHOT] = "snapshot", + [UNIT_SWAP] = "swap" }; DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);