Browse code

use readdir_r when available

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@962 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/10/04 00:12:13
Showing 10 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sun Oct  3 17:04:27 CEST 2004 (tk)
2
+----------------------------------
3
+  * libclamav, clamd: use readdir_r when available
4
+
1 5
 Sat Oct  2 23:02:39 CEST 2004 (tk)
2 6
 ----------------------------------
3 7
   * configure: improve config file installation (patch by Andrey J. Melnikoff
... ...
@@ -46,7 +46,7 @@ while test $# -gt 0; do
46 46
 	;;
47 47
 
48 48
     --version)
49
-	echo devel-20041002
49
+	echo devel-20041003
50 50
 	exit 0
51 51
 	;;
52 52
 
... ...
@@ -147,6 +147,12 @@
147 147
 /* "pragma pack" */
148 148
 #undef HAVE_PRAGMA_PACK
149 149
 
150
+/* readdir_r takes 2 arguments */
151
+#undef HAVE_READDIR_R_2
152
+
153
+/* readdir_r takes 3 arguments */
154
+#undef HAVE_READDIR_R_3
155
+
150 156
 /* Define to 1 if you have the <regex.h> header file. */
151 157
 #undef HAVE_REGEX_H
152 158
 
... ...
@@ -73,6 +73,9 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne
73 73
 {
74 74
 	DIR *dd;
75 75
 	struct dirent *dent;
76
+#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
77
+	struct dirent result;
78
+#endif
76 79
 	struct stat statbuf;
77 80
 	struct cfgstruct *cpt;
78 81
 	char *fname;
... ...
@@ -93,7 +96,13 @@ int dirscan(const char *dirname, const char **virname, unsigned long int *scanne
93 93
     }
94 94
 
95 95
     if((dd = opendir(dirname)) != NULL) {
96
+#ifdef HAVE_READDIR_R_3
97
+	while(!readdir_r(dd, &result, &dent) && dent) {
98
+#elif defined(HAVE_READDIR_R_2)
99
+	while((dent = (struct dirent *) readdir_r(dd, &result))) {
100
+#else
96 101
 	while((dent = readdir(dd))) {
102
+#endif
97 103
 	    if (!is_fd_connected(odesc)) {
98 104
 		logg("Client disconnected\n");
99 105
 		closedir(dd);
... ...
@@ -1028,6 +1028,7 @@ Optional Features:
1028 1028
   --enable-debug	  enable debug code
1029 1029
   --enable-bigstack	  increase thread stack size
1030 1030
   --disable-gethostbyname_r	  disable support for gethostbyname_r
1031
+  --disable-readdir_r		  disable support for readdir_r
1031 1032
 
1032 1033
 Optional Packages:
1033 1034
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
... ...
@@ -5016,7 +5017,7 @@ test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
5016 5016
 case $host in
5017 5017
 *-*-irix6*)
5018 5018
   # Find out which ABI we are using.
5019
-  echo '#line 5019 "configure"' > conftest.$ac_ext
5019
+  echo '#line 5020 "configure"' > conftest.$ac_ext
5020 5020
   if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
5021 5021
   (eval $ac_compile) 2>&5
5022 5022
   ac_status=$?
... ...
@@ -5589,7 +5590,7 @@ chmod -w .
5589 5589
 save_CFLAGS="$CFLAGS"
5590 5590
 CFLAGS="$CFLAGS -o out/conftest2.$ac_objext"
5591 5591
 compiler_c_o=no
5592
-if { (eval echo configure:5592: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>out/conftest.err; } && test -s out/conftest2.$ac_objext; then
5592
+if { (eval echo configure:5593: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>out/conftest.err; } && test -s out/conftest2.$ac_objext; then
5593 5593
   # The compiler can only warn and ignore the option if not recognized
5594 5594
   # So say no if there are warnings
5595 5595
   if test -s out/conftest.err; then
... ...
@@ -7516,7 +7517,7 @@ else
7516 7516
     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
7517 7517
   lt_status=$lt_dlunknown
7518 7518
   cat > conftest.$ac_ext <<EOF
7519
-#line 7519 "configure"
7519
+#line 7520 "configure"
7520 7520
 #include "confdefs.h"
7521 7521
 
7522 7522
 #if HAVE_DLFCN_H
... ...
@@ -7614,7 +7615,7 @@ else
7614 7614
     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
7615 7615
   lt_status=$lt_dlunknown
7616 7616
   cat > conftest.$ac_ext <<EOF
7617
-#line 7617 "configure"
7617
+#line 7618 "configure"
7618 7618
 #include "confdefs.h"
7619 7619
 
7620 7620
 #if HAVE_DLFCN_H
... ...
@@ -12719,6 +12720,142 @@ _ACEOF
12719 12719
 echo "${ECHO_T}yes, and it takes $ac_cv_gethostbyname_args arguments" >&6
12720 12720
 fi
12721 12721
 
12722
+
12723
+echo "$as_me:$LINENO: checking for readdir_r" >&5
12724
+echo $ECHO_N "checking for readdir_r... $ECHO_C" >&6
12725
+if test -z "$ac_cv_readdir_args"; then
12726
+    cat >conftest.$ac_ext <<_ACEOF
12727
+/* confdefs.h.  */
12728
+_ACEOF
12729
+cat confdefs.h >>conftest.$ac_ext
12730
+cat >>conftest.$ac_ext <<_ACEOF
12731
+/* end confdefs.h.  */
12732
+
12733
+#include <sys/types.h>
12734
+#include <dirent.h>
12735
+
12736
+int
12737
+main ()
12738
+{
12739
+
12740
+    struct dirent dir, *dirp;
12741
+    DIR *mydir;
12742
+    dirp = readdir_r(mydir, &dir);
12743
+
12744
+  ;
12745
+  return 0;
12746
+}
12747
+_ACEOF
12748
+rm -f conftest.$ac_objext
12749
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
12750
+  (eval $ac_compile) 2>conftest.er1
12751
+  ac_status=$?
12752
+  grep -v '^ *+' conftest.er1 >conftest.err
12753
+  rm -f conftest.er1
12754
+  cat conftest.err >&5
12755
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
12756
+  (exit $ac_status); } &&
12757
+	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
12758
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
12759
+  (eval $ac_try) 2>&5
12760
+  ac_status=$?
12761
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
12762
+  (exit $ac_status); }; } &&
12763
+	 { ac_try='test -s conftest.$ac_objext'
12764
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
12765
+  (eval $ac_try) 2>&5
12766
+  ac_status=$?
12767
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
12768
+  (exit $ac_status); }; }; then
12769
+  ac_cv_readdir_args=2
12770
+else
12771
+  echo "$as_me: failed program was:" >&5
12772
+sed 's/^/| /' conftest.$ac_ext >&5
12773
+
12774
+fi
12775
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
12776
+fi
12777
+if test -z "$ac_cv_readdir_args"; then
12778
+    cat >conftest.$ac_ext <<_ACEOF
12779
+/* confdefs.h.  */
12780
+_ACEOF
12781
+cat confdefs.h >>conftest.$ac_ext
12782
+cat >>conftest.$ac_ext <<_ACEOF
12783
+/* end confdefs.h.  */
12784
+
12785
+#include <sys/types.h>
12786
+#include <dirent.h>
12787
+
12788
+int
12789
+main ()
12790
+{
12791
+
12792
+        struct dirent dir, *dirp;
12793
+        DIR *mydir;
12794
+        int rc;
12795
+        rc = readdir_r(mydir, &dir, &dirp);
12796
+
12797
+  ;
12798
+  return 0;
12799
+}
12800
+_ACEOF
12801
+rm -f conftest.$ac_objext
12802
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
12803
+  (eval $ac_compile) 2>conftest.er1
12804
+  ac_status=$?
12805
+  grep -v '^ *+' conftest.er1 >conftest.err
12806
+  rm -f conftest.er1
12807
+  cat conftest.err >&5
12808
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
12809
+  (exit $ac_status); } &&
12810
+	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
12811
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
12812
+  (eval $ac_try) 2>&5
12813
+  ac_status=$?
12814
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
12815
+  (exit $ac_status); }; } &&
12816
+	 { ac_try='test -s conftest.$ac_objext'
12817
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
12818
+  (eval $ac_try) 2>&5
12819
+  ac_status=$?
12820
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
12821
+  (exit $ac_status); }; }; then
12822
+  ac_cv_readdir_args=3
12823
+else
12824
+  echo "$as_me: failed program was:" >&5
12825
+sed 's/^/| /' conftest.$ac_ext >&5
12826
+
12827
+fi
12828
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
12829
+fi
12830
+
12831
+# Check whether --enable-readdir_r or --disable-readdir_r was given.
12832
+if test "${enable_readdir_r+set}" = set; then
12833
+  enableval="$enable_readdir_r"
12834
+  ac_cv_readdir_args=""
12835
+fi;
12836
+
12837
+if test -z "$ac_cv_readdir_args"; then
12838
+    echo "$as_me:$LINENO: result: no" >&5
12839
+echo "${ECHO_T}no" >&6
12840
+else
12841
+    if test "$ac_cv_readdir_args" = 2; then
12842
+
12843
+cat >>confdefs.h <<\_ACEOF
12844
+#define HAVE_READDIR_R_2 1
12845
+_ACEOF
12846
+
12847
+    elif test "$ac_cv_readdir_args" = 3; then
12848
+
12849
+cat >>confdefs.h <<\_ACEOF
12850
+#define HAVE_READDIR_R_3 1
12851
+_ACEOF
12852
+
12853
+    fi
12854
+    echo "$as_me:$LINENO: result: yes, and it takes $ac_cv_readdir_args arguments" >&5
12855
+echo "${ECHO_T}yes, and it takes $ac_cv_readdir_args arguments" >&6
12856
+fi
12857
+
12722 12858
 if test "$test_clamav" = "yes"
