Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dash upstream as of v0.5.11.5 #10

Merged
merged 36 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e7a5030
options: Do not set commandname in procargs
herbertx Feb 25, 2019
86a841b
expand: Fix double-decrement in argstr
herbertx Feb 25, 2019
02a0056
eval: Reset handler when entering a subshell
herbertx Mar 3, 2019
b9f8565
parser: Fix old-style command substitution here-document crash
herbertx Mar 29, 2019
c4f4ee8
expand: Fix trailing newlines processing in backquote expanding
nmerinov Apr 29, 2019
7710a92
parser: Only accept single-digit parameter expansion outside of braces
herbertx May 27, 2019
f30bd15
shell: delete AC_PROG_YACC
MaskRay Oct 10, 2019
f613f95
redir: Clear saved redirections in subshell
herbertx Jan 19, 2020
fd5311a
builtin: Fix seconds part of times(1)
herbertx Jan 20, 2020
42a0e93
jobs: Rename DOWAIT_NORMAL to DOWAIT_NONBLOCK
dvlasenk Feb 19, 2020
ecd8262
var: Remove poplocalvars() always-zero argument, make it static
dvlasenk Feb 19, 2020
2a4f8f9
jobs: Fix infinite loop in waitproc
herbertx Apr 10, 2020
a256b37
parser: Fix handling of empty aliases
herbertx Apr 27, 2020
50fc8ed
parser: Catch errors in expandstr
herbertx Apr 28, 2020
07951cf
parser: Fix alias expansion after heredoc or newlines
herbertx Apr 28, 2020
24bc10e
expand: Remove unused expandmeta() flag parameter
dvlasenk Apr 29, 2020
2b6a5a3
shell: mktokens relative TMPDIR
mgree Apr 30, 2020
8e559f5
input: Fix compiling against libedit with -fno-common
May 2, 2020
3e3e7af
shell: Always use explicit large file API
herbertx May 7, 2020
ec7fc7c
parser: Save and restore heredoclist in expandstr
herbertx May 17, 2020
c09c60a
shell: Fix typos
tbm May 20, 2020
e8e2900
parser: Fix double-backslash nl in old-style command sub
herbertx May 26, 2020
3927929
Release 0.5.11.
herbertx Jun 1, 2020
7249493
jobs: Fix waitcmd busy loop
herbertx Jun 2, 2020
e80bd04
Release 0.5.11.1.
herbertx Jul 8, 2020
0493bbf
shell: Group readdir64/dirent64 with open64
herbertx Jul 22, 2020
a45870f
Release 0.5.11.2.
herbertx Aug 28, 2020
5f770b1
jobs: Only block in waitcmd on first run
herbertx Dec 2, 2020
9e0f6a7
Release 0.5.11.3.
herbertx Dec 23, 2020
a531698
eval: Do not cache value of eflag in evaltree
herbertx May 17, 2021
efc7765
Release 0.5.11.4.
herbertx Jun 4, 2021
2cb4711
parser: Fix VSLENGTH parsing with trailing garbage
herbertx Jun 21, 2021
663e4c8
Release 0.5.11.5.
herbertx Sep 3, 2021
b038a5d
merge
mgree Feb 24, 2022
805524f
bump version
mgree Feb 24, 2022
945334f
backout my busted alias handling; use theirs
mgree Feb 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([dash],[0.5.10.2])
AC_INIT([dash],[0.5.11.5])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS(config.h)
Expand All @@ -9,11 +9,11 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES(yes)])
dnl Checks for programs.
AC_PROG_CC
AC_USE_SYSTEM_EXTENSIONS

AC_PROG_YACC
dnl MMG 2018-09-26 support building the library
AM_PROG_AR


AC_MSG_CHECKING([for build system compiler])
if test "$cross_compiling" = yes; then
CC_FOR_BUILD=${CC_FOR_BUILD-cc}
Expand Down Expand Up @@ -150,8 +150,13 @@ AC_CHECK_FUNC(stat64,, [
AC_DEFINE(stat64, stat, [64-bit operations are the same as 32-bit])
])

dnl OS X apparently has stat64 but not open64.
AC_CHECK_FUNC(open64,, [
AC_DEFINE(open64, open, [64-bit operations are the same as 32-bit])
AC_DEFINE(readdir64, readdir,
[64-bit operations are the same as 32-bit])
AC_DEFINE(dirent64, dirent,
[64-bit operations are the same as 32-bit])
])

