Lines Matching defs:snctx

40     struct snotify_ctx *snctx;  /* Pointer up to the main snotify struct */
43 * We keep the variable here and not in snctx so that we're able
152 struct snotify_ctx *snctx;
154 snctx = talloc_get_type(ptr, struct snotify_ctx);
155 if (snctx == NULL) {
160 snctx->cb.fn(snctx->filename,
161 snctx->disp->caught_flags,
162 snctx->cb.pvt);
164 talloc_zfree(snctx->disp);
167 static struct snotify_dispatcher *create_dispatcher(struct snotify_ctx *snctx)
172 disp = talloc_zero(snctx, struct snotify_dispatcher);
178 tv.tv_sec += snctx->delay.tv_sec;
179 tv.tv_usec += snctx->delay.tv_usec;
183 (unsigned long) snctx->delay.tv_sec,
184 (unsigned long) snctx->delay.tv_usec);
186 disp->te = tevent_add_timer(snctx->ev, disp, tv,
188 snctx);
198 static struct snotify_dispatcher *get_dispatcher(struct snotify_ctx *snctx)
200 if (snctx->disp != NULL) {
202 return snctx->disp;
205 return create_dispatcher(snctx);
208 static errno_t dispatch_event(struct snotify_ctx *snctx,
213 if ((snctx->cb.mask & ev_flags) == 0) {
217 disp = get_dispatcher(snctx);
227 snctx->disp = disp;
231 static errno_t process_dir_event(struct snotify_ctx *snctx,
238 || strcmp(in_event->name, snctx->base_name) != 0) {
245 in_event->name, snctx->dir_name);
248 ret = dispatch_event(snctx, in_event->mask);
260 static errno_t process_file_event(struct snotify_ctx *snctx,
265 "Will reopen moved or deleted file %s\n", snctx->filename);
271 "received notification for watched file %s\n", snctx->filename);
273 return dispatch_event(snctx, in_event->mask);
276 static errno_t snotify_rewatch(struct snotify_ctx *snctx);
286 struct snotify_ctx *snctx;
291 snctx = talloc_get_type(data, struct snotify_ctx);
292 if (snctx == NULL) {
298 len = read(snctx->wctx->inotify_fd, ev_buf, sizeof(ev_buf));
324 if (snctx->wctx->dir_wd == in_event->wd) {
325 ret = process_dir_event(snctx, in_event);
336 } else if (snctx->wctx->file_wd == in_event->wd) {
337 ret = process_file_event(snctx, in_event);
352 ret = snotify_rewatch(snctx);
384 static errno_t copy_filenames(struct snotify_ctx *snctx,
398 snctx->dir_name = talloc_strdup(snctx, p);
399 if (snctx->dir_name == NULL) {
411 snctx->base_name = talloc_strdup(snctx, p);
412 if (snctx->base_name == NULL) {
416 snctx->filename = talloc_strdup(snctx, filename);
417 if (snctx->filename == NULL) {
424 static struct snotify_watch_ctx *snotify_watch(struct snotify_ctx *snctx,
430 wctx = talloc_zero(snctx, struct snotify_watch_ctx);
437 wctx->snctx = snctx;
449 wctx->tfd = tevent_add_fd(snctx->ev, wctx, wctx->inotify_fd,
451 snctx);
455 snctx->filename);
459 wctx->file_wd = inotify_add_watch(wctx->inotify_fd, snctx->filename, mask);
462 if (ret != ENOENT || (!(snctx->snotify_flags & SNOTIFY_WATCH_DIR))) {
471 if (snctx->snotify_flags & SNOTIFY_WATCH_DIR) {
477 snctx->dir_name, PARENT_DIR_MASK);
496 static errno_t snotify_rewatch(struct snotify_ctx *snctx)
498 talloc_free(snctx->wctx);
500 snctx->wctx = snotify_watch(snctx, snctx->cb.mask);
501 if (snctx->wctx == NULL) {
520 struct snotify_ctx *snctx;
522 snctx = talloc_zero(mem_ctx, struct snotify_ctx);
523 if (snctx == NULL) {
527 snctx->ev = ev;
528 snctx->snotify_flags = snotify_flags;
530 snctx->delay.tv_sec = delay->tv_sec;
531 snctx->delay.tv_usec = delay->tv_usec;
534 snctx->cb.fn = fn;
535 snctx->cb.fn_name = fn_name;
536 snctx->cb.mask = mask;
537 snctx->cb.pvt = pvt;
539 ret = copy_filenames(snctx, filename);
541 talloc_free(snctx);
545 snctx->wctx = snotify_watch(snctx, mask);
546 if (snctx->wctx == NULL) {
547 talloc_free(snctx);
555 snctx->filename,
559 (unsigned long) snctx->delay.tv_sec,
560 (unsigned long) snctx->delay.tv_usec);
562 return snctx;