meta-agl-profile-telematics: recipes-core: systemd: change canbus systemd match regex
[AGL/meta-agl.git] / meta-agl-profile-core / recipes-devtools / rpm / files / 0003-rpmSetCloseOnExec-use-getrlimit.patch
1 From 1f5438d677dca330642158ec0b1c0366c6a65725 Mon Sep 17 00:00:00 2001
2 From: Kir Kolyshkin <kolyshkin@gmail.com>
3 Date: Tue, 29 May 2018 18:09:27 -0700
4 Subject: [PATCH 3/3] rpmSetCloseOnExec: use getrlimit()
5
6 In case /proc is not available to get the actual list of opened fds,
7 we fall back to iterating through the list of all possible fds.
8
9 It is possible that during the course of the program execution the limit
10 on number of open file descriptors might be lowered, so using the
11 current limit, as returned by sysconf(_SC_OPEN_MAX), might omit some
12 fds. Therefore, it is better to use rlim_max from the structure
13 filled in by gertlimit(RLIMIT_NOFILE) to make sure we're checking
14 all fds.
15
16 This slows down the function, but only in the case /proc is not
17 available, which should be rare in practice.
18
19 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
20 (cherry picked from commit 307e28b4cb08b05bc044482058eeebc9f59bb9a9)
21 ---
22  rpmio/rpmio.c | 10 +++++++++-
23  1 file changed, 9 insertions(+), 1 deletion(-)
24
25 diff --git a/rpmio/rpmio.c b/rpmio/rpmio.c
26 index 8148aa2..0698e53 100644
27 --- a/rpmio/rpmio.c
28 +++ b/rpmio/rpmio.c
29 @@ -10,6 +10,7 @@
30  #include <sys/personality.h>
31  #endif
32  #include <sys/utsname.h>
33 +#include <sys/resource.h>
34  
35  #include <rpm/rpmlog.h>
36  #include <rpm/rpmmacro.h>
37 @@ -1495,7 +1496,14 @@ void rpmSetCloseOnExec(void)
38         DIR *dir = opendir("/proc/self/fd");
39         if (dir == NULL) { /* /proc not available */
40                 /* iterate over all possible fds, might be slow */
41 -               int open_max = sysconf(_SC_OPEN_MAX);
42 +               struct rlimit rl;
43 +               int open_max;
44 +
45 +               if (getrlimit(RLIMIT_NOFILE, &rl) == 0 && rl.rlim_max != RLIM_INFINITY)
46 +                       open_max = rl.rlim_max;
47 +               else
48 +                       open_max = sysconf(_SC_OPEN_MAX);
49 +
50                 if (open_max == -1)
51                         open_max = 1024;
52  
53 -- 
54 2.7.4
55