aboutsummaryrefslogtreecommitdiffstats
path: root/package/portmap/portmap-6.0-0003-NO_FORK-control-usage-of-fork-for-nommu-systems.patch
blob: 41396b6631094073ac1644d8c9e6f6096eddeefc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
From b3afea5757af1a7356ba30d2e0a7d5909ca18121 Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Fri, 19 Nov 2010 23:48:20 -0500
Subject: [PATCH 3/4] NO_FORK: control usage of fork() for nommu systems

nommu systems lack a fork() function, so add a NO_FORK flag to control
its usage.  We don't lose a ton of functionality in doing so, and on an
embedded system, this is OK.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 Makefile     |    5 +++++
 README       |    1 +
 pmap_check.c |    6 ++++--
 portmap.c    |    6 ++++++
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index cfcfdbb..9df5574 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,11 @@ MAN_SED += -e 's/USE_DNS/yes/'
 endif
 endif
 
+# For no-mmu systems, we have to disable the fork() functions.
+ifneq ($(NO_FORK),)
+CPPFLAGS += -DNO_FORK
+endif
+
 # Comment out if your RPC library does not allocate privileged ports for
 # requests from processes with root privilege, or the new portmap will
 # always reject requests to register/unregister services on privileged
diff --git a/README b/README
index e0b561a..bda1707 100644
--- a/README
+++ b/README
@@ -18,6 +18,7 @@ There is no "./configure", just use "make".
 
 Some make variable can be used to control compilation.
 
+ NO_FORK=	  if non-empty, don't use fork (good for nommu systems)
  NO_PIE=	  if non-empty, don't build portmap as a PIE
  NO_TCP_WRAPPER=  if non-empty, don't use tcp_wrappers
  USE_DNS=	  if set, tcp_wrappers can check peers based on hostname
diff --git a/pmap_check.c b/pmap_check.c
index 6b3e490..983414e 100644
--- a/pmap_check.c
+++ b/pmap_check.c
@@ -302,8 +302,10 @@ static void logit(int severity, struct sockaddr_in *addr,
      * getrpcbynumber() or syslog() does its thing.
      */
 
-    if (fork() == 0) {
-
+#ifndef NO_FORK
+    if (fork() == 0)
+#endif
+    {
 	/* Try to map program number to name. */
 
 	if (prognum == 0) {
diff --git a/portmap.c b/portmap.c
index 2a98881..94abc64 100644
--- a/portmap.c
+++ b/portmap.c
@@ -753,6 +755,7 @@ static void callit(struct svc_req *rqstp, SVCXPRT *xprt)
 	if ((pml = find_service(a.rmt_prog, a.rmt_vers,
 	    (u_long)IPPROTO_UDP)) == NULL)
 		return;
+#ifndef NO_FORK
 	/*
 	 * fork a child to do the work.  Parent immediately returns.
 	 * Child exits upon completion.
@@ -763,6 +766,7 @@ static void callit(struct svc_req *rqstp, SVCXPRT *xprt)
 			    a.rmt_prog);
 		return;
 	}
+#endif
 	port = pml->pml_map.pm_port;
 	get_myaddress(&me);
 	me.sin_port = htons(port);
@@ -783,7 +787,9 @@ static void callit(struct svc_req *rqstp, SVCXPRT *xprt)
 		clnt_destroy(client);
 	}
 	(void)close(so);
+#ifndef NO_FORK
 	exit(0);
+#endif
 }
 
 #ifndef IGNORE_SIGCHLD			/* Lionel Cons <cons@dxcern.cern.ch> */
-- 
1.7.3.1