From owner-freebsd-questions Sun Jul 30 23:55:39 2000 Delivered-To: freebsd-questions@freebsd.org Received: from csmail.cscoms.com (mail.cscoms.net [202.183.255.13]) by hub.freebsd.org (Postfix) with ESMTP id F13FF37B579 for ; Sun, 30 Jul 2000 23:55:27 -0700 (PDT) (envelope-from alain@alain.cscoms.net) Received: from alain.cscoms.net (alain [202.183.160.250]) by csmail.cscoms.com (8.10.2/8.10.2) with ESMTP id e6V6v0207167 for ; Mon, 31 Jul 2000 13:57:00 +0700 (ICT) Received: (from alain@localhost) by alain.cscoms.net (8.9.3/8.9.3) id NAA00563 for freebsd-questions@freebsd.org; Mon, 31 Jul 2000 13:55:35 +0700 Date: Mon, 31 Jul 2000 13:55:35 +0700 From: Alain Fauconnet To: freebsd-questions@freebsd.org Subject: Trouble with waitpid(2) porting poppasswd Message-ID: <20000731135534.A552@cscoms.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0.1i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Dear all, I am doing a port of the poppasswd utility (well, one of the numerous versions floating) because I have failed to find a port already available. For those who don't know, it's a daemon replying to requests on port #106 "a la POP" for users to change their passwords. There is a couple of source code samples on Eudora.COM because some versions of Eudora can use it on a server. Now to the point: basically what the daemon does is opening a pair of pseudo-ttys and forking a child. The child: - does a setsid(2) to start a new session - opens the slave part of the pty - does dup2(2) of stdin, stdout and stderr to the slave part of the pty - adjusts some terminal attributes (ICANON, ~ONLCR, ~ECHO...) - changes uid and gid to those of the target user - does execl(2) /usr/bin/passwd. Parent will then feed input to the prompts issued by the passwd command. So far, so good. It works (with some changes from the generic version). When everything is done, the parent does a: wpid = waitpid(pid, &wstat, 0) with pid is the value returned by fork(2). Here is the problem: on FreeBSD, the waitpid(2) hangs forever, although the pid is correct and ps shows the child process with status "SE" (trying to exit and sleeping for <30s). If I add the WNOHANG option, waitpid does return but the returned value is 0. This beats me. Why is waitpid ignoring its child ? I even tried to wait on (-pid) (i.e. waiting on the process group ID) with the same result. Can someone please explain me ? I'm not that much a system programmer (I used to be a long time ago...), more a system administrator ! Oh, by the way, this is on FreeBSD 4.0-RELEASE. Many thanks in advance, _Alain_ -- Alain FAUCONNET Sr. System Administrator CS Internet Co. Ltd. (Shin Corp) - Thailand To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message