static NTSTATUS vfswrap_notify_watch(vfs_handle_struct *vfs_handle, struct sys_notify_context *ctx, struct notify_entry *e, void (*callback)(struct sys_notify_context *ctx, void *private_data, struct notify_event *ev), void *private_data, void *handle) { /* * So far inotify is the only supported default notify mechanism. If * another platform like the the BSD's or a proprietary Unix comes * along and wants another default, we can play the same trick we * played with Posix ACLs. * * Until that is the case, hard-code inotify here. */ #ifdef HAVE_INOTIFY if (lp_kernel_change_notify(ctx->conn->params)) { return inotify_watch(ctx, e, callback, private_data, handle); } #endif /* * Do nothing, leave everything to notify_internal.c */ return NT_STATUS_OK; }
static int addwatch(const char *path, const char *name) { fscrawl_t f; char *npath = path_normalize(path, name, 1); if (!npath) return -1; if (inotify_watch(npath) < 0) goto clean; f = fsc_open(npath); if (!f) goto clean; for(;;) { notify_event *ev; fs_entry *ent = fsc_read(f); if (!ent) break; ev = notify_event_new(); notify_event_set_type(ev, NOTIFY_CREATE); notify_event_set_path(ev, ent->base); notify_event_set_filename(ev, ent->name); notify_event_set_dir(ev, ent->dir); if (ev->dir) { char *fullpath = path_normalize(ev->path, ent->name, 1); if (fullpath && inotify_watch(fullpath) < 0) xfree(fullpath); } queue_enqueue(init_ev_q, ev); } fsc_close(f); return 1; clean: xfree(npath); return -1; }
int main(int argc, char **argv) { int ret=0; signal(SIGINT, fsync_exit);/*register signal handler #include <signal.h>*/ signal(SIGTERM, fsync_exit);/*register signal handler*/ if(fsync_deal_arg(argc, argv) < 0) fsync_exit(); if(fsync_init(g_watch) < 0) fsync_exit(); inotify_watch(); fsync_exit(); return 0; }