xref: /original-bsd/local/toolchest/ksh/sh/apollo.c (revision 7c0785ab)
1 /*
2 
3  *      Copyright (c) 1984, 1985, 1986 AT&T
4  *      All Rights Reserved
5 
6  *      THIS IS UNPUBLISHED PROPRIETARY SOURCE
7  *      CODE OF AT&T.
8  *      The copyright notice above does not
9  *      evidence any actual or intended
10  *      publication of such source code.
11 
12  */
13 /*
14  * UNIX ksh
15  *
16  * D. G. Korn
17  * Bell Telephone Laboratories
18  * adapted from APOLLO changes to Bourne Shell
19  *
20  */
21 
22 #include	<invoke.h>
23 #include	<errno.h>
24 #include	<sys/types.h>
25 #include	<sys/stat.h>
26 #include        "defs.h"
27 #include        "brkincr.h"
28 #include	"stak.h"
29 
30 
31 #define PATHLEN	256
32 
33 
34 extern int errno;
35 extern void	failed();
36 extern void	fault();
37 extern char	*fullname();
38 extern void	p_prp();
39 extern void	p_setout();
40 extern char	**setenv();
41 extern void	sync_io();
42 extern MSG	*sysmsg[];
43 
44 
45 static int conlist[] = {0,1,2,3,-1};
46 
exec_here(com)47 int exec_here(com)
48 register char **com;
49 {
50 	register char *prog = com[1];
51 	char **arge;
52 	register char *path;
53 	char iname[PATHLEN];
54 	int (*oldsig)();
55 	int sig;
56 	int xitval;
57 	path = prog;
58 	/* see if program name contains a / */
59 	if(strchr(prog,'/')==0)
60 	{
61 		if((path = fullname(prog))==NULL)
62 			failed(prog,notfound);
63 		endstak(path+strlen(path));
64 	}
65 	arge = setenv();
66 	oldsig = signal(SIGQUIT,SIG_DFL);
67 	sync_io();
68 	errno = 0;
69 	xitval = invokeve(path,INV_WAIT,conlist,com+1,arge);
70 	if(errno==ENOEXEC)
71 	{
72 		char *savcom = com[0];
73 		if(get_shell(path,iname)<0)
74 			failed(badexec);
75 		com[0] = iname;
76 		xitval = invokeve(iname,INV_WAIT,conlist,com,arge);
77 		com[0] = savcom;
78 	}
79 	signal(SIGQUIT,oldsig);
80 	if(xitval>=0)
81 	{
82 		if(sig=(xitval&0177))
83 		{
84 			if(sig==2)
85 				fault(sig);
86 			if(*sysmsg[sig])
87 			{
88 				if(output!=stderr)
89 					p_setout(stderr);
90 				if((states&PROMPT)==0)
91 					p_prp(itos(getpid()),SP);
92 				fputs(sysmsg[sig],output);
93 				newline();
94 				p_setout(output);
95 				xitval = sig|SIGFLG;
96 			}
97 		}
98 		else
99 			xitval >>= 8;
100 	}
101 	else if(xitval == -1)
102 		failed(prog,badexec);
103 	return(xitval);
104 }
105 
106