Skip to content

Commit

Permalink
Merge branch 'egil/fix-crashdump-default/OTP-10602' into maint-r15
Browse files Browse the repository at this point in the history
* egil/fix-crashdump-default/OTP-10602:
  erts: Change default of erl_crash.dump
  • Loading branch information
Erlang/OTP committed Dec 6, 2012
2 parents 2eb32af + 7d92675 commit 99e66ce
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 23 deletions.
18 changes: 16 additions & 2 deletions erts/emulator/beam/break.c
Expand Up @@ -657,6 +657,7 @@ erl_crash_dump_v(char *file, int line, char* fmt, va_list args)
char dumpnamebuf[MAXPATHLEN]; char dumpnamebuf[MAXPATHLEN];
char* dumpname; char* dumpname;
int secs; int secs;
int env_erl_crash_dump_seconds_set = 1;


if (ERTS_SOMEONE_IS_CRASH_DUMPING) if (ERTS_SOMEONE_IS_CRASH_DUMPING)
return; return;
Expand All @@ -681,6 +682,8 @@ erl_crash_dump_v(char *file, int line, char* fmt, va_list args)


envsz = sizeof(env); envsz = sizeof(env);
/* ERL_CRASH_DUMP_SECONDS not set /* ERL_CRASH_DUMP_SECONDS not set
* if we have a heart port, break immediately
* otherwise dump crash indefinitely (until crash is complete)
* same as ERL_CRASH_DUMP_SECONDS = 0 * same as ERL_CRASH_DUMP_SECONDS = 0
* - do not write dump * - do not write dump
* - do not set an alarm * - do not set an alarm
Expand All @@ -702,16 +705,27 @@ erl_crash_dump_v(char *file, int line, char* fmt, va_list args)
*/ */


if (erts_sys_getenv__("ERL_CRASH_DUMP_SECONDS", env, &envsz) != 0) { if (erts_sys_getenv__("ERL_CRASH_DUMP_SECONDS", env, &envsz) != 0) {
return; /* break immediately */ env_erl_crash_dump_seconds_set = 0;
secs = -1;
} else { } else {
env_erl_crash_dump_seconds_set = 1;
secs = atoi(env); secs = atoi(env);
} }


if (secs == 0) { if (secs == 0) {
return; return;
} }


erts_sys_prepare_crash_dump(secs); /* erts_sys_prepare_crash_dump returns 1 if heart port is found, otherwise 0
* If we don't find heart (0) and we don't have ERL_CRASH_DUMP_SECONDS set
* we should continue writing a dump
*
* beware: secs -1 means no alarm
*/

if (erts_sys_prepare_crash_dump(secs) && !env_erl_crash_dump_seconds_set ) {
return;
}


if (erts_sys_getenv__("ERL_CRASH_DUMP",&dumpnamebuf[0],&dumpnamebufsize) != 0) if (erts_sys_getenv__("ERL_CRASH_DUMP",&dumpnamebuf[0],&dumpnamebufsize) != 0)
dumpname = "erl_crash.dump"; dumpname = "erl_crash.dump";
Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/beam/sys.h
Expand Up @@ -652,7 +652,7 @@ void erts_sys_schedule_interrupt_timed(int set, erts_short_time_t msec);
void erts_sys_main_thread(void); void erts_sys_main_thread(void);
#endif #endif


extern void erts_sys_prepare_crash_dump(int secs); extern int erts_sys_prepare_crash_dump(int secs);
extern void erts_sys_pre_init(void); extern void erts_sys_pre_init(void);
extern void erl_sys_init(void); extern void erl_sys_init(void);
extern void erl_sys_args(int *argc, char **argv); extern void erl_sys_args(int *argc, char **argv);
Expand Down
52 changes: 36 additions & 16 deletions erts/emulator/sys/unix/sys.c
Expand Up @@ -686,7 +686,7 @@ static RETSIGTYPE break_handler(int sig)
} }
#endif /* 0 */ #endif /* 0 */