12723 12859
 then
12724 12860
         if test "$use_id" = "no"
... ...
@@ -1,5 +1,6 @@
1 1
 dnl
2 2
 dnl   Copyright (C) 2002 - 2004 Tomasz Kojm <tkojm@clamav.net>
3
+dnl   gethostbyname_r and readdir_r checks (c) COPYRIGHT MIT 1995
3 4
 dnl
4 5
 dnl   This program is free software; you can redistribute it and/or modify
5 6
 dnl   it under the terms of the GNU General Public License as published by
... ...
@@ -580,6 +581,51 @@ else
580 580
     AC_MSG_RESULT([yes, and it takes $ac_cv_gethostbyname_args arguments])
581 581
 fi
582 582
 
583
+dnl Check for readdir_r and number of its arguments
584
+dnl Code from libwww/configure.in
585
+
586
+AC_MSG_CHECKING(for readdir_r)
587
+if test -z "$ac_cv_readdir_args"; then
588
+    AC_TRY_COMPILE(
589
+    [
590
+#include <sys/types.h>
591
+#include <dirent.h>
592
+    ],
593
+    [
594
+    struct dirent dir, *dirp;
595
+    DIR *mydir;
596
+    dirp = readdir_r(mydir, &dir);
597
+    ], ac_cv_readdir_args=2)
598
+fi
599
+if test -z "$ac_cv_readdir_args"; then
600
+    AC_TRY_COMPILE(
601
+        [
602
+#include <sys/types.h>
603
+#include <dirent.h>
604
+    ],
605
+    [
606
+        struct dirent dir, *dirp;
607
+        DIR *mydir;
608
+        int rc;
609
+        rc = readdir_r(mydir, &dir, &dirp);
610
+    ], ac_cv_readdir_args=3)
611
+fi
612
+
613
+AC_ARG_ENABLE(readdir_r,
614
+[  --disable-readdir_r		  disable support for readdir_r],
615
+ac_cv_readdir_args="",)
616
+
617
+if test -z "$ac_cv_readdir_args"; then
618
+    AC_MSG_RESULT(no)
619
+else
620
+    if test "$ac_cv_readdir_args" = 2; then
621
+	AC_DEFINE(HAVE_READDIR_R_2,1,[readdir_r takes 2 arguments])
622
+    elif test "$ac_cv_readdir_args" = 3; then
623
+	AC_DEFINE(HAVE_READDIR_R_3,1,[readdir_r takes 3 arguments])
624
+    fi
625
+    AC_MSG_RESULT([yes, and it takes $ac_cv_readdir_args arguments])
626
+fi
627
+
583 628
 dnl Check for clamav in /etc/passwd
