... | ... |
@@ -56,6 +56,23 @@ |
56 | 56 |
#include "others.h" |
57 | 57 |
#include "scanner.h" |
58 | 58 |
|
59 |
+static int onas_ddd_init_ht(uint32_t ht_size); |
|
60 |
+static int onas_ddd_init_wdlt(uint64_t nwatches); |
|
61 |
+static int onas_ddd_grow_wdlt(); |
|
62 |
+ |
|
63 |
+static int onas_ddd_watch(const char *pathname, int fan_fd, uint64_t fan_mask, int in_fd, uint64_t in_mask); |
|
64 |
+static int onas_ddd_watch_hierarchy(const char* pathname, size_t len, int fd, uint64_t mask, uint32_t type); |
|
65 |
+static int onas_ddd_unwatch(const char *pathname, int fan_fd, int in_fd); |
|
66 |
+static int onas_ddd_unwatch_hierarchy(const char* pathname, size_t len, int fd, uint32_t type); |
|
67 |
+ |
|
68 |
+static void onas_ddd_handle_in_moved_to(struct ddd_thrarg *tharg, const char *path, const char *child_path, const struct inotify_event *event, int wd, uint64_t in_mask); |
|
69 |
+static void onas_ddd_handle_in_create(struct ddd_thrarg *tharg, const char *path, const char *child_path, const struct inotify_event *event, int wd, uint64_t in_mask); |
|
70 |
+static void onas_ddd_handle_in_moved_from(struct ddd_thrarg *tharg, const char *path, const char *child_path, const struct inotify_event *event, int wd); |
|
71 |
+static void onas_ddd_handle_in_delete(struct ddd_thrarg *tharg, const char *path, const char *child_path, const struct inotify_event *event, int wd); |
|
72 |
+static void onas_ddd_handle_extra_scanning(struct ddd_thrarg *tharg, const char *pathname, int options); |
|
73 |
+ |
|
74 |
+static void onas_ddd_exit(int sig); |
|
75 |
+ |
|
59 | 76 |
/* TODO: Unglobalize these. */ |
60 | 77 |
static struct onas_ht *ddd_ht; |
61 | 78 |
static char **wdlt; |
... | ... |
@@ -162,7 +179,7 @@ static int onas_ddd_watch_hierarchy(const char* pathname, size_t len, int fd, ui |
162 | 162 |
|
163 | 163 |
if (wd < 0) return CL_EARG; |
164 | 164 |
|
165 |
- if (wd >= wdlt_len) { |
|
165 |
+ if ((uint32_t) wd >= wdlt_len) { |
|
166 | 166 |
onas_ddd_grow_wdlt(); |
167 | 167 |
} |
168 | 168 |
|
... | ... |
@@ -273,9 +290,6 @@ void *onas_ddd_th(void *arg) { |
273 | 273 |
sigset_t sigset; |
274 | 274 |
struct sigaction act; |
275 | 275 |
const struct optstruct *pt; |
276 |
- short int scan; |
|
277 |
- int sizelimit = 0, extinfo; |
|
278 |
- STATBUF sb; |
|
279 | 276 |
uint64_t in_mask = IN_ONLYDIR | IN_MOVE | IN_DELETE | IN_CREATE; |
280 | 277 |
fd_set rfds; |
281 | 278 |
char buf[4096]; |
... | ... |
@@ -392,7 +406,7 @@ void *onas_ddd_th(void *arg) { |
392 | 392 |
char *p = buf; |
393 | 393 |
const char *path = NULL; |
394 | 394 |
const char *child = NULL; |
395 |
- for(p; p < buf + bread; p += sizeof(struct inotify_event) + event->len) { |
|
395 |
+ for(; p < buf + bread; p += sizeof(struct inotify_event) + event->len) { |
|
396 | 396 |
|
397 | 397 |
event = (const struct inotify_event *) p; |
398 | 398 |
wd = event->wd; |
... | ... |
@@ -37,24 +37,9 @@ struct ddd_thrarg { |
37 | 37 |
const struct cl_limits *limits; |
38 | 38 |
}; |
39 | 39 |
|
40 |
-static int onas_ddd_init_ht(uint32_t ht_size); |
|
41 |
-static int onas_ddd_init_wdlt(uint64_t nwatches); |
|
42 |
-static int onas_ddd_grow_wdlt(); |
|
43 |
- |
|
44 |
-static int onas_ddd_watch(const char *pathname, int fan_fd, uint64_t fan_mask, int in_fd, uint64_t in_mask); |
|
45 |
-static int onas_ddd_watch_hierarchy(const char* pathname, size_t len, int fd, uint64_t mask, uint32_t type); |
|
46 |
-static int onas_ddd_unwatch(const char *pathname, int fan_fd, int in_fd); |
|
47 |
-static int onas_ddd_unwatch_hierarchy(const char* pathname, size_t len, int fd, uint32_t type); |
|
48 |
- |
|
49 |
-static void onas_ddd_handle_in_moved_to(struct ddd_thrarg *tharg, const char *path, const char *child_path, const struct inotify_event *event, int wd, uint64_t in_mask); |
|
50 |
-static void onas_ddd_handle_in_create(struct ddd_thrarg *tharg, const char *path, const char *child_path, const struct inotify_event *event, int wd, uint64_t in_mask); |
|
51 |
-static void onas_ddd_handle_in_moved_from(struct ddd_thrarg *tharg, const char *path, const char *child_path, const struct inotify_event *event, int wd); |
|
52 |
-static void onas_ddd_handle_in_delete(struct ddd_thrarg *tharg, const char *path, const char *child_path, const struct inotify_event *event, int wd); |
|
53 |
-static void onas_ddd_handle_extra_scanning(struct ddd_thrarg *tharg, const char *pathname, int options); |
|
54 | 40 |
|
55 | 41 |
int onas_ddd_init(uint64_t nwatches, size_t ht_size); |
56 | 42 |
void *onas_ddd_th(void *arg); |
57 |
-static void onas_ddd_exit(int sig); |
|
58 | 43 |
|
59 | 44 |
|
60 | 45 |
#endif |
... | ... |
@@ -52,7 +52,16 @@ |
52 | 52 |
#include "others.h" |
53 | 53 |
#include "scanner.h" |
54 | 54 |
|
55 |
+static struct onas_bucket *onas_bucket_init(); |
|
56 |
+static void onas_free_bucket(struct onas_bucket *bckt); |
|
57 |
+static int onas_bucket_insert(struct onas_bucket *bckt, struct onas_element *elem); |
|
58 |
+static int onas_bucket_remove(struct onas_bucket *bckt, struct onas_element *elem); |
|
55 | 59 |
|
60 |
+static int onas_add_hashnode_child(struct onas_hnode *node, const char* dirname); |
|
61 |
+ |
|
62 |
+static struct onas_lnode *onas_listnode_init(void); |
|
63 |
+ |
|
64 |
+static struct onas_hnode *onas_hashnode_init(void); |
|
56 | 65 |
|
57 | 66 |
static inline uint32_t onas_hshift(uint32_t hash) { |
58 | 67 |
|
... | ... |
@@ -72,7 +81,7 @@ static inline uint32_t onas_hshift(uint32_t hash) { |
72 | 72 |
static inline int onas_hash(const char* key, size_t keylen, uint32_t size) { |
73 | 73 |
|
74 | 74 |
uint32_t hash = 1; |
75 |
- int i; |
|
75 |
+ uint32_t i; |
|
76 | 76 |
|
77 | 77 |
for (i = 0; i < keylen; i++) { |
78 | 78 |
hash += key[i]; |
... | ... |
@@ -112,7 +121,7 @@ void onas_free_ht(struct onas_ht *ht) { |
112 | 112 |
return; |
113 | 113 |
} |
114 | 114 |
|
115 |
- int i = 0; |
|
115 |
+ uint32_t i = 0; |
|
116 | 116 |
for (i = 0; i < ht->size; i++) { |
117 | 117 |
onas_free_bucket(ht->htable[i]); |
118 | 118 |
ht->htable[i] = NULL; |
... | ... |
@@ -144,7 +153,7 @@ static void onas_free_bucket(struct onas_bucket *bckt) { |
144 | 144 |
|
145 | 145 |
if (!bckt) return; |
146 | 146 |
|
147 |
- int i = 0; |
|
147 |
+ uint32_t i = 0; |
|
148 | 148 |
struct onas_element *curr = NULL; |
149 | 149 |
|
150 | 150 |
for (i = 0; i < bckt->size; i++) { |
... | ... |
@@ -197,7 +206,7 @@ int onas_ht_insert(struct onas_ht *ht, struct onas_element *elem) { |
197 | 197 |
struct onas_bucket *bckt = ht->htable[idx]; |
198 | 198 |
|
199 | 199 |
int ret = 0; |
200 |
- int bsize = 0; |
|
200 |
+ uint32_t bsize = 0; |
|
201 | 201 |
|
202 | 202 |
if (bckt == NULL) { |
203 | 203 |
ht->htable[idx] = onas_bucket_init(); |
... | ... |
@@ -324,7 +333,7 @@ static int onas_bucket_remove(struct onas_bucket *bckt, struct onas_element *ele |
324 | 324 |
/* Dealing with hash nodes and list nodes */ |
325 | 325 |
|
326 | 326 |
/* Function to initialize hashnode. */ |
327 |
-struct onas_hnode *onas_hashnode_init() { |
|
327 |
+static struct onas_hnode *onas_hashnode_init(void) { |
|
328 | 328 |
struct onas_hnode *hnode = NULL; |
329 | 329 |
if(!(hnode = (struct onas_hnode *) cli_malloc(sizeof(struct onas_hnode)))) { |
330 | 330 |
return NULL; |
... | ... |
@@ -358,7 +367,7 @@ struct onas_hnode *onas_hashnode_init() { |
358 | 358 |
} |
359 | 359 |
|
360 | 360 |
/* Function to initialize listnode. */ |
361 |
-struct onas_lnode *onas_listnode_init() { |
|
361 |
+static struct onas_lnode *onas_listnode_init(void) { |
|
362 | 362 |
struct onas_lnode *lnode = NULL; |
363 | 363 |
if(!(lnode = (struct onas_lnode *) cli_malloc(sizeof(struct onas_lnode)))) { |
364 | 364 |
return NULL; |
... | ... |
@@ -458,7 +467,7 @@ int onas_rm_listnode(struct onas_lnode *head, const char *dirname) { |
458 | 458 |
struct onas_lnode *curr = head; |
459 | 459 |
size_t n = strlen(dirname); |
460 | 460 |
|
461 |
- while (curr = curr->next) { |
|
461 |
+ while ((curr = curr->next)) { |
|
462 | 462 |
if (!strncmp(curr->dirname, dirname, n)) { |
463 | 463 |
struct onas_lnode *tmp = curr->prev; |
464 | 464 |
tmp->next = curr->next; |
... | ... |
@@ -532,7 +541,7 @@ int onas_ht_rm_child(struct onas_ht *ht, const char *prntpath, size_t prntlen, c |
532 | 532 |
|
533 | 533 |
hnode = elem->data; |
534 | 534 |
|
535 |
- if (ret = onas_rm_listnode(hnode->childhead, &(childpath[idx]))) return CL_EARG; |
|
535 |
+ if ((ret = onas_rm_listnode(hnode->childhead, &(childpath[idx])))) return CL_EARG; |
|
536 | 536 |
|
537 | 537 |
return CL_SUCCESS; |
538 | 538 |
} |
... | ... |
@@ -570,13 +579,13 @@ int onas_ht_add_hierarchy(struct onas_ht *ht, const char *pathname) { |
570 | 570 |
if (prnt) onas_ht_add_child(ht, prnt, strlen(prnt), pathname, len); |
571 | 571 |
free(prnt); |
572 | 572 |
|
573 |
- char * const pathargv[] = { pathname, NULL }; |
|
573 |
+ char * const pathargv[] = { (char*) pathname, NULL }; |
|
574 | 574 |
if (!(ftsp = fts_open(pathargv, ftspopts, NULL))) { |
575 | 575 |
logg("!ScanOnAccess: Could not open '%s'\n", pathname); |
576 | 576 |
return CL_EARG; |
577 | 577 |
} |
578 | 578 |
|
579 |
- while(curr = fts_read(ftsp)) { |
|
579 |
+ while((curr = fts_read(ftsp))) { |
|
580 | 580 |
|
581 | 581 |
struct onas_hnode *hnode = NULL; |
582 | 582 |
|
... | ... |
@@ -599,7 +608,7 @@ int onas_ht_add_hierarchy(struct onas_ht *ht, const char *pathname) { |
599 | 599 |
continue; |
600 | 600 |
} |
601 | 601 |
|
602 |
- if(childlist = fts_children(ftsp, 0)) { |
|
602 |
+ if((childlist = fts_children(ftsp, 0))) { |
|
603 | 603 |
do { |
604 | 604 |
if (childlist->fts_info & FTS_D && |
605 | 605 |
!(childlist->fts_info & FTS_DNR) && |
... | ... |
@@ -608,7 +617,7 @@ int onas_ht_add_hierarchy(struct onas_ht *ht, const char *pathname) { |
608 | 608 |
return CL_EMEM; |
609 | 609 |
} |
610 | 610 |
|
611 |
- } while (childlist = childlist->fts_link); |
|
611 |
+ } while ((childlist = childlist->fts_link)); |
|
612 | 612 |
} |
613 | 613 |
|
614 | 614 |
struct onas_element *elem = onas_element_init(hnode, hnode->pathname, hnode->pathlen); |
... | ... |
@@ -97,20 +97,12 @@ int onas_ht_add_hierarchy(struct onas_ht *ht, const char *pathname); |
97 | 97 |
int onas_ht_add_child(struct onas_ht *ht, const char *prntpath, size_t prntlen, const char *childpath, size_t childlen); |
98 | 98 |
int onas_ht_rm_child(struct onas_ht *ht, const char *prntpath, size_t prntlen, const char *childpath, size_t childlen); |
99 | 99 |
|
100 |
-static struct onas_bucket *onas_bucket_init(); |
|
101 |
-static void onas_free_bucket(struct onas_bucket *bckt); |
|
102 |
-static int onas_bucket_insert(struct onas_bucket *bckt, struct onas_element *elem); |
|
103 |
-static int onas_bucket_remove(struct onas_bucket *bckt, struct onas_element *elem); |
|
104 |
- |
|
105 | 100 |
void onas_free_element(struct onas_element *elem); |
106 | 101 |
struct onas_element *onas_element_init(struct onas_hnode *value, const char *key, size_t klen); |
107 | 102 |
|
108 | 103 |
void onas_free_hashnode(struct onas_hnode *hnode); |
109 |
-struct onas_hnode *onas_hashnode_init(); |
|
110 |
-static int onas_add_hashnode_child(struct onas_hnode *node, const char* dirname); |
|
111 | 104 |
|
112 | 105 |
void onas_free_listnode(struct onas_lnode *lnode); |
113 |
-struct onas_lnode *onas_listnode_init(); |
|
114 | 106 |
int onas_add_listnode(struct onas_lnode *tail, struct onas_lnode *node); |
115 | 107 |
int onas_rm_listnode(struct onas_lnode *head, const char *dirname); |
116 | 108 |
|
... | ... |
@@ -39,6 +39,11 @@ |
39 | 39 |
|
40 | 40 |
#include "onaccess_scth.h" |
41 | 41 |
|
42 |
+static void onas_scth_handle_dir(const char *pathname); |
|
43 |
+static void onas_scth_handle_file(const char *pathname); |
|
44 |
+ |
|
45 |
+static void onas_scth_exit(int sig); |
|
46 |
+ |
|
42 | 47 |
static void onas_scth_exit(int sig) { |
43 | 48 |
logg("*ScanOnAccess: onas_scth_exit(), signal %d\n", sig); |
44 | 49 |
|
... | ... |
@@ -50,11 +55,11 @@ static void onas_scth_handle_dir(const char *pathname) { |
50 | 50 |
int ftspopts = FTS_PHYSICAL | FTS_XDEV; |
51 | 51 |
FTSENT *curr = NULL; |
52 | 52 |
|
53 |
- char *const pathargv[] = { pathname, NULL }; |
|
53 |
+ char *const pathargv[] = { (char *) pathname, NULL }; |
|
54 | 54 |
if (!(ftsp = fts_open(pathargv, ftspopts, NULL))) return; |
55 | 55 |
|
56 | 56 |
/* Offload scanning work to fanotify thread to avoid potential deadlocks. */ |
57 |
- while (curr = fts_read(ftsp)) { |
|
57 |
+ while ((curr = fts_read(ftsp))) { |
|
58 | 58 |
if (curr->fts_info != FTS_D) { |
59 | 59 |
int fd = open(curr->fts_path, O_RDONLY); |
60 | 60 |
if (fd > 0) close(fd); |
... | ... |
@@ -79,8 +84,6 @@ void *onas_scan_th(void *arg) { |
79 | 79 |
struct scth_thrarg *tharg = (struct scth_thrarg *) arg; |
80 | 80 |
sigset_t sigset; |
81 | 81 |
struct sigaction act; |
82 |
- const struct optstruct *pt; |
|
83 |
- short int scan; |
|
84 | 82 |
|
85 | 83 |
/* ignore all signals except SIGUSR1 */ |
86 | 84 |
sigfillset(&sigset); |
... | ... |
@@ -27,13 +27,9 @@ |
27 | 27 |
struct scth_thrarg { |
28 | 28 |
int options; |
29 | 29 |
const struct optstruct *opts; |
30 |
- const char *pathname; |
|
30 |
+ char *pathname; |
|
31 | 31 |
}; |
32 | 32 |
|
33 |
-static void onas_scth_handle_dir(const char *pathname); |
|
34 |
-static void onas_scth_handle_file(const char *pathname); |
|
35 |
- |
|
36 | 33 |
void *onas_scan_th(void *arg); |
37 |
-static void onas_scth_exit(int sig); |
|
38 | 34 |
|
39 | 35 |
#endif |