You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.6 KiB

  1. From f48b5fd8ab03c200eaf5e3a9b03bcd01b2659cf3 Mon Sep 17 00:00:00 2001
  2. From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  3. Date: Thu, 2 Nov 2017 16:00:33 +0100
  4. Subject: [PATCH] Fix compilation on toolchain without prlimit
  5. Some toolchains which are not bionic like uclibc does not support
  6. prlimit or prlimit64. In this case, return an error.
  7. Moreover, if prlimit64 is available, use lxc implementation of prlimit.
  8. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  9. ---
  10. configure.ac | 4 ++++
  11. src/lxc/Makefile.am | 6 ++++++
  12. src/lxc/conf.c | 12 +++++++++---
  13. 3 files changed, 19 insertions(+), 3 deletions(-)
  14. diff --git a/configure.ac b/configure.ac
  15. index 642b78e7e1..63df7466cb 100644
  16. --- a/configure.ac
  17. +++ b/configure.ac
  18. @@ -643,6 +643,10 @@ AC_CHECK_FUNCS([prlimit],
  19. AM_CONDITIONAL(HAVE_PRLIMIT, true)
  20. AC_DEFINE(HAVE_PRLIMIT,1,[Have prlimit]),
  21. AM_CONDITIONAL(HAVE_PRLIMIT, false))
  22. +AC_CHECK_FUNCS([prlimit64],
  23. + AM_CONDITIONAL(HAVE_PRLIMIT64, true)
  24. + AC_DEFINE(HAVE_PRLIMIT64,1,[Have prlimit64]),
  25. + AM_CONDITIONAL(HAVE_PRLIMIT64, false))
  26. # Check for some libraries
  27. AC_SEARCH_LIBS(sem_open, [rt pthread])
  28. diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
  29. index fff32ae4f3..8f0c11ecae 100644
  30. --- a/src/lxc/Makefile.am
  31. +++ b/src/lxc/Makefile.am
  32. @@ -45,7 +45,10 @@ noinst_HEADERS += \
  33. ../include/ifaddrs.h \
  34. ../include/openpty.h \
  35. ../include/lxcmntent.h
  36. +endif
  37. +
  38. if !HAVE_PRLIMIT
  39. +if HAVE_PRLIMIT64
  40. noinst_HEADERS += ../include/prlimit.h
  41. endif
  42. endif
  43. @@ -142,7 +145,10 @@ liblxc_la_SOURCES += \
  44. ../include/ifaddrs.c ../include/ifaddrs.h \
  45. ../include/openpty.c ../include/openpty.h \
  46. ../include/lxcmntent.c ../include/lxcmntent.h
  47. +endif
  48. +
  49. if !HAVE_PRLIMIT
  50. +if HAVE_PRLIMIT64
  51. liblxc_la_SOURCES += ../include/prlimit.c ../include/prlimit.h
  52. endif
  53. endif
  54. diff --git a/src/lxc/conf.c b/src/lxc/conf.c
  55. index 44d9784303..8a66f2d02c 100644
  56. --- a/src/lxc/conf.c
  57. +++ b/src/lxc/conf.c
  58. @@ -100,13 +100,14 @@
  59. #if IS_BIONIC
  60. #include <../include/lxcmntent.h>
  61. -#ifndef HAVE_PRLIMIT
  62. -#include <../include/prlimit.h>
  63. -#endif
  64. #else
  65. #include <mntent.h>
  66. #endif
  67. +#if !defined(HAVE_PRLIMIT) && defined(HAVE_PRLIMIT64)
  68. +#include <../include/prlimit.h>
  69. +#endif
  70. +
  71. lxc_log_define(lxc_conf, lxc);
  72. #if HAVE_LIBCAP
  73. @@ -2457,10 +2458,15 @@ int setup_resource_limits(struct lxc_list *limits, pid_t pid) {
  74. return -1;
  75. }
  76. +#if HAVE_PRLIMIT || HAVE_PRLIMIT64
  77. if (prlimit(pid, resid, &lim->limit, NULL) != 0) {
  78. ERROR("failed to set limit %s: %s", lim->resource, strerror(errno));
  79. return -1;
  80. }
  81. +#else
  82. + ERROR("Cannot set limit %s as prlimit is missing", lim->resource);
  83. + return -1;
  84. +#endif
  85. }
  86. return 0;
  87. }