]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add support for nommu systems.
authorGuy Harris <[email protected]>
Wed, 1 Dec 2010 00:18:32 +0000 (16:18 -0800)
committerGuy Harris <[email protected]>
Wed, 1 Dec 2010 00:18:32 +0000 (16:18 -0800)
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 <[email protected]>
config.h.in
configure
configure.in
tcpdump.c

index 3be38477210efa0040fc61c9fe439a176bfbda09..3086710ca5a804fa6644a243bd91c83d27a1200a 100644 (file)
 /* Define to 1 if you have the <fcntl.h> 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
 
 /* Define to 1 if you have the <unistd.h> 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
 
index 593c6af64c17c0bcbed60cac2df6a72c74d0a2ef..05ea8b6fe65166f4e90a451a4ba9a80c8239aeee 100755 (executable)
--- a/configure
+++ b/configure
@@ -6138,7 +6138,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
index 6fa27cc94f3584fbbcaff5c3689bc7f8c310c0b6..e2d417036d9961bfaccedbe89356a0274f2a2e00 100644 (file)
@@ -549,7 +549,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
index c8da36baa92592284844e58af56b537a647b3f55..19318047f33f0c3169f850a2df10515e50f0329d 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1250,8 +1250,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)
@@ -1464,13 +1466,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)
@@ -1514,11 +1516,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
@@ -1534,15 +1540,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)