diff --git a/core/uwsgi.c b/core/uwsgi.c index 9f3d6907..1b01d37e 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -457,6 +457,8 @@ static struct uwsgi_option uwsgi_base_options[] = { {"alarm", required_argument, 0, "create a new alarm, syntax: ", uwsgi_opt_add_string_list, &uwsgi.alarm_list, UWSGI_OPT_MASTER}, {"alarm-freq", required_argument, 0, "tune the anti-loop alam system (default 3 seconds)", uwsgi_opt_set_int, &uwsgi.alarm_freq, 0}, {"alarm-fd", required_argument, 0, "raise the specified alarm when an fd is read for read (by default it reads 1 byte, set 8 for eventfd)", uwsgi_opt_add_string_list, &uwsgi.alarm_fd_list, UWSGI_OPT_MASTER}, + {"alarm-segfault", required_argument, 0, "raise the specified alarm when the segmentation fault handler is executed", uwsgi_opt_add_string_list, &uwsgi.alarm_segfault, UWSGI_OPT_MASTER}, + {"segfault-alarm", required_argument, 0, "raise the specified alarm when the segmentation fault handler is executed", uwsgi_opt_add_string_list, &uwsgi.alarm_segfault, UWSGI_OPT_MASTER}, #ifdef UWSGI_PCRE {"log-alarm", required_argument, 0, "raise the specified alarm when a log line matches the specified regexp, syntax: [,alarm...] ", uwsgi_opt_add_string_list, &uwsgi.alarm_logs_list, UWSGI_OPT_MASTER | UWSGI_OPT_LOG_MASTER}, {"alarm-log", required_argument, 0, "raise the specified alarm when a log line matches the specified regexp, syntax: [,alarm...] ", uwsgi_opt_add_string_list, &uwsgi.alarm_logs_list, UWSGI_OPT_MASTER | UWSGI_OPT_LOG_MASTER}, @@ -1447,15 +1449,28 @@ void uwsgi_backtrace(int depth) { bt_strings = backtrace_symbols(btrace, bt_size); - uwsgi_log("*** backtrace of %d ***\n", (int) getpid()); + struct uwsgi_buffer *ub = uwsgi_buffer_new(uwsgi.page_size); + uwsgi_buffer_append(ub, "*** backtrace of ",17); + uwsgi_buffer_num64(ub, (int64_t) getpid()); + uwsgi_buffer_append(ub, " ***\n", 5); for (i = 0; i < bt_size; i++) { - uwsgi_log("%s\n", bt_strings[i]); + uwsgi_buffer_append(ub, bt_strings[i], strlen(bt_strings[i])); + uwsgi_buffer_append(ub, "\n", 1); } free(btrace); - uwsgi_log("*** end of backtrace ***\n"); + uwsgi_buffer_append(ub, "*** end of backtrace ***\n", 25); + uwsgi_log("%.*s", ub->pos, ub->buf); + + struct uwsgi_string_list *usl = uwsgi.alarm_segfault; + while(usl) { + uwsgi_alarm_trigger(usl->value, ub->buf, ub->pos); + usl = usl->next; + } + + uwsgi_buffer_destroy(ub); #endif } diff --git a/uwsgi.h b/uwsgi.h index d32bfea3..92e3e6f8 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1848,6 +1848,7 @@ struct uwsgi_server { struct uwsgi_string_list *alarm_logs_list; struct uwsgi_alarm_fd *alarm_fds; struct uwsgi_string_list *alarm_fd_list; + struct uwsgi_string_list *alarm_segfault; struct uwsgi_alarm *alarms; struct uwsgi_alarm_instance *alarm_instances; struct uwsgi_alarm_log *alarm_logs;