What is a good way to do general execs?

Stephen J. Friedl friedl at mtndew.UUCP
Fri Jun 8 12:52:43 AEST 1990


Hi folks,

    We have an application where a background daemon sometimes
has to run a user-supplied program with my arguments, and I am trying
to find a good way to do it.  I don't want to use system(3) because
I want to have control over the fork/exec chain (I catch SIGCLD)
and I just don't like using system anyway.

     Execv works great if I'm running a binary, but it doesn't
like to run shell scripts directly (this is Sys V).  To get around
this I try the following:

	i = 0;
	argv[i++] = "/bin/sh";
	argv[i++] = userprog;
	argv[i++] = myarg_1;
	argv[i++] = myarg_2;
	argv[i++] = you_get_the_idea;
	argv[i++] = NULL;

	execv(argv[1], argv+1);
	execv(argv[0], argv+0);
	error("cannot run userprog %s (errno = %d)", userprog, errno);

     Here I try to run the user's program directly, and if it
doesn't work then I try running with with a shell.  The problem
is that this looks too easy.

     I have thought about this from a handful of directions and
it seems to be workable.  Because the first argument is a
filename, I don't have to worry about the string containing scam
characters such a ! or ; or others.  I provide the other args and
presumably I trust myself :-).

     Does anybody see anything wrong with this? 

     Steve

-- 
Stephen J. Friedl, KA8CMY / Software Consultant / Tustin, CA / 3B2-kind-of-guy
+1 714 544 6561  / friedl at mtndew.Tustin.CA.US  / {uunet,attmail}!mtndew!friedl

"I will defend to your death my right to my opinion" - me



More information about the Comp.unix.wizards mailing list