chiark / gitweb /
audit: suppress repeated audit events when deserializing
[elogind.git] / src / manager.c
index 9684efac8b1cc3c2e4baa98b4aed133fa8f8ce2b..6640420fb76d5c5ca57765f866a1352ed8a518b5 100644 (file)
@@ -1392,9 +1392,15 @@ static int transaction_add_job_and_dependencies(
         assert(type < _JOB_TYPE_MAX);
         assert(unit);
 
-        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);
+        if (unit->meta.load_state != UNIT_LOADED && unit->meta.load_state != UNIT_FAILED) {
+                dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s is not loaded properly.", unit->meta.id);
+                return -EINVAL;
+        }
+
+        if (type != JOB_STOP && unit->meta.load_state == UNIT_FAILED) {
+                dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s failed to load: %s. You might find more information in the logs.",
+                               unit->meta.id,
+                               strerror(-unit->meta.load_error));
                 return -EINVAL;
         }
 
@@ -2254,6 +2260,11 @@ void manager_send_unit_audit(Manager *m, Unit *u, int type, bool success) {
         if (m->audit_fd < 0)
                 return;
 
+        /* Don't generate audit events if the service was already
+         * started and we're just deserializing */
+        if (m->n_deserializing > 0)
+                return;
+
         if (!(p = unit_name_to_prefix_and_instance(u->meta.id))) {
                 log_error("Failed to allocate unit name for audit message: %s", strerror(ENOMEM));
                 return;