summaryrefslogtreecommitdiffstats
path: root/bin/sh/exec.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-09-01 10:22:36 +0000
committerpeter <peter@FreeBSD.org>1996-09-01 10:22:36 +0000
commit5195be912eb257c05a0c97e561e72f01af2583ff (patch)
treee47ab3981b495c675a987dd1e943d1f4c823f314 /bin/sh/exec.c
parent2fc7d7d1fa299368ccdddede67b31695266698bd (diff)
downloadFreeBSD-src-5195be912eb257c05a0c97e561e72f01af2583ff.zip
FreeBSD-src-5195be912eb257c05a0c97e561e72f01af2583ff.tar.gz
Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is a
merge of parallel duplicate work by Steve Price and myself. :-] There are some changes to the build that are my fault... mkinit.c was trying (poorly) to duplicate some of the work that make(1) is designed to do. The Makefile hackery is my fault too, the depend list was incomplete because of some explicit OBJS+= entries, so mkdep wasn't picking up their source file #includes. This closes a pile of /bin/sh PR's, but not all of them.. Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter
Diffstat (limited to 'bin/sh/exec.c')
-rw-r--r--bin/sh/exec.c89
1 files changed, 48 insertions, 41 deletions
diff --git a/bin/sh/exec.c b/bin/sh/exec.c
index e9061e8..4b6b1b4 100644
--- a/bin/sh/exec.c
+++ b/bin/sh/exec.c
@@ -33,13 +33,20 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: exec.c,v 1.3 1994/09/24 02:57:32 davidg Exp $
+ * $Id: exec.c,v 1.4 1995/05/30 00:07:12 rgrimes Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 5/31/93";
+static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
#endif /* not lint */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+
/*
* When commands are first encountered, they are entered in a hash table.
* This ensures that a full path search will not have to be done for them
@@ -66,11 +73,8 @@ static char sccsid[] = "@(#)exec.c 8.1 (Berkeley) 5/31/93";
#include "error.h"
#include "init.h"
#include "mystring.h"
+#include "show.h"
#include "jobs.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
#define CMDTABLESIZE 31 /* should be prime */
@@ -91,21 +95,12 @@ STATIC struct tblentry *cmdtable[CMDTABLESIZE];
STATIC int builtinloc = -1; /* index in path of %builtin, or -1 */
-#ifdef __STDC__
-STATIC void tryexec(char *, char **, char **);
-STATIC void execinterp(char **, char **);
-STATIC void printentry(struct tblentry *, int);
-STATIC void clearcmdentry(int);
-STATIC struct tblentry *cmdlookup(char *, int);
-STATIC void delete_cmd_entry(void);
-#else
-STATIC void tryexec();
-STATIC void execinterp();
-STATIC void printentry();
-STATIC void clearcmdentry();
-STATIC struct tblentry *cmdlookup();
-STATIC void delete_cmd_entry();
-#endif
+STATIC void tryexec __P((char *, char **, char **));
+STATIC void execinterp __P((char **, char **));
+STATIC void printentry __P((struct tblentry *, int));
+STATIC void clearcmdentry __P((int));
+STATIC struct tblentry *cmdlookup __P((char *, int));
+STATIC void delete_cmd_entry __P((void));
@@ -118,7 +113,8 @@ void
shellexec(argv, envp, path, index)
char **argv, **envp;
char *path;
- {
+ int index;
+{
char *cmdname;
int e;
@@ -147,7 +143,9 @@ tryexec(cmd, argv, envp)
char **envp;
{
int e;
+#ifndef BSD
char *p;
+#endif
#ifdef SYSV
do {
@@ -286,7 +284,7 @@ padvance(path, name)
growstackblock();
q = stackblock();
if (p != start) {
- bcopy(start, q, p - start);
+ memcpy(q, start, p - start);
q += p - start;
*q++ = '/';
}
@@ -308,7 +306,11 @@ padvance(path, name)
/*** Command hashing code ***/
-hashcmd(argc, argv) char **argv; {
+int
+hashcmd(argc, argv)
+ int argc;
+ char **argv;
+{
struct tblentry **pp;
struct tblentry *cmdp;
int c;
@@ -335,9 +337,9 @@ hashcmd(argc, argv) char **argv; {
while ((name = *argptr) != NULL) {
if ((cmdp = cmdlookup(name, 0)) != NULL
&& (cmdp->cmdtype == CMDNORMAL
- || cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0))
+ || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)))
delete_cmd_entry();
- find_command(name, &entry, 1);
+ find_command(name, &entry, 1, pathval());
if (verbose) {
if (entry.cmdtype != CMDUNKNOWN) { /* if no error msg */
cmdp = cmdlookup(name, 0);
@@ -398,14 +400,15 @@ printentry(cmdp, verbose)
*/
void
-find_command(name, entry, printerr)
+find_command(name, entry, printerr, path)
char *name;
struct cmdentry *entry;
- {
+ int printerr;
+ char *path;
+{
struct tblentry *cmdp;
int index;
int prev;
- char *path;
char *fullname;
struct stat statb;
int e;
@@ -441,7 +444,6 @@ find_command(name, entry, printerr)
prev = cmdp->param.index;
}
- path = pathval();
e = ENOENT;
index = -1;
loop:
@@ -481,7 +483,7 @@ loop:
goto loop;
}
e = EACCES; /* if we fail, this will be the error */
- if ((statb.st_mode & S_IFMT) != S_IFREG)
+ if (!S_ISREG(statb.st_mode))
goto loop;
if (pathopt) { /* this is a %func directory */
stalloc(strlen(fullname) + 1);
@@ -535,8 +537,8 @@ success:
int
find_builtin(name)
char *name;
- {
- const register struct builtincmd *bp;
+{
+ register const struct builtincmd *bp;
for (bp = builtincmd ; bp->name ; bp++) {
if (*bp->name == *name && equal(bp->name, name))
@@ -560,7 +562,7 @@ hashcd() {
for (pp = cmdtable ; pp < &cmdtable[CMDTABLESIZE] ; pp++) {
for (cmdp = *pp ; cmdp ; cmdp = cmdp->next) {
if (cmdp->cmdtype == CMDNORMAL
- || cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0)
+ || (cmdp->cmdtype == CMDBUILTIN && builtinloc >= 0))
cmdp->rehash = 1;
}
}
@@ -577,7 +579,7 @@ hashcd() {
void
changepath(newval)
char *newval;
- {
+{
char *old, *new;
int index;
int firstchange;
@@ -591,8 +593,8 @@ changepath(newval)
for (;;) {
if (*old != *new) {
firstchange = index;
- if (*old == '\0' && *new == ':'
- || *old == ':' && *new == '\0')
+ if ((*old == '\0' && *new == ':')
+ || (*old == ':' && *new == '\0'))
firstchange++;
old = new; /* ignore subsequent differences */
}
@@ -620,7 +622,9 @@ changepath(newval)
*/
STATIC void
-clearcmdentry(firstchange) {
+clearcmdentry(firstchange)
+ int firstchange;
+{
struct tblentry **tblp;
struct tblentry **pp;
struct tblentry *cmdp;
@@ -629,8 +633,10 @@ clearcmdentry(firstchange) {
for (tblp = cmdtable ; tblp < &cmdtable[CMDTABLESIZE] ; tblp++) {
pp = tblp;
while ((cmdp = *pp) != NULL) {
- if (cmdp->cmdtype == CMDNORMAL && cmdp->param.index >= firstchange
- || cmdp->cmdtype == CMDBUILTIN && builtinloc >= firstchange) {
+ if ((cmdp->cmdtype == CMDNORMAL &&
+ cmdp->param.index >= firstchange)
+ || (cmdp->cmdtype == CMDBUILTIN &&
+ builtinloc >= firstchange)) {
*pp = cmdp->next;
ckfree(cmdp);
} else {
@@ -692,7 +698,8 @@ struct tblentry **lastcmdentry;
STATIC struct tblentry *
cmdlookup(name, add)
char *name;
- {
+ int add;
+{
int hashval;
register char *p;
struct tblentry *cmdp;
OpenPOWER on IntegriCloud