]> 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:19:52 +0000 (16:19 -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 aafcbd43d8efcdb25f3daec93b8e17547ce02982..82ddaa0e206bc837510756b0a9a4fec369d06099 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 f6551cb04aa8a76396c6952de125962d287bf626..4ee6f4bb02e9d5df05d6c7309a485d07b6cefdde 100755 (executable)
--- 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
index 9a8342c209bf32fc4b5ff9d032a7fa8a6f910dda..ab46e715a5f30fbfc270445bcb32133c89655d9b 100644 (file)
@@ -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
index a347bc2cc87ffaacdbf5847f3f92714f1c938956..5b66ece81d2c6f33c8cadac19c1acd0b0426ba59 100644 (file)
--- 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)