X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Funit.c;h=33e9cef86508cc9a6f902de10e1426aac69847a0;hb=e543deaeb5c4af128a27ea0a7e858dacefe32305;hp=881f91a677880a30fb1728f98373393c748d29f1;hpb=6c073082e7e3859cb6020db8c548325f342b7ba6;p=elogind.git diff --git a/src/unit.c b/src/unit.c index 881f91a67..33e9cef86 100644 --- a/src/unit.c +++ b/src/unit.c @@ -990,8 +990,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { * even if they might map to the same high-level * UnitActiveState! That means that ns == os is OK an expected * behaviour here. For example: if a mount point is remounted - * this function will be called too and the utmp code below - * relies on that! */ + * this function will be called too! */ dual_timestamp_get(&ts); @@ -1034,7 +1033,9 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { job_finish_and_invalidate(u->meta.job, true); else if (u->meta.job->state == JOB_RUNNING && ns != UNIT_ACTIVATING) { unexpected = true; - job_finish_and_invalidate(u->meta.job, false); + + if (UNIT_IS_INACTIVE_OR_MAINTENANCE(ns)) + job_finish_and_invalidate(u->meta.job, ns != UNIT_MAINTENANCE); } break; @@ -1047,7 +1048,9 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { job_finish_and_invalidate(u->meta.job, true); else if (ns != UNIT_ACTIVATING && ns != UNIT_RELOADING) { unexpected = true; - job_finish_and_invalidate(u->meta.job, false); + + if (UNIT_IS_INACTIVE_OR_MAINTENANCE(ns)) + job_finish_and_invalidate(u->meta.job, ns != UNIT_MAINTENANCE); } } @@ -1057,7 +1060,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { case JOB_RESTART: case JOB_TRY_RESTART: - if (ns == UNIT_INACTIVE || ns == UNIT_MAINTENANCE) + if (UNIT_IS_INACTIVE_OR_MAINTENANCE(ns)) job_finish_and_invalidate(u->meta.job, true); else if (u->meta.job->state == JOB_RUNNING && ns != UNIT_DEACTIVATING) { unexpected = true; @@ -1111,9 +1114,11 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { log_open(); if (u->meta.type == UNIT_SERVICE && - !UNIT_IS_ACTIVE_OR_RELOADING(os)) + !UNIT_IS_ACTIVE_OR_RELOADING(os)) { /* Write audit record if we have just finished starting up */ manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_START, 1); + u->meta.in_audit = true; + } } else { @@ -1128,10 +1133,22 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { if (u->meta.type == UNIT_SERVICE && UNIT_IS_INACTIVE_OR_MAINTENANCE(ns) && - !UNIT_IS_INACTIVE_OR_MAINTENANCE(os)) + !UNIT_IS_INACTIVE_OR_MAINTENANCE(os)) { - /* Write audit record if we have just finished shutting down */ - manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, ns == UNIT_INACTIVE); + /* Hmm, if there was no start record written + * write it now, so that we always have a nice + * pair */ + if (!u->meta.in_audit) { + manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_START, ns == UNIT_INACTIVE); + + if (ns == UNIT_INACTIVE) + manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, true); + } else + /* Write audit record if we have just finished shutting down */ + manager_send_unit_audit(u->meta.manager, u, AUDIT_SERVICE_STOP, ns == UNIT_INACTIVE); + + u->meta.in_audit = false; + } } /* Maybe we finished startup and are now ready for being