summaryrefslogtreecommitdiffabout
path: root/src/direvent.h
authorSergey Poznyakoff <gray@gnu.org.ua>2016-08-23 05:36:01 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2016-08-25 19:29:47 (GMT)
commita60dcd92df15705bb84f644c99fd166e101dc681 (patch) (side-by-side diff)
tree883906dc48ff03ca96a0b63ef8ee28dc10bcb150 /src/direvent.h
parent6f39bd7e00acee689ce9a8a3916888a815242557 (diff)
downloaddirevent-a60dcd92df15705bb84f644c99fd166e101dc681.tar.gz
direvent-a60dcd92df15705bb84f644c99fd166e101dc681.tar.bz2
Further modify struct handler.
Instead of accomodating two types of functionality, the new struct handler has a pointer to the function that is responsible for handling the event, and a pointer to data for that function (closure). Additionally, a pointer to deallocator function is also provided. Existing functionality is reimplemented using this new struct. New types of handlers can easily be added. * src/config.c (eventconf)<ev_mask,fpat,prog_handler>: New members <handler>: Remove. All uses changed. * src/direvent.h (filpatlist_t) (event_handler_fn, handler_free_fn): New data types. (handler): Remove union and type. Add two pointer to functions that are to implement the functionality (run and free) and a pointer to data for them. (prog_handler): New struct. (prog_handler_alloc,prog_handler_free) (prog_handler_envrealloc) (watchpoint_run_handlers): New protos. (run_handler,filename_pattern_free) (filename_pattern_match): Remove (filpatlist_add, filpatlist_add_exact) (filpatlist_destroy, filpatlist_match): New protos. * src/ev_inotify.c (process_event): Use watchpoint_run_handlers * src/ev_kqueue.c: Likewise. * src/fnpat.c: Major rewrite. * src/handler.c (handler_copy) (handler_envrealloc,handler_add_pattern) (handler_add_exact_filename): Remove (handler_alloc): Change arguments. (watchpoint_run_handlers): New function. * src/progman.c (prog_handler_alloc) (prog_handler_envrealloc): New functions. * src/watcher.c: Reimplement sentinel watchers.
Diffstat (limited to 'src/direvent.h') (more/less context) (ignore whitespace changes)
-rw-r--r--src/direvent.h89
1 files changed, 45 insertions, 44 deletions
diff --git a/src/direvent.h b/src/direvent.h
index faa1657..d69fa34 100644
--- a/src/direvent.h
+++ b/src/direvent.h
@@ -72,40 +72,25 @@ struct filename_pattern {
} v;
};
-enum handler_type {
- HANDLER_EXTERN,
- HANDLER_SENTINEL
-};
+typedef struct filpatlist *filpatlist_t;
+
+struct watchpoint;
+
+typedef int (*event_handler_fn) (struct watchpoint *wp,
+ event_mask *event,
+ const char *dir,
+ const char *file,
+ void *data);
+typedef void (*handler_free_fn) (void *data);
/* Handler structure */
struct handler {
- size_t refcnt; /* Reference counter */
- event_mask ev_mask; /* Event mask */
- struct grecs_list *fnames; /* File name patterns */
- enum handler_type type;
- union {
- struct {
- int flags; /* Handler flags */
- char *command; /* Handler command (with eventual
- arguments) */
- uid_t uid; /* Run as this user (unless 0) */
- gid_t *gidv; /* Run with these groups' privileges */
- size_t gidc; /* Number of elements in gidv */
- unsigned timeout; /* Handler timeout */
- char **env; /* Environment */
- } prog;
- struct {
- struct watchpoint *watchpoint;
- } sentinel;
- } v;
-#define prog_flags v.prog.flags
-#define prog_command v.prog.command
-#define prog_uid v.prog.uid
-#define prog_gidv v.prog.gidv
-#define prog_gidc v.prog.gidc
-#define prog_timeout v.prog.timeout
-#define prog_env v.prog.env
-#define sentinel_watchpoint v.sentinel.watchpoint
+ size_t refcnt; /* Reference counter */
+ event_mask ev_mask; /* Event mask */
+ filpatlist_t fnames; /* File name patterns */
+ event_handler_fn run;
+ handler_free_fn free;
+ void *data;
};
typedef struct handler_list *handler_list_t;
@@ -133,16 +118,27 @@ struct watchpoint {
#define __cat2__(a,b) a ## b
#define handler_matches_event(h,m,f,n) \
- (((h)->ev_mask.__cat2__(m,_mask) & (f)) && \
- filename_pattern_match((h)->fnames, n) == 0)
+ (((h)->ev_mask.__cat2__(m,_mask) & (f)) && \
+ filpatlist_match((h)->fnames, n) == 0)
-struct handler *handler_alloc(enum handler_type type);
+struct handler *handler_alloc(event_mask ev_mask);
void handler_free(struct handler *hp);
-struct handler *handler_copy(struct handler *orig);
-size_t handler_envrealloc(struct handler *hp, size_t count);
-
-void handler_add_pattern(struct handler *hp, struct filename_pattern *pat);
-void handler_add_exact_filename(struct handler *hp, const char *filename);
+
+struct prog_handler {
+ int flags; /* Handler flags */
+ char *command; /* Handler command (with eventual arguments) */
+ uid_t uid; /* Run as this user (unless 0) */
+ gid_t *gidv; /* Run with these groups' privileges */
+ size_t gidc; /* Number of elements in gidv */
+ unsigned timeout; /* Handler timeout */
+ char **env; /* Environment */
+};
+
+struct handler *prog_handler_alloc(event_mask ev_mask, filpatlist_t fpat,
+ struct prog_handler *p);
+void prog_handler_free(struct prog_handler *);
+size_t prog_handler_envrealloc(struct prog_handler *hp, size_t count);
+
extern int foreground;
extern int debug_level;
@@ -248,6 +244,10 @@ void watchpoint_gc(void);
int watchpoint_pattern_match(struct watchpoint *dwp, const char *file_name);
+void watchpoint_run_handlers(struct watchpoint *wp, int evflags,
+ const char *dirname, const char *filename);
+
+
void setup_watchers(void);
void shutdown_watchers(void);
@@ -257,7 +257,7 @@ struct watchpoint *watchpoint_install(const char *path, int *pnew);
struct watchpoint *watchpoint_install_ptr(struct watchpoint *dw);
void watchpoint_suspend(struct watchpoint *dwp);
void watchpoint_destroy(struct watchpoint *dwp);
-struct watchpoint *watchpoint_install_sentinel(struct watchpoint *dwp);
+int watchpoint_install_sentinel(struct watchpoint *dwp);
int watch_pathname(struct watchpoint *parent, const char *dirname, int isdir, int notify);
@@ -292,8 +292,6 @@ size_t handler_list_size(handler_list_t hlist);
struct process *process_lookup(pid_t pid);
void process_cleanup(int expect_term);
void process_timeouts(void);
-int run_handler(struct watchpoint *dp, struct handler *hp, event_mask *event,
- const char *dir, const char *file);
char **environ_setup(char **hint, char **kve);
#define NITEMS(a) ((sizeof(a)/sizeof((a)[0])))
@@ -308,6 +306,9 @@ int sigv_set_all(void (*handler)(int), int sigc, int *sigv,
int sigv_set_tab(int sigc, struct sigtab *sigtab, struct sigaction *retsa);
int sigv_set_action_tab(int sigc, struct sigtab *sigtab, struct sigaction *sa);
-void filename_pattern_free(void *p);
-int filename_pattern_match(struct grecs_list *lp, const char *name);
+struct grecs_locus;
+int filpatlist_add(filpatlist_t *fptr, char const *arg, struct grecs_locus *loc);
+void filpatlist_add_exact(filpatlist_t *fptr, char const *arg);
+void filpatlist_destroy(filpatlist_t *fptr);
+int filpatlist_match(filpatlist_t fp, const char *name);

Return to:

Send suggestions and report system problems to the System administrator.