comparison cli-main.c @ 1065:23103e1e9548

Fix error handling for dbclient async connect
author Matt Johnston <matt@ucc.asn.au>
date Tue, 03 Mar 2015 20:53:00 +0800
parents 0da8ba489c23
children fb58cf341951
comparison
equal deleted inserted replaced
1064:0b365b6a6f08 1065:23103e1e9548
85 #endif /* DBMULTI stuff */ 85 #endif /* DBMULTI stuff */
86 86
87 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { 87 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
88 88
89 char fmtbuf[300]; 89 char fmtbuf[300];
90 char exitmsg[500];
90 91
91 if (!sessinitdone) { 92 if (!sessinitdone) {
92 snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s", 93 snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s",
93 format); 94 format);
94 } else { 95 } else {
96 "Connection to %s@%s:%s exited: %s", 97 "Connection to %s@%s:%s exited: %s",
97 cli_opts.username, cli_opts.remotehost, 98 cli_opts.username, cli_opts.remotehost,
98 cli_opts.remoteport, format); 99 cli_opts.remoteport, format);
99 } 100 }
100 101
102 /* Arguments to the exit printout may be unsafe to use after session_cleanup() */
103 vsnprintf(exitmsg, sizeof(exitmsg), fmtbuf, param);
104
101 /* Do the cleanup first, since then the terminal will be reset */ 105 /* Do the cleanup first, since then the terminal will be reset */
102 session_cleanup(); 106 session_cleanup();
103 /* Avoid printing onwards from terminal cruft */ 107 /* Avoid printing onwards from terminal cruft */
104 fprintf(stderr, "\n"); 108 fprintf(stderr, "\n");
105 109
106 _dropbear_log(LOG_INFO, fmtbuf, param); 110 dropbear_log(LOG_INFO, "%s", exitmsg);;
107 exit(exitcode); 111 exit(exitcode);
108 } 112 }
109 113
110 static void cli_dropbear_log(int UNUSED(priority), 114 static void cli_dropbear_log(int UNUSED(priority),
111 const char* format, va_list param) { 115 const char* format, va_list param) {