From: Guy Harris Date: Wed, 1 Dec 2010 00:18:32 +0000 (-0800) Subject: Add support for nommu systems. X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/aee61926e8d2e4f7e52bf53d66970045d921b9f0 Add support for nommu systems. Rather than hardcode the WIN32 define, add proper fork checks to the configure script and check those. This fixes building for nommu systems which lack the fork function. While we're here though, add support for this functionality via vfork so that it does work on nommu systems. And fix an old bug where we exit properly in the forked child when the exec failed instead of just returning to the calling code (which isn't expecting it). Reviewed-By: Guy Harris --- diff --git a/config.h.in b/config.h.in index aafcbd43..82ddaa0e 100644 --- a/config.h.in +++ b/config.h.in @@ -105,6 +105,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_FCNTL_H +/* Define to 1 if you have the `fork' function. */ +#undef HAVE_FORK + /* Define to 1 if you have the `getnameinfo' function. */ #undef HAVE_GETNAMEINFO @@ -237,6 +240,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have the `vfork' function. */ +#undef HAVE_VFORK + /* Define to 1 if you have the `vfprintf' function. */ #undef HAVE_VFPRINTF diff --git a/configure b/configure index f6551cb0..4ee6f4bb 100755 --- a/configure +++ b/configure @@ -8133,7 +8133,9 @@ done -for ac_func in strftime + + +for ac_func in fork vfork strftime do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` { echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/configure.in b/configure.in index 9a8342c2..ab46e715 100644 --- a/configure.in +++ b/configure.in @@ -531,7 +531,7 @@ AC_STRUCT_RES_STATE(ac_cv_res_state) AC_REPLACE_FUNCS(vfprintf strcasecmp strlcat strlcpy strdup strsep) -AC_CHECK_FUNCS(strftime) +AC_CHECK_FUNCS(fork vfork strftime) AC_CHECK_FUNCS(setlinebuf alarm) needsnprintf=no diff --git a/tcpdump.c b/tcpdump.c index a347bc2c..5b66ece8 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -1244,8 +1244,10 @@ main(int argc, char **argv) (void)setsignal(SIGPIPE, cleanup); (void)setsignal(SIGTERM, cleanup); (void)setsignal(SIGINT, cleanup); - (void)setsignal(SIGCHLD, child_cleanup); #endif /* WIN32 */ +#if defined(HAVE_FORK) || defined(HAVE_VFORK) + (void)setsignal(SIGCHLD, child_cleanup); +#endif /* Cooperate with nohup(1) */ #ifndef WIN32 if ((oldhandler = setsignal(SIGHUP, cleanup)) != SIG_DFL) @@ -1458,13 +1460,13 @@ cleanup(int signo _U_) On windows, we do not use a fork, so we do not care less about waiting a child processes to die */ -#ifndef WIN32 +#if defined(HAVE_FORK) || defined(HAVE_VFORK) static RETSIGTYPE child_cleanup(int signo _U_) { wait(NULL); } -#endif /* WIN32 */ +#endif /* HAVE_FORK && HAVE_VFORK */ static void info(register int verbose) @@ -1508,11 +1510,15 @@ info(register int verbose) infoprint = 0; } -#ifndef WIN32 +#if defined(HAVE_FORK) || defined(HAVE_VFORK) static void compress_savefile(const char *filename) { +# ifdef HAVE_FORK if (fork()) +# else + if (vfork()) +# endif return; /* * Set to lowest priority so that this doesn't disturb the capture @@ -1528,15 +1534,20 @@ compress_savefile(const char *filename) zflag, filename, strerror(errno)); +# ifdef HAVE_FORK + exit(1); +# else + _exit(1); +# endif } -#else /* WIN32 */ +#else /* HAVE_FORK && HAVE_VFORK */ static void compress_savefile(const char *filename) { fprintf(stderr, - "compress_savefile failed. Functionality not implemented under windows\n"); + "compress_savefile failed. Functionality not implemented under your system\n"); } -#endif /* WIN32 */ +#endif /* HAVE_FORK && HAVE_VFORK */ static void dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)