Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!nrl-cmf!mailrus!chianti!grindef
From: grindef@chianti.cc.umich.edu (Wes Craig)
Newsgroups: comp.windows.x
Subject: Cheap hack for starting remote xterms
Message-ID: <560@mailrus.cc.umich.edu>
Date: 8 Jul 88 01:29:25 GMT
Sender: usenet@mailrus.cc.umich.edu
Reply-To: grindef@chianti.cc.umich.edu (Wes Craig)
Organization: University of Michigan Computing Center, Ann Arbor
Lines: 63

Ever wonder about all those rsh's you've been spawning from your
window manager that never go away? We were bored enough one night
to try and do something about 'em. So.... Here's "exeqt.c" - clip out
and enjoy...
####### cut here and at end. Not a shar file. (No kidding, eh?  :) ########
/*
 * This is a grungy little program for executing programs in the
 * background, without use of a control terminal. (In the style
 * of most common daemon processes...) The intent was to create a
 * program one could start via rsh, to initiate xterm sessions,
 * without keeping extra local rsh & remote rshd and shell processes
 * alive.
 *
 * Could be a bit less cavalier about return codes...
 *
 * No warrantees. Use at your own risk. The authors are not responsible
 * in any way for anything at all.
 *   -- Howard Chu & Wes Craig, University of Michigan    July 7 1988
 *	hyc@umix.cc.umich.edu	grindef@umix.cc.umich.edu
 */

#ifndef lint
static char rcsid[] = "$Header: exeqt.c,v 1.2 88/07/07 21:05:39 grindef Exp $";
#endif

#include 
#include 

main(argc, argv)
	int             argc;
	char           *argv[];
{
	char           *path, *getenv(), *index(), *i, j[1024];
	path = getenv("PATH");
	while (path) {
		i = index(path, ':');
		if (i) {
			*i = 0;
			i++;
		}
		strcpy(j, path);
		strcat(j, "/");
		strcat(j, argv[1]);
		if (!access(j, X_OK || F_OK)) {
			if (fork())
				exit();
			else{
				int s;
				for (s=0; s < 10; s++)
					close(s);
				open("/", O_RDONLY);
				dup2(0, 1);
				dup2(0, 2);
				s=open("/dev/tty", O_RDWR);
				ioctl(s, TIOCNOTTY, 0);
				close(s);

				execv(j, &argv[1]);
			}
		}
		path = i;
	}
}
##### cut here too... #####