portmap-6.0-0003-NO_FORK-control-usage-of-fork-for-nommu-systems.patch 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. From b3afea5757af1a7356ba30d2e0a7d5909ca18121 Mon Sep 17 00:00:00 2001
  2. From: Mike Frysinger <vapier@gentoo.org>
  3. Date: Fri, 19 Nov 2010 23:48:20 -0500
  4. Subject: [PATCH 3/4] NO_FORK: control usage of fork() for nommu systems
  5. nommu systems lack a fork() function, so add a NO_FORK flag to control
  6. its usage. We don't lose a ton of functionality in doing so, and on an
  7. embedded system, this is OK.
  8. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
  9. ---
  10. Makefile | 5 +++++
  11. README | 1 +
  12. pmap_check.c | 6 ++++--
  13. portmap.c | 6 ++++++
  14. 4 files changed, 16 insertions(+), 2 deletions(-)
  15. diff --git a/Makefile b/Makefile
  16. index cfcfdbb..9df5574 100644
  17. --- a/Makefile
  18. +++ b/Makefile
  19. @@ -27,6 +27,11 @@ MAN_SED += -e 's/USE_DNS/yes/'
  20. endif
  21. endif
  22. +# For no-mmu systems, we have to disable the fork() functions.
  23. +ifneq ($(NO_FORK),)
  24. +CPPFLAGS += -DNO_FORK
  25. +endif
  26. +
  27. # Comment out if your RPC library does not allocate privileged ports for
  28. # requests from processes with root privilege, or the new portmap will
  29. # always reject requests to register/unregister services on privileged
  30. diff --git a/README b/README
  31. index e0b561a..bda1707 100644
  32. --- a/README
  33. +++ b/README
  34. @@ -18,6 +18,7 @@ There is no "./configure", just use "make".
  35. Some make variable can be used to control compilation.
  36. + NO_FORK= if non-empty, don't use fork (good for nommu systems)
  37. NO_PIE= if non-empty, don't build portmap as a PIE
  38. NO_TCP_WRAPPER= if non-empty, don't use tcp_wrappers
  39. USE_DNS= if set, tcp_wrappers can check peers based on hostname
  40. diff --git a/pmap_check.c b/pmap_check.c
  41. index 6b3e490..983414e 100644
  42. --- a/pmap_check.c
  43. +++ b/pmap_check.c
  44. @@ -302,8 +302,10 @@ static void logit(int severity, struct sockaddr_in *addr,
  45. * getrpcbynumber() or syslog() does its thing.
  46. */
  47. - if (fork() == 0) {
  48. -
  49. +#ifndef NO_FORK
  50. + if (fork() == 0)
  51. +#endif
  52. + {
  53. /* Try to map program number to name. */
  54. if (prognum == 0) {
  55. diff --git a/portmap.c b/portmap.c
  56. index 2a98881..94abc64 100644
  57. --- a/portmap.c
  58. +++ b/portmap.c
  59. @@ -753,6 +755,7 @@ static void callit(struct svc_req *rqstp, SVCXPRT *xprt)
  60. if ((pml = find_service(a.rmt_prog, a.rmt_vers,
  61. (u_long)IPPROTO_UDP)) == NULL)
  62. return;
  63. +#ifndef NO_FORK
  64. /*
  65. * fork a child to do the work. Parent immediately returns.
  66. * Child exits upon completion.
  67. @@ -763,6 +766,7 @@ static void callit(struct svc_req *rqstp, SVCXPRT *xprt)
  68. a.rmt_prog);
  69. return;
  70. }
  71. +#endif
  72. port = pml->pml_map.pm_port;
  73. get_myaddress(&me);
  74. me.sin_port = htons(port);
  75. @@ -783,7 +787,9 @@ static void callit(struct svc_req *rqstp, SVCXPRT *xprt)
  76. clnt_destroy(client);
  77. }
  78. (void)close(so);
  79. +#ifndef NO_FORK
  80. exit(0);
  81. +#endif
  82. }
  83. #ifndef IGNORE_SIGCHLD /* Lionel Cons <cons@dxcern.cern.ch> */
  84. --
  85. 1.7.3.1