Commit 87f0e418 authored by Lennart Poettering's avatar Lennart Poettering
Browse files

s/name/unit

parent fd79db6a
...@@ -2,7 +2,7 @@ CFLAGS=-Wall -Wextra -O0 -g -pipe -D_GNU_SOURCE -fdiagnostics-show-option -Wno-u ...@@ -2,7 +2,7 @@ CFLAGS=-Wall -Wextra -O0 -g -pipe -D_GNU_SOURCE -fdiagnostics-show-option -Wno-u
LIBS=-lrt -lcap LIBS=-lrt -lcap
COMMON= \ COMMON= \
name.o \ unit.o \
util.o \ util.o \
set.o \ set.o \
hashmap.o \ hashmap.o \
......
...@@ -2,43 +2,43 @@ ...@@ -2,43 +2,43 @@
#include <errno.h> #include <errno.h>
#include "name.h" #include "unit.h"
#include "automount.h" #include "automount.h"
#include "load-fragment.h" #include "load-fragment.h"
#include "load-fstab.h" #include "load-fstab.h"
#include "load-dropin.h" #include "load-dropin.h"
static int automount_init(Name *n) { static int automount_init(Unit *u) {
int r; int r;
Automount *a = AUTOMOUNT(n); Automount *a = AUTOMOUNT(u);
assert(a); assert(a);
exec_context_init(&a->exec_context); exec_context_init(&a->exec_context);
/* Load a .automount file */ /* Load a .automount file */
if ((r = name_load_fragment(n)) < 0 && errno != -ENOENT) if ((r = unit_load_fragment(u)) < 0 && errno != -ENOENT)
return r; return r;
/* Load entry from /etc/fstab */ /* Load entry from /etc/fstab */
if ((r = name_load_fstab(n)) < 0) if ((r = unit_load_fstab(u)) < 0)
return r; return r;
/* Load drop-in directory data */ /* Load drop-in directory data */
if ((r = name_load_dropin(n)) < 0) if ((r = unit_load_dropin(u)) < 0)
return r; return r;
return 0; return 0;
} }
static void automount_done(Name *n) { static void automount_done(Unit *u) {
Automount *d = AUTOMOUNT(n); Automount *d = AUTOMOUNT(u);
assert(d); assert(d);
free(d->path); free(d->path);
} }
static void automount_dump(Name *n, FILE *f, const char *prefix) { static void automount_dump(Unit *u, FILE *f, const char *prefix) {
static const char* const state_table[_AUTOMOUNT_STATE_MAX] = { static const char* const state_table[_AUTOMOUNT_STATE_MAX] = {
[AUTOMOUNT_DEAD] = "dead", [AUTOMOUNT_DEAD] = "dead",
...@@ -59,7 +59,7 @@ static void automount_dump(Name *n, FILE *f, const char *prefix) { ...@@ -59,7 +59,7 @@ static void automount_dump(Name *n, FILE *f, const char *prefix) {
}; };
AutomountExecCommand c; AutomountExecCommand c;
Automount *s = AUTOMOUNT(n); Automount *s = AUTOMOUNT(u);
assert(s); assert(s);
...@@ -79,23 +79,23 @@ static void automount_dump(Name *n, FILE *f, const char *prefix) { ...@@ -79,23 +79,23 @@ static void automount_dump(Name *n, FILE *f, const char *prefix) {
} }
} }
static NameActiveState automount_active_state(Name *n) { static UnitActiveState automount_active_state(Unit *u) {
static const NameActiveState table[_AUTOMOUNT_STATE_MAX] = { static const UnitActiveState table[_AUTOMOUNT_STATE_MAX] = {
[AUTOMOUNT_DEAD] = NAME_INACTIVE, [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
[AUTOMOUNT_START_PRE] = NAME_ACTIVATING, [AUTOMOUNT_START_PRE] = UNIT_ACTIVATING,
[AUTOMOUNT_START_POST] = NAME_ACTIVATING, [AUTOMOUNT_START_POST] = UNIT_ACTIVATING,
[AUTOMOUNT_WAITING] = NAME_ACTIVE, [AUTOMOUNT_WAITING] = UNIT_ACTIVE,
[AUTOMOUNT_RUNNING] = NAME_ACTIVE, [AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
[AUTOMOUNT_STOP_PRE] = NAME_DEACTIVATING, [AUTOMOUNT_STOP_PRE] = UNIT_DEACTIVATING,
[AUTOMOUNT_STOP_POST] = NAME_DEACTIVATING, [AUTOMOUNT_STOP_POST] = UNIT_DEACTIVATING,
[AUTOMOUNT_MAINTAINANCE] = NAME_INACTIVE, [AUTOMOUNT_MAINTAINANCE] = UNIT_INACTIVE,
}; };
return table[AUTOMOUNT(n)->state]; return table[AUTOMOUNT(u)->state];
} }
const NameVTable automount_vtable = { const UnitVTable automount_vtable = {
.suffix = ".mount", .suffix = ".mount",
.init = automount_init, .init = automount_init,
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
typedef struct Automount Automount; typedef struct Automount Automount;
#include "name.h" #include "unit.h"
typedef enum AutomountState { typedef enum AutomountState {
AUTOMOUNT_DEAD, AUTOMOUNT_DEAD,
...@@ -41,6 +41,6 @@ struct Automount { ...@@ -41,6 +41,6 @@ struct Automount {
Mount *mount; Mount *mount;
}; };
extern const NameVTable automount_vtable; extern const UnitVTable automount_vtable;
#endif #endif
...@@ -109,7 +109,7 @@ static int parse_line(const char *filename, unsigned line, char **section, const ...@@ -109,7 +109,7 @@ static int parse_line(const char *filename, unsigned line, char **section, const
} }
} }
r = config_parse(fn, sections, t, userdata); r = config_parse(fn, NULL, sections, t, userdata);
free(path); free(path);
return r; return r;
} }
...@@ -162,19 +162,20 @@ static int parse_line(const char *filename, unsigned line, char **section, const ...@@ -162,19 +162,20 @@ static int parse_line(const char *filename, unsigned line, char **section, const
} }
/* Go through the file and parse each line */ /* Go through the file and parse each line */
int config_parse(const char *filename, const char* const * sections, const ConfigItem *t, void *userdata) { int config_parse(const char *filename, FILE *f, const char* const * sections, const ConfigItem *t, void *userdata) {
unsigned line = 0; unsigned line = 0;
char *section = NULL; char *section = NULL;
FILE *f;
int r; int r;
assert(filename); assert(filename);
assert(t); assert(t);
if (!(f = fopen(filename, "re"))) { if (!f) {
r = -errno; if (!(f = fopen(filename, "re"))) {
log_error("Failed to open configuration file '%s': %s", filename, strerror(-r)); r = -errno;
goto finish; log_error("Failed to open configuration file '%s': %s", filename, strerror(-r));
goto finish;
}
} }
while (!feof(f)) { while (!feof(f)) {
......
...@@ -21,7 +21,7 @@ typedef struct ConfigItem { ...@@ -21,7 +21,7 @@ typedef struct ConfigItem {
/* The configuration file parsing routine. Expects a table of /* The configuration file parsing routine. Expects a table of
* config_items in *t that is terminated by an item where lvalue is * config_items in *t that is terminated by an item where lvalue is
* NULL */ * NULL */
int config_parse(const char *filename, const char* const * sections, const ConfigItem *t, void *userdata); int config_parse(const char *filename, FILE *f, const char* const * sections, const ConfigItem *t, void *userdata);
/* Generic parsers */ /* Generic parsers */
int config_parse_int(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); int config_parse_int(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
......
/*-*- Mode: C; c-basic-offset: 8 -*-*/ /*-*- Mode: C; c-basic-offset: 8 -*-*/
#include "name.h" #include "unit.h"
#include "device.h" #include "device.h"
#include "strv.h" #include "strv.h"
static void device_done(Name *n) { static void device_done(Unit *u) {
Device *d = DEVICE(n); Device *d = DEVICE(u);
assert(d); assert(d);
strv_free(d->sysfs); strv_free(d->sysfs);
} }
static void device_dump(Name *n, FILE *f, const char *prefix) { static void device_dump(Unit *u, FILE *f, const char *prefix) {
static const char* const state_table[_DEVICE_STATE_MAX] = { static const char* const state_table[_DEVICE_STATE_MAX] = {
[DEVICE_DEAD] = "dead", [DEVICE_DEAD] = "dead",
[DEVICE_AVAILABLE] = "available" [DEVICE_AVAILABLE] = "available"
}; };
Device *s = DEVICE(n); Device *s = DEVICE(u);
assert(s); assert(s);
...@@ -27,14 +27,14 @@ static void device_dump(Name *n, FILE *f, const char *prefix) { ...@@ -27,14 +27,14 @@ static void device_dump(Name *n, FILE *f, const char *prefix) {
prefix, state_table[s->state]); prefix, state_table[s->state]);
} }
static NameActiveState device_active_state(Name *n) { static UnitActiveState device_active_state(Unit *u) {
return DEVICE(n)->state == DEVICE_DEAD ? NAME_INACTIVE : NAME_ACTIVE; return DEVICE(u)->state == DEVICE_DEAD ? UNIT_INACTIVE : UNIT_ACTIVE;
} }
const NameVTable device_vtable = { const UnitVTable device_vtable = {
.suffix = ".device", .suffix = ".device",
.init = name_load_fragment_and_dropin, .init = unit_load_fragment_and_dropin,
.done = device_done, .done = device_done,
.dump = device_dump, .dump = device_dump,
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
typedef struct Device Device; typedef struct Device Device;
#include "name.h" #include "unit.h"
/* We simply watch devices, we cannot plug/unplug them. That /* We simply watch devices, we cannot plug/unplug them. That
* simplifies the state engine greatly */ * simplifies the state engine greatly */
...@@ -24,6 +24,6 @@ struct Device { ...@@ -24,6 +24,6 @@ struct Device {
char **sysfs; char **sysfs;
}; };
extern const NameVTable device_vtable; extern const UnitVTable device_vtable;
#endif #endif
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
- need gc for active jobs that nothing cares for - need gc for active jobs that nothing cares for
- need gc for names that are not referenced anymore - need gc for units that are not referenced anymore
- refreshing of names (i.e. reload config files) - refreshing of units (i.e. reload config files)
- dbusification - dbusification
...@@ -37,6 +37,6 @@ ...@@ -37,6 +37,6 @@
- templating/instances - templating/instances
- verify fragment data after loading: refuse cycles on yourself, service names contradicting, more than one Start executable, ... - verify fragment data after loading: refuse cycles on yourself, service units contradicting, more than one Start executable, ...
- rate limit startups - rate limit startups
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
#include "macro.h" #include "macro.h"
#include "job.h" #include "job.h"
Job* job_new(Manager *m, JobType type, Name *name) { Job* job_new(Manager *m, JobType type, Unit *unit) {
Job *j; Job *j;
assert(m); assert(m);
assert(type < _JOB_TYPE_MAX); assert(type < _JOB_TYPE_MAX);
assert(name); assert(unit);
if (!(j = new0(Job, 1))) if (!(j = new0(Job, 1)))
return NULL; return NULL;
...@@ -19,7 +19,7 @@ Job* job_new(Manager *m, JobType type, Name *name) { ...@@ -19,7 +19,7 @@ Job* job_new(Manager *m, JobType type, Name *name) {
j->manager = m; j->manager = m;
j->id = m->current_job_id++; j->id = m->current_job_id++;
j->type = type; j->type = type;
j->name = name; j->unit = unit;
/* We don't link it here, that's what job_dependency() is for */ /* We don't link it here, that's what job_dependency() is for */
...@@ -31,8 +31,8 @@ void job_free(Job *j) { ...@@ -31,8 +31,8 @@ void job_free(Job *j) {
/* Detach from next 'bigger' objects */ /* Detach from next 'bigger' objects */
if (j->installed) { if (j->installed) {
if (j->name->meta.job == j) if (j->unit->meta.job == j)
j->name->meta.job = NULL; j->unit->meta.job = NULL;
hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id)); hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id));
j->installed = false; j->installed = false;
...@@ -142,7 +142,7 @@ void job_dump(Job *j, FILE*f, const char *prefix) { ...@@ -142,7 +142,7 @@ void job_dump(Job *j, FILE*f, const char *prefix) {
"%s\tState: %s\n" "%s\tState: %s\n"
"%s\tForced: %s\n", "%s\tForced: %s\n",
prefix, j->id, prefix, j->id,
prefix, name_id(j->name), job_type_to_string(j->type), prefix, unit_id(j->unit), job_type_to_string(j->type),
prefix, job_state_table[j->state], prefix, job_state_table[j->state],
prefix, yes_no(j->forced)); prefix, yes_no(j->forced));
} }
...@@ -257,12 +257,12 @@ bool job_type_is_conflicting(JobType a, JobType b) { ...@@ -257,12 +257,12 @@ bool job_type_is_conflicting(JobType a, JobType b) {
bool job_is_runnable(Job *j) { bool job_is_runnable(Job *j) {
Iterator i; Iterator i;
Name *other; Unit *other;
assert(j); assert(j);
assert(j->installed); assert(j->installed);
/* Checks whether there is any job running for the names this /* Checks whether there is any job running for the units this
* job needs to be running after (in the case of a 'positive' * job needs to be running after (in the case of a 'positive'
* job type) or before (in the case of a 'negative' job type * job type) or before (in the case of a 'negative' job type
* . */ * . */
...@@ -277,7 +277,7 @@ bool job_is_runnable(Job *j) { ...@@ -277,7 +277,7 @@ bool job_is_runnable(Job *j) {
* dependencies, regardless whether they are * dependencies, regardless whether they are
* starting or stopping something. */ * starting or stopping something. */
SET_FOREACH(other, j->name->meta.dependencies[NAME_AFTER], i) SET_FOREACH(other, j->unit->meta.dependencies[UNIT_AFTER], i)
if (other->meta.job) if (other->meta.job)
return false; return false;
} }
...@@ -285,7 +285,7 @@ bool job_is_runnable(Job *j) { ...@@ -285,7 +285,7 @@ bool job_is_runnable(Job *j) {
/* Also, if something else is being stopped and we should /* Also, if something else is being stopped and we should
* change state after it, then lets wait. */ * change state after it, then lets wait. */
SET_FOREACH(other, j->name->meta.dependencies[NAME_BEFORE], i) SET_FOREACH(other, j->unit->meta.dependencies[UNIT_BEFORE], i)
if (other->meta.job && if (other->meta.job &&
(other->meta.job->type == JOB_STOP || (other->meta.job->type == JOB_STOP ||
other->meta.job->type == JOB_RESTART || other->meta.job->type == JOB_RESTART ||
...@@ -328,16 +328,16 @@ int job_run_and_invalidate(Job *j) { ...@@ -328,16 +328,16 @@ int job_run_and_invalidate(Job *j) {
switch (j->type) { switch (j->type) {
case JOB_START: case JOB_START:
r = name_start(j->name); r = unit_start(j->unit);
if (r == -EBADR) if (r == -EBADR)
r = 0; r = 0;
break; break;
case JOB_VERIFY_ACTIVE: { case JOB_VERIFY_ACTIVE: {
NameActiveState t = name_active_state(j->name); UnitActiveState t = unit_active_state(j->unit);
if (NAME_IS_ACTIVE_OR_RELOADING(t)) if (UNIT_IS_ACTIVE_OR_RELOADING(t))
r = -EALREADY; r = -EALREADY;
else if (t == NAME_ACTIVATING) else if (t == UNIT_ACTIVATING)
r = -EAGAIN; r = -EAGAIN;
else else
r = -ENOEXEC; r = -ENOEXEC;
...@@ -345,39 +345,39 @@ int job_run_and_invalidate(Job *j) { ...@@ -345,39 +345,39 @@ int job_run_and_invalidate(Job *j) {
} }
case JOB_STOP: case JOB_STOP:
r = name_stop(j->name); r = unit_stop(j->unit);
break; break;
case JOB_RELOAD: case JOB_RELOAD:
r = name_reload(j->name); r = unit_reload(j->unit);
break; break;
case JOB_RELOAD_OR_START: case JOB_RELOAD_OR_START:
if (name_active_state(j->name) == NAME_ACTIVE) if (unit_active_state(j->unit) == UNIT_ACTIVE)
r = name_reload(j->name); r = unit_reload(j->unit);
else else
r = name_start(j->name); r = unit_start(j->unit);
break; break;
case JOB_RESTART: { case JOB_RESTART: {
NameActiveState t = name_active_state(j->name); UnitActiveState t = unit_active_state(j->unit);
if (t == NAME_INACTIVE || t == NAME_ACTIVATING) { if (t == UNIT_INACTIVE || t == UNIT_ACTIVATING) {
j->type = JOB_START; j->type = JOB_START;
r = name_start(j->name); r = unit_start(j->unit);
} else } else
r = name_stop(j->name); r = unit_stop(j->unit);
break; break;
} }
case JOB_TRY_RESTART: { case JOB_TRY_RESTART: {
NameActiveState t = name_active_state(j->name); UnitActiveState t = unit_active_state(j->unit);
if (t == NAME_INACTIVE || t == NAME_DEACTIVATING) if (t == UNIT_INACTIVE || t == UNIT_DEACTIVATING)
r = -ENOEXEC; r = -ENOEXEC;
else if (t == NAME_ACTIVATING) { else if (t == UNIT_ACTIVATING) {
j->type = JOB_START; j->type = JOB_START;
r = name_start(j->name); r = unit_start(j->unit);
} else } else
r = name_stop(j->name); r = unit_stop(j->unit);
break; break;
} }
...@@ -397,9 +397,9 @@ int job_run_and_invalidate(Job *j) { ...@@ -397,9 +397,9 @@ int job_run_and_invalidate(Job *j) {
} }
int job_finish_and_invalidate(Job *j, bool success) { int job_finish_and_invalidate(Job *j, bool success) {
Name *n; Unit *u;
Name *other; Unit *other;
NameType t; UnitType t;
Iterator i; Iterator i;
assert(j); assert(j);
...@@ -413,7 +413,7 @@ int job_finish_and_invalidate(Job *j, bool success) { ...@@ -413,7 +413,7 @@ int job_finish_and_invalidate(Job *j, bool success) {
return 0; return 0;
} }
n = j->name; u = j->unit;
t = j->type; t = j->type;
job_free(j); job_free(j);
...@@ -424,14 +424,14 @@ int job_finish_and_invalidate(Job *j, bool success) { ...@@ -424,14 +424,14 @@ int job_finish_and_invalidate(Job *j, bool success) {
t == JOB_VERIFY_ACTIVE || t == JOB_VERIFY_ACTIVE ||
t == JOB_RELOAD_OR_START) { t == JOB_RELOAD_OR_START) {
SET_FOREACH(other, n->meta.dependencies[NAME_REQUIRED_BY], i) SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
if (other->meta.job && if (other->meta.job &&
(other->meta.type == JOB_START || (other->meta.type == JOB_START ||
other->meta.type == JOB_VERIFY_ACTIVE || other->meta.type == JOB_VERIFY_ACTIVE ||
other->meta.type == JOB_RELOAD_OR_START)) other->meta.type == JOB_RELOAD_OR_START))