All the setrlimit calls have been moved to a new setup_limits function
that is called regardless the presence of the -U and -G options.
The new RLIMIT_CORE limit is set to allow the core dump to be written
in case of a crash (for more details: man core).
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
src/main.c | 32 ++++++++++++++++++++------------
1 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/src/main.c b/src/main.c
index dea78f7..67b3d3c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1323,19 +1323,10 @@ static void setup_host_name(void)
uuid, name.nodename);
}
-static void setup_groups(void)
+static void setup_limits(void)
{
- int rv, i, j, h;
- int pngroups, sngroups, ngroups_max;
- gid_t *pgroup, *sgroup;
- struct rlimit rlim;
-
- if (!com.uname || !com.gname)
- return;
-
- /* before switching to a different user/group we must configure
- the limits for memlock and rtprio */
- rlim.rlim_cur = rlim.rlim_max= -1;
+ int rv;
+ struct rlimit rlim = { .rlim_cur = -1, .rlim_max= -1 };
rv = setrlimit(RLIMIT_MEMLOCK, &rlim);
if (rv < 0) {
@@ -1349,6 +1340,22 @@ static void setup_groups(void)
exit(EXIT_FAILURE);
}
+ rv = setrlimit(RLIMIT_CORE, &rlim);
+ if (rv < 0) {
+ log_error("cannot set the limits for core dumps %i", errno);
+ exit(EXIT_FAILURE);
+ }
+}
+
+static void setup_groups(void)
+{
+ int rv, i, j, h;
+ int pngroups, sngroups, ngroups_max;
+ gid_t *pgroup, *sgroup;
+
+ if (!com.uname || !com.gname)
+ return;
+
ngroups_max = sysconf(_SC_NGROUPS_MAX);
if (ngroups_max < 0) {
log_error("cannot get the max number of groups %i", errno);
@@ -1553,6 +1560,7 @@ static int do_daemon(void)
}
}
+ setup_limits();
setup_helper();
/* main task never does disk io, so we don't really need to set
--
1.7.1