Add code to check and report our stack usage if HUSH_STACKCHECK is defined.

This only covers exec'd instances of hush (run by the user, or by re_execute_shell), not the forked, pre-exec part.
This commit is contained in:
Stephen Heumann 2014-12-02 20:53:45 -06:00
parent 7b989fb6bc
commit e97a83d054

View File

@ -884,6 +884,9 @@ struct lineedit_statics *lineedit_ptr_to_statics;
char *hush_exec_path;
#ifdef __GNO__
static bool stackcheck = 0;
#endif
/* Function prototypes for builtins */
static int builtin_cd(char **argv) FAST_FUNC;
@ -1403,6 +1406,8 @@ void _exit_wrapper(int status) {
if (getpid() == G.last_execed_pid) {
// We're the root shell or one that's been exec'd...
// Call regular _exit()
if (stackcheck)
fprintf(stderr, "hush stack usage (pid %i): %i bytes\n", getpid(), _endStackCheck());
_exit(status);
} else {
// We're a forked child.
@ -8202,6 +8207,12 @@ int hush_main(int argc, char **argv)
struct variable *cur_var;
struct variable *shell_ver;
#if defined(__GNO__) && HUSH_DEBUG
if (getenv("HUSH_STACKCHECK") != NULL) {
_beginStackCheck();
stackcheck = 1;
}
#endif
INIT_G();
hush_exec_path = get_exec_path();
#ifdef __GNO__