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
LIBS=-lrt -lcap
COMMON= \
name.o \
unit.o \
util.o \
set.o \
hashmap.o \
......
......@@ -2,43 +2,43 @@
#include <errno.h>
#include "name.h"
#include "unit.h"
#include "automount.h"
#include "load-fragment.h"
#include "load-fstab.h"
#include "load-dropin.h"
static int automount_init(Name *n) {
static int automount_init(Unit *u) {
int r;
Automount *a = AUTOMOUNT(n);
Automount *a = AUTOMOUNT(u);
assert(a);
exec_context_init(&a->exec_context);
/* Load a .automount file */
if ((r = name_load_fragment(n)) < 0 && errno != -ENOENT)
if ((r = unit_load_fragment(u)) < 0 && errno != -ENOENT)
return r;
/* Load entry from /etc/fstab */
if ((r = name_load_fstab(n)) < 0)
if ((r = unit_load_fstab(u)) < 0)
return r;
/* Load drop-in directory data */
if ((r = name_load_dropin(n)) < 0)
if ((r = unit_load_dropin(u)) < 0)
return r;
return 0;
}
static void automount_done(Name *n) {
Automount *d = AUTOMOUNT(n);
static void automount_done(Unit *u) {
Automount *d = AUTOMOUNT(u);
assert(d);
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] = {
[AUTOMOUNT_DEAD] = "dead",
......@@ -59,7 +59,7 @@ static void automount_dump(Name *n, FILE *f, const char *prefix) {
};
AutomountExecCommand c;
Automount *s = AUTOMOUNT(n);
Automount *s = AUTOMOUNT(u);
assert(s);
......@@ -79,23 +79,23 @@ static void automount_dump(Name *n, FILE *f, const char *prefix) {
}
}
static NameActiveState automount_active_state(Name *n) {
static const NameActiveState table[_AUTOMOUNT_STATE_MAX] = {
[AUTOMOUNT_DEAD] = NAME_INACTIVE,
[AUTOMOUNT_START_PRE] = NAME_ACTIVATING,
[AUTOMOUNT_START_POST] = NAME_ACTIVATING,
[AUTOMOUNT_WAITING] = NAME_ACTIVE,
[AUTOMOUNT_RUNNING] = NAME_ACTIVE,
[AUTOMOUNT_STOP_PRE] = NAME_DEACTIVATING,
[AUTOMOUNT_STOP_POST] = NAME_DEACTIVATING,
[AUTOMOUNT_MAINTAINANCE] = NAME_INACTIVE,
static UnitActiveState automount_active_state(Unit *u) {
static const UnitActiveState table[_AUTOMOUNT_STATE_MAX] = {
[AUTOMOUNT_DEAD] = UNIT_INACTIVE,
[AUTOMOUNT_START_PRE] = UNIT_ACTIVATING,
[AUTOMOUNT_START_POST] = UNIT_ACTIVATING,
[AUTOMOUNT_WAITING] = UNIT_ACTIVE,
[AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
[AUTOMOUNT_STOP_PRE] = UNIT_DEACTIVATING,
[AUTOMOUNT_STOP_POST] = UNIT_DEACTIVATING,
[AUTOMOUNT_MAINTAINANCE] = UNIT_INACTIVE,
};
return table[AUTOMOUNT(n)->state];
return table[AUTOMOUNT(u)->state];
}
const NameVTable automount_vtable = {
const UnitVTable automount_vtable = {
.suffix = ".mount",
.init = automount_init,
......
......@@ -5,7 +5,7 @@
typedef struct Automount Automount;
#include "name.h"
#include "unit.h"
typedef enum AutomountState {
AUTOMOUNT_DEAD,
......@@ -41,6 +41,6 @@ struct Automount {
Mount *mount;
};
extern const NameVTable automount_vtable;
extern const UnitVTable automount_vtable;
#endif
......@@ -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);
return r;
}
......@@ -162,19 +162,20 @@ static int parse_line(const char *filename, unsigned line, char **section, const
}
/* 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;
char *section = NULL;
FILE *f;
int r;
assert(filename);
assert(t);
if (!(f = fopen(filename, "re"))) {
r = -errno;
log_error("Failed to open configuration file '%s': %s", filename, strerror(-r));
goto finish;
if (!f) {
if (!(f = fopen(filename, "re"))) {
r = -errno;
log_error("Failed to open configuration file '%s': %s", filename, strerror(-r));
goto finish;
}
}
while (!feof(f)) {
......
......@@ -21,7 +21,7 @@ typedef struct ConfigItem {
/* The configuration file parsing routine. Expects a table of
* config_items in *t that is terminated by an item where lvalue is
* 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 */
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 -*-*/
#include "name.h"
#include "unit.h"
#include "device.h"
#include "strv.h"
static void device_done(Name *n) {
Device *d = DEVICE(n);
static void device_done(Unit *u) {
Device *d = DEVICE(u);
assert(d);
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] = {
[DEVICE_DEAD] = "dead",
[DEVICE_AVAILABLE] = "available"
};
Device *s = DEVICE(n);
Device *s = DEVICE(u);
assert(s);
......@@ -27,14 +27,14 @@ static void device_dump(Name *n, FILE *f, const char *prefix) {
prefix, state_table[s->state]);
}
static NameActiveState device_active_state(Name *n) {
return DEVICE(n)->state == DEVICE_DEAD ? NAME_INACTIVE : NAME_ACTIVE;
static UnitActiveState device_active_state(Unit *u) {
return DEVICE(u)->state == DEVICE_DEAD ? UNIT_INACTIVE : UNIT_ACTIVE;
}
const NameVTable device_vtable = {
const UnitVTable device_vtable = {
.suffix = ".device",
.init = name_load_fragment_and_dropin,
.init = unit_load_fragment_and_dropin,
.done = device_done,
.dump = device_dump,
......
......@@ -5,7 +5,7 @@
typedef struct Device Device;
#include "name.h"
#include "unit.h"
/* We simply watch devices, we cannot plug/unplug them. That
* simplifies the state engine greatly */
......@@ -24,6 +24,6 @@ struct Device {
char **sysfs;
};
extern const NameVTable device_vtable;
extern const UnitVTable device_vtable;
#endif
......@@ -3,9 +3,9 @@
- 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
......@@ -37,6 +37,6 @@
- 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
......@@ -6,12 +6,12 @@
#include "macro.h"
#include "job.h"
Job* job_new(Manager *m, JobType type, Name *name) {
Job* job_new(Manager *m, JobType type, Unit *unit) {
Job *j;
assert(m);
assert(type < _JOB_TYPE_MAX);
assert(name);
assert(unit);
if (!(j = new0(Job, 1)))
return NULL;
......@@ -19,7 +19,7 @@ Job* job_new(Manager *m, JobType type, Name *name) {
j->manager = m;
j->id = m->current_job_id++;
j->type = type;
j->name = name;
j->unit = unit;
/* We don't link it here, that's what job_dependency() is for */
......@@ -31,8 +31,8 @@ void job_free(Job *j) {
/* Detach from next 'bigger' objects */
if (j->installed) {
if (j->name->meta.job == j)
j->name->meta.job = NULL;
if (j->unit->meta.job == j)
j->unit->meta.job = NULL;
hashmap_remove(j->manager->jobs, UINT32_TO_PTR(j->id));
j->installed = false;
......@@ -142,7 +142,7 @@ void job_dump(Job *j, FILE*f, const char *prefix) {
"%s\tState: %s\n"
"%s\tForced: %s\n",
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, yes_no(j->forced));
}
......@@ -257,12 +257,12 @@ bool job_type_is_conflicting(JobType a, JobType b) {
bool job_is_runnable(Job *j) {
Iterator i;
Name *other;
Unit *other;
assert(j);
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 type) or before (in the case of a 'negative' job type
* . */
......@@ -277,7 +277,7 @@ bool job_is_runnable(Job *j) {
* dependencies, regardless whether they are
* 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)
return false;
}
......@@ -285,7 +285,7 @@ bool job_is_runnable(Job *j) {
/* Also, if something else is being stopped and we should
* 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 &&
(other->meta.job->type == JOB_STOP ||
other->meta.job->type == JOB_RESTART ||
......@@ -328,16 +328,16 @@ int job_run_and_invalidate(Job *j) {
switch (j->type) {
case JOB_START:
r = name_start(j->name);
r = unit_start(j->unit);
if (r == -EBADR)
r = 0;
break;
case JOB_VERIFY_ACTIVE: {
NameActiveState t = name_active_state(j->name);
if (NAME_IS_ACTIVE_OR_RELOADING(t))
UnitActiveState t = unit_active_state(j->unit);
if (UNIT_IS_ACTIVE_OR_RELOADING(t))
r = -EALREADY;
else if (t == NAME_ACTIVATING)
else if (t == UNIT_ACTIVATING)
r = -EAGAIN;
else
r = -ENOEXEC;
......@@ -345,39 +345,39 @@ int job_run_and_invalidate(Job *j) {
}
case JOB_STOP:
r = name_stop(j->name);
r = unit_stop(j->unit);
break;
case JOB_RELOAD:
r = name_reload(j->name);
r = unit_reload(j->unit);
break;
case JOB_RELOAD_OR_START:
if (name_active_state(j->name) == NAME_ACTIVE)
r = name_reload(j->name);
if (unit_active_state(j->unit) == UNIT_ACTIVE)
r = unit_reload(j->unit);
else
r = name_start(j->name);
r = unit_start(j->unit);
break;
case JOB_RESTART: {
NameActiveState t = name_active_state(j->name);
if (t == NAME_INACTIVE || t == NAME_ACTIVATING) {
UnitActiveState t = unit_active_state(j->unit);
if (t == UNIT_INACTIVE || t == UNIT_ACTIVATING) {
j->type = JOB_START;
r = name_start(j->name);
r = unit_start(j->unit);
} else
r = name_stop(j->name);
r = unit_stop(j->unit);
break;
}
case JOB_TRY_RESTART: {
NameActiveState t = name_active_state(j->name);
if (t == NAME_INACTIVE || t == NAME_DEACTIVATING)
UnitActiveState t = unit_active_state(j->unit);
if (t == UNIT_INACTIVE || t == UNIT_DEACTIVATING)
r = -ENOEXEC;
else if (t == NAME_ACTIVATING) {
else if (t == UNIT_ACTIVATING) {
j->type = JOB_START;
r = name_start(j->name);
r = unit_start(j->unit);
} else
r = name_stop(j->name);
r = unit_stop(j->unit);
break;
}
......@@ -397,9 +397,9 @@ int job_run_and_invalidate(Job *j) {
}
int job_finish_and_invalidate(Job *j, bool success) {
Name *n;
Name *other;
NameType t;
Unit *u;
Unit *other;
UnitType t;
Iterator i;
assert(j);
......@@ -413,7 +413,7 @@ int job_finish_and_invalidate(Job *j, bool success) {
return 0;
}
n = j->name;
u = j->unit;
t = j->type;
job_free(j);
......@@ -424,14 +424,14 @@ int job_finish_and_invalidate(Job *j, bool success) {
t == JOB_VERIFY_ACTIVE ||
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 &&
(other->meta.type == JOB_START ||
other->meta.type == JOB_VERIFY_ACTIVE ||
other->meta.type == JOB_RELOAD_OR_START))
job_finish_and_invalidate(other->meta.job, false);
SET_FOREACH(other, n->meta.dependencies[NAME_SOFT_REQUIRED_BY], i)
SET_FOREACH(other, u->meta.dependencies[UNIT_SOFT_REQUIRED_BY], i)
if (other->meta.job &&
!other->meta.job->forced &&
(other->meta.type == JOB_START ||
......@@ -441,7 +441,7 @@ int job_finish_and_invalidate(Job *j, bool success) {
} else if (t == JOB_STOP) {
SET_FOREACH(other, n->meta.dependencies[NAME_CONFLICTS], i)
SET_FOREACH(other, u->meta.dependencies[UNIT_CONFLICTS], i)
if (other->meta.job &&
(t == JOB_START ||
t == JOB_VERIFY_ACTIVE ||
......@@ -451,10 +451,10 @@ int job_finish_and_invalidate(Job *j, bool success) {
}
/* Try to start the next jobs that can be started */
SET_FOREACH(other, n->meta.dependencies[NAME_AFTER], i)
SET_FOREACH(other, u->meta.dependencies[UNIT_AFTER], i)
if (other->meta.job)
job_schedule_run(other->meta.job);
SET_FOREACH(other, n->meta.dependencies[NAME_BEFORE], i)
SET_FOREACH(other, u->meta.dependencies[UNIT_BEFORE], i)
if (other->meta.job)
job_schedule_run(other->meta.job);
......
......@@ -13,12 +13,12 @@ typedef enum JobState JobState;
typedef enum JobMode JobMode;
#include "manager.h"
#include "name.h"
#include "unit.h"
#include "hashmap.h"
#include "list.h"
enum JobType {
JOB_START, /* if a name does not support being started, we'll just wait until it becomes active */
JOB_START, /* if a unit does not support being started, we'll just wait until it becomes active */
JOB_VERIFY_ACTIVE,
JOB_STOP,
......@@ -64,7 +64,7 @@ struct Job {
Manager *manager;
uint32_t id;
Name *name;
Unit *unit;
JobType type;
JobState state;
......@@ -86,7 +86,7 @@ struct Job {
};
Job* job_new(Manager *m, JobType type, Name *name);
Job* job_new(Manager *m, JobType type, Unit *unit);
void job_free(Job *job);
void job_dump(Job *j, FILE*f, const char *prefix);
......
......@@ -2,8 +2,8 @@
#include "load-dropin.h"
int name_load_dropin(Name *n) {
assert(n);
int unit_load_dropin(Unit *u) {
assert(u);
/* Load dependencies from supplementary drop-in directories */
......
......@@ -3,10 +3,10 @@
#ifndef fooloaddropinhfoo
#define fooloaddropinhfoo
#include "name.h"
#include "unit.h"
/* Read service data supplementary drop-in directories */
int name_load_dropin(Name *n);
int unit_load_dropin(Unit *u);
#endif
/*-*- Mode: C; c-basic-offset: 8 -*-*/
#include <linux/oom.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <linux/oom.h>
#include <unistd.h>
#include <fcntl.h>
#include "name.h"
#include "unit.h"
#include "strv.h"
#include "conf-parser.h"
#include "load-fragment.h"
......@@ -20,8 +22,8 @@ static int config_parse_deps(
void *data,
void *userdata) {
NameDependency d = PTR_TO_UINT(data);
Name *name = userdata;
UnitDependency d = PTR_TO_UINT(data);
Unit *u = userdata;
char *w;
size_t l;
char *state;
......@@ -33,18 +35,18 @@ static int config_parse_deps(
FOREACH_WORD(w, &l, rvalue, state) {
char *t;
int r;
Name *other;
Unit *other;
if (!(t = strndup(w, l)))
return -ENOMEM;
r = manager_load_name(name->meta.manager, t, &other);
r = manager_load_unit(u->meta.manager, t, &other);
free(t);
if (r < 0)
return r;
if ((r = name_add_dependency(name, d, other)) < 0)
if ((r = unit_add_dependency(u, d, other)) < 0)
return r;
}
......@@ -60,8 +62,7 @@ static int config_parse_names(
void *data,
void *userdata) {
Set **set = data;
Name *name = userdata;
Unit *u = userdata;
char *w;
size_t l;
char *state;
......@@ -74,42 +75,33 @@ static int config_parse_names(
FOREACH_WORD(w, &l, rvalue, state) {
char *t;
int r;
Name *other;
Unit *other;
if (!(t = strndup(w, l)))
return -ENOMEM;
other = manager_get_name(name->meta.manager, t);
other = manager_get_unit(u->meta.manager, t);
if (other) {
if (other != name) {
if (other != u) {
if (other->meta.load_state != NAME_STUB) {
if (other->meta.load_state != UNIT_STUB) {
free(t);
return -EEXIST;
}
if ((r = name_merge(name, other)) < 0) {
if ((r = unit_merge(u, other)) < 0) {
free(t);
return r;
}
}
} else {
if (!*set)
if (!(*set = set_new(trivial_hash_func, trivial_compare_func))) {
free(t);
return -ENOMEM;
}
if ((r = set_put(*set, t)) < 0) {
if ((r = unit_add_name(u, t)) < 0) {