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

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
This diff is collapsed.
......@@ -3,10 +3,10 @@
#ifndef fooloadfragmenthfoo
#define fooloadfragmenthfoo
#include "name.h"
#include "unit.h"
/* Read service data from .desktop file style configuration fragments */
int name_load_fragment(Name *n);
int unit_load_fragment(Unit *u);
#endif
......@@ -2,8 +2,8 @@
#include "load-fstab.h"
int name_load_fstab(Name *n) {
assert(n);
int unit_load_fstab(Unit *u) {
assert(u);
/* Load dependencies from /etc/fstab */
......
......@@ -3,10 +3,10 @@
#ifndef fooloadfstabhfoo
#define fooloadfstabhfoo
#include "name.h"
#include "unit.h"
/* Read service data from /etc/fstab */
int name_load_fstab(Name *n);
int unit_load_fstab(Unit *u);
#endif
......@@ -10,7 +10,7 @@
int main(int argc, char *argv[]) {
Manager *m = NULL;
Name *target = NULL;
Unit *target = NULL;
Job *job = NULL;
int r, retval = 1;
......@@ -21,7 +21,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
if ((r = manager_load_name(m, "default.target", &target)) < 0) {
if ((r = manager_load_unit(m, "default.target", &target)) < 0) {
log_error("Failed to load default target: %s", strerror(-r));
goto finish;
}
......@@ -31,8 +31,8 @@ int main(int argc, char *argv[]) {
goto finish;
}
printf("→ By names:\n");
manager_dump_names(m, stdout, "\t");
printf("→ By units:\n");
manager_dump_units(m, stdout, "\t");
printf("→ By jobs:\n");
manager_dump_jobs(m, stdout, "\t");
......
This diff is collapsed.
......@@ -10,7 +10,7 @@
typedef struct Manager Manager;
typedef enum ManagerEventType ManagerEventType;
#include "name.h"
#include "unit.h"
#include "job.h"
#include "hashmap.h"
#include "list.h"
......@@ -25,28 +25,28 @@ enum ManagerEventType {
struct Manager {
uint32_t current_job_id;
/* Note that the set of names we know of is allowed to be
/* Note that the set of units we know of is allowed to be
* incosistent. However the subset of it that is loaded may
* not, and the list of jobs may neither. */
/* Active jobs and names */
Hashmap *names; /* name string => Name object n:1 */
/* Active jobs and units */
Hashmap *units; /* name string => Unit object n:1 */
Hashmap *jobs; /* job id => Job object 1:1 */
/* Names that need to be loaded */
/* Units that need to be loaded */
LIST_HEAD(Meta, load_queue); /* this is actually more a stack than a queue, but uh. */
/* Jobs that need to be run */
LIST_HEAD(Job, run_queue); /* more a stack than a queue, too */
/* Jobs to be added */
Hashmap *transaction_jobs; /* Name object => Job object list 1:1 */
Hashmap *transaction_jobs; /* Unit object => Job object list 1:1 */
JobDependency *transaction_anchor;
bool dispatching_load_queue:1;
bool dispatching_run_queue:1;
Hashmap *watch_pids; /* pid => Name object n:1 */
Hashmap *watch_pids; /* pid => Unit object n:1 */
int epoll_fd;
int signal_fd;
......@@ -56,12 +56,12 @@ Manager* manager_new(void);
void manager_free(Manager *m);
Job *manager_get_job(Manager *m, uint32_t id);
Name *manager_get_name(Manager *m, const char *name);
Unit *manager_get_unit(Manager *m, const char *name);
int manager_load_name(Manager *m, const char *name, Name **_ret);
int manager_add_job(Manager *m, JobType type, Name *name, JobMode mode, bool force, Job **_ret);
int manager_load_unit(Manager *m, const char *name, Unit **_ret);
int manager_add_job(Manager *m, JobType type, Unit *unit, JobMode mode, bool force, Job **_ret);
void manager_dump_names(Manager *s, FILE *f, const char *prefix);
void manager_dump_units(Manager *s, FILE *f, const char *prefix);
void manager_dump_jobs(Manager *s, FILE *f, const char *prefix);
void manager_transaction_unlink_job(Manager *m, Job *j);
......
......@@ -2,41 +2,41 @@
#include <errno.h>
#include "name.h"
#include "unit.h"
#include "mount.h"
#include "load-fragment.h"
#include "load-fstab.h"
#include "load-dropin.h"
static int mount_init(Name *n) {
static int mount_init(Unit *u) {
int r;
Mount *m = MOUNT(n);
Mount *m = MOUNT(u);
assert(m);
/* Load a .mount 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 r;
}
static void mount_done(Name *n) {
Mount *d = MOUNT(n);
static void mount_done(Unit *u) {
Mount *d = MOUNT(u);
assert(d);
free(d->path);
}
static void mount_dump(Name *n, FILE *f, const char *prefix) {
static void mount_dump(Unit *u, FILE *f, const char *prefix) {
static const char* const state_table[_MOUNT_STATE_MAX] = {
[MOUNT_DEAD] = "dead",
......@@ -46,7 +46,7 @@ static void mount_dump(Name *n, FILE *f, const char *prefix) {
[MOUNT_MAINTAINANCE] = "maintainance"
};
Mount *s = MOUNT(n);
Mount *s = MOUNT(u);
assert(s);
......@@ -57,20 +57,20 @@ static void mount_dump(Name *n, FILE *f, const char *prefix) {
prefix, s->path);
}
static NameActiveState mount_active_state(Name *n) {
static UnitActiveState mount_active_state(Unit *u) {
static const NameActiveState table[_MOUNT_STATE_MAX] = {
[MOUNT_DEAD] = NAME_INACTIVE,
[MOUNT_MOUNTING] = NAME_ACTIVATING,
[MOUNT_MOUNTED] = NAME_ACTIVE,
[MOUNT_UNMOUNTING] = NAME_DEACTIVATING,