tcpdump-4.1.1-vfork.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. https://sourceforge.net/tracker/?func=detail&aid=3120897&group_id=53066&atid=469575
  2. From 6f8927c609d1f986a45010b7acae0eb570668642 Mon Sep 17 00:00:00 2001
  3. From: Mike Frysinger <vapier@gentoo.org>
  4. Date: Sat, 27 Nov 2010 17:18:05 -0500
  5. Subject: [PATCH] add support for nommu systems
  6. Rather than hardcode the WIN32 define, add proper fork checks to the
  7. configure script and check those. This fixes building for nommu systems
  8. which lack the fork function.
  9. While we're here though, add support for this functionality via vfork
  10. so that it does work on nommu systems. And fix an old bug where we
  11. exit properly in the forked child when the exec failed instead of just
  12. returning to the calling code (which isn't expecting it).
  13. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
  14. ---
  15. --- tcpdump-4.0.0/config.h.in
  16. +++ tcpdump-4.0.0/config.h.in
  17. @@ -151,6 +151,9 @@
  18. /* Define to 1 if you have the <fcntl.h> header file. */
  19. #undef HAVE_FCNTL_H
  20. +/* Define to 1 if you have the `fork' function. */
  21. +#undef HAVE_FORK
  22. +
  23. /* Define to 1 if you have the `getnameinfo' function. */
  24. #undef HAVE_GETNAMEINFO
  25. @@ -274,6 +277,9 @@
  26. /* Define to 1 if you have the <unistd.h> header file. */
  27. #undef HAVE_UNISTD_H
  28. +/* Define to 1 if you have the `vfork' function. */
  29. +#undef HAVE_VFORK
  30. +
  31. /* Define to 1 if you have the `vfprintf' function. */
  32. #undef HAVE_VFPRINTF
  33. --- tcpdump-4.0.0/configure
  34. +++ tcpdump-4.0.0/configure
  35. @@ -7976,7 +7976,7 @@ done
  36. -for ac_func in strftime
  37. +for ac_func in fork vfork strftime
  38. do
  39. as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
  40. { echo "$as_me:$LINENO: checking for $ac_func" >&5
  41. diff --git a/tcpdump.c b/tcpdump.c
  42. index c8da36b..abf3e69 100644
  43. --- a/tcpdump.c
  44. +++ b/tcpdump.c
  45. @@ -1250,8 +1250,10 @@ main(int argc, char **argv)
  46. (void)setsignal(SIGPIPE, cleanup);
  47. (void)setsignal(SIGTERM, cleanup);
  48. (void)setsignal(SIGINT, cleanup);
  49. - (void)setsignal(SIGCHLD, child_cleanup);
  50. #endif /* WIN32 */
  51. +#if defined(HAVE_FORK) || defined(HAVE_VFORK)
  52. + (void)setsignal(SIGCHLD, child_cleanup);
  53. +#endif
  54. /* Cooperate with nohup(1) */
  55. #ifndef WIN32
  56. if ((oldhandler = setsignal(SIGHUP, cleanup)) != SIG_DFL)
  57. @@ -1464,13 +1466,13 @@ cleanup(int signo _U_)
  58. On windows, we do not use a fork, so we do not care less about
  59. waiting a child processes to die
  60. */
  61. -#ifndef WIN32
  62. +#if defined(HAVE_FORK) || defined(HAVE_VFORK)
  63. static RETSIGTYPE
  64. child_cleanup(int signo _U_)
  65. {
  66. wait(NULL);
  67. }
  68. -#endif /* WIN32 */
  69. +#endif /* HAVE_FORK || HAVE_VFORK */
  70. static void
  71. info(register int verbose)
  72. @@ -1514,11 +1516,15 @@ info(register int verbose)
  73. infoprint = 0;
  74. }
  75. -#ifndef WIN32
  76. +#if defined(HAVE_FORK) || defined(HAVE_VFORK)
  77. static void
  78. compress_savefile(const char *filename)
  79. {
  80. +# ifdef HAVE_FORK
  81. if (fork())
  82. +# else
  83. + if (vfork())
  84. +# endif
  85. return;
  86. /*
  87. * Set to lowest priority so that this doesn't disturb the capture
  88. @@ -1534,15 +1540,20 @@ compress_savefile(const char *filename)
  89. zflag,
  90. filename,
  91. strerror(errno));
  92. +# ifdef HAVE_FORK
  93. + exit(1);
  94. +# else
  95. + _exit(1);
  96. +# endif
  97. }
  98. -#else /* WIN32 */
  99. +#else /* HAVE_FORK || HAVE_VFORK */
  100. static void
  101. compress_savefile(const char *filename)
  102. {
  103. fprintf(stderr,
  104. - "compress_savefile failed. Functionality not implemented under windows\n");
  105. + "compress_savefile failed. Functionality not implemented under your system\n");
  106. }
  107. -#endif /* WIN32 */
  108. +#endif /* HAVE_FORK || HAVE_VFORK */
  109. static void
  110. dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
  111. --
  112. 1.7.3.1