1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-05 06:52:22 +03:00
systemd/job.c

74 lines
1.8 KiB
C
Raw Normal View History

2009-11-18 02:42:52 +03:00
/*-*- Mode: C; c-basic-offset: 8 -*-*/
#include <assert.h>
#include "macro.h"
#include "job.h"
Job* job_new(Manager *m, JobType type, Name *name) {
Job *j;
assert(m);
assert(type < _JOB_TYPE_MAX);
assert(name);
if (!(j = new0(Job, 1)))
return NULL;
j->manager = m;
j->id = m->current_job_id++;
j->type = type;
j->name = name;
/* We don't link it here, that's what job_link() is for */
return j;
}
void job_free(Job *j) {
assert(j);
/* Detach from next 'bigger' objects */
if (j->linked) {
2010-01-19 06:15:20 +03:00
if (j->name->meta.job == j)
j->name->meta.job = NULL;
2009-11-18 02:42:52 +03:00
hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id));
}
hashmap_remove(j->manager->jobs_to_add, j->name);
set_remove(j->manager->jobs_to_remove, j);
2009-11-18 02:42:52 +03:00
/* Free data and next 'smaller' objects */
2009-11-18 02:42:52 +03:00
free(j);
}
2010-01-19 02:22:34 +03:00
void job_dump(Job *j, FILE*f) {
static const char* const job_type_table[_JOB_TYPE_MAX] = {
2010-01-19 04:56:37 +03:00
[JOB_START] = "start",
[JOB_STOP] = "stop",
[JOB_VERIFY_STARTED] = "verify-started",
[JOB_RELOAD] = "reload",
[JOB_RESTART] = "restart",
[JOB_TRY_RESTART] = "try-restart",
[JOB_RESTART_FINISH] = "restart-finish"
2010-01-19 02:22:34 +03:00
};
static const char* const job_state_table[_JOB_STATE_MAX] = {
2010-01-19 04:56:37 +03:00
[JOB_WAITING] = "waiting",
[JOB_RUNNING] = "running",
[JOB_DONE] = "done"
2010-01-19 02:22:34 +03:00
};
assert(j);
assert(f);
2010-01-19 06:15:20 +03:00
fprintf(f, "Job %u (%s) → %s in state %s\n",
2010-01-19 02:22:34 +03:00
j->id,
name_id(j->name),
job_type_table[j->type],
job_state_table[j->state]);
}