Mercurial > dropbear
comparison svr-chansession.c @ 1625:79eef94ccea9
Split ChanType closehandler() and cleanup() so that dbclient doesn't
lose exit status messages
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 14 Nov 2018 22:57:56 +0800 |
parents | 47f36d8565cf |
children | 592a18dac250 |
comparison
equal
deleted
inserted
replaced
1624:1f3fb83b0524 | 1625:79eef94ccea9 |
---|---|
49 static int sessionwinchange(const struct ChanSess *chansess); | 49 static int sessionwinchange(const struct ChanSess *chansess); |
50 static void execchild(const void *user_data_chansess); | 50 static void execchild(const void *user_data_chansess); |
51 static void addchildpid(struct ChanSess *chansess, pid_t pid); | 51 static void addchildpid(struct ChanSess *chansess, pid_t pid); |
52 static void sesssigchild_handler(int val); | 52 static void sesssigchild_handler(int val); |
53 static void closechansess(const struct Channel *channel); | 53 static void closechansess(const struct Channel *channel); |
54 static void cleanupchansess(const struct Channel *channel); | |
54 static int newchansess(struct Channel *channel); | 55 static int newchansess(struct Channel *channel); |
55 static void chansessionrequest(struct Channel *channel); | 56 static void chansessionrequest(struct Channel *channel); |
56 static int sesscheckclose(const struct Channel *channel); | 57 static int sesscheckclose(const struct Channel *channel); |
57 | 58 |
58 static void send_exitsignalstatus(const struct Channel *channel); | 59 static void send_exitsignalstatus(const struct Channel *channel); |
67 "session", /* name */ | 68 "session", /* name */ |
68 newchansess, /* inithandler */ | 69 newchansess, /* inithandler */ |
69 sesscheckclose, /* checkclosehandler */ | 70 sesscheckclose, /* checkclosehandler */ |
70 chansessionrequest, /* reqhandler */ | 71 chansessionrequest, /* reqhandler */ |
71 closechansess, /* closehandler */ | 72 closechansess, /* closehandler */ |
73 cleanupchansess /* cleanup */ | |
72 }; | 74 }; |
73 | 75 |
74 /* required to clear environment */ | 76 /* required to clear environment */ |
75 extern char** environ; | 77 extern char** environ; |
76 | 78 |
89 } | 91 } |
90 | 92 |
91 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { | 93 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { |
92 unsigned int i; | 94 unsigned int i; |
93 struct exitinfo *ex = NULL; | 95 struct exitinfo *ex = NULL; |
94 TRACE(("sigchld handler: pid %d", pid)) | 96 TRACE(("svr_chansess_checksignal : pid %d", pid)) |
95 | 97 |
96 ex = NULL; | 98 ex = NULL; |
97 /* find the corresponding chansess */ | 99 /* find the corresponding chansess */ |
98 for (i = 0; i < svr_ses.childpidsize; i++) { | 100 for (i = 0; i < svr_ses.childpidsize; i++) { |
99 if (svr_ses.childpids[i].pid == pid) { | 101 if (svr_ses.childpids[i].pid == pid) { |
283 li = login_alloc_entry(chansess->pid, ses.authstate.username, | 285 li = login_alloc_entry(chansess->pid, ses.authstate.username, |
284 svr_ses.remotehost, chansess->tty); | 286 svr_ses.remotehost, chansess->tty); |
285 return li; | 287 return li; |
286 } | 288 } |
287 | 289 |
290 /* send exit status message before the channel is closed */ | |
291 static void closechansess(const struct Channel *channel) { | |
292 struct ChanSess *chansess; | |
293 | |
294 TRACE(("enter closechansess")) | |
295 | |
296 chansess = (struct ChanSess*)channel->typedata; | |
297 | |
298 if (chansess == NULL) { | |
299 TRACE(("leave closechansess: chansess == NULL")) | |
300 return; | |
301 } | |
302 | |
303 send_exitsignalstatus(channel); | |
304 TRACE(("leave closechansess")) | |
305 } | |
306 | |
288 /* clean a session channel */ | 307 /* clean a session channel */ |
289 static void closechansess(const struct Channel *channel) { | 308 static void cleanupchansess(const struct Channel *channel) { |
290 | 309 |
291 struct ChanSess *chansess; | 310 struct ChanSess *chansess; |
292 unsigned int i; | 311 unsigned int i; |
293 struct logininfo *li; | 312 struct logininfo *li; |
294 | 313 |
298 | 317 |
299 if (chansess == NULL) { | 318 if (chansess == NULL) { |
300 TRACE(("leave closechansess: chansess == NULL")) | 319 TRACE(("leave closechansess: chansess == NULL")) |
301 return; | 320 return; |
302 } | 321 } |
303 | |
304 send_exitsignalstatus(channel); | |
305 | 322 |
306 m_free(chansess->cmd); | 323 m_free(chansess->cmd); |
307 m_free(chansess->term); | 324 m_free(chansess->term); |
308 | 325 |
309 #if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT | 326 #if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT |