X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=job.c;h=6e04683fdd8bb7f1f501aee4de0261fda572686c;hb=3a0ecb08f4b3bfa84ff3d04bc7816730df35139e;hp=ff30864e438fd2a3e666babcc7057aae94c6a8a2;hpb=87f0e418cf2c58b3201d06a60e3696ec672d2662;p=elogind.git
diff --git a/job.c b/job.c
index ff30864e4..6e04683fd 100644
--- a/job.c
+++ b/job.c
@@ -1,10 +1,34 @@
/*-*- Mode: C; c-basic-offset: 8 -*-*/
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with systemd; If not, see .
+***/
+
#include
#include
+#include "set.h"
+#include "unit.h"
#include "macro.h"
-#include "job.h"
+#include "strv.h"
+#include "load-fragment.h"
+#include "load-dropin.h"
+#include "log.h"
Job* job_new(Manager *m, JobType type, Unit *unit) {
Job *j;
@@ -31,6 +55,8 @@ void job_free(Job *j) {
/* Detach from next 'bigger' objects */
if (j->installed) {
+ bus_job_send_removed_signal(j);
+
if (j->unit->meta.job == j)
j->unit->meta.job = NULL;
@@ -39,7 +65,13 @@ 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);
+
+ if (j->in_dbus_queue)
+ LIST_REMOVE(Job, dbus_queue, j->manager->dbus_job_queue, j);
free(j);
}
@@ -108,30 +140,8 @@ void job_dependency_delete(Job *subject, Job *object, bool *matters) {
job_dependency_free(l);
}
-const char* job_type_to_string(JobType t) {
-
- static const char* const job_type_table[_JOB_TYPE_MAX] = {
- [JOB_START] = "start",
- [JOB_VERIFY_ACTIVE] = "verify-active",
- [JOB_STOP] = "stop",
- [JOB_RELOAD] = "reload",
- [JOB_RELOAD_OR_START] = "reload-or-start",
- [JOB_RESTART] = "restart",
- [JOB_TRY_RESTART] = "try-restart",
- };
-
- if (t < 0 || t >= _JOB_TYPE_MAX)
- return "n/a";
-
- return job_type_table[t];
-}
-
void job_dump(Job *j, FILE*f, const char *prefix) {
- static const char* const job_state_table[_JOB_STATE_MAX] = {
- [JOB_WAITING] = "waiting",
- [JOB_RUNNING] = "running"
- };
assert(j);
assert(f);
@@ -143,7 +153,7 @@ void job_dump(Job *j, FILE*f, const char *prefix) {
"%s\tForced: %s\n",
prefix, j->id,
prefix, unit_id(j->unit), job_type_to_string(j->type),
- prefix, job_state_table[j->state],
+ prefix, job_state_to_string(j->state),
prefix, yes_no(j->forced));
}
@@ -255,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;
@@ -324,6 +373,7 @@ int job_run_and_invalidate(Job *j) {
return -EAGAIN;
j->state = JOB_RUNNING;
+ job_add_to_dbus_queue(j);
switch (j->type) {
@@ -399,17 +449,26 @@ 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));
+ 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->state = JOB_RUNNING;
j->type = JOB_START;
- job_schedule_run(j);
+
+ job_add_to_run_queue(j);
return 0;
}
@@ -453,15 +512,15 @@ int job_finish_and_invalidate(Job *j, bool success) {
/* Try to start the next jobs that can be started */
SET_FOREACH(other, u->meta.dependencies[UNIT_AFTER], i)
if (other->meta.job)
- job_schedule_run(other->meta.job);
+ job_add_to_run_queue(other->meta.job);
SET_FOREACH(other, u->meta.dependencies[UNIT_BEFORE], i)
if (other->meta.job)
- job_schedule_run(other->meta.job);
+ job_add_to_run_queue(other->meta.job);
return 0;
}
-void job_schedule_run(Job *j) {
+void job_add_to_run_queue(Job *j) {
assert(j);
assert(j->installed);
@@ -471,3 +530,51 @@ void job_schedule_run(Job *j) {
LIST_PREPEND(Job, run_queue, j->manager->run_queue, j);
j->in_run_queue = true;
}
+
+void job_add_to_dbus_queue(Job *j) {
+ assert(j);
+ assert(j->installed);
+
+ if (j->in_dbus_queue)
+ return;
+
+ LIST_PREPEND(Job, dbus_queue, j->manager->dbus_job_queue, j);
+ j->in_dbus_queue = true;
+}
+
+char *job_dbus_path(Job *j) {
+ char *p;
+
+ assert(j);
+
+ if (asprintf(&p, "/org/freedesktop/systemd1/job/%lu", (unsigned long) j->id) < 0)
+ return NULL;
+
+ return p;
+}
+
+static const char* const job_state_table[_JOB_STATE_MAX] = {
+ [JOB_WAITING] = "waiting",
+ [JOB_RUNNING] = "running"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(job_state, JobState);
+
+static const char* const job_type_table[_JOB_TYPE_MAX] = {
+ [JOB_START] = "start",
+ [JOB_VERIFY_ACTIVE] = "verify-active",
+ [JOB_STOP] = "stop",
+ [JOB_RELOAD] = "reload",
+ [JOB_RELOAD_OR_START] = "reload-or-start",
+ [JOB_RESTART] = "restart",
+ [JOB_TRY_RESTART] = "try-restart",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(job_type, JobType);
+
+static const char* const job_mode_table[_JOB_MODE_MAX] = {
+ [JOB_FAIL] = "fail",
+ [JOB_REPLACE] = "replace"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(job_mode, JobMode);