summaryrefslogtreecommitdiffhomepage
path: root/cli-main.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2016-07-11 23:09:33 +0800
committerMatt Johnston <matt@ucc.asn.au>2016-07-11 23:09:33 +0800
commit8fd720c3e319da773b48c0b191f049dbd1e3c7f0 (patch)
treefb575456077d85b5ace47795cda6edcfa51ef3ca /cli-main.c
parent4f5d0756c240db5b71547e9e0737679a1016d46f (diff)
Improve exit message formatting
Diffstat (limited to 'cli-main.c')
-rw-r--r--cli-main.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/cli-main.c b/cli-main.c
index 787d770..b4404a1 100644
--- a/cli-main.c
+++ b/cli-main.c
@@ -98,29 +98,30 @@ int main(int argc, char ** argv) {
#endif /* DBMULTI stuff */
static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
+ char exitmsg[150];
+ char fullmsg[300];
- char fmtbuf[300];
- char exitmsg[500];
+ /* Note that exit message must be rendered before session cleanup */
+ /* Render the formatted exit message */
+ vsnprintf(exitmsg, sizeof(exitmsg), format, param);
+
+ /* Add the prefix depending on session/auth state */
if (!sessinitdone) {
- snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s",
- format);
+ snprintf(fullmsg, sizeof(fullmsg), "Exited: %s", exitmsg);
} else {
- snprintf(fmtbuf, sizeof(fmtbuf),
+ snprintf(fullmsg, sizeof(fullmsg),
"Connection to %s@%s:%s exited: %s",
cli_opts.username, cli_opts.remotehost,
- cli_opts.remoteport, format);
+ cli_opts.remoteport, exitmsg);
}
- /* Arguments to the exit printout may be unsafe to use after session_cleanup() */
- vsnprintf(exitmsg, sizeof(exitmsg), fmtbuf, param);
-
/* Do the cleanup first, since then the terminal will be reset */
session_cleanup();
/* Avoid printing onwards from terminal cruft */
fprintf(stderr, "\n");
- dropbear_log(LOG_INFO, "%s", exitmsg);;
+ dropbear_log(LOG_INFO, "%s", fullmsg);
exit(exitcode);
}