clsync
mon_fanotify.c
Go to the documentation of this file.
1 /*
2  clsync - file tree sync utility based on inotify/kqueue
3 
4  Copyright (C) 2013-2014 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #if 0
21 
22 int fanotify_add_watch_dir ( int fanotify_d, struct ctx *ctx_p, const char *const accpath )
23 {
24  return fanotify_mark ( fanotify_d, FAN_MARK_ADD | FAN_MARK_DONT_FOLLOW,
25  FANOTIFY_MARKMASK, AT_FDCWD, accpath );
26 }
27 
28 int fanotify_loop ( int fanotify_d, ctx_t *ctx_p, indexes_t *indexes_p )
29 {
30  struct fanotify_event_metadata buf[BUFSIZ / sizeof ( struct fanotify_event_metadata ) + 1];
31  int state = STATE_RUNNING;
32  state_p = &state;
33 
34  while ( state != STATE_EXIT ) {
35  struct fanotify_event_metadata *metadata;
36  size_t len = read ( fanotify_d, ( void * ) buf, sizeof ( buf ) - sizeof ( *buf ) );
37  metadata = buf;
38 
39  if ( len == -1 ) {
40  error ( "cannot read(%i, &metadata, sizeof(metadata)).", fanotify_d );
41  return errno;
42  }
43 
44  while ( FAN_EVENT_OK ( metadata, len ) ) {
45  debug ( 2, "metadata->pid: %i; metadata->fd: %i", metadata->pid, metadata->fd );
46 
47  if ( metadata->fd != FAN_NOFD ) {
48  if ( metadata->fd >= 0 ) {
49  char *fpath = fd2fpath_malloc ( metadata->fd );
50  sync_queuesync ( fpath_rel, 0, ctx_p, indexes_p, QUEUE_AUTO );
51  debug ( 2, "Event %i on \"%s\".", metadata->mask, fpath );
52  free ( fpath );
53  }
54  }
55 
56  close ( metadata->fd );
57  metadata = FAN_EVENT_NEXT ( metadata, len );
58  }
59 
60  int ret;
61 
62  if ( ( ret = sync_idle ( fanotify_d, ctx_p, indexes_p ) ) ) {
63  error ( "got error while sync_idle()." );
64  return ret;
65  }
66  }
67 
68  return 0;
69 }
70 #endif
71 
ctx
Definition: ctx.h:315
close
close(fd_w)
indexes
Definition: indexes.h:34
STATE_EXIT
@ STATE_EXIT
Definition: ctx.h:259
STATE_RUNNING
@ STATE_RUNNING
Definition: ctx.h:261
FANOTIFY_MARKMASK
#define FANOTIFY_MARKMASK
Definition: configuration.h:105
QUEUE_AUTO
@ QUEUE_AUTO
Definition: ctx.h:179
error
#define error(...)
Definition: error.h:36
fanotify_add_watch_dir
int fanotify_add_watch_dir(struct ctx *ctx_p, const char *const accpath)
fd2fpath_malloc
char * fd2fpath_malloc(int fd)
Definition: fileutils.c:26
debug
#define debug(debug_level,...)
Definition: error.h:50
BUFSIZ
#define BUFSIZ
Definition: configuration.h:6
state_p
volatile state_t * state_p
Definition: sync.c:546
sync_idle
int sync_idle(ctx_t *ctx_p, indexes_t *indexes_p)
Definition: sync.c:3196
sync_queuesync
static int sync_queuesync(const char *fpath_rel, eventinfo_t *evinfo, ctx_t *ctx_p, indexes_t *indexes_p, queue_id_t queue_id)
Definition: sync.c:1251
ctx_p
ctx_t * ctx_p
Definition: mon_kqueue.c:85