584 629
 if test "$test_clamav" = "yes"
585 630
 then
... ...
@@ -359,6 +359,9 @@ int cli_rmdirs(const char *dirname)
359 359
 {
360 360
 	DIR *dd;
361 361
 	struct dirent *dent;
362
+#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
363
+	struct dirent result;
364
+#endif
362 365
 	struct stat maind, statbuf;
363 366
 	char *fname;
364 367
 
... ...
@@ -371,7 +374,13 @@ int cli_rmdirs(const char *dirname)
371 371
 	while(stat(dirname, &maind) != -1) {
372 372
 	    if(!rmdir(dirname)) break;
373 373
 
374
+#ifdef HAVE_READDIR_R_3
375
+	    while(!readdir_r(dd, &result, &dent) && dent) {
376
+#elif defined(HAVE_READDIR_R_2)
377
+	    while((dent = (struct dirent *) readdir_r(dd, &result))) {
378
+#else
374 379
 	    while((dent = readdir(dd))) {
380
+#endif
375 381
 #ifndef C_INTERIX
376 382
 		if(dent->d_ino)
377 383
 #endif
... ...
@@ -690,6 +690,9 @@ int cl_loaddbdir(const char *dirname, struct cl_node **root, unsigned int *signo
690 690
 {
691 691
 	DIR *dd;
692 692
 	struct dirent *dent;
693
+#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
694
+	struct dirent result;
695
+#endif
693 696
 	char *dbfile;
694 697
 	int ret;
695 698
 
... ...
@@ -701,7 +704,13 @@ int cl_loaddbdir(const char *dirname, struct cl_node **root, unsigned int *signo
701 701
 
702 702
     cli_dbgmsg("Loading databases from %s\n", dirname);
703 703
 
704
+#ifdef HAVE_READDIR_R_3
705
+    while(!readdir_r(dd, &result, &dent) && dent) {
706
+#elif defined(HAVE_READDIR_R_2)
707
+    while((dent = (struct dirent *) readdir_r(dd, &result))) {
708
+#else
704 709
     while((dent = readdir(dd))) {
710
+#endif
705 711
 #ifndef C_INTERIX
706 712
 	if(dent->d_ino)
707 713
 #endif
... ...
@@ -746,6 +755,9 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
746 746
 {
747 747
 	DIR *dd;
748 748
 	struct dirent *dent;
749
+#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
750
+	struct dirent result;
751
+#endif
749 752
         char *fname;
750 753
 
751 754
 
... ...
@@ -765,7 +777,13 @@ int cl_statinidir(const char *dirname, struct cl_stat *dbstat)
765 765
 
766 766
     cli_dbgmsg("Stat()ing files in %s\n", dirname);
767 767
 
768
+#ifdef HAVE_READDIR_R_3
769
+    while(!readdir_r(dd, &result, &dent) && dent) {
770
+#elif defined(HAVE_READDIR_R_2)
771
+    while((dent = (struct dirent *) readdir_r(dd, &result))) {
772
+#else
768 773
     while((dent = readdir(dd))) {
774
+#endif
769 775
 #ifndef C_INTERIX
770 776
 	if(dent->d_ino)
771 777
 #endif
... ...
@@ -796,6 +814,9 @@ int cl_statchkdir(const struct cl_stat *dbstat)
796 796
 {
797 797
 	DIR *dd;
798 798
 	struct dirent *dent;
799
+#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
800
+	struct dirent result;
801
+#endif
799 802
 	struct stat sb;
800 803
 	int i, found;
801 804
 	char *fname;
... ...
@@ -813,7 +834,13 @@ int cl_statchkdir(const struct cl_stat *dbstat)
813 813
 
814 814
     cli_dbgmsg("Stat()ing files in %s\n", dbstat->dir);
815 815
 
816
+#ifdef HAVE_READDIR_R_3
817
+    while(!readdir_r(dd, &result, &dent) && dent) {
818
+#elif defined(HAVE_READDIR_R_2)
819
+    while((dent = (struct dirent *) readdir_r(dd, &result))) {
820
+#else
816 821
     while((dent = readdir(dd))) {
822
+#endif
817 823
 #ifndef C_INTERIX
818 824
 	if(dent->d_ino)
819 825
 #endif
... ...
@@ -739,12 +739,21 @@ static int cli_scandir(const char *dirname, const char **virname, long int *scan
739 739
 {
740 740
 	DIR *dd;
741 741
 	struct dirent *dent;
742
+#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
743
+	struct dirent result;
744
+#endif
742 745
 	struct stat statbuf;
743 746
 	char *fname;
744 747
 
745 748
 
746 749
     if((dd = opendir(dirname)) != NULL) {
750
+#ifdef HAVE_READDIR_R_3
751
+	while(!readdir_r(dd, &result, &dent) && dent) {
752
+#elif defined(HAVE_READDIR_R_2)
753
+	while((dent = (struct dirent *) readdir_r(dd, &result))) {
754
+#else
747 755
 	while((dent = readdir(dd))) {
756
+#endif
748 757
 #ifndef C_INTERIX
749 758
 	    if(dent->d_ino)
750 759
 #endif
... ...
@@ -790,6 +799,9 @@ static int cli_vba_scandir(const char *dirname, const char **virname, long int *
790 790
 	vba_project_t *vba_project;
791 791
 	DIR *dd;
792 792
 	struct dirent *dent;
793
+#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2)
794
+	struct dirent result;
795
+#endif
793 796
 	struct stat statbuf;
794 797
 	char *fname, *fullname;
795 798
 	unsigned char *data;
... ...
@@ -879,7 +891,13 @@ static int cli_vba_scandir(const char *dirname, const char **virname, long int *
879 879
     	return ret;
880 880
 
881 881
     if((dd = opendir(dirname)) != NULL) {
882
+#ifdef HAVE_READDIR_R_3
883
+	while(!readdir_r(dd, &result, &dent) && dent) {
884
+#elif defined(HAVE_READDIR_R_2)
885
+	while((dent = (struct dirent *) readdir_r(dd, &result))) {
886
+#else
882 887
 	while((dent = readdir(dd))) {
888
+#endif
883 889
 #ifndef C_INTERIX
884 890
 	    if(dent->d_ino)
885 891
 #endif
... ...
@@ -58,7 +58,7 @@ host_triplet = @host@
58 58
 target_triplet = @target@
59 59
 bin_PROGRAMS = sigtool$(EXEEXT)
60 60
 subdir = sigtool
61
-DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
61
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in COPYING
62 62
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
63 63
 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
64 64
 	$(top_srcdir)/configure.in