Skip to content

Commit

Permalink
s/name/unit
Browse files Browse the repository at this point in the history
  • Loading branch information
poettering committed Jan 26, 2010
1 parent fd79db6 commit 87f0e41
Show file tree
Hide file tree
Showing 38 changed files with 1,739 additions and 1,577 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
46 changes: 23 additions & 23 deletions automount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions automount.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

typedef struct Automount Automount;

#include "name.h"
#include "unit.h"

typedef enum AutomountState {
AUTOMOUNT_DEAD,
Expand Down Expand Up @@ -41,6 +41,6 @@ struct Automount {
Mount *mount;
};

extern const NameVTable automount_vtable;
extern const UnitVTable automount_vtable;

#endif
15 changes: 8 additions & 7 deletions conf-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion conf-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions device.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*-*- 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);

Expand All @@ -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,

Expand Down
4 changes: 2 additions & 2 deletions device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -24,6 +24,6 @@ struct Device {
char **sysfs;
};

extern const NameVTable device_vtable;
extern const UnitVTable device_vtable;

#endif
6 changes: 3 additions & 3 deletions fixme
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Loading

0 comments on commit 87f0e41

Please sign in to comment.