comparison svr-chansession.c @ 609:306a907d23e7

Avoid segfault when handling childpid race
author Matt Johnston <matt@ucc.asn.au>
date Thu, 31 Mar 2011 14:42:11 +0000
parents 810dfc792ca9
children 818108bf7749 67fbba2c2a85
comparison
equal deleted inserted replaced
608:4fbf9a7556ed 609:306a907d23e7
690 690
691 ses.maxfd = MAX(ses.maxfd, channel->writefd); 691 ses.maxfd = MAX(ses.maxfd, channel->writefd);
692 ses.maxfd = MAX(ses.maxfd, channel->readfd); 692 ses.maxfd = MAX(ses.maxfd, channel->readfd);
693 ses.maxfd = MAX(ses.maxfd, channel->errfd); 693 ses.maxfd = MAX(ses.maxfd, channel->errfd);
694 694
695 sleep(1);
696
695 addchildpid(chansess, chansess->pid); 697 addchildpid(chansess, chansess->pid);
696 698
697 if (svr_ses.lastexit.exitpid != -1) { 699 if (svr_ses.lastexit.exitpid != -1) {
698 unsigned int i; 700 unsigned int i;
699 TRACE(("parent side: lastexitpid is %d", svr_ses.lastexit.exitpid)) 701 TRACE(("parent side: lastexitpid is %d", svr_ses.lastexit.exitpid))
703 for (i = 0; i < svr_ses.childpidsize; i++) { 705 for (i = 0; i < svr_ses.childpidsize; i++) {
704 if (svr_ses.childpids[i].pid == svr_ses.lastexit.exitpid) { 706 if (svr_ses.childpids[i].pid == svr_ses.lastexit.exitpid) {
705 TRACE(("found match for lastexitpid")) 707 TRACE(("found match for lastexitpid"))
706 svr_ses.childpids[i].chansess->exit = svr_ses.lastexit; 708 svr_ses.childpids[i].chansess->exit = svr_ses.lastexit;
707 svr_ses.lastexit.exitpid = -1; 709 svr_ses.lastexit.exitpid = -1;
710 break;
708 } 711 }
709 } 712 }
710 } 713 }
711 714
712 TRACE(("leave noptycommand")) 715 TRACE(("leave noptycommand"))