26 #define _FILE_OFFSET_BITS 64
29 #ifdef HAVE_SYS_RESOURCE_H
30 #include <sys/resource.h>
40 SCLogInfo(
"Configuring core dump is not yet supported on Windows.");
46 static bool unlimited =
false;
47 static rlim_t max_dump = 0;
55 if (!unlimited && !max_dump) {
61 dumpable = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
63 SCLogNotice(
"Failed to get dumpable state of process, "
64 "core dumps may not be abled: %s", strerror(errno));
66 else if (unlimited || max_dump > 0) {
68 if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
69 SCLogInfo(
"Unable to make this process dumpable.");
87 #ifdef HAVE_SYS_RESOURCE_H
89 const char *dump_size_config = NULL;
90 size_t rlim_size =
sizeof(rlim_t);
92 if (
ConfGet (
"coredump.max-dump", &dump_size_config) == 0) {
96 if (dump_size_config == NULL) {
100 if (strcasecmp (dump_size_config,
"unlimited") == 0) {
105 if (strchr (dump_size_config,
'-') != NULL) {
106 SCLogInfo (
"Negative value for core dump size; ignored.");
111 SCLogInfo (
"Unexpected type for rlim_t");
115 if (rlim_size == 8) {
116 max_dump = (rlim_t) strtoull (dump_size_config, NULL, 10);
118 else if (rlim_size == 4) {
119 max_dump = (rlim_t) strtoul (dump_size_config, NULL, 10);
121 if ((errno == ERANGE) || (errno != 0 && max_dump == 0)) {
122 SCLogInfo (
"Illegal core dump size: %s.", dump_size_config);
125 SCLogInfo (
"Max dump is %"PRIu64, (uint64_t) max_dump);
131 struct rlimit new_lim;
134 if (getrlimit (RLIMIT_CORE, &lim) == -1) {
135 SCLogInfo (
"Can't read coredump limit for this process.");
141 if (lim.rlim_max == RLIM_INFINITY && lim.rlim_cur == RLIM_INFINITY) {
146 new_lim.rlim_max = RLIM_INFINITY;
147 new_lim.rlim_cur = RLIM_INFINITY;
148 if (setrlimit (RLIMIT_CORE, &new_lim) == 0) {
152 if (errno == EPERM) {
155 if (lim.rlim_cur < lim.rlim_max) {
156 new_lim.rlim_cur = lim.rlim_max;
157 if (setrlimit (RLIMIT_CORE, & new_lim) == 0) {
158 SCLogInfo (
"Could not set core dump size to unlimited; core dump size set to the hard limit.");
162 SCLogInfo (
"Failed to set core dump size to unlimited or to the hard limit.");
166 SCLogInfo (
"Could not set core dump size to unlimited; it's set to the hard limit.");
173 new_lim.rlim_cur = max_dump;
176 if (lim.rlim_max == RLIM_INFINITY) {
178 new_lim.rlim_max = lim.rlim_max;
180 #ifdef RLIM_SAVED_MAX
181 else if (lim.rlim_max == RLIM_SAVED_MAX) {
183 new_lim.rlim_max = lim.rlim_max;
186 else if (lim.rlim_max < max_dump) {
188 new_lim.rlim_max = max_dump;
192 new_lim.rlim_max = lim.rlim_max;
194 if (setrlimit (RLIMIT_CORE, &new_lim) == 0) {
195 SCLogInfo (
"Core dump setting attempted is %"PRIu64, (uint64_t) new_lim.rlim_cur);
196 struct rlimit actual_lim;
197 if (getrlimit (RLIMIT_CORE, &actual_lim) == 0) {
198 if (actual_lim.rlim_cur == RLIM_INFINITY) {
201 #ifdef RLIM_SAVED_CUR
202 else if (actual_lim.rlim_cur == RLIM_SAVED_CUR) {
203 SCLogInfo (
"Core dump size set to soft limit.");
207 SCLogInfo (
"Core dump size set to %"PRIu64, (uint64_t) actual_lim.rlim_cur);
213 if (errno == EINVAL || errno == EPERM) {
216 if ((lim.rlim_cur < max_dump && lim.rlim_cur < lim.rlim_max)
217 #ifdef RLIM_SAVED_CUR
218 || (lim.rlim_cur == RLIM_SAVED_CUR)
221 new_lim.rlim_max = lim.rlim_max;
222 new_lim.rlim_cur = lim.rlim_max;
223 if (setrlimit (RLIMIT_CORE, &new_lim) == 0) {
224 SCLogInfo(
"Core dump size set to the hard limit.");
231 SCLogInfo (
"Could't set coredump size to %s.", dump_size_config);