dnl Check if struct stat has st_mtim.
Expand Down
4 changes: 2 additions & 2 deletions libdash.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
name: "libdash"
version: "0.1.1"
version: "0.1.2"
synopsis: "Bindings to the dash shell's parser"
maintainer: "Michael Greenberg <michael.greenberg@pomona.edu>"
authors: "Michael Greenberg <michael.greenberg@pomona.edu>"
Expand Down Expand Up @@ -39,6 +39,6 @@ install: [
]
dev-repo: "git+https:///github.com/mgree/libdash"
url {
src: "https://github.com/mgree/libdash/archive/v0.1.1.tar.gz"
src: "https://github.com/mgree/libdash/archive/v0.1.2.tar.gz"
}

4 changes: 2 additions & 2 deletions src/TOUR
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ string was going to be:
p = stackptr;
*p++ = c; /* repeated as many times as needed */
stackptr = p;
The folloing three macros (defined in memalloc.h) perform these
The following three macros (defined in memalloc.h) perform these
operations, but grow the stack if you run off the end:
STARTSTACKSTR(p);
STPUTC(c, p); /* repeated as many times as needed */
Expand Down Expand Up @@ -198,7 +198,7 @@ EXECUTION: Command execution is handled by the following files:
eval.c The top level routines.
redir.c Code to handle redirection of input and output.
jobs.c Code to handle forking, waiting, and job control.
exec.c Code to to path searches and the actual exec sys call.
exec.c Code to path searches and the actual exec sys call.
expand.c Code to evaluate arguments.
var.c Maintains the variable symbol table. Called from expand.c.

