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