Skip to content

Commit 73109eb

Browse files
Mickey Solaval-ms
authored andcommitted
clamonacc: add logging to watchpoint hierarchy add
Patch provides more insight into error conditions which may arise when adding a directory to the watch hierarchy. If a specific file caused the issue, the filename is provided to help users with any troubleshooting needed.
1 parent dcaaf86 commit 73109eb

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

clamonacc/inotif/inotif.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,20 @@ static int onas_ddd_watch_hierarchy(const char *pathname, size_t len, int fd, ui
202202
struct onas_element *elem = NULL;
203203
int wd = 0;
204204

205-
if (onas_ht_get(ddd_ht, pathname, len, &elem) != CL_SUCCESS) return CL_EARG;
205+
if (onas_ht_get(ddd_ht, pathname, len, &elem) != CL_SUCCESS) {
206+
logg(LOGG_ERROR, "ClamInotif: could not add element to hash table for %s\n", pathname);
207+
return CL_EARG;
208+
}
206209

207210
hnode = elem->data;
208211

209212
if (type & ONAS_IN) {
210213
wd = inotify_add_watch(fd, pathname, (uint32_t)mask);
211214

212-
if (wd < 0) return CL_EARG;
213-
215+
if (wd < 0) {
216+
logg(LOGG_ERROR, "ClamInotif: watch descriptor issue when adding watch for %s\n", pathname);
217+
return CL_EARG;
218+
}
214219
if ((uint32_t)wd >= wdlt_len) {
215220
onas_ddd_grow_wdlt();
216221
}
@@ -221,9 +226,13 @@ static int onas_ddd_watch_hierarchy(const char *pathname, size_t len, int fd, ui
221226

222227
hnode->watched |= ONAS_INWATCH;
223228
} else if (type & ONAS_FAN) {
224-
if (fanotify_mark(fd, FAN_MARK_ADD, mask, AT_FDCWD, hnode->pathname) < 0) return CL_EARG;
229+
if (fanotify_mark(fd, FAN_MARK_ADD, mask, AT_FDCWD, hnode->pathname) < 0) {
230+
logg(LOGG_ERROR, "ClamInotif: error when marking %s to be watched by fanotify\n", hnode->pathname);
231+
return CL_EARG;
232+
}
225233
hnode->watched |= ONAS_FANWATCH;
226234
} else {
235+
logg(LOGG_ERROR, "ClamInotif: when adding watch for %s, neither fanotify or inotify were specified\n", pathname);
227236
return CL_EARG;
228237
}
229238

@@ -235,14 +244,18 @@ static int onas_ddd_watch_hierarchy(const char *pathname, size_t len, int fd, ui
235244

236245
size_t size = len + strlen(curr->dirname) + 2;
237246
char *child_path = (char *)cli_malloc(size);
238-
if (child_path == NULL)
247+
if (child_path == NULL) {
248+
logg(LOGG_ERROR, "ClamInotif: out of memory when when adding child for %s\n", hnode->pathname);
239249
return CL_EMEM;
250+
}
251+
240252
if (hnode->pathname[len - 1] == '/')
241253
snprintf(child_path, --size, "%s%s", hnode->pathname, curr->dirname);
242254
else
243255
snprintf(child_path, size, "%s/%s", hnode->pathname, curr->dirname);
244256

245257
if (onas_ddd_watch_hierarchy(child_path, strlen(child_path), fd, mask, type)) {
258+
logg(LOGG_ERROR, "ClamInotif: issue when adding watch for %s\n", child_path);
246259
return CL_EARG;
247260
}
248261
free(child_path);
@@ -474,7 +487,7 @@ void *onas_ddd_th(void *arg)
474487

475488
include_list = onas_get_opt_list(pt->strarg, &num_indirs, &err);
476489
if (NULL == include_list) {
477-
logg(LOGG_ERROR, "ClamInotif: could not parse include list (%d)\n", err);
490+
logg(LOGG_ERROR, "ClamInotif: could not parse include list (%s)\n", cl_strerror(err));
478491
return NULL;
479492
}
480493

@@ -531,7 +544,7 @@ void *onas_ddd_th(void *arg)
531544

532545
exclude_list = onas_get_opt_list(pt->strarg, &num_exdirs, &err);
533546
if (NULL == exclude_list) {
534-
logg(LOGG_ERROR, "ClamInotif: could not parse exclude list (%d)\n", err);
547+
logg(LOGG_ERROR, "ClamInotif: could not parse exclude list (%s)\n", cl_strerror(err));
535548
return NULL;
536549
}
537550

@@ -568,7 +581,7 @@ void *onas_ddd_th(void *arg)
568581
if (err) {
569582

570583
if (0 == errno) {
571-
logg(LOGG_ERROR, "ClamInotif: could not watch path '%s', %d\n ", pt->strarg, err);
584+
logg(LOGG_ERROR, "ClamInotif: could not watch path '%s', %s\n ", pt->strarg, cl_strerror(err));
572585
} else {
573586
logg(LOGG_ERROR, "ClamInotif: could not watch path '%s', %s\n", pt->strarg, strerror(errno));
574587
if (errno == EINVAL && optget(ctx->clamdopts, "OnAccessPrevention")->enabled) {
@@ -599,7 +612,7 @@ void *onas_ddd_th(void *arg)
599612
err = onas_ddd_watch(include_list[idx], ctx->fan_fd, ctx->fan_mask, onas_in_fd, in_mask);
600613
if (err) {
601614
if (0 == errno) {
602-
logg(LOGG_ERROR, "ClamInotif: could not watch path '%s', %d\n ", include_list[idx], err);
615+
logg(LOGG_ERROR, "ClamInotif: could not watch path '%s', %s\n ", include_list[idx], cl_strerror(err));
603616
} else {
604617
logg(LOGG_ERROR, "ClamInotif: could not watch path '%s', %s\n", include_list[idx], strerror(errno));
605618
if (errno == EINVAL && optget(ctx->clamdopts, "OnAccessPrevention")->enabled) {

0 commit comments

Comments
 (0)