} while (again);
}
-static int transaction_is_destructive(Manager *m, JobMode mode) {
+static int transaction_is_destructive(Manager *m) {
Iterator i;
Job *j;
} while (again);
}
-static int transaction_apply(Manager *m, JobMode mode) {
+static int transaction_apply(Manager *m) {
Iterator i;
Job *j;
int r;
/* Ninth step: check whether we can actually apply this */
if (mode == JOB_FAIL)
- if ((r = transaction_is_destructive(m, mode)) < 0) {
+ if ((r = transaction_is_destructive(m)) < 0) {
log_debug("Requested transaction contradicts existing jobs: %s", strerror(-r));
goto rollback;
}
/* Tenth step: apply changes */
- if ((r = transaction_apply(m, mode)) < 0) {
+ if ((r = transaction_apply(m)) < 0) {
log_debug("Failed to apply transaction: %s", strerror(-r));
goto rollback;
}
return r;
}
+static int transaction_add_isolate_jobs(Manager *m) {
+ Iterator i;
+ Unit *u;
+ char *k;
+ int r;
+
+ assert(m);
+
+ HASHMAP_FOREACH_KEY(u, k, m->units, i) {
+
+ /* ignore aliases */
+ if (u->meta.id != k)
+ continue;
+
+ if (UNIT_VTABLE(u)->no_isolate)
+ continue;
+
+ /* No need to stop inactive jobs */
+ if (unit_active_state(u) == UNIT_INACTIVE)
+ continue;
+
+ /* Is there already something listed for this? */
+ if (hashmap_get(m->transaction_jobs, u))
+ continue;
+
+ if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, u, NULL, true, false, NULL)) < 0)
+ log_warning("Cannot add isolate job for unit %s, ignoring: %s", u->meta.id, strerror(-r));
+ }
+
+ return 0;
+}
+
int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool override, Job **_ret) {
int r;
Job *ret;
assert(unit);
assert(mode < _JOB_MODE_MAX);
+ if (mode == JOB_ISOLATE && type != JOB_START)
+ return -EINVAL;
+
log_debug("Trying to enqueue job %s/%s", unit->meta.id, job_type_to_string(type));
if ((r = transaction_add_job_and_dependencies(m, type, unit, NULL, true, override, &ret)) < 0) {
return r;
}
+ if (mode == JOB_ISOLATE)
+ if ((r = transaction_add_isolate_jobs(m)) < 0) {
+ transaction_abort(m);
+ return r;
+ }
+
if ((r = transaction_activate(m, mode)) < 0)
return r;
" cancel [JOB...] Cancel one or more jobs\n" +
" start [NAME...] Start on or more units\n" +
" stop [NAME...] Stop on or more units\n" +
+ " enter [NAME] Start one unit and stop all others\n" +
" restart [NAME...] Restart on or more units\n" +
" reload [NAME...] Reload on or more units\n" +
" monitor Monitor unit/job changes\n" +
u.reload(mode);
}
+ } else if (args[1] == "isolate") {
+
+ if (args.length != 3) {
+ stderr.printf("Missing argument.\n");
+ return 1;
+ }
+
+ ObjectPath p = manager.get_unit(args[2]);
+
+ Unit u = bus.get_object(
+ "org.freedesktop.systemd1",
+ p,
+ "org.freedesktop.systemd1.Unit") as Unit;
+
+ u.start("isolate");
+
} else if (args[1] == "monitor") {
manager.subscribe();