🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #34501

shell escape (was: Umoria lockup)

#34501
From: to_stdnet
Date: Thu, 13 Oct 1988 10:07
102 lines
3592 bytes
From: dal@syntel.UUCP (Dale Schumacher)

[n62@nikhefh.hep.nl (Klamer Schutte) writes...]
> In article <7168@jhunix.HCF.JHU.EDU> ins_bjjb@jhunix.UUCP (Jared J Brennan) writes:
>>Bugs:
>>
>>   The shell escape function doesn't exactly do a shell escape.  You can't
>>    return to the shell you called Moria from.  You can, however, call a
>>    paging program, a disk formatter, ANOTHER shell, or whatever.
> 
> This is not supposed to be a bug on a ST. The only possibility it has is to
> make a system call which is handled by the shell ( like U*IX system() ) by
> calling a routine who's pointer is in the system variables ( I don't know
> which; sorry )
> 
> A possibility you do have is when moria does a shell escape ( or some other
> programs as well ) is to setenv SHELL to the name of the shell; I set it to
> the name of a small program ( source on request ) which just reads a line
> and executes it by calling system on this line.

The following is (again?) the system() function from dLibs.  It uses the
_shell_p system variable, if possible, and then tries the SHELL environment
variable, followed by trying to forkXXX() the program directly, using the
PATH environment variable to find the program.  As an aside, the 1.2 release
of dLibs is a couple of weeks (if that) away.  This release will coincide
with the release of Sozobon C (public domain, GOOD, and MUCH smaller than GCC).

------------------------------------8<------------------------------------
#include <osbind.h>
#include <stdio.h>
#include <string.h>
#include <basepage.h>

static parse_args(cmdln, argv)
	char *cmdln;
	register char *argv[];
	{
	register char *p;
	static char delim[] = " \t\r\n";

	if(p = strtok(cmdln, delim))
		{
		do
			{
			*argv++ = p;
			}
			while(p = strtok(NULL, delim));
		}
	}

int system(command)
	register char *command;
	{
	register char *p;
	register int (*shell)();
	char rv[2];
	char cmdln[1024];
	char *args[64];
	char *getenv();

	if(!command)
		return(ERROR);

	/* get _shell_p value */
	p = (char *) Super(0L);
	shell = (int (*)()) *((long *) 0x4F6L);
	Super(p);

	/* validate _shell_p */
	if((shell)				/* Shell available. */
	&& (((long) shell) < ((long) _base))	/* Reasonable shell pointer. */
	&& (strncmp(shell, "PATH", 4)))		/* Not corrupted */
		{
		return((*shell)(command));	/* execute the command */
		}

	strcpy(cmdln, command);		/* copy the command line for parsing */

	if((p = getenv("SHELL")) && (*p))	/* Can I use SHELL variable? */
		{
		args[0] = p;
		parse_args(cmdln, (args + 1));
		forkvpe(p, args, NULL);
		wait(&rv);
		return((rv[1] == 0) ? rv[0] : rv[1]);
		}

	/* tokenize the command line and execute a program found on the path */
	parse_args(cmdln, args);
	p = args[0];
	forkvpe(p, args, NULL);
	wait(&rv);
	return((rv[1] == 0) ? rv[0] : rv[1]);
	}
------------------------------------8<------------------------------------

--
      Dale Schumacher                         399 Beacon Ave.
      (alias: Dalnefre')                      St. Paul, MN  55104
      ...pwcs!stag!syntel!dal                 United States of America
    "It's not reality that's important, but how you perceive things."
 
Technical Details
Message-ID: <620@stag.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!uwvax!umn-d-ub!nic.MR.NET!shamash!nis!ems!pwcs!stag!daemon

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!uwvax!umn-d-ub!nic.MR.NET!shamash!nis!ems!pwcs!stag!daemon
From: to_stdnet@stag.UUCP
Newsgroups: comp.sys.atari.st
Subject: shell escape (was: Umoria lockup)
Message-ID: <620@stag.UUCP>
Date: 13 Oct 88 10:07:47 GMT
Sender: daemon@stag.UUCP
Lines: 102