Permalink
Browse files

Update sh to r338473

  • Loading branch information...
bdrewery committed Oct 23, 2018
1 parent deb8b16 commit d2867740a30eb85dc7d56c52bb5dddfca3ff3b24
@@ -36,7 +36,7 @@ static char sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/bin/sh/cd.c 320340 2017-06-25 21:53:08Z jilles $");
__FBSDID("$FreeBSD: head/bin/sh/cd.c 336320 2018-07-15 21:55:17Z jilles $");
#include <sys/types.h>
#include <sys/stat.h>
@@ -120,7 +120,7 @@ cdcmd(int argc __unused, char **argv __unused)
(dest[0] == '.' && dest[1] == '.' && (dest[2] == '/' || dest[2] == '\0')) ||
(path = bltinlookup("CDPATH", 1)) == NULL)
path = "";
while ((p = padvance(&path, dest)) != NULL) {
while ((p = padvance(&path, NULL, dest)) != NULL) {
if (stat(p, &statb) < 0) {
if (errno != ENOENT)
errno1 = errno;
@@ -36,7 +36,7 @@ static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/bin/sh/exec.c 317882 2017-05-06 13:28:42Z jilles $");
__FBSDID("$FreeBSD: head/bin/sh/exec.c 336320 2018-07-15 21:55:17Z jilles $");
#include <sys/types.h>
#include <sys/stat.h>
@@ -113,15 +113,16 @@ void
shellexec(char **argv, char **envp, const char *path, int idx)
{
char *cmdname;
const char *opt;
int e;
if (strchr(argv[0], '/') != NULL) {
tryexec(argv[0], argv, envp);
e = errno;
} else {
e = ENOENT;
while ((cmdname = padvance(&path, argv[0])) != NULL) {
if (--idx < 0 && pathopt == NULL) {
while ((cmdname = padvance(&path, &opt, argv[0])) != NULL) {
if (--idx < 0 && opt == NULL) {
tryexec(cmdname, argv, envp);
if (errno != ENOENT && errno != ENOTDIR)
e = errno;
@@ -174,16 +175,14 @@ tryexec(char *cmd, char **argv, char **envp)
* Do a path search. The variable path (passed by reference) should be
* set to the start of the path before the first call; padvance will update
* this value as it proceeds. Successive calls to padvance will return
* the possible path expansions in sequence. If an option (indicated by
* a percent sign) appears in the path entry then the global variable
* pathopt will be set to point to it; otherwise pathopt will be set to
* NULL.
* the possible path expansions in sequence. If popt is not NULL, options
* are processed: if an option (indicated by a percent sign) appears in
* the path entry then *popt will be set to point to it; else *popt will be
* set to NULL. If popt is NULL, percent signs are not special.
*/
const char *pathopt;
char *
padvance(const char **path, const char *name)
padvance(const char **path, const char **popt, const char *name)
{
const char *p, *start;
char *q;
@@ -192,8 +191,12 @@ padvance(const char **path, const char *name)
if (*path == NULL)
return NULL;
start = *path;
for (p = start; *p && *p != ':' && *p != '%'; p++)
; /* nothing */
if (popt != NULL)
for (p = start; *p && *p != ':' && *p != '%'; p++)
; /* nothing */
else
for (p = start; *p && *p != ':'; p++)
; /* nothing */
namelen = strlen(name);
len = p - start + namelen + 2; /* "2" is for '/' and '\0' */
STARTSTACKSTR(q);
@@ -204,10 +207,12 @@ padvance(const char **path, const char *name)
*q++ = '/';
}
memcpy(q, name, namelen + 1);
pathopt = NULL;
if (*p == '%') {
pathopt = ++p;
while (*p && *p != ':') p++;
if (popt != NULL) {
if (*p == '%') {
*popt = ++p;
while (*p && *p != ':') p++;
} else
*popt = NULL;
}
if (*p == ':')
*path = p + 1;
@@ -277,14 +282,14 @@ static void
printentry(struct tblentry *cmdp, int verbose)
{
int idx;
const char *path;
const char *path, *opt;
char *name;
if (cmdp->cmdtype == CMDNORMAL) {
idx = cmdp->param.index;
path = pathval();
do {
name = padvance(&path, cmdp->cmdname);
name = padvance(&path, &opt, cmdp->cmdname);
stunalloc(name);
} while (--idx >= 0);
out1str(name);
@@ -321,6 +326,7 @@ find_command(const char *name, struct cmdentry *entry, int act,
{
struct tblentry *cmdp, loc_cmd;
int idx;
const char *opt;
char *fullname;
struct stat statb;
int e;
@@ -363,10 +369,11 @@ find_command(const char *name, struct cmdentry *entry, int act,
e = ENOENT;
idx = -1;
for (;(fullname = padvance(&path, name)) != NULL; stunalloc(fullname)) {
for (;(fullname = padvance(&path, &opt, name)) != NULL;
stunalloc(fullname)) {
idx++;
if (pathopt) {
if (strncmp(pathopt, "func", 4) == 0) {
if (opt) {
if (strncmp(opt, "func", 4) == 0) {
/* handled below */
} else {
continue; /* ignore unimplemented options */
@@ -382,7 +389,7 @@ find_command(const char *name, struct cmdentry *entry, int act,
e = EACCES; /* if we fail, this will be the error */
if (!S_ISREG(statb.st_mode))
continue;
if (pathopt) { /* this is a %func directory */
if (opt) { /* this is a %func directory */
readcmdfile(fullname);
if ((cmdp = cmdlookup(name, 0)) == NULL || cmdp->cmdtype != CMDFUNCTION)
error("%s not defined in %s", name, fullname);
@@ -703,10 +710,11 @@ typecmd_impl(int argc, char **argv, int cmd, const char *path)
case CMDNORMAL: {
if (strchr(argv[i], '/') == NULL) {
const char *path2 = path;
const char *opt2;
char *name;
int j = entry.u.index;
do {
name = padvance(&path2, argv[i]);
name = padvance(&path2, &opt2, argv[i]);
stunalloc(name);
} while (--j >= 0);
if (cmd == TYPECMD_SMALLV)
@@ -30,7 +30,7 @@
* SUCH DAMAGE.
*
* @(#)exec.h 8.3 (Berkeley) 6/8/95
* $FreeBSD: head/bin/sh/exec.h 314436 2017-02-28 23:42:47Z imp $
* $FreeBSD: head/bin/sh/exec.h 336320 2018-07-15 21:55:17Z jilles $
*/
/* values of cmdtype */
@@ -61,11 +61,10 @@ struct cmdentry {
#define DO_ERR 0x01 /* prints errors */
#define DO_NOFUNC 0x02 /* don't return shell functions, for command */
extern const char *pathopt; /* set by padvance */
extern int exerrno; /* last exec error */
void shellexec(char **, char **, const char *, int) __dead2;
char *padvance(const char **, const char *);
char *padvance(const char **, const char **, const char *);
void find_command(const char *, struct cmdentry *, int, const char *);
int find_builtin(const char *, int *);
void hashcd(void);
@@ -40,7 +40,7 @@ static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/bin/sh/expand.c 318269 2017-05-14 13:14:19Z jilles $");
__FBSDID("$FreeBSD: head/bin/sh/expand.c 338473 2018-09-05 19:16:09Z jilles $");
#include <sys/types.h>
#include <sys/time.h>
@@ -896,7 +896,7 @@ reprocess(int startloc, int flag, int subtype, int quoted,
startp = stackblock() + startloc;
len = expdest - startp;
if (len >= SIZE_MAX / 2)
if (len >= SIZE_MAX / 2 || len > PTRDIFF_MAX)
abort();
INTOFF;
if (len >= buflen) {
@@ -912,7 +912,7 @@ reprocess(int startloc, int flag, int subtype, int quoted,
INTON;
memcpy(buf, startp, len);
buf[len] = '\0';
STADJUST(-len, expdest);
STADJUST(-(ptrdiff_t)len, expdest);
for (zpos = 0;;) {
zlen = strlen(buf + zpos);
strtodest(buf + zpos, flag, subtype, quoted, dst);
@@ -1342,8 +1342,10 @@ patmatch(const char *pattern, const char *string)
}
if (c == '[' && *p == ':') {
found |= match_charclass(p, chr, &end);
if (end != NULL)
if (end != NULL) {
p = end;
continue;
}
}
if (c == CTLESC)
c = *p++;
@@ -36,7 +36,7 @@ static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/bin/sh/jobs.c 327475 2018-01-01 22:31:52Z jilles $");
__FBSDID("$FreeBSD: head/bin/sh/jobs.c 328818 2018-02-02 22:53:58Z jilles $");
#include <sys/ioctl.h>
#include <sys/param.h>
@@ -362,7 +362,7 @@ showjob(struct job *jp, int mode)
const char *statestr, *coredump;
struct procstat *ps;
struct job *j;
int col, curr, i, jobno, prev, procno;
int col, curr, i, jobno, prev, procno, status;
char c;
procno = (mode == SHOWJOBS_PGIDS) ? 1 : jp->nprocs;
@@ -376,11 +376,12 @@ showjob(struct job *jp, int mode)
}
#endif
coredump = "";
ps = jp->ps + jp->nprocs - 1;
status = jp->ps[jp->nprocs - 1].status;
if (jp->state == 0) {
statestr = "Running";
#if JOBS
} else if (jp->state == JOBSTOPPED) {
ps = jp->ps + jp->nprocs - 1;
while (!WIFSTOPPED(ps->status) && ps > jp->ps)
ps--;
if (WIFSTOPPED(ps->status))
@@ -391,20 +392,20 @@ showjob(struct job *jp, int mode)
if (statestr == NULL)
statestr = "Suspended";
#endif
} else if (WIFEXITED(ps->status)) {
if (WEXITSTATUS(ps->status) == 0)
} else if (WIFEXITED(status)) {
if (WEXITSTATUS(status) == 0)
statestr = "Done";
else {
fmtstr(statebuf, sizeof(statebuf), "Done(%d)",
WEXITSTATUS(ps->status));
WEXITSTATUS(status));
statestr = statebuf;
}
} else {
i = WTERMSIG(ps->status);
i = WTERMSIG(status);
statestr = strsignal(i);
if (statestr == NULL)
statestr = "Unknown signal";
if (WCOREDUMP(ps->status))
if (WCOREDUMP(status))
coredump = " (core dumped)";
}
@@ -36,14 +36,13 @@ static char sccsid[] = "@(#)mail.c 8.2 (Berkeley) 5/4/95";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/bin/sh/mail.c 314436 2017-02-28 23:42:47Z imp $");
__FBSDID("$FreeBSD: head/bin/sh/mail.c 336303 2018-07-15 09:14:30Z jilles $");
/*
* Routines to check for mail. (Perhaps make part of main.c?)
*/
#include "shell.h"
#include "exec.h" /* defines padvance() */
#include "mail.h"
#include "var.h"
#include "output.h"
@@ -72,9 +71,9 @@ void
chkmail(int silent)
{
int i;
const char *mpath;
char *mpath;
char *p;
char *q;
char *msg;
struct stackmark smark;
struct stat statb;
@@ -83,30 +82,33 @@ chkmail(int silent)
if (nmboxes == 0)
return;
setstackmark(&smark);
mpath = mpathset()? mpathval() : mailval();
mpath = stsavestr(mpathset()? mpathval() : mailval());
for (i = 0 ; i < nmboxes ; i++) {
p = padvance(&mpath, "");
if (p == NULL)
break;
p = mpath;
if (*p == '\0')
continue;
for (q = p ; *q ; q++);
if (q[-1] != '/')
abort();
q[-1] = '\0'; /* delete trailing '/' */
break;
mpath = strchrnul(mpath, ':');
if (*mpath != '\0') {
*mpath++ = '\0';
if (p == mpath - 1)
continue;
}
msg = strchr(p, '%');
if (msg != NULL)
*msg++ = '\0';
#ifdef notdef /* this is what the System V shell claims to do (it lies) */
if (stat(p, &statb) < 0)
statb.st_mtime = 0;
if (statb.st_mtime > mailtime[i] && ! silent) {
out2str(pathopt? pathopt : "you have mail");
out2str(msg? msg : "you have mail");
out2c('\n');
}
mailtime[i] = statb.st_mtime;
#else /* this is what it should do */
if (stat(p, &statb) < 0)
statb.st_size = 0;
if (statb.st_size > mailtime[i] && ! silent) {
out2str(pathopt? pathopt : "you have mail");
out2str(msg? msg : "you have mail");
out2c('\n');
}
mailtime[i] = statb.st_size;
@@ -44,7 +44,7 @@ static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/28/95";
#endif
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/bin/sh/main.c 326025 2017-11-20 19:49:47Z pfg $");
__FBSDID("$FreeBSD: head/bin/sh/main.c 336320 2018-07-15 21:55:17Z jilles $");
#include <stdio.h>
#include <signal.h>
@@ -294,14 +294,15 @@ static char *
find_dot_file(char *basename)
{
char *fullname;
const char *opt;
const char *path = pathval();
struct stat statb;
/* don't try this for absolute or relative paths */
if( strchr(basename, '/'))
return basename;
while ((fullname = padvance(&path, basename)) != NULL) {
while ((fullname = padvance(&path, &opt, basename)) != NULL) {
if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) {
/*
* Don't bother freeing here, since it will
@@ -32,9 +32,9 @@
# SUCH DAMAGE.
#
# @(#)mkbuiltins 8.2 (Berkeley) 5/4/95
# $FreeBSD: head/bin/sh/mkbuiltins 319576 2017-06-04 21:02:48Z bdrewery $
# $FreeBSD: head/bin/sh/mkbuiltins 328934 2018-02-06 15:41:35Z arichardson $
temp=`/usr/bin/mktemp -t ka`
temp=`mktemp -t ka`
havehist=1
if [ "X$1" = "X-h" ]; then
havehist=0
Oops, something went wrong.

0 comments on commit d286774

Please sign in to comment.