mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 19:21:53 +03:00
core: split out audit message generation from unit_notify()
Just some refactoring, no change in behaviour.
This commit is contained in:
parent
438311a518
commit
6eb65e7ca4
@ -2340,6 +2340,36 @@ static void unit_update_on_console(Unit *u) {
|
|||||||
manager_unref_console(u->manager);
|
manager_unref_console(u->manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void unit_emit_audit_start(Unit *u) {
|
||||||
|
assert(u);
|
||||||
|
|
||||||
|
if (u->type != UNIT_SERVICE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Write audit record if we have just finished starting up */
|
||||||
|
manager_send_unit_audit(u->manager, u, AUDIT_SERVICE_START, true);
|
||||||
|
u->in_audit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unit_emit_audit_stop(Unit *u, UnitActiveState state) {
|
||||||
|
assert(u);
|
||||||
|
|
||||||
|
if (u->type != UNIT_SERVICE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (u->in_audit) {
|
||||||
|
/* Write audit record if we have just finished shutting down */
|
||||||
|
manager_send_unit_audit(u->manager, u, AUDIT_SERVICE_STOP, state == UNIT_INACTIVE);
|
||||||
|
u->in_audit = false;
|
||||||
|
} else {
|
||||||
|
/* Hmm, if there was no start record written write it now, so that we always have a nice pair */
|
||||||
|
manager_send_unit_audit(u->manager, u, AUDIT_SERVICE_START, state == UNIT_INACTIVE);
|
||||||
|
|
||||||
|
if (state == UNIT_INACTIVE)
|
||||||
|
manager_send_unit_audit(u->manager, u, AUDIT_SERVICE_STOP, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags) {
|
void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags) {
|
||||||
bool unexpected;
|
bool unexpected;
|
||||||
const char *reason;
|
const char *reason;
|
||||||
@ -2478,35 +2508,14 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlag
|
|||||||
if (UNIT_IS_ACTIVE_OR_RELOADING(ns) && !UNIT_IS_ACTIVE_OR_RELOADING(os)) {
|
if (UNIT_IS_ACTIVE_OR_RELOADING(ns) && !UNIT_IS_ACTIVE_OR_RELOADING(os)) {
|
||||||
/* This unit just finished starting up */
|
/* This unit just finished starting up */
|
||||||
|
|
||||||
if (u->type == UNIT_SERVICE) {
|
unit_emit_audit_start(u);
|
||||||
/* Write audit record if we have just finished starting up */
|
|
||||||
manager_send_unit_audit(m, u, AUDIT_SERVICE_START, true);
|
|
||||||
u->in_audit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
manager_send_unit_plymouth(m, u);
|
manager_send_unit_plymouth(m, u);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UNIT_IS_INACTIVE_OR_FAILED(ns) && !UNIT_IS_INACTIVE_OR_FAILED(os)) {
|
if (UNIT_IS_INACTIVE_OR_FAILED(ns) && !UNIT_IS_INACTIVE_OR_FAILED(os)) {
|
||||||
/* This unit just stopped/failed. */
|
/* This unit just stopped/failed. */
|
||||||
|
|
||||||
if (u->type == UNIT_SERVICE) {
|
unit_emit_audit_stop(u, ns);
|
||||||
|
|
||||||
if (u->in_audit) {
|
|
||||||
/* Write audit record if we have just finished shutting down */
|
|
||||||
manager_send_unit_audit(m, u, AUDIT_SERVICE_STOP, ns == UNIT_INACTIVE);
|
|
||||||
u->in_audit = false;
|
|
||||||
} else {
|
|
||||||
/* Hmm, if there was no start record written write it now, so that we always
|
|
||||||
* have a nice pair */
|
|
||||||
manager_send_unit_audit(m, u, AUDIT_SERVICE_START, ns == UNIT_INACTIVE);
|
|
||||||
|
|
||||||
if (ns == UNIT_INACTIVE)
|
|
||||||
manager_send_unit_audit(m, u, AUDIT_SERVICE_STOP, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write a log message about consumed resources */
|
|
||||||
unit_log_resources(u);
|
unit_log_resources(u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user