mirror of
https://github.com/AuxXxilium/eudev.git
synced 2024-12-25 03:49:00 +07:00
add new manager initializer callbacks to per-unit type vtable
This commit is contained in:
parent
fb624d04e5
commit
7824bbebe3
24
manager.c
24
manager.c
@ -71,7 +71,21 @@ static int manager_load_special_units(Manager *m) {
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
static int manager_enumerate(Manager *m) {
|
||||||
|
int r;
|
||||||
|
UnitType c;
|
||||||
|
|
||||||
|
assert(m);
|
||||||
|
|
||||||
|
for (c = 0; c < _UNIT_TYPE_MAX; c++)
|
||||||
|
if (unit_vtable[c]->enumerate)
|
||||||
|
if ((r = unit_vtable[c]->enumerate(m)) < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Manager* manager_new(void) {
|
Manager* manager_new(void) {
|
||||||
Manager *m;
|
Manager *m;
|
||||||
@ -102,6 +116,9 @@ Manager* manager_new(void) {
|
|||||||
if (manager_load_special_units(m) < 0)
|
if (manager_load_special_units(m) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
if (manager_enumerate(m) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
@ -110,6 +127,7 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void manager_free(Manager *m) {
|
void manager_free(Manager *m) {
|
||||||
|
UnitType c;
|
||||||
Unit *u;
|
Unit *u;
|
||||||
Job *j;
|
Job *j;
|
||||||
|
|
||||||
@ -121,6 +139,10 @@ void manager_free(Manager *m) {
|
|||||||
while ((u = hashmap_first(m->units)))
|
while ((u = hashmap_first(m->units)))
|
||||||
unit_free(u);
|
unit_free(u);
|
||||||
|
|
||||||
|
for (c = 0; c < _UNIT_TYPE_MAX; c++)
|
||||||
|
if (unit_vtable[c]->shutdown)
|
||||||
|
unit_vtable[c]->shutdown(m);
|
||||||
|
|
||||||
hashmap_free(m->units);
|
hashmap_free(m->units);
|
||||||
hashmap_free(m->jobs);
|
hashmap_free(m->jobs);
|
||||||
hashmap_free(m->transaction_jobs);
|
hashmap_free(m->transaction_jobs);
|
||||||
|
3
unit.h
3
unit.h
@ -160,6 +160,9 @@ struct UnitVTable {
|
|||||||
void (*fd_event)(Unit *u, int fd, uint32_t events, Watch *w);
|
void (*fd_event)(Unit *u, int fd, uint32_t events, Watch *w);
|
||||||
void (*sigchld_event)(Unit *u, pid_t pid, int code, int status);
|
void (*sigchld_event)(Unit *u, pid_t pid, int code, int status);
|
||||||
void (*timer_event)(Unit *u, uint64_t n_elapsed, Watch *w);
|
void (*timer_event)(Unit *u, uint64_t n_elapsed, Watch *w);
|
||||||
|
|
||||||
|
int (*enumerate)(Manager *m);
|
||||||
|
void (*shutdown)(Manager *m);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX];
|
extern const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX];
|
||||||
|
Loading…
Reference in New Issue
Block a user