X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=name.h;h=17bb35d6a74e197c5ccba3aca693007421c81c24;hb=c22cbe2672db2c95647c9412cfb4331d2be279a7;hp=8c526baed6b525e4a091e324ae8f2aaf1738249e;hpb=83c60c9f0c7581b607dc5c0f84582978894e3d4a;p=elogind.git diff --git a/name.h b/name.h index 8c526baed..17bb35d6a 100644 --- a/name.h +++ b/name.h @@ -21,14 +21,17 @@ typedef enum NameDependency NameDependency; #include "list.h" #include "socket-util.h" #include "execute.h" +#include "util.h" #define NAME_MAX 32 +#define DEFAULT_TIMEOUT_USEC (20*USEC_PER_SEC) +#define DEFAULT_RESTART_USEC (100*USEC_PER_MSEC) enum NameType { NAME_SERVICE = 0, NAME_TIMER, NAME_SOCKET, - NAME_MILESTONE, + NAME_TARGET, NAME_DEVICE, NAME_MOUNT, NAME_AUTOMOUNT, @@ -72,6 +75,8 @@ enum NameDependency { NAME_WANTS, NAME_REQUISITE, NAME_SOFT_REQUISITE, + + /* Inverse of the above */ NAME_REQUIRED_BY, /* inverse of 'requires' and 'requisite' is 'required_by' */ NAME_SOFT_REQUIRED_BY, /* inverse of 'soft_requires' and 'soft_requisite' is 'soft_required_by' */ NAME_WANTED_BY, /* inverse of 'wants' */ @@ -82,7 +87,9 @@ enum NameDependency { /* Order */ NAME_BEFORE, /* inverse of before is after and vice versa */ NAME_AFTER, - _NAME_DEPENDENCY_MAX + + _NAME_DEPENDENCY_MAX, + _NAME_DEPENDENCY_INVALID = -1 }; struct Meta { @@ -90,6 +97,8 @@ struct Meta { NameType type; NameLoadState load_state; + char *id; /* One name is special because we use it for identification. Points to an entry in the names set */ + Set *names; Set *dependencies[_NAME_DEPENDENCY_MAX]; @@ -100,15 +109,19 @@ struct Meta { Job *job; bool linked:1; + bool in_load_queue:1; + + usec_t active_enter_timestamp; + usec_t active_exit_timestamp; /* Load queue */ - LIST_FIELDS(Meta); + LIST_FIELDS(Meta, load_queue); }; #include "service.h" #include "timer.h" #include "socket.h" -#include "milestone.h" +#include "target.h" #include "device.h" #include "mount.h" #include "automount.h" @@ -119,7 +132,7 @@ union Name { Service service; Timer timer; Socket socket; - Milestone milestone; + Target target; Device device; Mount mount; Automount automount; @@ -129,20 +142,33 @@ union Name { struct NameVTable { const char *suffix; - int (*load)(Name *n); + int (*init)(Name *n); + void (*done)(Name *n); + void (*dump)(Name *n, FILE *f, const char *prefix); int (*start)(Name *n); int (*stop)(Name *n); int (*reload)(Name *n); + + bool (*can_reload)(Name *n); + /* Boils down the more complex internal state of this name to * a simpler one that the engine can understand */ NameActiveState (*active_state)(Name *n); - void (*free_hook)(Name *n); + void (*fd_event)(Name *n, int fd, uint32_t events); + void (*sigchld_event)(Name *n, pid_t pid, int code, int status); + void (*timer_event)(Name *n, int id, uint64_t n_elapsed); + + void (*retry)(Name *n); }; +extern const NameVTable * const name_vtable[_NAME_TYPE_MAX]; + +#define NAME_VTABLE(n) name_vtable[(n)->meta.type] + /* For casting a name into the various name types */ #define DEFINE_CAST(UPPERCASE, MixedCase) \ static inline MixedCase* UPPERCASE(Name *name) { \ @@ -158,16 +184,16 @@ struct NameVTable { DEFINE_CAST(SOCKET, Socket); DEFINE_CAST(TIMER, Timer); DEFINE_CAST(SERVICE, Service); -DEFINE_CAST(MILESTONE, Milestone); +DEFINE_CAST(TARGET, Target); DEFINE_CAST(DEVICE, Device); DEFINE_CAST(MOUNT, Mount); DEFINE_CAST(AUTOMOUNT, Automount); DEFINE_CAST(SNAPSHOT, Snapshot); -NameActiveState name_active_state(Name *name); - bool name_type_can_start(NameType t); bool name_type_can_reload(NameType t); +bool name_can_reload(Name *n); +#define name_can_start(n) name_type_can_start((n)->meta.type) NameType name_type_from_string(const char *n); bool name_is_valid(const char *n); @@ -183,6 +209,10 @@ int name_load(Name *name); const char* name_id(Name *n); const char *name_description(Name *n); +int name_add_name(Name *n, const char *text); + +NameActiveState name_active_state(Name *name); + void name_dump(Name *n, FILE *f, const char *prefix); int name_start(Name *n); @@ -191,4 +221,19 @@ int name_reload(Name *n); void name_notify(Name *n, NameActiveState os, NameActiveState ns); +int name_watch_fd(Name *n, int fd, uint32_t events); +void name_unwatch_fd(Name *n, int fd); + +int name_watch_pid(Name *n, pid_t pid); +void name_unwatch_pid(Name *n, pid_t pid); + +int name_watch_timer(Name *n, usec_t delay, int *id); +void name_unwatch_timer(Name *n, int *id); + +char *name_change_suffix(const char *t, const char *suffix); + +bool name_job_is_applicable(Name *n, JobType j); + +int name_add_dependency(Name *n, NameDependency d, Name *other); + #endif