From owner-freebsd-questions Fri Dec 27 3: 5:48 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EB9D537B401 for ; Fri, 27 Dec 2002 03:05:46 -0800 (PST) Received: from east.ath.cx (catv-50622a7a.nyircatv.broadband.hu [80.98.42.122]) by mx1.FreeBSD.org (Postfix) with ESMTP id CBC9443EE1 for ; Fri, 27 Dec 2002 03:05:44 -0800 (PST) (envelope-from witch@kronos.HomeUnix.com) X-Complaints-To: abuse@kronos.homeunix.com X-SMTP-Authenticated: CRAM-MD5 X-message-flag: Ditch the crappy mail client and get a real one! Received: from slave.east.ath.cx (fua484n4l6rbms2k@slave.kronos.homeunix.com [10.1.1.1]) (authenticated bits=0) by east.ath.cx (8.12.6/8.12.6) with ESMTP id gBRB5gAV069346 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Fri, 27 Dec 2002 12:05:43 +0100 (CET) (envelope-from witch@slave.east.ath.cx) Received: from slave.east.ath.cx (localhost [127.0.0.1]) by slave.east.ath.cx (8.12.6/8.12.6) with ESMTP id gBRB5g51022061 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Fri, 27 Dec 2002 12:05:42 +0100 (CET) (envelope-from witch@slave.east.ath.cx) Received: (from witch@localhost) by slave.east.ath.cx (8.12.6/8.12.6/Submit) id gBRB5bi6022015; Fri, 27 Dec 2002 12:05:37 +0100 (CET) Date: Fri, 27 Dec 2002 12:05:36 +0100 (CET) From: Andrew Prewett Reply-To: Andrew Prewett To: freebsd-questions@freebsd.org Subject: RE: Problems with a C application that changes users and run 'screen -x' In-Reply-To: Message-ID: <20021227112521.O16052@slave.east.ath.cx> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Dec 20 Paul Everlund wrote: > On Fri, 20 Dec 2002, Paul Everlund wrote: > > Found an error in my reply... > > > On Fri, 20 Dec 2002, Aaron Burke wrote: > > > [big snip] > > > I think execlp is writing over your current process. So first your > > process is exchanged with ppp, then ppp is exchanged with screen. You > > have to make a copy of your current process, a.out, by using fork, and > > then exchange the process image in this copy using execlp. > > Correction... Your a.out process is replaced with ppp, then nothing > else happens, as screen never is called du to the replacement. the process image replaced with "su" and the second execlp() newer called if the first execlp() call succeeds... (which won't) else replaced with "screen" if the second execlp() call succeeds (which won't)... (if exec??() returns, then an error has occured) Here is some code for the OP to start with: #include #include #include #include #include int main(void) { pid_t pid; int s; switch (pid = fork()) { case -1: perror("fork"); exit(EX_OSERR); case 0: /* I'm the child. */ execlp("/usr/bin/su", "/usr/bin/su", "arg1", "arg2", "argn", NULL); /* kaboom */ /* perror("execlp"); */ exit(EX_SOFTWARE); default: /* I'm the parent */ waitpid(pid, &s, 0); break; } return WEXITSTATUS(s); } -andrew To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message