29 #ifdef HAVE_SYS_RESOURCE_H
30 #include <sys/resource.h>
32 #ifdef HAVE_SYS_PRCTL_H
33 #include <sys/prctl.h>
44 SCLogInfo(
"Configuring core dump is not yet supported on Windows.");
50 static bool unlimited =
false;
51 static rlim_t max_dump = 0;
59 if (!unlimited && !max_dump) {
65 dumpable = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
67 SCLogNotice(
"Failed to get dumpable state of process, "
68 "core dumps may not be enabled: %s",
71 else if (unlimited || max_dump > 0) {
73 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
74 SCLogInfo(
"Unable to make this process dumpable.");
92 #ifdef HAVE_SYS_RESOURCE_H
94 const char *dump_size_config = NULL;
95 size_t rlim_size =
sizeof(rlim_t);
97 if (
ConfGet (
"coredump.max-dump", &dump_size_config) == 0) {
101 if (dump_size_config == NULL) {
102 SCLogError(
"malformed value for coredump.max-dump: NULL");
105 if (strcasecmp (dump_size_config,
"unlimited") == 0) {
110 if (strchr (dump_size_config,
'-') != NULL) {
111 SCLogInfo (
"Negative value for core dump size; ignored.");
116 SCLogInfo (
"Unexpected type for rlim_t");
120 if (rlim_size == 8) {
121 max_dump = (rlim_t) strtoull (dump_size_config, NULL, 10);
123 else if (rlim_size == 4) {
124 max_dump = (rlim_t) strtoul (dump_size_config, NULL, 10);
126 if ((errno == ERANGE) || (errno != 0 && max_dump == 0)) {
127 SCLogInfo (
"Illegal core dump size: %s.", dump_size_config);
130 SCLogInfo (
"Max dump is %"PRIu64, (uint64_t) max_dump);
136 struct rlimit new_lim;
139 if (getrlimit (RLIMIT_CORE, &lim) == -1) {
140 SCLogInfo (
"Can't read coredump limit for this process.");
146 if (lim.rlim_max == RLIM_INFINITY && lim.rlim_cur == RLIM_INFINITY) {
151 new_lim.rlim_max = RLIM_INFINITY;
152 new_lim.rlim_cur = RLIM_INFINITY;
153 if (setrlimit (RLIMIT_CORE, &new_lim) == 0) {
157 if (errno == EPERM) {
160 if (lim.rlim_cur < lim.rlim_max) {
161 new_lim.rlim_cur = lim.rlim_max;
162 if (setrlimit (RLIMIT_CORE, & new_lim) == 0) {
163 SCLogInfo (
"Could not set core dump size to unlimited; core dump size set to the hard limit.");
167 SCLogInfo (
"Failed to set core dump size to unlimited or to the hard limit.");
171 SCLogInfo (
"Could not set core dump size to unlimited; it's set to the hard limit.");
178 new_lim.rlim_cur = max_dump;
181 if (lim.rlim_max == RLIM_INFINITY) {
183 new_lim.rlim_max = lim.rlim_max;
185 #ifdef RLIM_SAVED_MAX
186 else if (lim.rlim_max == RLIM_SAVED_MAX) {
188 new_lim.rlim_max = lim.rlim_max;
191 else if (lim.rlim_max < max_dump) {
193 new_lim.rlim_max = max_dump;
197 new_lim.rlim_max = lim.rlim_max;
199 if (setrlimit (RLIMIT_CORE, &new_lim) == 0) {
200 SCLogInfo (
"Core dump setting attempted is %"PRIu64, (uint64_t) new_lim.rlim_cur);
201 struct rlimit actual_lim;
202 if (getrlimit (RLIMIT_CORE, &actual_lim) == 0) {
203 if (actual_lim.rlim_cur == RLIM_INFINITY) {
206 #ifdef RLIM_SAVED_CUR
207 else if (actual_lim.rlim_cur == RLIM_SAVED_CUR) {
208 SCLogInfo (
"Core dump size set to soft limit.");
212 SCLogInfo (
"Core dump size set to %"PRIu64, (uint64_t) actual_lim.rlim_cur);
218 if (errno == EINVAL || errno == EPERM) {
221 if ((lim.rlim_cur < max_dump && lim.rlim_cur < lim.rlim_max)
222 #ifdef RLIM_SAVED_CUR
223 || (lim.rlim_cur == RLIM_SAVED_CUR)
226 new_lim.rlim_max = lim.rlim_max;
227 new_lim.rlim_cur = lim.rlim_max;
228 if (setrlimit (RLIMIT_CORE, &new_lim) == 0) {
229 SCLogInfo(
"Core dump size set to the hard limit.");
236 SCLogInfo(
"Couldn't set coredump size to %s.", dump_size_config);