int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb, int flags) { int events; int wd; loop->counters.fs_event_init++; /* We don't support any flags yet. */ assert(!flags); if (init_inotify(loop)) return -1; events = IN_ATTRIB | IN_CREATE | IN_MODIFY | IN_DELETE | IN_DELETE_SELF | IN_MOVED_FROM | IN_MOVED_TO; wd = inotify_add_watch(loop->inotify_fd, filename, events); if (wd == -1) return uv__set_sys_error(loop, errno); uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); handle->filename = strdup(filename); handle->cb = cb; handle->fd = wd; add_watcher(handle); return 0; }
static void constructed (GObject *object) { G_OBJECT_CLASS (nm_inotify_helper_parent_class)->constructed (object); init_inotify (NM_INOTIFY_HELPER (object)); }
int main(int argc, char** argv) { if (argc > 1) { if (strcmp(argv[1], "--help") == 0) { printf(USAGE_MSG); return 0; } else if (strcmp(argv[1], "--version") == 0) { printf(VERSION_MSG); return 0; } else if (strcmp(argv[1], "--selftest") == 0) { self_test = true; } else { printf("unrecognized option: %s\n", argv[1]); printf(HELP_MSG); return 1; } } init_log(); if (!self_test) { userlog(LOG_INFO, "started (v." VERSION ")"); } else { userlog(LOG_INFO, "started (self-test mode) (v." VERSION ")"); } setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); roots = array_create(20); if (init_inotify() && roots != NULL) { set_inotify_callback(&inotify_callback); if (!self_test) { main_loop(); } else { run_self_test(); } unregister_roots(); } else { printf("GIVEUP\n"); } close_inotify(); array_delete(roots); userlog(LOG_INFO, "finished"); closelog(); return 0; }
int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb, const char* path, unsigned int flags) { struct watcher_list* w; int events; int err; int wd; if (uv__is_active(handle)) return -EINVAL; err = init_inotify(handle->loop); if (err) return err; events = UV__IN_ATTRIB | UV__IN_CREATE | UV__IN_MODIFY | UV__IN_DELETE | UV__IN_DELETE_SELF | UV__IN_MOVE_SELF | UV__IN_MOVED_FROM | UV__IN_MOVED_TO; wd = uv__inotify_add_watch(handle->loop->inotify_fd, path, events); if (wd == -1) return -errno; w = find_watcher(handle->loop, wd); if (w) goto no_insert; w = uv__malloc(sizeof(*w) + strlen(path) + 1); if (w == NULL) return -ENOMEM; w->wd = wd; w->path = strcpy((char*)(w + 1), path); QUEUE_INIT(&w->watchers); w->iterating = 0; RB_INSERT(watcher_root, CAST(&handle->loop->inotify_watchers), w); no_insert: uv__handle_start(handle); QUEUE_INSERT_TAIL(&w->watchers, &handle->watchers); handle->path = w->path; handle->cb = cb; handle->wd = wd; return 0; }
int main (int argc, char **argv) { if (argc != 2) usage (argv[0], 1); split_path (argv[1]); init_inotify (); if (! exists (watch_path)) loop_inotify (); deinit_inotify (); free_path (); return 0; }
NMInotifyHelper * nm_inotify_helper_get (void) { static NMInotifyHelper *singleton = NULL; if (!singleton) { singleton = (NMInotifyHelper *) g_object_new (NM_TYPE_INOTIFY_HELPER, NULL); if (!singleton) return NULL; if (!init_inotify (singleton)) { g_object_unref (singleton); return NULL; } } else g_object_ref (singleton); g_assert (singleton); return singleton; }