*BSD News Article 11470


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA1765 ; Tue, 23 Feb 93 14:57:11 EST
Newsgroups: comp.os.386bsd.bugs,comp.unix.bsd
Path: sserve!manuel.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!menudo.uh.edu!uuneo!sugar!karl
From: karl@NeoSoft.com (Karl Lehenbauer)
Subject: Patch to allow arguments on "#!" lines
Organization: NeoSoft Communications Services -- (713) 684-5900
Date: Sat, 20 Feb 1993 02:03:05 GMT
Message-ID: <C2q5p6.9K1@sugar.neosoft.com>
Lines: 97

This patch is from sim@cory.berkeley.edu (Peng-Toh Sim).  It fixes a bug
in 386BSD where arguments on pound-bang lines (#!) were dropped.

After applying this patch, starting a script where the first line reads

#!/usr/local/bin/wishx -f

....will fire up Extended Wish, the X-windows scripting environment based
on the Tool command language (Tcl) and the Tk toolkit.  (See comp.lang.tcl
and ftp to barkley.berkeley.edu for more info.)

*** kern_execve.c.pre-neosoft	Fri Feb 19 14:30:37 1993
--- kern_execve.c	Fri Feb 19 14:30:46 1993
***************
*** 111,116 ****
--- 111,117 ----
  	struct vmspace *vs;
  	caddr_t newframe;
  	char shellname[MAXINTERP];			/* 05 Aug 92*/
+  	char *shellargs;
  	union {
  		char	ex_shell[MAXINTERP];	/* #! and interpreter name */
  		struct	exec ex_hdr;
***************
*** 201,206 ****
--- 202,220 ----
  			*sp++ = *cp++;
  		*sp = '\0';
  
+  		/* copy the args in the #! line */
+  		while (*cp == ' ')
+  		  cp++;
+  		if (*cp) {
+  		    sp++;
+  		    shellargs = sp;
+  		    while (*cp)
+  		      *sp++ = *cp++;
+  		    *sp = '\0';
+  		} else {
+  		    shellargs = 0;
+  		}
+ 
  		indir = 1;              /* indicate this is a script file */
  		vput(ndp->ni_vp);
  		FREE(ndp->ni_pnbuf, M_NAMEI);
***************
*** 274,280 ****
  	/* first, do (shell name if any then) args */
  	if (indir)  {
  		ep = shellname;
! twice:
  		if (ep) {
  			/* did we outgrow initial argbuf, if so, die */
  			if (argbufp >= (char **)stringbuf) {
--- 288,294 ----
  	/* first, do (shell name if any then) args */
  	if (indir)  {
  		ep = shellname;
! thrice:
  		if (ep) {
  			/* did we outgrow initial argbuf, if so, die */
  			if (argbufp >= (char **)stringbuf) {
***************
*** 294,304 ****
  			limitonargs -= stringlen;
  		}
  
  		if (indir) {
  			indir = 0;
  			/* orginal executable is 1st argument with scripts */
  			ep = uap->fname;
! 			goto twice;
  		}
  		/* terminate in case no more args to script */
  		suword(argbufp, 0);
--- 308,324 ----
  			limitonargs -= stringlen;
  		}
  
+ 		if (shellargs) {
+ 		    ep = shellargs;
+ 		    shellargs = 0;
+ 		    goto thrice;
+ 		}
+ 
  		if (indir) {
  			indir = 0;
  			/* orginal executable is 1st argument with scripts */
  			ep = uap->fname;
! 			goto thrice;
  		}
  		/* terminate in case no more args to script */
  		suword(argbufp, 0);
-- 
-- Email info@NeoSoft.com for info on getting interactive Internet access.
"I didn't have time to write a short letter, so I wrote a long one instead."
-- Twain