#include <assert.h>#include <err.h>#include <errno.h>#include <fcntl.h>#include <stdbool.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/param.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/time.h>#include <unistd.h>#include "pnotify.h"#include "pnotify-internal.h"#include "queue.h"#include "thread.h"Go to the source code of this file.
Defines | |
| #define | CTX_GET() ((struct pnotify_ctx *) pthread_getspecific(CTX_KEY)) |
| #define | CTX_SET(ctx) (pthread_setspecific(CTX_KEY, ctx)) |
Functions | |
| LIST_HEAD (pnwatchhead, pn_watch) | |
| void | pnotify_init_once (void) |
| pnotify_ctx * | pnotify_init () |
| int | pnotify_add_watch (struct pnotify_watch *watch) |
| int | pnotify_rm_watch (int wd) |
| int | pnotify_get_event (struct pnotify_event *evt, struct pnotify_ctx *ctx) |
| int | pnotify_print_event (struct pnotify_event *evt) |
| void | pnotify_dump (struct pnotify_ctx *ctx) |
| void | pnotify_free (struct pnotify_ctx *ctx) |
| int | pnotify_watch_vnode (const char *path, int mask, void(*cb)(), void *arg) |
| int | pnotify_watch_fd (int fd, int mask, void(*cb)(), void *arg) |
| int | pnotify_set_timer (int interval, int mask, void(*cb)(), void *arg) |
| int | pnotify_trap_signal (int signum, void(*cb)(), void *arg) |
| int | pnotify_call_function (int(*func)(), size_t nargs,...) |
| int | pnotify_dispatch () |
| void | pn_event_add (struct pnotify_ctx *ctx, struct pnotify_event *evt) |
Variables | |
| pnotify_vtable *const | sys = &BSD_VTABLE |
Definition in file pnotify.c.
| LIST_HEAD | ( | pnwatchhead | , | |
| pn_watch | ||||
| ) |
A list of watched files and/or directories
Definition at line 63 of file pnotify.c.
References pn_watch::wd.
| int pnotify_add_watch | ( | struct pnotify_watch * | watch | ) |
Add a watch.
| watch | a watch structure |
Definition at line 164 of file pnotify.c.
References pnotify_vtable::add_watch, pnotify_watch::arg, pnotify_watch::cb, pnotify_watch::ctx, CTX_GET, pnotify_watch::ident, pnotify_watch::mask, pn_resource_id::path, pn_resource_id::signum, sys, pnotify_watch::type, WATCH_FD, WATCH_SIGNAL, WATCH_TIMER, and WATCH_VNODE.
Referenced by pnotify_set_timer(), pnotify_trap_signal(), pnotify_watch_fd(), and pnotify_watch_vnode().
| int pnotify_dispatch | ( | ) |
Wait for events and dispatch callbacks.
Definition at line 481 of file pnotify.c.
References pn_watch::arg, pn_watch::cb, pnotify_event::mask, pnotify_get_event(), pn_watch::type, pnotify_event::watch, WATCH_TIMER, and WATCH_VNODE.
| void pnotify_dump | ( | struct pnotify_ctx * | ) |
Print the context to standard output.
Definition at line 337 of file pnotify.c.
References pnotify_print_event().
| void pnotify_free | ( | struct pnotify_ctx * | ctx | ) |
Free all resources associated with an event queue.
All internal data structures will be freed.
| ctx | a context returned by pnotify_init() or NULL for the current context |
Definition at line 355 of file pnotify.c.
References pnotify_vtable::cleanup, pnotify_ctx::event_count, pnotify_ctx::mutex, pnotify_rm_watch(), sys, pnotify_event::watch, and pn_watch::wd.
| int pnotify_get_event | ( | struct pnotify_event * | , | |
| struct pnotify_ctx * | ||||
| ) |
Wait for an event to occur.
| evt | an event structure that will store the result | |
| ctx | a context returned by pnotify_init() or NULL for the current context |
Definition at line 286 of file pnotify.c.
References CTX_GET, and pnotify_ctx::event_count.
Referenced by pnotify_dispatch().
| struct pnotify_ctx* pnotify_init | ( | ) |
Initialize a pnotify event queue.
Before adding watches, the queue must be initialized via a call to pnotify_init().
Definition at line 122 of file pnotify.c.
References pnotify_init_once().
| int pnotify_print_event | ( | struct pnotify_event * | ) |
Print debugging information about an event to standard output.
| evt | an event to be printed |
Definition at line 321 of file pnotify.c.
References pnotify_event::mask, pnotify_event::name, PN_ATTRIB, PN_CREATE, PN_DELETE, PN_ERROR, PN_MODIFY, pnotify_event::watch, and pn_watch::wd.
Referenced by pnotify_dump().
| int pnotify_rm_watch | ( | int | wd | ) |
Remove a watch.
| wd | watch descriptor |
Definition at line 247 of file pnotify.c.
References pn_watch::parent_wd, pn_rm_timer(), pnotify_vtable::rm_watch, sys, WATCH_TIMER, and pn_watch::wd.
Referenced by pnotify_free().
| int pnotify_set_timer | ( | int | interval, | |
| int | mask, | |||
| void(*)() | cb, | |||
| void * | arg | |||
| ) |
Set a timer to fire after specific number of seconds
If the mask is set to PN_ONESHOT, the timer will be automatically deleted after one occurrance. If the mask is PN_DEFAULT, the timer will repeat forever.
| interval | the number of seconds between timer events | |
| mask | either PN_DEFAULT or PN_ONESHOT |
Definition at line 429 of file pnotify.c.
References pnotify_watch::arg, pnotify_watch::cb, pnotify_watch::ident, pn_resource_id::interval, pnotify_watch::mask, pn_add_timer(), pnotify_add_watch(), pnotify_watch::type, and WATCH_TIMER.
| int pnotify_trap_signal | ( | int | signum, | |
| void(*)() | cb, | |||
| void * | arg | |||
| ) |
Trap a specific signal and generate an event when it is received.
When a signal is trapped, it is no longer delivered to the program and is converted into an event instead.
| signum | the signal to be trapped |
Definition at line 455 of file pnotify.c.
References pnotify_watch::arg, pnotify_watch::cb, CTX_GET, pnotify_watch::ident, pnotify_watch::mask, PN_SIGNAL, pn_trap_signal(), pnotify_add_watch(), pn_resource_id::signum, pnotify_watch::type, and WATCH_SIGNAL.
| int pnotify_watch_fd | ( | int | fd, | |
| int | mask, | |||
| void(*)() | cb, | |||
| void * | arg | |||
| ) |
Watch for changes to a file descriptor
Definition at line 415 of file pnotify.c.
References pnotify_watch::arg, pnotify_watch::cb, pn_resource_id::fd, pnotify_watch::ident, pnotify_watch::mask, pnotify_add_watch(), pnotify_watch::type, and WATCH_FD.
| int pnotify_watch_vnode | ( | const char * | path, | |
| int | mask, | |||
| void(*)() | cb, | |||
| void * | arg | |||
| ) |
Watch for changes to a vnode
| path | the path to a file or directory to be monitored | |
| mask | a bitmask of events to monitor |
Definition at line 400 of file pnotify.c.
References pnotify_watch::arg, pnotify_watch::cb, pnotify_watch::ident, pnotify_watch::mask, pn_resource_id::path, pnotify_add_watch(), pnotify_watch::type, and WATCH_VNODE.
1.5.1