Expand Down
26 changes: 13 additions & 13 deletions src/bltin/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,46 +473,46 @@ static int isoperand(char **tp)
static int
newerf (const char *f1, const char *f2)
{
struct stat b1, b2;
struct stat64 b1, b2;

#ifdef HAVE_ST_MTIM
return (stat (f1, &b1) == 0 &&
stat (f2, &b2) == 0 &&
return (stat64(f1, &b1) == 0 &&
stat64(f2, &b2) == 0 &&
( b1.st_mtim.tv_sec > b2.st_mtim.tv_sec ||
(b1.st_mtim.tv_sec == b2.st_mtim.tv_sec && (b1.st_mtim.tv_nsec > b2.st_mtim.tv_nsec )))
);
#else
return (stat (f1, &b1) == 0 &&
stat (f2, &b2) == 0 &&
return (stat64(f1, &b1) == 0 &&
stat64(f2, &b2) == 0 &&
b1.st_mtime > b2.st_mtime);
#endif
}

static int
olderf (const char *f1, const char *f2)
{
struct stat b1, b2;
struct stat64 b1, b2;

#ifdef HAVE_ST_MTIM
return (stat (f1, &b1) == 0 &&
stat (f2, &b2) == 0 &&
return (stat64(f1, &b1) == 0 &&
stat64(f2, &b2) == 0 &&
(b1.st_mtim.tv_sec < b2.st_mtim.tv_sec ||
(b1.st_mtim.tv_sec == b2.st_mtim.tv_sec && (b1.st_mtim.tv_nsec < b2.st_mtim.tv_nsec )))
);
#else
return (stat (f1, &b1) == 0 &&
stat (f2, &b2) == 0 &&
return (stat64(f1, &b1) == 0 &&
stat64(f2, &b2) == 0 &&
b1.st_mtime < b2.st_mtime);
#endif
}

static int
equalf (const char *f1, const char *f2)
{
struct stat b1, b2;
struct stat64 b1, b2;

return (stat (f1, &b1) == 0 &&
stat (f2, &b2) == 0 &&
return (stat64(f1, &b1) == 0 &&
stat64(f2, &b2) == 0 &&
b1.st_dev == b2.st_dev &&
b1.st_ino == b2.st_ino);
}
Expand Down
30 changes: 21 additions & 9 deletions src/bltin/times.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,28 @@
int timescmd() {
struct tms buf;
long int clk_tck = sysconf(_SC_CLK_TCK);
int mutime, mstime, mcutime, mcstime;
double utime, stime, cutime, cstime;

times(&buf);
printf("%dm%fs %dm%fs\n%dm%fs %dm%fs\n",
(int) (buf.tms_utime / clk_tck / 60),
((double) buf.tms_utime) / clk_tck,
(int) (buf.tms_stime / clk_tck / 60),
((double) buf.tms_stime) / clk_tck,
(int) (buf.tms_cutime / clk_tck / 60),
((double) buf.tms_cutime) / clk_tck,
(int) (buf.tms_cstime / clk_tck / 60),
((double) buf.tms_cstime) / clk_tck);

utime = (double)buf.tms_utime / clk_tck;
mutime = utime / 60;
utime -= mutime * 60.0;

stime = (double)buf.tms_stime / clk_tck;
mstime = stime / 60;
stime -= mstime * 60.0;

cutime = (double)buf.tms_cutime / clk_tck;
mcutime = cutime / 60;
cutime -= mcutime * 60.0;

cstime = (double)buf.tms_cstime / clk_tck;
mcstime = cstime / 60;
cstime -= mcstime * 60.0;

printf("%dm%fs %dm%fs\n%dm%fs %dm%fs\n", mutime, utime, mstime, stime,
mcutime, cutime, mcstime, cstime);
return 0;
}
4 changes: 2 additions & 2 deletions src/cd.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ cdcmd(int argc, char **argv)
const char *path;
const char *p;
char c;
struct stat statb;
struct stat64 statb;
int flags;
int len;

Expand Down Expand Up @@ -132,7 +132,7 @@ cdcmd(int argc, char **argv)
c = *p;
p = stalloc(len);

if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
if (stat64(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
if (c && c != ':')
flags |= CD_PRINT;
docd:
Expand Down
22 changes: 9 additions & 13 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
* Evaluate a command.
*/

#include "init.h"
#include "main.h"
#include "shell.h"
#include "nodes.h"
#include "syntax.h"
Expand Down Expand Up @@ -243,18 +245,10 @@ evaltree(union node *n, int flags)
popredir(0);
goto setstatus;
case NCMD:
#ifdef notyet
if (eflag && !(flags & EV_TESTED))
checkexit = ~0;
status = evalcommand(n, flags, (struct backcmd *)NULL);
goto setstatus;
#else
evalfn = evalcommand;
checkexit:
if (eflag && !(flags & EV_TESTED))
checkexit = ~0;
checkexit = ~flags & EV_TESTED;
goto calleval;
#endif
case NFOR:
evalfn = evalfor;
goto calleval;
Expand Down Expand Up @@ -314,7 +308,7 @@ evaltree(union node *n, int flags)
out:
dotrap();

if (checkexit & status)
if (eflag && checkexit && status)
goto exexit;

if (flags & EV_EXIT) {
Expand Down Expand Up @@ -482,16 +476,18 @@ evalsubshell(union node *n, int flags)
lineno -= funcline - 1;

expredir(n->nredir.redirect);
if (!backgnd && flags & EV_EXIT && !have_traps())
goto nofork;
INTOFF;
if (!backgnd && flags & EV_EXIT && !have_traps()) {
forkreset();
goto nofork;
}
jp = makejob(n, 1);
if (forkshell(jp, n, backgnd) == 0) {
INTON;
flags |= EV_EXIT;
if (backgnd)
flags &=~ EV_TESTED;
nofork:
INTON;
redirect(n->nredir.redirect, 0);
evaltreenr(n->nredir.n, flags);
/* never returns */
Expand Down
18 changes: 8 additions & 10 deletions src/expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ STATIC char *evalvar(char *, int);
static size_t strtodest(const char *p, int flags);
static size_t memtodest(const char *p, size_t len, int flags);
STATIC ssize_t varvalue(char *, int, int, int);
STATIC void expandmeta(struct strlist *, int);
STATIC void expandmeta(struct strlist *);
#ifdef HAVE_GLOB
STATIC void addglob(const glob_t *);
#else
Expand Down Expand Up @@ -205,7 +205,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
ifsbreakup(p, -1, &exparg);
*exparg.lastp = NULL;
exparg.lastp = &exparg.list;
expandmeta(exparg.list, flag);
expandmeta(exparg.list);
} else {
sp = (struct strlist *)stalloc(sizeof (struct strlist));
sp->text = p;
Expand Down Expand Up @@ -285,7 +285,7 @@ static char *argstr(char *p, int flag)
q = stnputs(p, length, expdest);
q[-1] &= end - 1;
expdest = q - (flag & EXP_WORD ? end : 0);
newloc = expdest - (char *)stackblock() - end;
newloc = q - (char *)stackblock() - end;
if (breakall && !inquotes && newloc > startloc) {
recordregion(startloc, newloc, 0);
}
Expand Down Expand Up @@ -525,7 +525,7 @@ expbackq(union node *cmd, int flag)

/* Eat all trailing newlines */
dest = expdest;
for (; dest > (char *)stackblock() && dest[-1] == '\n';)
for (; dest > ((char *)stackblock() + startloc) && dest[-1] == '\n';)
STUNPUTC(dest);
expdest = dest;

Expand Down Expand Up @@ -1155,9 +1155,7 @@ void ifsfree(void)

#ifdef HAVE_GLOB
STATIC void
expandmeta(str, flag)
struct strlist *str;
int flag;
expandmeta(struct strlist *str)
{
/* TODO - EXP_REDIR */

Expand Down Expand Up @@ -1221,7 +1219,7 @@ STATIC unsigned expdir_max;


STATIC void
expandmeta(struct strlist *str, int flag)
expandmeta(struct strlist *str)
{
static const char metachars[] = {
'*', '?', '[', 0
Expand Down Expand Up @@ -1286,7 +1284,7 @@ expmeta(char *name, unsigned name_len, unsigned expdir_len)
int metaflag;
struct stat64 statb;
DIR *dirp;
struct dirent *dp;
struct dirent64 *dp;
int atend;
int matchdot;
int esc;
Expand Down Expand Up @@ -1363,7 +1361,7 @@ expmeta(char *name, unsigned name_len, unsigned expdir_len)
p++;
if (*p == '.')
matchdot++;
while (! int_pending() && (dp = readdir(dirp)) != NULL) {
while (! int_pending() && (dp = readdir64(dirp)) != NULL) {
if (dp->d_name[0] == '.' && ! matchdot)
continue;
if (pmatch(start, dp->d_name)) {
Expand Down
1 change: 1 addition & 0 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@

void init(void);
void exitreset(void);
void forkreset(void);
void reset(void);
32 changes: 10 additions & 22 deletions src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ MKINIT char basebuf[IBUFSIZ]; /* buffer for top level input file */
struct parsefile *parsefile = &basepf; /* current input file */
int whichprompt; /* 1 == PS1, 2 == PS2 */

#ifndef SMALL
EditLine *el; /* cookie for editline package */
#endif

STATIC void pushfile(void);
static int preadfd(void);
/*
Expand All @@ -80,6 +76,7 @@ static int preadbuffer(void);

#ifdef mkinit
INCLUDE <stdio.h>
INCLUDE <unistd.h>
INCLUDE "input.h"
INCLUDE "error.h"

Expand All @@ -93,6 +90,14 @@ RESET {
basepf.lleft = basepf.nleft = 0;
popallfiles();
}

FORKRESET {
popallfiles();
if (parsefile->fd > 0) {
close(parsefile->fd);
parsefile->fd = 0;
}
}
#endif


Expand Down Expand Up @@ -390,7 +395,7 @@ setinputfile(const char *fname, int flags)
int fd;

INTOFF;
if ((fd = open(fname, O_RDONLY)) < 0) {
if ((fd = open64(fname, O_RDONLY)) < 0) {
if (flags & INPUT_NOFILE_OK)
goto out;
exitstatus = 127;
Expand Down Expand Up @@ -500,20 +505,3 @@ popallfiles(void)
{
unwindfiles(&basepf);
}



/*
* Close the file(s) that the shell is reading commands from. Called
* after a fork is done.
*/

void
closescript(void)
{
popallfiles();
if (parsefile->fd > 0) {
close(parsefile->fd);
parsefile->fd = 0;
}
}
1 change: 0 additions & 1 deletion src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,3 @@ void setinputstring(char *);
void popfile(void);
void unwindfiles(struct parsefile *);
void popallfiles(void);
void closescript(void);
Loading