Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Dec 2002 12:05:36 +0100 (CET)
From:      Andrew Prewett <andrew@kronos.HomeUnix.com>
To:        freebsd-questions@freebsd.org
Subject:   RE: Problems with a C application that changes users and run 'screen -x'
Message-ID:  <20021227112521.O16052@slave.east.ath.cx>
In-Reply-To: <Pine.GSO.4.44.0212201120540.19980-100000@kvist.cs.umu.se>
References:  <Pine.GSO.4.44.0212201120540.19980-100000@kvist.cs.umu.se>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <sysexits.h>

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021227112521.O16052>