blob: 32e3eb2cb4cbf064775b8eaa26084c5cb99ba1cf [file] [log] [blame]
These are context diffs against the NetBSD-current version as of 93/09/18.
Use "patch -p0 -s < LINUX.DIFFS" to patch the source code.
--- Makefile
+++ Makefile 1993/10/04 18:48:13
@@ -1,41 +1,59 @@
# Makefile,v 1.7 1993/08/09 04:58:18 mycroft Exp
PROG= sh
-SRCS= builtins.c cd.c dirent.c echo.c error.c eval.c exec.c expand.c \
+SRCS= builtins.c cd.c dirent.c bltin/echo.c error.c eval.c exec.c expand.c \
input.c jobs.c mail.c main.c memalloc.c miscbltin.c \
mystring.c nodes.c options.c parser.c redir.c show.c \
- syntax.c trap.c output.c var.c
-OBJS+= init.o
-CFLAGS+=-DSHELL -I. -I${.CURDIR}
-.PATH: ${.CURDIR}/bltin
-CLEANFILES+=\
+ syntax.c trap.c output.c var.c bltin/test.c
+
+OBJ1 = init.o
+OBJ2 = builtins.o cd.o dirent.o bltin/echo.o error.o eval.o exec.o expand.o \
+ input.o jobs.o mail.o main.o memalloc.o miscbltin.o \
+ mystring.o nodes.o options.o parser.o redir.o show.o \
+ syntax.o trap.o output.o var.o bltin/test.o
+
+OBJS = $(OBJ1) $(OBJ2)
+
+CFLAGS = -O2 -fomit-frame-pointer -m486 -DSHELL -I/usr/include/bsd -I.
+LDFLAGS = -s -lbsd
+
+CLEANFILES =\
builtins.c builtins.h init.c mkinit mknodes mksyntax \
nodes.c nodes.h syntax.c syntax.h token.def
-.depend parser.o: token.def
+all: $(OBJS)
+ $(CC) -o $(PROG) $(OBJS) $(LDFLAGS)
+
+install: all
+ install sh /bin/ash
+ install -m 644 sh.1 /usr/man/man1/ash.1
+
+parser.o: token.def
token.def: mktokens
- sh ${.CURDIR}/mktokens
+ sh ./mktokens
-builtins.h builtins.c: ${.CURDIR}/mkbuiltins ${.CURDIR}/builtins
- cd ${.CURDIR}; sh mkbuiltins
+builtins.h builtins.c: mkbuiltins builtins
+ sh ./mkbuiltins
-init.c: mkinit ${SRCS}
- ./mkinit '${CC} -c ${CFLAGS} init.c' ${.ALLSRC}
- touch ${.TARGET}
+init.c: mkinit $(SRCS)
+ ./mkinit '${CC} -c $(CFLAGS) init.c' $(SRCS)
+ touch init.c
-mkinit: ${.CURDIR}/mkinit.c
- ${CC} ${CFLAGS} ${LDFLAGS} ${.CURDIR}/mkinit.c -o $@ ${LDADD}
+mkinit: mkinit.c
+ $(CC) $(CFLAGS) $(LDFLAGS) mkinit.c -o $@ $(LDADD)
-nodes.c nodes.h: mknodes ${.CURDIR}/nodetypes ${.CURDIR}/nodes.c.pat
- ./mknodes ${.CURDIR}/nodetypes ${.CURDIR}/nodes.c.pat
+nodes.c nodes.h: mknodes nodetypes nodes.c.pat
+ ./mknodes nodetypes nodes.c.pat
-mknodes: ${.CURDIR}/mknodes.c
- ${CC} ${CFLAGS} ${LDFLAGS} ${.CURDIR}/mknodes.c -o $@ ${LDADD}
+mknodes: mknodes.c
+ $(CC) $(CFLAGS) $(LDFLAGS) mknodes.c -o $@ $(LDADD)
syntax.c syntax.h: mksyntax
./mksyntax
-mksyntax: ${.CURDIR}/mksyntax.c ${.CURDIR}/parser.h
- ${CC} ${CFLAGS} ${LDFLAGS} ${.CURDIR}/mksyntax.c -o $@ ${LDADD}
+mksyntax: mksyntax.c parser.h
+ $(CC) $(CFLAGS) $(LDFLAGS) mksyntax.c -o $@ $(LDADD)
+
+clean:
+ rm -f core $(CLEANFILES) $(PROG) $(OBJS)
-.include <bsd.prog.mk>
--- bltin/test.c
+++ bltin/test.c 1993/10/04 18:48:13
@@ -0,0 +1,390 @@
+/*
+ * test(1); version 7-like -- author Erik Baalbergen
+ * modified by Eric Gisin to be used as built-in.
+ * modified by Arnold Robbins to add SVR3 compatibility
+ * (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
+ */
+
+static char *RCSid = "$Id: LINUX.DIFFS,v 1.1.1.1 2002/08/17 01:36:06 hpa Exp $";
+
+#include <stddef.h>
+/*#include <string.h>*/
+#include <signal.h>
+#include <errno.h>
+#include <setjmp.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "bltin.h"
+
+/* test(1) accepts the following grammar:
+ oexpr ::= aexpr | aexpr "-o" oexpr ;
+ aexpr ::= nexpr | nexpr "-a" aexpr ;
+ nexpr ::= primary ! "!" primary
+ primary ::= unary-operator operand
+ | operand binary-operator operand
+ | operand
+ | "(" oexpr ")"
+ ;
+ unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"|
+ "-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S";
+
+ binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
+ "-nt"|"-ot"|"-ef";
+ operand ::= <any legal UNIX file name>
+*/
+
+#define evaluate(x) getn(x)
+#define errorf error
+
+#define EOI 0
+#define FILRD 1
+#define FILWR 2
+#define FILREG 3
+#define FILID 4
+#define FILGZ 5
+#define FILTT 6
+#define STZER 7
+#define STNZE 8
+#define STEQL 9
+#define STNEQ 10
+#define INTEQ 11
+#define INTNE 12
+#define INTGE 13
+#define INTGT 14
+#define INTLE 15
+#define INTLT 16
+#define UNOT 17
+#define BAND 18
+#define BOR 19
+#define LPAREN 20
+#define RPAREN 21
+#define OPERAND 22
+#define FILEX 23
+#define FILCDEV 24
+#define FILBDEV 25
+#define FILFIFO 26
+#define FILSETU 27
+#define FILSETG 28
+#define FILSTCK 29
+#define FILSYM 30
+#define FILNT 31
+#define FILOT 32
+#define FILEQ 33
+#define FILSOCK 34
+#define FILUID 35
+#define FILGID 36
+#define OPTION 37
+
+#define UNOP 1
+#define BINOP 2
+#define BUNOP 3
+#define BBINOP 4
+#define PAREN 5
+
+struct t_op {
+ char *op_text;
+ short op_num, op_type;
+} const ops [] = {
+ {"-r", FILRD, UNOP},
+ {"-w", FILWR, UNOP},
+ {"-x", FILEX, UNOP},
+ {"-f", FILREG, UNOP},
+ {"-d", FILID, UNOP},
+ {"-c", FILCDEV,UNOP},
+ {"-b", FILBDEV,UNOP},
+ {"-p", FILFIFO,UNOP},
+ {"-u", FILSETU,UNOP},
+ {"-g", FILSETG,UNOP},
+ {"-k", FILSTCK,UNOP},
+ {"-s", FILGZ, UNOP},
+ {"-t", FILTT, UNOP},
+ {"-z", STZER, UNOP},
+ {"-n", STNZE, UNOP},
+#if 0 /* conficts with binary -o */
+ {"-o", OPTION, UNOP},
+#endif
+ {"-U", FILUID, UNOP},
+ {"-G", FILGID, UNOP},
+ {"-L", FILSYM, UNOP},
+ {"-S", FILSOCK,UNOP},
+ {"=", STEQL, BINOP},
+ {"!=", STNEQ, BINOP},
+ {"-eq", INTEQ, BINOP},
+ {"-ne", INTNE, BINOP},
+ {"-ge", INTGE, BINOP},
+ {"-gt", INTGT, BINOP},
+ {"-le", INTLE, BINOP},
+ {"-lt", INTLT, BINOP},
+ {"-nt", FILNT, BINOP},
+ {"-ot", FILOT, BINOP},
+ {"-ef", FILEQ, BINOP},
+ {"!", UNOT, BUNOP},
+ {"-a", BAND, BBINOP},
+ {"-o", BOR, BBINOP},
+ {"(", LPAREN, PAREN},
+ {")", RPAREN, PAREN},
+ {0, 0, 0}
+};
+
+char **t_wp;
+struct t_op const *t_wp_op;
+
+static void syntax();
+
+int
+testcmd(argc, wp)
+ char **wp;
+{
+ int res;
+
+ t_wp = wp+1;
+ if (strcmp(wp[0], "[") == 0) {
+ while (*wp != NULL)
+ wp++;
+ if (strcmp(*--wp, "]") != 0)
+ errorf("[: missing ]");
+ *wp = NULL;
+ }
+ res = *t_wp == NULL || !oexpr(t_lex(*t_wp));
+
+ if (*t_wp != NULL && *++t_wp != NULL)
+ syntax(*t_wp, "unknown operand");
+
+ return res;
+}
+
+static void
+syntax(op, msg)
+ char *op;
+ char *msg;
+{
+ if (op && *op)
+ errorf("%s: %s", op, msg);
+ else
+ errorf("%s", msg);
+}
+
+oexpr(n)
+{
+ int res;
+
+ res = aexpr(n);
+ if (t_lex(*++t_wp) == BOR)
+ return oexpr(t_lex(*++t_wp)) || res;
+ t_wp--;
+ return res;
+}
+
+aexpr(n)
+{
+ int res;
+
+ res = nexpr(n);
+ if (t_lex(*++t_wp) == BAND)
+ return aexpr(t_lex(*++t_wp)) && res;
+ t_wp--;
+ return res;
+}
+
+nexpr(n)
+ int n; /* token */
+{
+ if (n == UNOT)
+ return !nexpr(t_lex(*++t_wp));
+ return primary(n);
+}
+
+primary(n)
+ int n; /* token */
+{
+ register char *opnd1, *opnd2;
+ int res;
+
+ if (n == EOI)
+ syntax(NULL, "argument expected");
+ if (n == LPAREN) {
+ res = oexpr(t_lex(*++t_wp));
+ if (t_lex(*++t_wp) != RPAREN)
+ syntax(NULL, "closing paren expected");
+ return res;
+ }
+ if (t_wp_op && t_wp_op->op_type == UNOP) {
+ /* unary expression */
+ if (*++t_wp == NULL && n != FILTT)
+ syntax(t_wp_op->op_text, "argument expected");
+ switch (n) {
+ /**
+ case OPTION:
+ return flag[option(*t_wp)];
+ **/
+ case STZER:
+ return strlen(*t_wp) == 0;
+ case STNZE:
+ return strlen(*t_wp) != 0;
+ case FILTT:
+ if (**t_wp < '0' || **t_wp > '9')
+ return filstat("0", n);
+ default: /* all other FIL* */
+ return filstat(*t_wp, n);
+ }
+ }
+ opnd1 = *t_wp;
+ (void) t_lex(*++t_wp);
+ if (t_wp_op && t_wp_op->op_type == BINOP) {
+ struct t_op const *op = t_wp_op;
+
+ if ((opnd2 = *++t_wp) == (char *)0)
+ syntax(op->op_text, "argument expected");
+
+ switch (op->op_num) {
+ case STEQL:
+ return strcmp(opnd1, opnd2) == 0;
+ case STNEQ:
+ return strcmp(opnd1, opnd2) != 0;
+ case INTEQ:
+ return evaluate(opnd1) == evaluate(opnd2);
+ case INTNE:
+ return evaluate(opnd1) != evaluate(opnd2);
+ case INTGE:
+ return evaluate(opnd1) >= evaluate(opnd2);
+ case INTGT:
+ return evaluate(opnd1) > evaluate(opnd2);
+ case INTLE:
+ return evaluate(opnd1) <= evaluate(opnd2);
+ case INTLT:
+ return evaluate(opnd1) < evaluate(opnd2);
+ case FILNT:
+ return newerf (opnd1, opnd2);
+ case FILOT:
+ return olderf (opnd1, opnd2);
+ case FILEQ:
+ return equalf (opnd1, opnd2);
+ }
+ }
+ t_wp--;
+ return strlen(opnd1) > 0;
+}
+
+filstat(nm, mode)
+ char *nm;
+{
+ struct stat s;
+
+ switch (mode) {
+ case FILRD:
+ return access(nm, 4) == 0;
+ case FILWR:
+ return access(nm, 2) == 0;
+ case FILEX:
+ return access(nm, 1) == 0;
+ case FILREG:
+ return stat(nm, &s) == 0 && (s.st_mode & S_IFMT) == S_IFREG;
+ case FILID:
+ return stat(nm, &s) == 0 && (s.st_mode & S_IFMT) == S_IFDIR;
+ case FILCDEV:
+ return stat(nm, &s) == 0 && (s.st_mode & S_IFMT) == S_IFCHR;
+ case FILBDEV:
+ return stat(nm, &s) == 0 && (s.st_mode & S_IFMT) == S_IFBLK;
+ case FILFIFO:
+#ifdef S_IFIFO
+ return stat(nm, &s) == 0 && (s.st_mode & S_IFMT) == S_IFIFO;
+#else
+ return 0;
+#endif
+ case FILSETU:
+ return stat(nm, &s) == 0 && (s.st_mode & S_ISUID) == S_ISUID;
+ case FILSETG:
+ return stat(nm, &s) == 0 && (s.st_mode & S_ISGID) == S_ISGID;
+ case FILSTCK:
+ return stat(nm, &s) == 0 && (s.st_mode & S_ISVTX) == S_ISVTX;
+ case FILGZ:
+ return stat(nm, &s) == 0 && s.st_size > 0L;
+ case FILTT:
+ return isatty(getn(nm));
+ case FILUID:
+ return stat(nm, &s) == 0 && s.st_uid == geteuid();
+ case FILGID:
+ return stat(nm, &s) == 0 && s.st_gid == getegid();
+#ifdef S_IFLNK
+ case FILSYM:
+ return lstat(nm, &s) == 0 && (s.st_mode & S_IFMT) == S_IFLNK;
+#endif
+#ifdef S_IFSOCK
+ case FILSOCK:
+ return stat(nm, &s) == 0 && (s.st_mode & S_IFMT) == S_IFSOCK;
+#endif
+ default:
+ return 1;
+ }
+}
+
+int
+t_lex(s)
+ register char *s;
+{
+ register struct t_op const *op = ops;
+
+ if (s == 0) {
+ t_wp_op = (struct t_op *)0;
+ return EOI;
+ }
+ while (op->op_text) {
+ if (strcmp(s, op->op_text) == 0) {
+ t_wp_op = op;
+ return op->op_num;
+ }
+ op++;
+ }
+ t_wp_op = (struct t_op *)0;
+ return OPERAND;
+}
+
+newerf (f1, f2)
+char *f1, *f2;
+{
+ struct stat b1, b2;
+
+ return (stat (f1, &b1) == 0 &&
+ stat (f2, &b2) == 0 &&
+ b1.st_mtime > b2.st_mtime);
+}
+
+olderf (f1, f2)
+char *f1, *f2;
+{
+ struct stat b1, b2;
+
+ return (stat (f1, &b1) == 0 &&
+ stat (f2, &b2) == 0 &&
+ b1.st_mtime < b2.st_mtime);
+}
+
+equalf (f1, f2)
+char *f1, *f2;
+{
+ struct stat b1, b2;
+
+ return (stat (f1, &b1) == 0 &&
+ stat (f2, &b2) == 0 &&
+ b1.st_dev == b2.st_dev &&
+ b1.st_ino == b2.st_ino);
+}
+
+/* atoi with error detection */
+
+getn(as)
+ char *as;
+{
+ register char *s;
+ register int n;
+
+ s = as;
+ if (*s == '-')
+ s++;
+ for (n = 0; *s >= '0' && *s <= '9'; s++)
+ n = (n*10) + (*s-'0');
+ if (*s)
+ errorf("%s: bad number", as);
+ return (*as == '-') ? -n : n;
+}
+
--- builtins
+++ builtins 1993/10/04 18:48:13
@@ -79,6 +79,7 @@
setcmd set
setvarcmd setvar
shiftcmd shift
+testcmd test [
trapcmd trap
truecmd : true
umaskcmd umask
--- cd.c
+++ cd.c 1993/10/04 18:48:13
@@ -121,7 +121,7 @@
print = 1;
#endif
INTOFF;
- if (chdir(dest) < 0) {
+ if (dest[0] != '\0' && chdir(dest) < 0) {
INTON;
return -1;
}
@@ -217,7 +217,7 @@
STPUTC('\0', p);
p = grabstackstr(p);
INTOFF;
- if (chdir(p) < 0) {
+ if (p[0] != '\0' && chdir(p) < 0) {
INTON;
return -1;
}
--- error.h
+++ error.h 1993/10/04 18:48:13
@@ -109,6 +109,8 @@
*/
#ifdef BSD
+#ifndef linux
#define setjmp(jmploc) _setjmp(jmploc)
#define longjmp(jmploc, val) _longjmp(jmploc, val)
+#endif
#endif
--- exec.c
+++ exec.c 1993/10/04 18:48:14
@@ -485,7 +485,10 @@
stunalloc(fullname);
goto success;
}
- if (statb.st_uid == geteuid()) {
+ if (geteuid() == 0) {
+ if ((statb.st_mode & 0111) == 0)
+ goto loop;
+ } else if (statb.st_uid == geteuid()) {
if ((statb.st_mode & 0100) == 0)
goto loop;
} else if (statb.st_gid == getegid()) {
--- jobs.c
+++ jobs.c 1993/10/04 18:48:14
@@ -129,7 +129,9 @@
continue;
}
} while (0);
- if (ioctl(2, TIOCGETD, (char *)&ldisc) < 0 || ldisc != NTTYDISC) {
+/* if (ioctl(2, TIOCGETD, (char *)&ldisc) < 0 || ldisc != NTTYDISC) {*/
+ /* crude hack for linux */
+ if (ioctl(2, TIOCGETD, (char *)&ldisc) < 0) {
out2str("ash: need new tty driver to run job control; job control turned off\n");
jflag = 0;
return;
@@ -578,6 +580,7 @@
}
return pid;
}
+#if JOBS
if (rootshell && mode != FORK_NOJOB && jflag) {
if (jp == NULL || jp->nprocs == 0)
pgrp = pid;
@@ -585,6 +588,7 @@
pgrp = jp->ps[0].pid;
setpgrp(pid, pgrp);
}
+#endif
if (mode == FORK_BG)
backgndpid = pid; /* set $! */
if (jp) {
@@ -634,8 +638,10 @@
INTOFF;
TRACE(("waitforjob(%%%d) called\n", jp - jobtab + 1));
while (jp->state == 0) {
- dowait(1, jp);
+ if (dowait(1, jp) == -1 && errno == ECHILD) {
+ error("waitforjob: no children");
}
+ }
#if JOBS
if (jp->jobctl) {
if (ioctl(2, TIOCSPGRP, (char *)&mypgrp) < 0)
@@ -657,8 +663,10 @@
if (! JOBS || jp->state == JOBDONE)
freejob(jp);
CLEAR_PENDING_INT;
+#if 0
if ((status & 0x7F) == SIGINT)
kill(getpid(), SIGINT);
+#endif
INTON;
return st;
}
--- main.c
+++ main.c 1993/10/04 18:48:14
@@ -104,6 +104,9 @@
#if PROFILE
monitor(4, etext, profile_buf, sizeof profile_buf, 50);
#endif
+#ifdef linux
+ signal(SIGCHLD,SIG_DFL);
+#endif /* linux */
state = 0;
if (setjmp(jmploc.loc)) {
/*
@@ -318,9 +321,9 @@
/*
* Should never be called.
*/
+#endif
void
exit(exitstatus) {
_exit(exitstatus);
}
-#endif
--- miscbltin.c
+++ miscbltin.c 1993/10/04 18:48:14
@@ -207,12 +207,16 @@
} while (*++ap != '\0');
umask(mask);
} else {
+#ifndef __linux__
void *set;
if ((set = setmode (ap)) == 0)
+#endif
error("Illegal number: %s", ap);
+#ifndef __linux__
mask = getmode (set, ~mask & 0777);
umask(~mask & 0777);
+#endif
}
}
return 0;
--- options.h
+++ options.h 1993/10/04 18:48:14
@@ -57,11 +57,12 @@
#define xflag optval[7]
#define zflag optval[8]
#define vflag optval[9]
+#define uflag optval[10]
-#define NOPTS 10
+#define NOPTS 11
#ifdef DEFINE_OPTIONS
-const char optchar[NOPTS+1] = "efIijnsxzv"; /* shell flags */
+const char optchar[NOPTS+1] = "efIijnsxzvu"; /* shell flags */
char optval[NOPTS+1]; /* values of option flags */
#else
extern const char optchar[NOPTS+1];
--- redir.c
+++ redir.c 1993/10/04 18:48:14
@@ -57,7 +57,7 @@
#define EMPTY -2 /* marks an unused slot in redirtab */
-#define PIPESIZE 4096 /* amount of buffering in a pipe */
+#define PIPESIZE 4095 /* amount of buffering in a pipe */
MKINIT
--- shell.h
+++ shell.h 1993/10/04 18:48:14
@@ -55,13 +55,13 @@
*/
-#define JOBS 1
+#define JOBS 0
#define SYMLINKS 1
#define DIRENT 1
#define UDIR 0
#define ATTY 0
#define BSD
-#define DEBUG 1
+/* #define DEBUG */
#ifdef __STDC__
typedef void *pointer;
--- var.c
+++ var.c 1993/10/04 18:48:14
@@ -235,7 +235,7 @@
vp->flags &=~ (VTEXTFIXED|VSTACK|VUNSET);
vp->flags |= flags;
vp->text = s;
- if (vp == &vmpath || (vp == &vmail && ! mpathset()))
+ if (iflag && (vp == &vmpath || (vp == &vmail && ! mpathset())))
chkmail(1);
INTON;
return;
@@ -283,10 +283,12 @@
for (v = *hashvar(name) ; v ; v = v->next) {
if (varequal(v->text, name)) {
if (v->flags & VUNSET)
- return NULL;
+ break;
return strchr(v->text, '=') + 1;
}
}
+ if (uflag)
+ error("%.*s: variable not set", strchr(name, '=') - name, name);
return NULL;
}