summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2014-08-19 06:50:54 +0000
committersjg <sjg@FreeBSD.org>2014-08-19 06:50:54 +0000
commitd7cd1d425cc1ea9451fa235e3af9b6625c3e0de2 (patch)
treeb04f4bd7cd887f50e7d98af35f46b9834ff86c80 /bin
parent3c8e37b1d04827f33c0c9a7594bd1b1ef7cdb3d3 (diff)
parent4fbde208c6460d576f64d6dc3cdc6cab085a4283 (diff)
downloadFreeBSD-src-d7cd1d425cc1ea9451fa235e3af9b6625c3e0de2.zip
FreeBSD-src-d7cd1d425cc1ea9451fa235e3af9b6625c3e0de2.tar.gz
Merge head from 7/28
Diffstat (limited to 'bin')
-rw-r--r--bin/chio/chio.110
-rw-r--r--bin/csh/Makefile4
-rw-r--r--bin/csh/Makefile.depend3
-rw-r--r--bin/ed/Makefile4
-rw-r--r--bin/freebsd-version/freebsd-version.12
-rw-r--r--bin/ls/Makefile4
-rw-r--r--bin/ls/Makefile.depend1
-rw-r--r--bin/mv/mv.c17
-rw-r--r--bin/pkill/pkill.13
-rw-r--r--bin/ps/keyword.c2
-rw-r--r--bin/ps/ps.114
-rw-r--r--bin/rm/rm.11
-rw-r--r--bin/rm/rm.c2
-rw-r--r--bin/rmail/Makefile2
-rw-r--r--bin/setfacl/setfacl.14
-rw-r--r--bin/sh/Makefile4
-rw-r--r--bin/sh/Makefile.depend3
-rw-r--r--bin/sh/arith_yacc.c2
-rw-r--r--bin/sh/eval.c10
-rw-r--r--bin/sh/exec.c14
-rw-r--r--bin/sh/expand.c19
-rw-r--r--bin/sh/jobs.c5
-rw-r--r--bin/sh/main.c2
-rw-r--r--bin/sh/miscbltin.c76
-rw-r--r--bin/sh/mystring.c15
-rw-r--r--bin/sh/mystring.h1
-rw-r--r--bin/sh/options.c39
-rw-r--r--bin/sh/tests/builtins/Makefile6
-rw-r--r--bin/sh/tests/builtins/break6.08
-rw-r--r--bin/sh/tests/builtins/getopts1.02
-rw-r--r--bin/sh/tests/builtins/getopts6.07
-rw-r--r--bin/sh/tests/builtins/getopts7.06
-rw-r--r--bin/sh/tests/builtins/getopts8.08
-rw-r--r--bin/sh/tests/builtins/getopts8.0.stdout5
-rw-r--r--bin/sh/tests/parameters/Makefile3
-rw-r--r--bin/sh/tests/parameters/positional3.04
-rw-r--r--bin/sh/tests/parameters/positional4.04
-rw-r--r--bin/sh/tests/parameters/positional5.014
38 files changed, 205 insertions, 125 deletions
diff --git a/bin/chio/chio.1 b/bin/chio/chio.1
index 920c31e..a61242b 100644
--- a/bin/chio/chio.1
+++ b/bin/chio/chio.1
@@ -151,7 +151,6 @@ This command will query the status of the specified media unit, and
will move it to the element specified in its source attribute.
This is a convenient way to return media from a drive or portal
to its previous element in the changer.
-.Pp
.It Ic position Xo
.Ar <to ET> <to EU>
.Op Cm inv
@@ -173,7 +172,6 @@ Report which picker unit the changer is currently configured to use.
.Xc
Configure the changer to use picker
.Ar <unit> .
-.Pp
.It Ic ielem Xo
.Op Ar <timeout>
.Xc
@@ -292,13 +290,11 @@ Configure the changer to use picker 2 (third picker) for operations.
The
.Nm
program and SCSI changer driver were written by
-.An Jason R. Thorpe Aq thorpej@and.com
+.An Jason R. Thorpe Aq Mt thorpej@and.com
for And Communications,
.Pa http://www.and.com/ .
.Pp
Additional work by
-.An Hans Huebner
-.Aq hans@artcom.de
+.An Hans Huebner Aq Mt hans@artcom.de
and
-.An Steve Gunn
-.Aq csg@waterspout.com .
+.An Steve Gunn Aq Mt csg@waterspout.com .
diff --git a/bin/csh/Makefile b/bin/csh/Makefile
index c8845f9..9f305b4 100644
--- a/bin/csh/Makefile
+++ b/bin/csh/Makefile
@@ -40,8 +40,8 @@ MLINKS= csh.1 tcsh.1
# utilities of the same name are handled with the associated manpage,
# builtin.1 in share/man/man1/.
-DPADD= ${LIBTERMCAP} ${LIBCRYPT}
-LDADD= -ltermcap -lcrypt
+DPADD= ${LIBTERMCAPW} ${LIBCRYPT}
+LDADD= -ltermcapw -lcrypt
LINKS= ${BINDIR}/csh ${BINDIR}/tcsh
diff --git a/bin/csh/Makefile.depend b/bin/csh/Makefile.depend
index 7d24a2b..d86382c 100644
--- a/bin/csh/Makefile.depend
+++ b/bin/csh/Makefile.depend
@@ -3,6 +3,7 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
+ bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
@@ -12,7 +13,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/libcrypt \
- lib/ncurses/ncurses \
+ lib/ncurses/ncursesw \
.include <dirdeps.mk>
diff --git a/bin/ed/Makefile b/bin/ed/Makefile
index fb1c37d..cc47a42 100644
--- a/bin/ed/Makefile
+++ b/bin/ed/Makefile
@@ -7,9 +7,7 @@ SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
LINKS= ${BINDIR}/ed ${BINDIR}/red
MLINKS= ed.1 red.1
-.if !defined(RELEASE_CRUNCH) && \
- ${MK_OPENSSL} != "no" && \
- ${MK_ED_CRYPTO} != "no"
+.if ${MK_OPENSSL} != "no" && ${MK_ED_CRYPTO} != "no"
CFLAGS+=-DDES
DPADD= ${LIBCRYPTO}
LDADD= -lcrypto
diff --git a/bin/freebsd-version/freebsd-version.1 b/bin/freebsd-version/freebsd-version.1
index 1eea5bb..7e471bf 100644
--- a/bin/freebsd-version/freebsd-version.1
+++ b/bin/freebsd-version/freebsd-version.1
@@ -121,4 +121,4 @@ command appeared in
The
.Nm
utility and this manual page were written by
-.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org .
+.An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .
diff --git a/bin/ls/Makefile b/bin/ls/Makefile
index 7149d91..dce2046 100644
--- a/bin/ls/Makefile
+++ b/bin/ls/Makefile
@@ -11,8 +11,8 @@ LDADD= -lutil
.if !defined(RELEASE_CRUNCH) && \
${MK_LS_COLORS} != no
CFLAGS+= -DCOLORLS
-DPADD+= ${LIBTERMCAP}
-LDADD+= -ltermcap
+DPADD+= ${LIBTERMCAPW}
+LDADD+= -ltermcapw
.endif
.include <bsd.prog.mk>
diff --git a/bin/ls/Makefile.depend b/bin/ls/Makefile.depend
index fa30ba5..549c3a2 100644
--- a/bin/ls/Makefile.depend
+++ b/bin/ls/Makefile.depend
@@ -11,7 +11,6 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/libutil \
- lib/ncurses/ncurses \
lib/ncurses/ncursesw \
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index 2710f89..3e832ac 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -278,6 +278,7 @@ fastcopy(const char *from, const char *to, struct stat *sbp)
static char *bp = NULL;
mode_t oldmode;
int nread, from_fd, to_fd;
+ struct stat tsb;
if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
warn("fastcopy: open() failed (from): %s", from);
@@ -336,10 +337,18 @@ err: if (unlink(to))
* if the server supports flags and we were trying to *remove* flags
* on a file that we copied, i.e., that we didn't create.)
*/
- errno = 0;
- if (fchflags(to_fd, sbp->st_flags))
- if (errno != EOPNOTSUPP || sbp->st_flags != 0)
- warn("%s: set flags (was: 0%07o)", to, sbp->st_flags);
+ if (fstat(to_fd, &tsb) == 0) {
+ if ((sbp->st_flags & ~UF_ARCHIVE) !=
+ (tsb.st_flags & ~UF_ARCHIVE)) {
+ if (fchflags(to_fd,
+ sbp->st_flags | (tsb.st_flags & UF_ARCHIVE)))
+ if (errno != EOPNOTSUPP ||
+ ((sbp->st_flags & ~UF_ARCHIVE) != 0))
+ warn("%s: set flags (was: 0%07o)",
+ to, sbp->st_flags);
+ }
+ } else
+ warn("%s: cannot stat", to);
tval[0].tv_sec = sbp->st_atime;
tval[1].tv_sec = sbp->st_mtime;
diff --git a/bin/pkill/pkill.1 b/bin/pkill/pkill.1
index 1ca383f..3f219b6 100644
--- a/bin/pkill/pkill.1
+++ b/bin/pkill/pkill.1
@@ -291,5 +291,4 @@ Solaris 7.
They made their first appearance in
.Fx 5.3 .
.Sh AUTHORS
-.An Andrew Doran
-.Aq ad@NetBSD.org
+.An Andrew Doran Aq Mt ad@NetBSD.org
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index 21e6791..3a0c323 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -87,8 +87,10 @@ static VAR var[] = {
{"etimes", "ELAPSED", NULL, USER, elapseds, 0, CHAR, NULL, 0},
{"euid", "", "uid", 0, NULL, 0, CHAR, NULL, 0},
{"f", "F", NULL, 0, kvar, KOFF(ki_flag), INT, "x", 0},
+ {"f2", "F2", NULL, 0, kvar, KOFF(ki_flag2), INT, "08x", 0},
{"fib", "FIB", NULL, 0, kvar, KOFF(ki_fibnum), INT, "d", 0},
{"flags", "", "f", 0, NULL, 0, CHAR, NULL, 0},
+ {"flags2", "", "f2", 0, NULL, 0, CHAR, NULL, 0},
{"gid", "GID", NULL, 0, kvar, KOFF(ki_groups), UINT, UIDFMT, 0},
{"group", "GROUP", NULL, LJUST, egroupname, 0, CHAR, NULL, 0},
{"ignored", "", "sigignore", 0, NULL, 0, CHAR, NULL, 0},
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index c4239ea..3d7edf7 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -29,7 +29,7 @@
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
-.Dd May 2, 2014
+.Dd June 6, 2014
.Dt PS 1
.Os
.Sh NAME
@@ -340,6 +340,15 @@ the include file
.It Dv "P_SWAPPINGIN" Ta No "0x40000000" Ta "Process is being swapped in"
.It Dv "P_PPTRACE" Ta No "0x80000000" Ta "Vforked child issued ptrace(PT_TRACEME)"
.El
+.It Cm flags2
+The flags kept in
+.Va p_flag2
+associated with the process as in
+the include file
+.In sys/proc.h :
+.Bl -column P2_INHERIT_PROTECTED 0x00000001
+.It Dv "P2_INHERIT_PROTECTED" Ta No "0x00000001" Ta "New children get P_PROTECTED"
+.El
.It Cm label
The MAC label of the process.
.It Cm lim
@@ -534,6 +543,9 @@ default FIB number, see
.It Cm flags
the process flags, in hexadecimal (alias
.Cm f )
+.It Cm flags2
+the additional set of process flags, in hexadecimal (alias
+.Cm f2 )
.It Cm gid
effective group ID (alias
.Cm egid )
diff --git a/bin/rm/rm.1 b/bin/rm/rm.1
index 824b627..840b560 100644
--- a/bin/rm/rm.1
+++ b/bin/rm/rm.1
@@ -121,7 +121,6 @@ each directory's contents are processed (as well as before the attempt
is made to remove the directory).
If the user does not respond affirmatively, the file hierarchy rooted in
that directory is skipped.
-.Pp
.It Fl r
Equivalent to
.Fl R .
diff --git a/bin/rm/rm.c b/bin/rm/rm.c
index 976b4ee..46807b9 100644
--- a/bin/rm/rm.c
+++ b/bin/rm/rm.c
@@ -335,7 +335,7 @@ err:
warn("%s", p->fts_path);
eval = 1;
}
- if (errno)
+ if (!fflag && errno)
err(1, "fts_read");
fts_close(fts);
}
diff --git a/bin/rmail/Makefile b/bin/rmail/Makefile
index ad788a4..c07c9e1 100644
--- a/bin/rmail/Makefile
+++ b/bin/rmail/Makefile
@@ -14,6 +14,8 @@ MAN= rmail.8
WARNS?= 2
CFLAGS+=-I${SENDMAIL_DIR}/include -I.
+NO_PIE= yes
+
LIBSMDIR= ${.OBJDIR}/../../lib/libsm
LIBSM= ${LIBSMDIR}/libsm.a
diff --git a/bin/setfacl/setfacl.1 b/bin/setfacl/setfacl.1
index 4104315..7894233 100644
--- a/bin/setfacl/setfacl.1
+++ b/bin/setfacl/setfacl.1
@@ -485,6 +485,6 @@ NFSv4 ACL support was introduced in
The
.Nm
utility was written by
-.An Chris D. Faulhaber Aq jedgar@fxp.org .
+.An Chris D. Faulhaber Aq Mt jedgar@fxp.org .
NFSv4 ACL support was implemented by
-.An Edward Tomasz Napierala Aq trasz@FreeBSD.org .
+.An Edward Tomasz Napierala Aq Mt trasz@FreeBSD.org .
diff --git a/bin/sh/Makefile b/bin/sh/Makefile
index 6a982bc..ad43d33 100644
--- a/bin/sh/Makefile
+++ b/bin/sh/Makefile
@@ -18,8 +18,8 @@ SRCS= ${SHSRCS} ${GENSRCS} ${GENHDRS}
# utilities of the same name are handled with the associated manpage,
# builtin.1 in share/man/man1/.
-DPADD= ${LIBEDIT} ${LIBTERMCAP}
-LDADD= -ledit -ltermcap
+DPADD= ${LIBEDIT} ${LIBTERMCAPW}
+LDADD= -ledit -ltermcapw
CFLAGS+=-DSHELL -I. -I${.CURDIR}
# for debug:
diff --git a/bin/sh/Makefile.depend b/bin/sh/Makefile.depend
index cd6f78e..b2615f6 100644
--- a/bin/sh/Makefile.depend
+++ b/bin/sh/Makefile.depend
@@ -3,6 +3,7 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
+ bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
include \
@@ -11,7 +12,7 @@ DIRDEPS = \
lib/libc \
lib/libcompiler_rt \
lib/libedit \
- lib/ncurses/ncurses \
+ lib/ncurses/ncursesw \
.include <dirdeps.mk>
diff --git a/bin/sh/arith_yacc.c b/bin/sh/arith_yacc.c
index fbf9a64..815d885 100644
--- a/bin/sh/arith_yacc.c
+++ b/bin/sh/arith_yacc.c
@@ -139,7 +139,7 @@ static arith_t do_binop(int op, arith_t a, arith_t b)
case ARITH_SUB:
return (uintmax_t)a - (uintmax_t)b;
case ARITH_LSHIFT:
- return a << b;
+ return (uintmax_t)a << b;
case ARITH_RSHIFT:
return a >> b;
case ARITH_LT:
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 4f7559e..3fd3050 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -1250,8 +1250,16 @@ bltincmd(int argc, char **argv)
int
breakcmd(int argc, char **argv)
{
- int n = argc > 1 ? number(argv[1]) : 1;
+ long n;
+ char *end;
+ if (argc > 1) {
+ /* Allow arbitrarily large numbers. */
+ n = strtol(argv[1], &end, 10);
+ if (!is_digit(argv[1][0]) || *end != '\0')
+ error("Illegal number: %s", argv[1]);
+ } else
+ n = 1;
if (n > loopnest)
n = loopnest;
if (n > 0) {
diff --git a/bin/sh/exec.c b/bin/sh/exec.c
index e547e31..c9d4126 100644
--- a/bin/sh/exec.c
+++ b/bin/sh/exec.c
@@ -362,15 +362,13 @@ find_command(const char *name, struct cmdentry *entry, int act,
e = ENOENT;
idx = -1;
-loop:
- while ((fullname = padvance(&path, name)) != NULL) {
- stunalloc(fullname);
+ for (;(fullname = padvance(&path, name)) != NULL; stunalloc(fullname)) {
idx++;
if (pathopt) {
- if (prefix("func", pathopt)) {
+ if (strncmp(pathopt, "func", 4) == 0) {
/* handled below */
} else {
- goto loop; /* ignore unimplemented options */
+ continue; /* ignore unimplemented options */
}
}
if (fullname[0] != '/')
@@ -378,13 +376,12 @@ loop:
if (stat(fullname, &statb) < 0) {
if (errno != ENOENT && errno != ENOTDIR)
e = errno;
- goto loop;
+ continue;
}
e = EACCES; /* if we fail, this will be the error */
if (!S_ISREG(statb.st_mode))
- goto loop;
+ continue;
if (pathopt) { /* this is a %func directory */
- stalloc(strlen(fullname) + 1);
readcmdfile(fullname);
if ((cmdp = cmdlookup(name, 0)) == NULL || cmdp->cmdtype != CMDFUNCTION)
error("%s not defined in %s", name, fullname);
@@ -405,6 +402,7 @@ loop:
#endif
TRACE(("searchexec \"%s\" returns \"%s\"\n", name, fullname));
INTOFF;
+ stunalloc(fullname);
cmdp = cmdlookup(name, 1);
if (cmdp->cmdtype == CMDFUNCTION)
cmdp = &loc_cmd;
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index a126ca6..15afc9c 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -846,9 +846,11 @@ varisset(const char *name, int nulok)
}
} else if (is_digit(*name)) {
char *ap;
- int num = atoi(name);
+ long num;
- if (num > shellparam.nparam)
+ errno = 0;
+ num = strtol(name, NULL, 10);
+ if (errno != 0 || num > shellparam.nparam)
return 0;
if (num == 0)
@@ -928,17 +930,16 @@ numvar:
STPUTC(sep, expdest);
}
break;
- case '0':
- p = arg0;
- strtodest(p, flag, subtype, quoted);
- break;
default:
if (is_digit(*name)) {
num = atoi(name);
- if (num > 0 && num <= shellparam.nparam) {
+ if (num == 0)
+ p = arg0;
+ else if (num > 0 && num <= shellparam.nparam)
p = shellparam.p[num - 1];
- strtodest(p, flag, subtype, quoted);
- }
+ else
+ break;
+ strtodest(p, flag, subtype, quoted);
}
break;
}
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c
index af5887e..93553c1 100644
--- a/bin/sh/jobs.c
+++ b/bin/sh/jobs.c
@@ -562,6 +562,7 @@ getjob_nonotfound(const char *name)
{
int jobno;
struct job *found, *jp;
+ size_t namelen;
pid_t pid;
int i;
@@ -603,10 +604,12 @@ currentjob: if ((jp = getcurjob(NULL)) == NULL)
if (found != NULL)
return (found);
} else {
+ namelen = strlen(name);
found = NULL;
for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) {
if (jp->used && jp->nprocs > 0
- && prefix(name + 1, jp->ps[0].cmd)) {
+ && strncmp(jp->ps[0].cmd, name + 1,
+ namelen - 1) == 0) {
if (found)
error("%s: ambiguous", name);
found = jp;
diff --git a/bin/sh/main.c b/bin/sh/main.c
index e4974ea..08f234e 100644
--- a/bin/sh/main.c
+++ b/bin/sh/main.c
@@ -140,11 +140,13 @@ main(int argc, char *argv[])
#endif
rootpid = getpid();
rootshell = 1;
+ INTOFF;
initvar();
setstackmark(&smark);
setstackmark(&smark2);
procargs(argc, argv);
pwd_init(iflag);
+ INTON;
if (iflag)
chkmail(1);
if (argv[0] && argv[0][0] == '-') {
diff --git a/bin/sh/miscbltin.c b/bin/sh/miscbltin.c
index 27fa53d..027d8ae 100644
--- a/bin/sh/miscbltin.c
+++ b/bin/sh/miscbltin.c
@@ -411,13 +411,32 @@ static const struct limits limits[] = {
{ (char *) 0, (char *)0, 0, 0, '\0' }
};
+enum limithow { SOFT = 0x1, HARD = 0x2 };
+
+static void
+printlimit(enum limithow how, const struct rlimit *limit,
+ const struct limits *l)
+{
+ rlim_t val = 0;
+
+ if (how & SOFT)
+ val = limit->rlim_cur;
+ else if (how & HARD)
+ val = limit->rlim_max;
+ if (val == RLIM_INFINITY)
+ out1str("unlimited\n");
+ else
+ {
+ val /= l->factor;
+ out1fmt("%jd\n", (intmax_t)val);
+ }
+}
+
int
ulimitcmd(int argc __unused, char **argv __unused)
{
- int c;
rlim_t val = 0;
- enum { SOFT = 0x1, HARD = 0x2 }
- how = SOFT | HARD;
+ enum limithow how = SOFT | HARD;
const struct limits *l;
int set, all = 0;
int optc, what;
@@ -453,17 +472,22 @@ ulimitcmd(int argc __unused, char **argv __unused)
if (strcmp(p, "unlimited") == 0)
val = RLIM_INFINITY;
else {
- val = 0;
+ char *end;
+ uintmax_t uval;
- while ((c = *p++) >= '0' && c <= '9')
- {
- val = (val * 10) + (long)(c - '0');
- if (val < 0)
- break;
- }
- if (c)
+ if (*p < '0' || *p > '9')
+ error("bad number");
+ errno = 0;
+ uval = strtoumax(p, &end, 10);
+ if (errno != 0 || *end != '\0')
+ error("bad number");
+ if (uval > UINTMAX_MAX / l->factor)
+ error("bad number");
+ uval *= l->factor;
+ val = (rlim_t)uval;
+ if (val < 0 || (uintmax_t)val != uval ||
+ val == RLIM_INFINITY)
error("bad number");
- val *= l->factor;
}
}
if (all) {
@@ -471,10 +495,6 @@ ulimitcmd(int argc __unused, char **argv __unused)
char optbuf[40];
if (getrlimit(l->cmd, &limit) < 0)
error("can't get limit: %s", strerror(errno));
- if (how & SOFT)
- val = limit.rlim_cur;
- else if (how & HARD)
- val = limit.rlim_max;
if (l->units)
snprintf(optbuf, sizeof(optbuf),
@@ -483,13 +503,7 @@ ulimitcmd(int argc __unused, char **argv __unused)
snprintf(optbuf, sizeof(optbuf),
"(-%c) ", l->option);
out1fmt("%-18s %18s ", l->name, optbuf);
- if (val == RLIM_INFINITY)
- out1str("unlimited\n");
- else
- {
- val /= l->factor;
- out1fmt("%jd\n", (intmax_t)val);
- }
+ printlimit(how, &limit, l);
}
return 0;
}
@@ -503,19 +517,7 @@ ulimitcmd(int argc __unused, char **argv __unused)
limit.rlim_max = val;
if (setrlimit(l->cmd, &limit) < 0)
error("bad limit: %s", strerror(errno));
- } else {
- if (how & SOFT)
- val = limit.rlim_cur;
- else if (how & HARD)
- val = limit.rlim_max;
-
- if (val == RLIM_INFINITY)
- out1str("unlimited\n");
- else
- {
- val /= l->factor;
- out1fmt("%jd\n", (intmax_t)val);
- }
- }
+ } else
+ printlimit(how, &limit, l);
return 0;
}
diff --git a/bin/sh/mystring.c b/bin/sh/mystring.c
index de7e9b6..03ea8ba 100644
--- a/bin/sh/mystring.c
+++ b/bin/sh/mystring.c
@@ -61,21 +61,6 @@ char nullstr[1]; /* zero length string */
/*
- * prefix -- see if pfx is a prefix of string.
- */
-
-int
-prefix(const char *pfx, const char *string)
-{
- while (*pfx) {
- if (*pfx++ != *string++)
- return 0;
- }
- return 1;
-}
-
-
-/*
* Convert a string of digits to an integer, printing an error message on
* failure.
*/
diff --git a/bin/sh/mystring.h b/bin/sh/mystring.h
index 87b76c8..919fc86 100644
--- a/bin/sh/mystring.h
+++ b/bin/sh/mystring.h
@@ -35,7 +35,6 @@
#include <string.h>
-int prefix(const char *, const char *);
int number(const char *);
int is_number(const char *);
diff --git a/bin/sh/options.c b/bin/sh/options.c
index ad0291e..bf00a4e 100644
--- a/bin/sh/options.c
+++ b/bin/sh/options.c
@@ -446,6 +446,7 @@ getopts(char *optstr, char *optvar, char **optfirst, char ***optnext,
int ind = 0;
int err = 0;
char s[10];
+ const char *optarg = NULL;
if ((p = *optptr) == NULL || *p == '\0') {
/* Current word is done, advance */
@@ -471,14 +472,12 @@ atend:
if (optstr[0] == ':') {
s[0] = c;
s[1] = '\0';
- err |= setvarsafe("OPTARG", s, 0);
- }
- else {
- out1fmt("Illegal option -%c\n", c);
- (void) unsetvar("OPTARG");
+ optarg = s;
}
+ else
+ out2fmt_flush("Illegal option -%c\n", c);
c = '?';
- goto bad;
+ goto out;
}
if (*++q == ':')
q++;
@@ -489,33 +488,33 @@ atend:
if (optstr[0] == ':') {
s[0] = c;
s[1] = '\0';
- err |= setvarsafe("OPTARG", s, 0);
+ optarg = s;
c = ':';
}
else {
- out1fmt("No arg for -%c option\n", c);
- (void) unsetvar("OPTARG");
+ out2fmt_flush("No arg for -%c option\n", c);
c = '?';
}
- goto bad;
+ goto out;
}
if (p == **optnext)
(*optnext)++;
- setvarsafe("OPTARG", p, 0);
+ optarg = p;
p = NULL;
}
- else
- setvarsafe("OPTARG", "", 0);
- ind = *optnext - optfirst + 1;
- goto out;
-
-bad:
- ind = 1;
- *optnext = NULL;
- p = NULL;
+
out:
+ if (*optnext != NULL)
+ ind = *optnext - optfirst + 1;
*optptr = p;
+ if (optarg != NULL)
+ err |= setvarsafe("OPTARG", optarg, 0);
+ else {
+ INTOFF;
+ err |= unsetvar("OPTARG");
+ INTON;
+ }
fmtstr(s, sizeof(s), "%d", ind);
err |= setvarsafe("OPTIND", s, VNOFUNC);
s[0] = c;
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile
index c0b21dc..4c988da 100644
--- a/bin/sh/tests/builtins/Makefile
+++ b/bin/sh/tests/builtins/Makefile
@@ -14,6 +14,7 @@ FILES+= break2.0 break2.0.stdout
FILES+= break3.0
FILES+= break4.4
FILES+= break5.4
+FILES+= break6.0
FILES+= builtin1.0
FILES+= case1.0
FILES+= case2.0
@@ -83,6 +84,9 @@ FILES+= getopts2.0 getopts2.0.stdout
FILES+= getopts3.0
FILES+= getopts4.0
FILES+= getopts5.0
+FILES+= getopts6.0
+FILES+= getopts7.0
+FILES+= getopts8.0 getopts8.0.stdout
FILES+= hash1.0 hash1.0.stdout
FILES+= hash2.0 hash2.0.stdout
FILES+= hash3.0 hash3.0.stdout
@@ -96,7 +100,9 @@ FILES+= local1.0
FILES+= local2.0
FILES+= local3.0
FILES+= local4.0
+.if ${MK_NLS} != "no"
FILES+= locale1.0
+.endif
FILES+= printf1.0
FILES+= printf2.0
FILES+= printf3.0
diff --git a/bin/sh/tests/builtins/break6.0 b/bin/sh/tests/builtins/break6.0
new file mode 100644
index 0000000..09fc0d8
--- /dev/null
+++ b/bin/sh/tests/builtins/break6.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+# Per POSIX, this need only work if LONG_MAX > 4294967295.
+
+while :; do
+ break 4294967296
+ echo bad
+ exit 3
+done
diff --git a/bin/sh/tests/builtins/getopts1.0 b/bin/sh/tests/builtins/getopts1.0
index af31d55..64763bc 100644
--- a/bin/sh/tests/builtins/getopts1.0
+++ b/bin/sh/tests/builtins/getopts1.0
@@ -15,7 +15,7 @@ printf -- '-2-\n'
set -- -ab
getopts "ab:" OPTION
echo ${OPTION}
-getopts "ab:" OPTION
+getopts "ab:" OPTION 3>&2 2>&1 >&3 3>&-
echo ${OPTION}
# The 'shift' is aimed at causing an error.
diff --git a/bin/sh/tests/builtins/getopts6.0 b/bin/sh/tests/builtins/getopts6.0
new file mode 100644
index 0000000..1d3c39b
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts6.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+set -- -x -y
+getopts :x var || echo "First getopts bad: $?"
+getopts :x var
+r=$?
+[ r != 0 ] && [ "$OPTIND" = 3 ]
diff --git a/bin/sh/tests/builtins/getopts7.0 b/bin/sh/tests/builtins/getopts7.0
new file mode 100644
index 0000000..3745555
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts7.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -- -x
+getopts :x: var
+r=$?
+[ r != 0 ] && [ "$OPTIND" = 2 ]
diff --git a/bin/sh/tests/builtins/getopts8.0 b/bin/sh/tests/builtins/getopts8.0
new file mode 100644
index 0000000..da4af6b
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts8.0
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+set -- -yz -wx
+opt=wrong1 OPTARG=wrong2
+while getopts :x opt; do
+ echo "$opt:${OPTARG-unset}"
+done
+echo "OPTIND=$OPTIND"
diff --git a/bin/sh/tests/builtins/getopts8.0.stdout b/bin/sh/tests/builtins/getopts8.0.stdout
new file mode 100644
index 0000000..f10cefc
--- /dev/null
+++ b/bin/sh/tests/builtins/getopts8.0.stdout
@@ -0,0 +1,5 @@
+?:y
+?:z
+?:w
+x:unset
+OPTIND=3
diff --git a/bin/sh/tests/parameters/Makefile b/bin/sh/tests/parameters/Makefile
index fafc059..da49d14 100644
--- a/bin/sh/tests/parameters/Makefile
+++ b/bin/sh/tests/parameters/Makefile
@@ -13,6 +13,9 @@ FILES+= optind1.0
FILES+= optind2.0
FILES+= positional1.0
FILES+= positional2.0
+FILES+= positional3.0
+FILES+= positional4.0
+FILES+= positional5.0
FILES+= pwd1.0
FILES+= pwd2.0
diff --git a/bin/sh/tests/parameters/positional3.0 b/bin/sh/tests/parameters/positional3.0
new file mode 100644
index 0000000..1200469
--- /dev/null
+++ b/bin/sh/tests/parameters/positional3.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+r=$(${SH} -c 'echo ${01:+yes}${010:+yes}' '' a '' '' '' '' '' '' '' '' b)
+[ "$r" = yesyes ]
diff --git a/bin/sh/tests/parameters/positional4.0 b/bin/sh/tests/parameters/positional4.0
new file mode 100644
index 0000000..c1c380c
--- /dev/null
+++ b/bin/sh/tests/parameters/positional4.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+set -- "x$0" 2 3 4 5 6 7 8 9 "y$0"
+[ "${01}.${010}" = "$1.${10}" ]
diff --git a/bin/sh/tests/parameters/positional5.0 b/bin/sh/tests/parameters/positional5.0
new file mode 100644
index 0000000..eeaaba5
--- /dev/null
+++ b/bin/sh/tests/parameters/positional5.0
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+i=1
+r=0
+while [ $i -lt $((0x100000000)) ]; do
+ t=
+ eval t=\${$i-x}
+ case $t in
+ x) ;;
+ *) echo "Problem with \${$i}" >&2; r=1 ;;
+ esac
+ i=$((i + 0x10000000))
+done
+exit $r
OpenPOWER on IntegriCloud