#include "exit-status.h"
#include "virt.h"
#include "watchdog.h"
+#include "cgroup-util.h"
/* As soon as 16 units are in our GC queue, make sure to run a gc sweep */
#define GC_QUEUE_ENTRIES_MAX 16
return r;
}
+static void transaction_unlink_job(Manager *m, Job *j, bool delete_dependencies);
+
static void transaction_delete_job(Manager *m, Job *j, bool delete_dependencies) {
assert(m);
assert(j);
/* Deletes one job from the transaction */
- manager_transaction_unlink_job(m, j, delete_dependencies);
+ transaction_unlink_job(m, j, delete_dependencies);
if (!j->installed)
job_free(j);
assert(m);
while ((j = hashmap_first(m->transaction_jobs)))
- if (j->installed)
- transaction_delete_job(m, j, true);
- else
- job_free(j);
+ transaction_delete_job(m, j, true);
assert(hashmap_isempty(m->transaction_jobs));
assert(j->unit == other->unit);
assert(!j->installed);
- /* Merges 'other' into 'j' and then deletes j. */
+ /* Merges 'other' into 'j' and then deletes 'other'. */
j->type = t;
j->state = JOB_WAITING;
other->object_list = NULL;
transaction_delete_job(m, other, true);
}
+
static bool job_is_conflicted_by(Job *j) {
JobDependency *l;
}
while ((j = hashmap_steal_first(m->transaction_jobs))) {
+ Job *uj;
if (j->installed) {
/* log_debug("Skipping already installed job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id); */
continue;
}
- if (j->unit->job)
- job_free(j->unit->job);
+ uj = j->unit->job;
+ if (uj) {
+ job_uninstall(uj);
+ job_free(uj);
+ }
j->unit->job = j;
j->installed = true;
LIST_PREPEND(Job, transaction, f, j);
if (hashmap_replace(m->transaction_jobs, unit, f) < 0) {
+ LIST_REMOVE(Job, transaction, f, j);
job_free(j);
return NULL;
}
return j;
}
-void manager_transaction_unlink_job(Manager *m, Job *j, bool delete_dependencies) {
+static void transaction_unlink_job(Manager *m, Job *j, bool delete_dependencies) {
assert(m);
assert(j);
int manager_loop(Manager *m) {
int r;
- int wait_msec = -1;
RATELIMIT_DEFINE(rl, 1*USEC_PER_SEC, 50000);
if (r < 0)
return r;
- /* Sleep for half the watchdog time */
- if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM) {
- wait_msec = (int) (m->runtime_watchdog / 2 / USEC_PER_MSEC);
- if (wait_msec <= 0)
- wait_msec = 1;
- }
-
while (m->exit_code == MANAGER_RUNNING) {
struct epoll_event event;
int n;
+ int wait_msec = -1;
- if (wait_msec >= 0)
+ if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM)
watchdog_ping();
if (!ratelimit_test(&rl)) {
if (swap_dispatch_reload(m) > 0)
continue;
+ /* Sleep for half the watchdog time */
+ if (m->runtime_watchdog > 0 && m->running_as == MANAGER_SYSTEM) {
+ wait_msec = (int) (m->runtime_watchdog / 2 / USEC_PER_MSEC);
+ if (wait_msec <= 0)
+ wait_msec = 1;
+ } else
+ wait_msec = -1;
+
n = epoll_wait(m->epoll_fd, &event, 1, wait_msec);
if (n < 0) {
assert(m);
- if (!(l = strv_copy(controllers)))
+ l = strv_copy(controllers);
+ if (!l)
return -ENOMEM;
strv_free(m->default_controllers);
m->default_controllers = l;
+ cg_shorten_controllers(m->default_controllers);
+
return 0;
}