1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-31 05:47:30 +03:00

manager: clean up audit/plymouth code a bit

Let's add assert()s, and let's put checks in similar order to emphasize
the symmetry. Also let's do cheap checks first.
This commit is contained in:
Lennart Poettering 2024-03-12 16:06:43 +01:00
parent e516c4d286
commit ad60cdd050

View File

@ -3361,18 +3361,20 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
const char *msg; const char *msg;
int audit_fd, r; int audit_fd, r;
assert(m);
assert(u);
if (!MANAGER_IS_SYSTEM(m)) if (!MANAGER_IS_SYSTEM(m))
return; return;
/* Don't generate audit events if the service was already started and we're just deserializing */
if (MANAGER_IS_RELOADING(m))
return;
audit_fd = get_audit_fd(); audit_fd = get_audit_fd();
if (audit_fd < 0) if (audit_fd < 0)
return; return;
/* Don't generate audit events if the service was already
* started and we're just deserializing */
if (MANAGER_IS_RELOADING(m))
return;
r = unit_name_to_prefix_and_instance(u->id, &p); r = unit_name_to_prefix_and_instance(u->id, &p);
if (r < 0) { if (r < 0) {
log_warning_errno(r, "Failed to extract prefix and instance of unit name, ignoring: %m"); log_warning_errno(r, "Failed to extract prefix and instance of unit name, ignoring: %m");
@ -3389,21 +3391,22 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
log_warning_errno(errno, "Failed to send audit message, ignoring: %m"); log_warning_errno(errno, "Failed to send audit message, ignoring: %m");
} }
#endif #endif
} }
void manager_send_unit_plymouth(Manager *m, Unit *u) { void manager_send_unit_plymouth(Manager *m, Unit *u) {
_cleanup_free_ char *message = NULL; _cleanup_free_ char *message = NULL;
int c, r; int c, r;
/* Don't generate plymouth events if the service was already assert(m);
* started and we're just deserializing */ assert(u);
if (MANAGER_IS_RELOADING(m))
return;
if (!MANAGER_IS_SYSTEM(m)) if (!MANAGER_IS_SYSTEM(m))
return; return;
/* Don't generate plymouth events if the service was already started and we're just deserializing */
if (MANAGER_IS_RELOADING(m))
return;
if (detect_container() > 0) if (detect_container() > 0)
return; return;