debuggerd: report crashes even when out of file descriptors.
Use nasty clone hacks to let us close random file descriptors to be
able to connect to debuggerd when the fd table is full.
Bug: http://b/32013594
Test: crasher exhaustfd-SIGSEGV
Change-Id: I47772e9a5994da4473bd935b105d9c36827c017a
diff --git a/debuggerd/crasher.cpp b/debuggerd/crasher.cpp
index 7d3509c..cfcc26e 100644
--- a/debuggerd/crasher.cpp
+++ b/debuggerd/crasher.cpp
@@ -1,5 +1,6 @@
#include <assert.h>
#include <errno.h>
+#include <fcntl.h>
#include <pthread.h>
#include <sched.h>
#include <signal.h>
@@ -141,7 +142,13 @@
{
fprintf(stderr, "%s: init pid=%d tid=%d\n", __progname, getpid(), gettid());
- if (!strncmp(arg, "thread-", strlen("thread-"))) {
+ if (!strncmp(arg, "exhaustfd-", strlen("exhaustfd-"))) {
+ errno = 0;
+ while (errno != EMFILE) {
+ open("/dev/null", O_RDONLY);
+ }
+ return do_action(arg + strlen("exhaustfd-"));
+ } else if (!strncmp(arg, "thread-", strlen("thread-"))) {
return do_action_on_thread(arg + strlen("thread-"));
} else if (!strcmp(arg, "SIGSEGV-non-null")) {
sigsegv_non_null();
@@ -208,6 +215,8 @@
fprintf(stderr, " SIGTRAP cause a SIGTRAP\n");
fprintf(stderr, "prefix any of the above with 'thread-' to not run\n");
fprintf(stderr, "on the process' main thread.\n");
+ fprintf(stderr, "prefix any of the above with 'exhaustfd-' to exhaust\n");
+ fprintf(stderr, "all available file descriptors before crashing.\n");
return EXIT_SUCCESS;
}