2
1

0003-build-sys-Fix-pidfd_open-checking.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. From f37d178d5c25c547835d054fbb1eda32c25034b3 Mon Sep 17 00:00:00 2001
  2. From: Craig Small <csmall@dropbear.xyz>
  3. Date: Mon, 30 Sep 2024 17:26:01 +1000
  4. Subject: [PATCH] build-sys: Fix pidfd_open checking
  5. The previous build setup would check for pidfd_open using
  6. AC_CHECK_FUNC and would be incorrectly reported as true.
  7. Also, if pidfd_open() and __NR_pidfd_open were not present,
  8. pidwait would silently not be built.
  9. So, changes:
  10. compile a small programin using pidfd_open to test it properly
  11. conditionally try to find NR_pidfd_open if the function fails
  12. complain if neither are present
  13. have --disable-pidwait configure option so you are explicit in
  14. not wanting and knowing you wont get pidwait
  15. References:
  16. #352
  17. commit d9c3e3676d86094abaa239b3218f57bf49d70b4f
  18. commit 17f94796a9b3c4f1ff28829107a82107dcb362b4
  19. Signed-off-by: Craig Small <csmall@dropbear.xyz>
  20. Upstream: https://gitlab.com/procps-ng/procps/-/commit/2507bc475782ff5e0541d37c780dff1e293c9553
  21. Signed-off-by: Scott Fan <fancp2007@gmail.com>
  22. [Scott: backported to version 4.0.4]
  23. ---
  24. configure.ac | 45 ++++++++++++++++++++++++++++++---------------
  25. 1 file changed, 30 insertions(+), 15 deletions(-)
  26. diff --git a/configure.ac b/configure.ac
  27. index fec27e3f..0719fcd1 100644
  28. --- a/configure.ac
  29. +++ b/configure.ac
  30. @@ -170,21 +170,6 @@ AC_TRY_COMPILE([#include <errno.h>],
  31. AC_MSG_RESULT(yes),
  32. AC_MSG_RESULT(no))
  33. -AC_CHECK_FUNC([pidfd_open], [enable_pidwait=yes], [
  34. - AC_MSG_CHECKING([for __NR_pidfd_open])
  35. - AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  36. -#include <sys/syscall.h>
  37. -#ifndef __NR_pidfd_open
  38. -#error __NR_pidfd_open not defined
  39. -#endif
  40. - ])], [enable_pidwait=yes], [enable_pidwait=no])
  41. - AC_MSG_RESULT([$enable_pidwait])
  42. -])
  43. -if test "$enable_pidwait" = yes; then
  44. - AC_DEFINE([ENABLE_PIDWAIT], [1], [Enable pidwait])
  45. -fi
  46. -AM_CONDITIONAL([BUILD_PIDWAIT], [test x$enable_pidwait = xyes])
  47. -
  48. dnl watch8bit must be before the AC_ARG_WITH set as it sets up ncurses
  49. AC_SUBST([WITH_WATCH8BIT])
  50. AC_ARG_ENABLE([watch8bit],
  51. @@ -321,6 +306,36 @@ AC_ARG_ENABLE([pidof],
  52. )
  53. AM_CONDITIONAL(BUILD_PIDOF, test "x$enable_pidof" = xyes)
  54. +# If pidwait is enabled, we need either pidfd_open() or __NR_pidfd_open need to be defined
  55. +# Cannot use AC_CHECK_FUNC as it (incorrectly) passes with pidfd_open missing
  56. +AC_ARG_ENABLE([pidwait],
  57. + AS_HELP_STRING([--disable-pidwait], [do not build pidwait]),
  58. + [], [
  59. + enable_pidwait=yes
  60. + AC_DEFINE(ENABLE_PIDWAIT, 1, [enable pidwait])
  61. + ]
  62. +)
  63. +AM_CONDITIONAL(BUILD_PIDWAIT, test "x$enable_pidwait" = xyes)
  64. +AC_MSG_CHECKING([for pidfd_open()])
  65. +AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[ [pidfd_open(1,1)]]])],
  66. + have_pidfd_open=yes; AC_MSG_RESULT([yes]) ,
  67. + have_pidfd_open=no; AC_MSG_RESULT([no])
  68. + )
  69. +
  70. +AS_IF([[test "x$enable_pidwait" = xyes -a "x$have_pidfd_open" = xno]],
  71. + AC_MSG_CHECKING([for __NR_pidfd_open])
  72. + AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  73. +#include <sys/syscall.h>
  74. +#ifndef __NR_pidfd_open
  75. +#error __NR_pidfd_open not defined
  76. +#endif
  77. + ])],
  78. + AC_MSG_RESULT([yes]),
  79. + AC_MSG_RESULT([no])
  80. + AC_MSG_ERROR([Neither pidfd_open or __NR_pidfd_open found. Disable pidwait with configure option --disable-pidwait])
  81. + )
  82. + ,[])
  83. +
  84. AC_ARG_ENABLE([kill],
  85. AS_HELP_STRING([--disable-kill], [do not build kill]),
  86. [], [enable_kill=yes]
  87. --
  88. 2.43.0