Browse code

cli_ftw: when readdir fails, call the error callback (bb #1735).

Also report all failures to clamdscan.

Török Edvin authored on 2009/12/15 21:11:27
Showing 2 changed files
... ...
@@ -106,8 +106,7 @@ int scan_callback(struct stat *sb, char *filename, const char *msg, enum cli_ftw
106 106
 	    scandata->errors++;
107 107
 	    return CL_EMEM;
108 108
 	case error_stat:
109
-	    if (msg == scandata->toplevel_path)
110
-		conn_reply_errno(scandata->conn, msg, "lstat() failed:");
109
+	    conn_reply_errno(scandata->conn, msg, "lstat() failed:");
111 110
 	    logg("^lstat() failed on: %s\n", msg);
112 111
 	    scandata->errors++;
113 112
 	    return CL_SUCCESS;
... ...
@@ -569,10 +569,11 @@ static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb
569 569
 
570 570
     if((dd = opendir(dirname)) != NULL) {
571 571
 	struct dirent *dent;
572
+	int err;
572 573
 	errno = 0;
573 574
 	ret = CL_SUCCESS;
574 575
 #ifdef HAVE_READDIR_R_3
575
-	while(!readdir_r(dd, &result.d, &dent) && dent) {
576
+	while(!(err = readdir_r(dd, &result.d, &dent)) && dent) {
576 577
 #elif defined(HAVE_READDIR_R_2)
577 578
 	while((dent = (struct dirent *) readdir_r(dd, &result.d))) {
578 579
 #else
... ...
@@ -680,7 +681,19 @@ static int cli_ftw_dir(const char *dirname, int flags, int maxdepth, cli_ftw_cb
680 680
 	    }
681 681
 	    errno = 0;
682 682
 	}
683
+#ifndef HAVE_READDIR_R_3
684
+	err = errno;
685
+#endif
683 686
 	closedir(dd);
687
+	if (err) {
688
+	    char errs[128];
689
+	    cli_errmsg("Unable to readdir() directory %s: %s\n", dirname,
690
+		       cli_strerror(errno, errs, sizeof(errs)));
691
+	    /* report error to callback using error_stat */
692
+	    ret = callback(NULL, NULL, dirname, error_stat, data);
693
+	    if (ret != CL_SUCCESS)
694
+		return ret;
695
+	}
684 696
 
685 697
 	if (entries) {
686 698
 	    cli_qsort(entries, entries_cnt, sizeof(*entries), ftw_compare);