static ERTS_INLINE void static ERTS_INLINE int
prepare_crash_dump(int secs) prepare_crash_dump(int secs)
{ {
#define NUFBUF (3) #define NUFBUF (3)
Expand All @@ -698,19 +698,35 @@ prepare_crash_dump(int secs)
Eterm *hp = heap; Eterm *hp = heap;
Eterm list = NIL; Eterm list = NIL;
int heart_fd[2] = {-1,-1}; int heart_fd[2] = {-1,-1};
int has_heart = 0;


UseTmpHeapNoproc(NUFBUF); UseTmpHeapNoproc(NUFBUF);


if (ERTS_PREPARED_CRASH_DUMP) if (ERTS_PREPARED_CRASH_DUMP)
return; /* We have already been called */ return 0; /* We have already been called */


heart_port = erts_get_heart_port(); heart_port = erts_get_heart_port();

/* Positive secs means an alarm must be set
* 0 or negative means no alarm
*
* Set alarm before we try to write to a port
* we don't want to hang on a port write with
* no alarm.
*
*/

if (secs >= 0) {
alarm((unsigned int)secs);
}

if (heart_port) { if (heart_port) {
/* hearts input fd /* hearts input fd
* We "know" drv_data is the in_fd since the port is started with read|write * We "know" drv_data is the in_fd since the port is started with read|write
*/ */
heart_fd[0] = (int)heart_port->drv_data; heart_fd[0] = (int)heart_port->drv_data;
heart_fd[1] = (int)driver_data[heart_fd[0]].ofd; heart_fd[1] = (int)driver_data[heart_fd[0]].ofd;
has_heart = 1;


list = CONS(hp, make_small(8), list); hp += 2; list = CONS(hp, make_small(8), list); hp += 2;


Expand Down Expand Up @@ -752,20 +768,14 @@ prepare_crash_dump(int secs)
erts_silence_warn_unused_result(nice(nice_val)); erts_silence_warn_unused_result(nice(nice_val));
} }


/* Positive secs means an alarm must be set
* 0 or negative means no alarm
*/
if (secs > 0) {
alarm((unsigned int)secs);
}
UnUseTmpHeapNoproc(NUFBUF); UnUseTmpHeapNoproc(NUFBUF);
#undef NUFBUF #undef NUFBUF
return has_heart;
} }


void int erts_sys_prepare_crash_dump(int secs)
erts_sys_prepare_crash_dump(int secs)
{ {
prepare_crash_dump(secs); return prepare_crash_dump(secs);
} }


static ERTS_INLINE void static ERTS_INLINE void
Expand Down Expand Up @@ -802,12 +812,22 @@ static RETSIGTYPE request_break(int signum)
static ERTS_INLINE void static ERTS_INLINE void
sigusr1_exit(void) sigusr1_exit(void)
{ {
/* We do this at interrupt level, since the main reason for char env[21]; /* enough to hold any 64-bit integer */
wanting to generate a crash dump in this way is that the emulator size_t envsz;
is hung somewhere, so it won't be able to poll any flag we set here. int i, secs = -1;
*/
/* We do this at interrupt level, since the main reason for
* wanting to generate a crash dump in this way is that the emulator
* is hung somewhere, so it won't be able to poll any flag we set here.
*/
ERTS_SET_GOT_SIGUSR1; ERTS_SET_GOT_SIGUSR1;
prepare_crash_dump((int)0);
envsz = sizeof(env);
if ((i = erts_sys_getenv_raw("ERL_CRASH_DUMP_SECONDS", env, &envsz)) >= 0) {
secs = i != 0 ? 0 : atoi(env);
}

prepare_crash_dump(secs);
erl_exit(1, "Received SIGUSR1\n"); erl_exit(1, "Received SIGUSR1\n");
} }


Expand Down
4 changes: 2 additions & 2 deletions erts/emulator/sys/vxworks/sys.c
Expand Up @@ -296,10 +296,10 @@ void sys_sigrelease(int sig)
sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)NULL); sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)NULL);
} }


void int
erts_sys_prepare_crash_dump(void) erts_sys_prepare_crash_dump(void)
{ {

return 0;
} }


/* register signal handlers XXX - they don't work, need to find out why... */ /* register signal handlers XXX - they don't work, need to find out why... */
Expand Down
7 changes: 5 additions & 2 deletions erts/emulator/sys/win32/sys.c
Expand Up @@ -255,8 +255,7 @@ void erl_sys_args(int* argc, char** argv)
#endif #endif
} }


void int erts_sys_prepare_crash_dump(int secs)
erts_sys_prepare_crash_dump(int secs)
{ {
Port *heart_port; Port *heart_port;
Eterm heap[3]; Eterm heap[3];
Expand All @@ -271,10 +270,14 @@ erts_sys_prepare_crash_dump(int secs)


/* send to heart port, CMD = 8, i.e. prepare crash dump =o */ /* send to heart port, CMD = 8, i.e. prepare crash dump =o */
erts_write_to_port(NIL, heart_port, list); erts_write_to_port(NIL, heart_port, list);

return 1;
} }


/* Windows - free file descriptors are hopefully available */ /* Windows - free file descriptors are hopefully available */
/* Alarm not used on windows */ /* Alarm not used on windows */

return 0;
} }


static void static void
Expand Down

0 comments on commit 99e66ce

Please sign in to comment.