naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
923a60
From a7ec486dede56ab2ec28132133becf11e5685884 Mon Sep 17 00:00:00 2001
923a60
From: Michal Sekletar <msekletar@users.noreply.github.com>
923a60
Date: Mon, 16 May 2016 17:24:51 +0200
923a60
Subject: [PATCH] core: don't log job status message in case job was
923a60
 effectively NOP (#3199)
923a60
923a60
We currently generate log message about unit being started even when
923a60
unit was started already and job didn't do anything. This is because job
923a60
was requested explicitly and hence became anchor job of the transaction
923a60
thus we could not eliminate it. That is fine but, let's not pollute
923a60
journal with useless log messages.
923a60
923a60
$ systemctl start systemd-resolved
923a60
$ systemctl start systemd-resolved
923a60
$ systemctl start systemd-resolved
923a60
923a60
Current state:
923a60
$ journalctl -u systemd-resolved | grep Started
923a60
923a60
May 05 15:31:42 rawhide systemd[1]: Started Network Name Resolution.
923a60
May 05 15:31:59 rawhide systemd[1]: Started Network Name Resolution.
923a60
May 05 15:32:01 rawhide systemd[1]: Started Network Name Resolution.
923a60
923a60
After patch applied:
923a60
$ journalctl -u systemd-resolved | grep Started
923a60
923a60
May 05 16:42:12 rawhide systemd[1]: Started Network Name Resolution.
923a60
923a60
Fixes #1723
923a60
923a60
Cherry-picked from: 833f92ad39beca0e954e91e5764ffc83f8d0c1cf
923a60
Resolves: #1280014
923a60
---
923a60
 src/core/dbus-job.c    |  2 +-
923a60
 src/core/job.c         | 33 ++++++++++++++++++---------------
923a60
 src/core/job.h         |  2 +-
923a60
 src/core/manager.c     |  2 +-
923a60
 src/core/transaction.c |  2 +-
923a60
 src/core/unit.c        | 12 ++++++------
923a60
 6 files changed, 28 insertions(+), 25 deletions(-)
923a60
923a60
diff --git a/src/core/dbus-job.c b/src/core/dbus-job.c
923a60
index 8b5ea2566d..7ce5d57726 100644
923a60
--- a/src/core/dbus-job.c
923a60
+++ b/src/core/dbus-job.c
923a60
@@ -84,7 +84,7 @@ int bus_job_method_cancel(sd_bus *bus, sd_bus_message *message, void *userdata,
923a60
         if (r < 0)
923a60
                 return r;
923a60
 
923a60
-        job_finish_and_invalidate(j, JOB_CANCELED, true);
923a60
+        job_finish_and_invalidate(j, JOB_CANCELED, true, false);
923a60
 
923a60
         return sd_bus_reply_method_return(message, NULL);
923a60
 }
923a60
diff --git a/src/core/job.c b/src/core/job.c
923a60
index 7416386a18..c2876dec18 100644
923a60
--- a/src/core/job.c
923a60
+++ b/src/core/job.c
923a60
@@ -190,7 +190,7 @@ Job* job_install(Job *j) {
923a60
 
923a60
         if (uj) {
923a60
                 if (job_type_is_conflicting(uj->type, j->type))
923a60
-                        job_finish_and_invalidate(uj, JOB_CANCELED, false);
923a60
+                        job_finish_and_invalidate(uj, JOB_CANCELED, false, false);
923a60
                 else {
923a60
                         /* not conflicting, i.e. mergeable */
923a60
 
923a60
@@ -571,19 +571,19 @@ int job_run_and_invalidate(Job *j) {
923a60
         j = manager_get_job(m, id);
923a60
         if (j) {
923a60
                 if (r == -EALREADY)
923a60
-                        r = job_finish_and_invalidate(j, JOB_DONE, true);
923a60
+                        r = job_finish_and_invalidate(j, JOB_DONE, true, true);
923a60
                 else if (r == -EBADR)
923a60
-                        r = job_finish_and_invalidate(j, JOB_SKIPPED, true);
923a60
+                        r = job_finish_and_invalidate(j, JOB_SKIPPED, true, false);
923a60
                 else if (r == -ENOEXEC)
923a60
-                        r = job_finish_and_invalidate(j, JOB_INVALID, true);
923a60
+                        r = job_finish_and_invalidate(j, JOB_INVALID, true, false);
923a60
                 else if (r == -EPROTO)
923a60
-                        r = job_finish_and_invalidate(j, JOB_ASSERT, true);
923a60
+                        r = job_finish_and_invalidate(j, JOB_ASSERT, true, false);
923a60
                 else if (r == -ENOTSUP)
923a60
-                        r = job_finish_and_invalidate(j, JOB_UNSUPPORTED, true);
923a60
+                        r = job_finish_and_invalidate(j, JOB_UNSUPPORTED, true, false);
923a60
                 else if (r == -EAGAIN)
923a60
                         job_set_state(j, JOB_WAITING);
923a60
                 else if (r < 0)
923a60
-                        r = job_finish_and_invalidate(j, JOB_FAILED, true);
923a60
+                        r = job_finish_and_invalidate(j, JOB_FAILED, true, false);
923a60
         }
923a60
 
923a60
         return r;
923a60
@@ -792,7 +792,7 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
923a60
                                 NULL);
923a60
 }
923a60
 
923a60
-int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
923a60
+int job_finish_and_invalidate(Job *j, JobResult result, bool recursive, bool already) {
923a60
         Unit *u;
923a60
         Unit *other;
923a60
         JobType t;
923a60
@@ -810,8 +810,11 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
923a60
         log_unit_debug(u->id, "Job %s/%s finished, result=%s",
923a60
                        u->id, job_type_to_string(t), job_result_to_string(result));
923a60
 
923a60
-        job_print_status_message(u, t, result);
923a60
-        job_log_status_message(u, t, result);
923a60
+        /* If this job did nothing to respective unit we don't log the status message */
923a60
+        if (!already) {
923a60
+                job_print_status_message(u, t, result);
923a60
+                job_log_status_message(u, t, result);
923a60
+        }
923a60
 
923a60
         job_add_to_dbus_queue(j);
923a60
 
923a60
@@ -842,20 +845,20 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
923a60
                                 if (other->job &&
923a60
                                     (other->job->type == JOB_START ||
923a60
                                      other->job->type == JOB_VERIFY_ACTIVE))
923a60
-                                        job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true);
923a60
+                                        job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true, false);
923a60
 
923a60
                         SET_FOREACH(other, u->dependencies[UNIT_BOUND_BY], i)
923a60
                                 if (other->job &&
923a60
                                     (other->job->type == JOB_START ||
923a60
                                      other->job->type == JOB_VERIFY_ACTIVE))
923a60
-                                        job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true);
923a60
+                                        job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true, false);
923a60
 
