27 #define _FILE_OFFSET_BITS 64
30 #ifdef HAVE_SYS_RESOURCE_H
31 #include <sys/resource.h>
33 #ifdef HAVE_SYS_PRCTL_H
34 #include <sys/prctl.h>
45 SCLogInfo(
"Configuring core dump is not yet supported on Windows.");
51 static bool unlimited =
false;
52 static rlim_t max_dump = 0;
60 if (!unlimited && !max_dump) {
66 dumpable = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
68 SCLogNotice(
"Failed to get dumpable state of process, "
69 "core dumps may not be enabled: %s",
72 else if (unlimited || max_dump > 0) {
74 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
75 SCLogInfo(
"Unable to make this process dumpable.");
93 #ifdef HAVE_SYS_RESOURCE_H
95 const char *dump_size_config = NULL;
96 size_t rlim_size =
sizeof(rlim_t);
98 if (
ConfGet (
"coredump.max-dump", &dump_size_config) == 0) {
102 if (dump_size_config == NULL) {
103 SCLogError(
"malformed value for coredump.max-dump: NULL");
106 if (strcasecmp (dump_size_config,
"unlimited") == 0) {
111 if (strchr (dump_size_config,
'-') != NULL) {
112 SCLogInfo (
"Negative value for core dump size; ignored.");
117 SCLogInfo (
"Unexpected type for rlim_t");
121 if (rlim_size == 8) {
122 max_dump = (rlim_t) strtoull (dump_size_config, NULL, 10);
124 else if (rlim_size == 4) {
125 max_dump = (rlim_t) strtoul (dump_size_config, NULL, 10);
127 if ((errno == ERANGE) || (errno != 0 && max_dump == 0)) {
128 SCLogInfo (
"Illegal core dump size: %s.", dump_size_config);
131 SCLogInfo (
"Max dump is %"PRIu64, (uint64_t) max_dump);
137 struct rlimit new_lim;
140 if (getrlimit (RLIMIT_CORE, &lim) == -1) {
141 SCLogInfo (
"Can't read coredump limit for this process.");
147 if (lim.rlim_max == RLIM_INFINITY && lim.rlim_cur == RLIM_INFINITY) {
152 new_lim.rlim_max = RLIM_INFINITY;
153 new_lim.rlim_cur = RLIM_INFINITY;
154 if (setrlimit (RLIMIT_CORE, &new_lim) == 0) {
158 if (errno == EPERM) {
161 if (lim.rlim_cur < lim.rlim_max) {
162 new_lim.rlim_cur = lim.rlim_max;
163 if (setrlimit (RLIMIT_CORE, & new_lim) == 0) {
164 SCLogInfo (
"Could not set core dump size to unlimited; core dump size set to the hard limit.");
168 SCLogInfo (
"Failed to set core dump size to unlimited or to the hard limit.");
172 SCLogInfo (
"Could not set core dump size to unlimited; it's set to the hard limit.");
179 new_lim.rlim_cur = max_dump;
182 if (lim.rlim_max == RLIM_INFINITY) {
184 new_lim.rlim_max = lim.rlim_max;
186 #ifdef RLIM_SAVED_MAX
187 else if (lim.rlim_max == RLIM_SAVED_MAX) {
189 new_lim.rlim_max = lim.rlim_max;
192 else if (lim.rlim_max < max_dump) {
194 new_lim.rlim_max = max_dump;
198 new_lim.rlim_max = lim.rlim_max;
200 if (setrlimit (RLIMIT_CORE, &new_lim) == 0) {
201 SCLogInfo (
"Core dump setting attempted is %"PRIu64, (uint64_t) new_lim.rlim_cur);
202 struct rlimit actual_lim;
203 if (getrlimit (RLIMIT_CORE, &actual_lim) == 0) {
204 if (actual_lim.rlim_cur == RLIM_INFINITY) {
207 #ifdef RLIM_SAVED_CUR
208 else if (actual_lim.rlim_cur == RLIM_SAVED_CUR) {
209 SCLogInfo (
"Core dump size set to soft limit.");
213 SCLogInfo (
"Core dump size set to %"PRIu64, (uint64_t) actual_lim.rlim_cur);
219 if (errno == EINVAL || errno == EPERM) {
222 if ((lim.rlim_cur < max_dump && lim.rlim_cur < lim.rlim_max)
223 #ifdef RLIM_SAVED_CUR
224 || (lim.rlim_cur == RLIM_SAVED_CUR)
227 new_lim.rlim_max = lim.rlim_max;
228 new_lim.rlim_cur = lim.rlim_max;
229 if (setrlimit (RLIMIT_CORE, &new_lim) == 0) {
230 SCLogInfo(
"Core dump size set to the hard limit.");
237 SCLogInfo(
"Couldn't set coredump size to %s.", dump_size_config);