job.c revision 1ffba6fe82d65f2a87b53a21c7927bca8176038c
/*-*- Mode: C; c-basic-offset: 8 -*-*/
#include <assert.h>
#include <errno.h>
#include "macro.h"
#include "job.h"
Job *j;
assert(m);
return NULL;
j->manager = m;
j->id = m->current_job_id++;
/* We don't link it here, that's what job_dependency() is for */
return j;
}
assert(j);
/* Detach from next 'bigger' objects */
if (j->linked) {
}
free(j);
}
JobDependency *l;
/* Adds a new job link, which encodes that the 'subject' job
* needs the 'object' job in some way. If 'subject' is NULL
* this means the 'anchor' job (i.e. the one the user
* explcitily asked for) is the requester. */
return NULL;
if (subject) {
subject->subject_list = l;
} else {
}
if (l->subject_next)
l->subject_next->subject_prev = l;
l->subject_prev = NULL;
l->object_next->object_prev = l;
l->object_prev = NULL;
object->object_list = l;
return l;
}
void job_dependency_free(JobDependency *l) {
assert(l);
if (l->subject_prev)
else if (l->subject)
else
if (l->subject_next)
if (l->object_prev)
else
if (l->object_next)
free(l);
}
JobDependency *l;
break;
}
if (!l) {
if (matters)
*matters = false;
return;
}
if (matters)
}
const char* job_type_to_string(JobType t) {
static const char* const job_type_table[_JOB_TYPE_MAX] = {
[JOB_START] = "start",
[JOB_STOP] = "stop",
[JOB_VERIFY_STARTED] = "verify-started",
[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];
}
static const char* const job_state_table[_JOB_STATE_MAX] = {
[JOB_WAITING] = "waiting",
[JOB_RUNNING] = "running",
[JOB_DONE] = "done"
};
assert(j);
assert(f);
fprintf(f,
"%sJob %u:\n"
"%s\tAction: %s → %s\n"
"%s\tState: %s\n",
}
bool job_is_anchor(Job *j) {
JobDependency *l;
assert(j);
for (l = j->object_list; l; l = l->object_next)
if (!l->subject)
return true;
return false;
}
return
(a == c && b == d) ||
(a == d && b == c);
}
if (*a == b)
return 0;
/* Merging is associative! a merged with b merged with c is
* the same as a merged with c merged with b. */
/* Mergeability is transitive! if a can be merged with b and b
* with c then a also with c */
/* Also, if a merged with b cannot be merged with c, then
* either a or b cannot be merged with c either */
*a = JOB_START;
*a = JOB_RELOAD_OR_START;
*a = JOB_RESTART;
*a = JOB_RELOAD;
*a = JOB_TRY_RESTART;
else
return -EEXIST;
return 0;
}
return job_type_merge(&a, b) >= 0;
}
/* Checks whether operation a is a "superset" of b */
if (a == b)
return true;
switch (a) {
case JOB_START:
return b == JOB_VERIFY_STARTED;
case JOB_RELOAD:
return b == JOB_VERIFY_STARTED;
case JOB_RELOAD_OR_START:
return
b == JOB_RELOAD ||
b == JOB_START;
case JOB_RESTART:
return
b == JOB_START ||
b == JOB_VERIFY_STARTED ||
b == JOB_RELOAD ||
b == JOB_RELOAD_OR_START ||
b == JOB_TRY_RESTART;
case JOB_TRY_RESTART:
return
b == JOB_VERIFY_STARTED ||
b == JOB_RELOAD;
default:
return false;
}
}