923a60
                         SET_FOREACH(other, u->dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
923a60
                                 if (other->job &&
923a60
                                     !other->job->override &&
923a60
                                     (other->job->type == JOB_START ||
923a60
                                      other->job->type == JOB_VERIFY_ACTIVE))
923a60
-                                        job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true);
923a60
+                                        job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true, false);
923a60
 
923a60
                 } else if (t == JOB_STOP) {
923a60
 
923a60
@@ -863,7 +866,7 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) {
923a60
                                 if (other->job &&
923a60
                                     (other->job->type == JOB_START ||
923a60
                                      other->job->type == JOB_VERIFY_ACTIVE))
923a60
-                                        job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true);
923a60
+                                        job_finish_and_invalidate(other->job, JOB_DEPENDENCY, true, false);
923a60
                 }
923a60
         }
923a60
 
923a60
@@ -911,7 +914,7 @@ static int job_dispatch_timer(sd_event_source *s, uint64_t monotonic, void *user
923a60
         log_unit_warning(j->unit->id, "Job %s/%s timed out.", j->unit->id, job_type_to_string(j->type));
923a60
 
923a60
         u = j->unit;
923a60
-        job_finish_and_invalidate(j, JOB_TIMEOUT, true);
923a60
+        job_finish_and_invalidate(j, JOB_TIMEOUT, true, false);
923a60
 
923a60
         failure_action(u->manager, u->job_timeout_action, u->job_timeout_reboot_arg);
923a60
 
923a60
diff --git a/src/core/job.h b/src/core/job.h
923a60
index d967b68a3f..e4191ee775 100644
923a60
--- a/src/core/job.h
923a60
+++ b/src/core/job.h
923a60
@@ -220,7 +220,7 @@ void job_add_to_dbus_queue(Job *j);
923a60
 int job_start_timer(Job *j);
923a60
 
923a60
 int job_run_and_invalidate(Job *j);
923a60
-int job_finish_and_invalidate(Job *j, JobResult result, bool recursive);
923a60
+int job_finish_and_invalidate(Job *j, JobResult result, bool recursive, bool already);
923a60
 
923a60
 char *job_dbus_path(Job *j);
923a60
 
923a60
diff --git a/src/core/manager.c b/src/core/manager.c
923a60
index a1504bf17b..ee456fb790 100644
923a60
--- a/src/core/manager.c
923a60
+++ b/src/core/manager.c
923a60
@@ -1426,7 +1426,7 @@ void manager_clear_jobs(Manager *m) {
923a60
 
923a60
         while ((j = hashmap_first(m->jobs)))
923a60
                 /* No need to recurse. We're cancelling all jobs. */
923a60
-                job_finish_and_invalidate(j, JOB_CANCELED, false);
923a60
+                job_finish_and_invalidate(j, JOB_CANCELED, false, false);
923a60
 }
923a60
 
923a60
 static int manager_dispatch_run_queue(sd_event_source *source, void *userdata) {
923a60
diff --git a/src/core/transaction.c b/src/core/transaction.c
923a60
index b0b3d6bd60..aed64fa419 100644
923a60
--- a/src/core/transaction.c
923a60
+++ b/src/core/transaction.c
923a60
@@ -592,7 +592,7 @@ static int transaction_apply(Transaction *tr, Manager *m, JobMode mode) {
923a60
                         /* Not invalidating recursively. Avoids triggering
923a60
                          * OnFailure= actions of dependent jobs. Also avoids
923a60
                          * invalidating our iterator. */
923a60
-                        job_finish_and_invalidate(j, JOB_CANCELED, false);
923a60
+                        job_finish_and_invalidate(j, JOB_CANCELED, false, false);
923a60
                 }
923a60
         }
923a60
 
923a60
diff --git a/src/core/unit.c b/src/core/unit.c
923a60
index db5aa987ec..d6ead7d672 100644
923a60
--- a/src/core/unit.c
923a60
+++ b/src/core/unit.c
923a60
@@ -1851,12 +1851,12 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
923a60
                 case JOB_VERIFY_ACTIVE:
923a60
 
923a60
                         if (UNIT_IS_ACTIVE_OR_RELOADING(ns))
923a60
-                                job_finish_and_invalidate(u->job, JOB_DONE, true);
923a60
+                                job_finish_and_invalidate(u->job, JOB_DONE, true, false);
923a60
                         else if (u->job->state == JOB_RUNNING && ns != UNIT_ACTIVATING) {
923a60
                                 unexpected = true;
923a60
 
923a60
                                 if (UNIT_IS_INACTIVE_OR_FAILED(ns))
923a60
-                                        job_finish_and_invalidate(u->job, ns == UNIT_FAILED ? JOB_FAILED : JOB_DONE, true);
923a60
+                                        job_finish_and_invalidate(u->job, ns == UNIT_FAILED ? JOB_FAILED : JOB_DONE, true, false);
923a60
                         }
923a60
 
923a60
                         break;
923a60
@@ -1866,12 +1866,12 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
923a60
 
923a60
                         if (u->job->state == JOB_RUNNING) {
923a60
                                 if (ns == UNIT_ACTIVE)
923a60
-                                        job_finish_and_invalidate(u->job, reload_success ? JOB_DONE : JOB_FAILED, true);
923a60
+                                        job_finish_and_invalidate(u->job, reload_success ? JOB_DONE : JOB_FAILED, true, false);
923a60
                                 else if (ns != UNIT_ACTIVATING && ns != UNIT_RELOADING) {
923a60
                                         unexpected = true;
923a60
 
923a60
                                         if (UNIT_IS_INACTIVE_OR_FAILED(ns))
923a60
-                                                job_finish_and_invalidate(u->job, ns == UNIT_FAILED ? JOB_FAILED : JOB_DONE, true);
923a60
+                                                job_finish_and_invalidate(u->job, ns == UNIT_FAILED ? JOB_FAILED : JOB_DONE, true, false);
923a60
                                 }
923a60
                         }
923a60
 
923a60
@@ -1882,10 +1882,10 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
923a60
                 case JOB_TRY_RESTART:
923a60
 
923a60
                         if (UNIT_IS_INACTIVE_OR_FAILED(ns))
923a60
-                                job_finish_and_invalidate(u->job, JOB_DONE, true);
923a60
+                                job_finish_and_invalidate(u->job, JOB_DONE, true, false);
923a60
                         else if (u->job->state == JOB_RUNNING && ns != UNIT_DEACTIVATING) {
923a60
                                 unexpected = true;
923a60
-                                job_finish_and_invalidate(u->job, JOB_FAILED, true);
923a60
+                                job_finish_and_invalidate(u->job, JOB_FAILED, true, false);
923a60
                         }
923a60
 
923a60
                         break;