chiark / gitweb /
socket: optionally call accept() for incoming connections and spawn one service insta...
[elogind.git] / job.c
diff --git a/job.c b/job.c
index be42eaff62f5ed9fcbad31131833bf1aa0b3cc04..0e03fcdc77b4a943f9eec90259f75f3e99ea11c8 100644 (file)
--- a/job.c
+++ b/job.c
@@ -65,7 +65,7 @@ void job_free(Job *j) {
         }
 
         /* Detach from next 'smaller' objects */
-        manager_transaction_unlink_job(j->manager, j);
+        manager_transaction_unlink_job(j->manager, j, true);
 
         if (j->in_run_queue)
                 LIST_REMOVE(Job, run_queue, j->manager->run_queue, j);
@@ -152,9 +152,9 @@ void job_dump(Job *j, FILE*f, const char *prefix) {
                 "%s\tState: %s\n"
                 "%s\tForced: %s\n",
                 prefix, j->id,
-                prefix, unit_id(j->unit), job_type_to_string(j->type),
+                prefix, j->unit->meta.id, job_type_to_string(j->type),
                 prefix, job_state_to_string(j->state),
-                prefix, yes_no(j->forced));
+                prefix, yes_no(j->override));
 }
 
 bool job_is_anchor(Job *j) {
@@ -265,6 +265,45 @@ bool job_type_is_conflicting(JobType a, JobType b) {
         return (a == JOB_STOP) != (b == JOB_STOP);
 }
 
+bool job_type_is_redundant(JobType a, UnitActiveState b) {
+        switch (a) {
+
+        case JOB_START:
+                return
+                        b == UNIT_ACTIVE ||
+                        b == UNIT_ACTIVE_RELOADING;
+
+        case JOB_STOP:
+                return
+                        b == UNIT_INACTIVE;
+
+        case JOB_VERIFY_ACTIVE:
+                return
+                        b == UNIT_ACTIVE ||
+                        b == UNIT_ACTIVE_RELOADING;
+
+        case JOB_RELOAD:
+                return
+                        b == UNIT_ACTIVE_RELOADING;
+
+        case JOB_RELOAD_OR_START:
+                return
+                        b == UNIT_ACTIVATING ||
+                        b == UNIT_ACTIVE_RELOADING;
+
+        case JOB_RESTART:
+                return
+                        b == UNIT_ACTIVATING;
+
+        case JOB_TRY_RESTART:
+                return
+                        b == UNIT_ACTIVATING;
+
+        default:
+                assert_not_reached("Invalid job type");
+        }
+}
+
 bool job_is_runnable(Job *j) {
         Iterator i;
         Unit *other;
@@ -410,21 +449,21 @@ int job_run_and_invalidate(Job *j) {
 int job_finish_and_invalidate(Job *j, bool success) {
         Unit *u;
         Unit *other;
-        UnitType t;
+        JobType t;
         Iterator i;
 
         assert(j);
         assert(j->installed);
 
-        log_debug("Job %s/%s finished, success=%s", unit_id(j->unit), job_type_to_string(j->type), yes_no(success));
+        log_debug("Job %s/%s finished, success=%s", j->unit->meta.id, job_type_to_string(j->type), yes_no(success));
         job_add_to_dbus_queue(j);
 
         /* Patch restart jobs so that they become normal start jobs */
         if (success && (j->type == JOB_RESTART || j->type == JOB_TRY_RESTART)) {
 
                 log_debug("Converting job %s/%s → %s/%s",
-                          unit_id(j->unit), job_type_to_string(j->type),
-                          unit_id(j->unit), job_type_to_string(JOB_START));
+                          j->unit->meta.id, job_type_to_string(j->type),
+                          j->unit->meta.id, job_type_to_string(JOB_START));
 
                 j->state = JOB_RUNNING;
                 j->type = JOB_START;
@@ -446,26 +485,26 @@ int job_finish_and_invalidate(Job *j, bool success) {
 
                         SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
                                 if (other->meta.job &&
-                                    (other->meta.type == JOB_START ||
-                                     other->meta.type == JOB_VERIFY_ACTIVE ||
-                                     other->meta.type == JOB_RELOAD_OR_START))
+                                    (other->meta.job->type == JOB_START ||
+                                     other->meta.job->type == JOB_VERIFY_ACTIVE ||
+                                     other->meta.job->type == JOB_RELOAD_OR_START))
                                         job_finish_and_invalidate(other->meta.job, false);
 
-                        SET_FOREACH(other, u->meta.dependencies[UNIT_SOFT_REQUIRED_BY], i)
+                        SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
                                 if (other->meta.job &&
-                                    !other->meta.job->forced &&
-                                    (other->meta.type == JOB_START ||
-                                     other->meta.type == JOB_VERIFY_ACTIVE ||
-                                     other->meta.type == JOB_RELOAD_OR_START))
+                                    !other->meta.job->override &&
+                                    (other->meta.job->type == JOB_START ||
+                                     other->meta.job->type == JOB_VERIFY_ACTIVE ||
+                                     other->meta.job->type == JOB_RELOAD_OR_START))
                                         job_finish_and_invalidate(other->meta.job, false);
 
                 } else if (t == JOB_STOP) {
 
                         SET_FOREACH(other, u->meta.dependencies[UNIT_CONFLICTS], i)
                                 if (other->meta.job &&
-                                    (t == JOB_START ||
-                                     t == JOB_VERIFY_ACTIVE ||
-                                     t == JOB_RELOAD_OR_START))
+                                    (other->meta.job->type == JOB_START ||
+                                     other->meta.job->type == JOB_VERIFY_ACTIVE ||
+                                     other->meta.job->type == JOB_RELOAD_OR_START))
                                         job_finish_and_invalidate(other->meta.job, false);
                 }
         }