aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/break.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2016-11-22 14:37:31 +0100
committerSverker Eriksson <[email protected]>2016-11-22 14:37:31 +0100
commit491cd4c0c0a534ab89c3ebb4c413301c91c7167d (patch)
tree8859c2da401857dd280cf79917aea847b630b714 /erts/emulator/beam/break.c
parentdcc7f6b2901a632ff8398c1382c15eaabe562714 (diff)
downloadotp-491cd4c0c0a534ab89c3ebb4c413301c91c7167d.tar.gz
otp-491cd4c0c0a534ab89c3ebb4c413301c91c7167d.tar.bz2
otp-491cd4c0c0a534ab89c3ebb4c413301c91c7167d.zip
erts: Add env variable ERL_CRASH_DUMP_BYTES
to limit crash dump size
Diffstat (limited to 'erts/emulator/beam/break.c')
-rw-r--r--erts/emulator/beam/break.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/erts/emulator/beam/break.c b/erts/emulator/beam/break.c
index 2e8a384dec..33433df68a 100644
--- a/erts/emulator/beam/break.c
+++ b/erts/emulator/beam/break.c
@@ -661,6 +661,26 @@ bin_check(void)
#endif
+static Sint64 crash_dump_limit = ERTS_SINT64_MAX;
+static Sint64 crash_dump_written = 0;
+
+static int crash_dump_limited_writer(void* vfdp, char* buf, size_t len)
+{
+ const char stop_msg[] = "\n=abort: CRASH DUMP SIZE LIMIT REACHED\n";
+
+ crash_dump_written += len;
+ if (crash_dump_written <= crash_dump_limit) {
+ return erts_write_fd(vfdp, buf, len);
+ }
+
+ len -= (crash_dump_written - crash_dump_limit);
+ erts_write_fd(vfdp, buf, len);
+ erts_write_fd(vfdp, (char*)stop_msg, sizeof(stop_msg)-1);
+
+ /* We assume that crash dump was called from erts_exit_vv() */
+ erts_exit_epilogue();
+}
+
/* XXX THIS SHOULD BE IN SYSTEM !!!! */
void
erl_crash_dump_v(char *file, int line, char* fmt, va_list args)
@@ -760,6 +780,21 @@ erl_crash_dump_v(char *file, int line, char* fmt, va_list args)
return;
}
+ crash_dump_limit = ERTS_SINT64_MAX;
+ envsz = sizeof(env);
+ if (erts_sys_getenv__("ERL_CRASH_DUMP_BYTES", env, &envsz) == 0) {
+ Sint64 limit;
+ char* endptr;
+ errno = 0;
+ limit = ErtsStrToSint64(env, &endptr, 10);
+ if (errno == 0 && limit >= 0 && endptr != env && *endptr == 0) {
+ if (limit == 0)
+ return;
+ crash_dump_limit = limit;
+ to = &crash_dump_limited_writer;
+ }
+ }
+
if (erts_sys_getenv__("ERL_CRASH_DUMP",&dumpnamebuf[0],&dumpnamebufsize) != 0)
dumpname = "erl_crash.dump";
else