aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
commit98e0ffaefb0f241cda3a72395d3be04192ae0d47 (patch)
tree55c065b6730aaac2afb6c29933ee6ec5fa4c4249 /bin
parentb17ff922d4072ae132ece458f5b5d74a236880ac (diff)
parente81032ad243db32b8fd615b2d55ee94b9f6a5b6a (diff)
downloadsrc-98e0ffaefb0f241cda3a72395d3be04192ae0d47.tar.gz
src-98e0ffaefb0f241cda3a72395d3be04192ae0d47.zip
Merge sync of head
Notes
Notes: svn path=/projects/bmake/; revision=283595
Diffstat (limited to 'bin')
-rw-r--r--bin/cat/Makefile6
-rw-r--r--bin/cat/tests/Makefile18
-rw-r--r--bin/chflags/chflags.115
-rw-r--r--bin/chflags/chflags.c51
-rw-r--r--bin/chmod/chmod.114
-rw-r--r--bin/chmod/chmod.c90
-rw-r--r--bin/cp/cp.c29
-rw-r--r--bin/cp/utils.c11
-rw-r--r--bin/csh/Makefile5
-rw-r--r--bin/csh/config.h2
-rw-r--r--bin/csh/iconv_stub.h2
-rw-r--r--bin/date/date.17
-rw-r--r--bin/date/date.c10
-rw-r--r--bin/df/Makefile3
-rw-r--r--bin/ed/Makefile3
-rw-r--r--bin/ed/ed.12
-rw-r--r--bin/ed/glbl.c4
-rw-r--r--bin/expr/Makefile9
-rw-r--r--bin/expr/expr.18
-rw-r--r--bin/expr/expr.y20
-rw-r--r--bin/expr/tests/Makefile16
-rw-r--r--bin/freebsd-version/Makefile5
-rw-r--r--bin/kill/kill.c1
-rw-r--r--bin/ln/symlink.723
-rw-r--r--bin/ls/Makefile6
-rw-r--r--bin/mv/mv.c9
-rw-r--r--bin/pax/ar_io.c4
-rw-r--r--bin/pax/ar_subs.c1
-rw-r--r--bin/pax/buf_subs.c1
-rw-r--r--bin/pax/cache.c1
-rw-r--r--bin/pax/cpio.c2
-rw-r--r--bin/pax/extern.h1
-rw-r--r--bin/pax/file_subs.c1
-rw-r--r--bin/pax/gen_subs.c2
-rw-r--r--bin/pax/getoldopt.c3
-rw-r--r--bin/pax/options.c24
-rw-r--r--bin/pax/pat_rep.c2
-rw-r--r--bin/pax/pax.118
-rw-r--r--bin/pax/pax.c2
-rw-r--r--bin/pax/sel_subs.c1
-rw-r--r--bin/pax/tar.c2
-rw-r--r--bin/pax/tty_subs.c1
-rw-r--r--bin/pkill/Makefile3
-rw-r--r--bin/pkill/tests/pgrep-j_test.sh128
-rw-r--r--bin/pkill/tests/pkill-j_test.sh142
-rw-r--r--bin/ps/Makefile3
-rw-r--r--bin/ps/Makefile.depend1
-rw-r--r--bin/ps/keyword.c282
-rw-r--r--bin/ps/print.c36
-rw-r--r--bin/ps/ps.111
-rw-r--r--bin/ps/ps.c103
-rw-r--r--bin/ps/ps.h1
-rw-r--r--bin/rcp/Makefile1
-rw-r--r--bin/rmail/Makefile6
-rw-r--r--bin/sh/Makefile3
-rw-r--r--bin/sh/arith_yacc.h2
-rw-r--r--bin/sh/arith_yylex.c2
-rw-r--r--bin/sh/bltin/bltin.h2
-rw-r--r--bin/sh/cd.c12
-rw-r--r--bin/sh/error.c30
-rw-r--r--bin/sh/error.h3
-rw-r--r--bin/sh/eval.c18
-rw-r--r--bin/sh/eval.h2
-rw-r--r--bin/sh/expand.c139
-rw-r--r--bin/sh/expand.h1
-rw-r--r--bin/sh/histedit.c6
-rw-r--r--bin/sh/jobs.c12
-rw-r--r--bin/sh/mail.c2
-rw-r--r--bin/sh/memalloc.c12
-rw-r--r--bin/sh/memalloc.h1
-rw-r--r--bin/sh/miscbltin.c2
-rw-r--r--bin/sh/mknodes.c2
-rw-r--r--bin/sh/mksyntax.c6
-rw-r--r--bin/sh/mktokens4
-rw-r--r--bin/sh/nodetypes2
-rw-r--r--bin/sh/options.c12
-rw-r--r--bin/sh/options.h3
-rw-r--r--bin/sh/output.c91
-rw-r--r--bin/sh/parser.c4
-rw-r--r--bin/sh/sh.124
-rw-r--r--bin/sh/tests/builtins/Makefile2
-rw-r--r--bin/sh/tests/builtins/trap15.05
-rw-r--r--bin/sh/tests/builtins/trap16.020
-rw-r--r--bin/sh/tests/execution/Makefile1
-rw-r--r--bin/sh/tests/execution/set-x4.07
-rw-r--r--bin/sh/tests/expansion/Makefile4
-rw-r--r--bin/sh/tests/expansion/ifs5.04
-rw-r--r--bin/sh/tests/expansion/ifs6.06
-rw-r--r--bin/sh/tests/expansion/ifs7.05
-rw-r--r--bin/sh/tests/expansion/pathname5.03
-rw-r--r--bin/sh/trap.c17
-rw-r--r--bin/sh/trap.h1
-rw-r--r--bin/sh/var.c12
-rw-r--r--bin/sh/var.h2
94 files changed, 925 insertions, 713 deletions
diff --git a/bin/cat/Makefile b/bin/cat/Makefile
index 672a4eeeeff5..97e5812e4bf2 100644
--- a/bin/cat/Makefile
+++ b/bin/cat/Makefile
@@ -1,6 +1,12 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+.include <src.opts.mk>
+
PROG= cat
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
diff --git a/bin/cat/tests/Makefile b/bin/cat/tests/Makefile
new file mode 100644
index 000000000000..73f82e125d6f
--- /dev/null
+++ b/bin/cat/tests/Makefile
@@ -0,0 +1,18 @@
+# $FreeBSD$
+
+OBJTOP= ${.OBJDIR}/../../..
+SRCTOP= ${.CURDIR}/../../..
+TESTSRC= ${SRCTOP}/contrib/netbsd-tests/bin/cat
+
+TESTSDIR= ${TESTSBASE}/bin/cat
+
+NETBSD_ATF_TESTS_SH= cat_test
+
+FILESDIR= ${TESTSDIR}
+
+FILES= d_align.in
+FILES+= d_align.out
+
+.include <netbsd-tests.test.mk>
+
+.include <bsd.test.mk>
diff --git a/bin/chflags/chflags.1 b/bin/chflags/chflags.1
index 47d5b181b45d..755cbced269e 100644
--- a/bin/chflags/chflags.1
+++ b/bin/chflags/chflags.1
@@ -32,7 +32,7 @@
.\" @(#)chflags.1 8.4 (Berkeley) 5/2/95
.\" $FreeBSD$
.\"
-.Dd April 8, 2013
+.Dd April 20, 2015
.Dt CHFLAGS 1
.Os
.Sh NAME
@@ -66,8 +66,9 @@ nor modify the exit status to reflect such failures.
.It Fl H
If the
.Fl R
-option is specified, symbolic links on the command line are followed.
-(Symbolic links encountered in the tree traversal are not followed.)
+option is specified, symbolic links on the command line are followed
+and hence unaffected by the command.
+(Symbolic links encountered during traversal are not followed.)
.It Fl h
If the
.Ar file
@@ -83,8 +84,12 @@ If the
option is specified, no symbolic links are followed.
This is the default.
.It Fl R
-Change the file flags for the file hierarchies rooted
-in the files instead of just the files themselves.
+Change the file flags of the file hierarchies rooted in the files,
+instead of just the files themselves.
+Beware of unintentionally matching the
+.Dq Pa ".."
+hard link to the parent directory when using wildcards like
+.Dq Li ".*" .
.It Fl v
Cause
.Nm
diff --git a/bin/chflags/chflags.c b/bin/chflags/chflags.c
index e94c34df6eb1..2029ac5d7703 100644
--- a/bin/chflags/chflags.c
+++ b/bin/chflags/chflags.c
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <fts.h>
#include <stdio.h>
#include <stdlib.h>
@@ -65,7 +66,6 @@ main(int argc, char *argv[])
int Hflag, Lflag, Rflag, fflag, hflag, vflag;
int ch, fts_options, oct, rval;
char *flags, *ep;
- int (*change_flags)(const char *, unsigned long);
Hflag = Lflag = Rflag = fflag = hflag = vflag = 0;
while ((ch = getopt(argc, argv, "HLPRfhv")) != -1)
@@ -104,20 +104,23 @@ main(int argc, char *argv[])
usage();
if (Rflag) {
- fts_options = FTS_PHYSICAL;
if (hflag)
- errx(1, "the -R and -h options "
- "may not be specified together");
- if (Hflag)
- fts_options |= FTS_COMFOLLOW;
+ errx(1, "the -R and -h options may not be "
+ "specified together.");
if (Lflag) {
- fts_options &= ~FTS_PHYSICAL;
- fts_options |= FTS_LOGICAL;
- }
- } else
- fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
+ fts_options = FTS_LOGICAL;
+ } else {
+ fts_options = FTS_PHYSICAL;
- change_flags = hflag ? lchflags : chflags;
+ if (Hflag) {
+ fts_options |= FTS_COMFOLLOW;
+ }
+ }
+ } else if (hflag) {
+ fts_options = FTS_PHYSICAL;
+ } else {
+ fts_options = FTS_LOGICAL;
+ }
flags = *argv;
if (*flags >= '0' && *flags <= '7') {
@@ -142,12 +145,21 @@ main(int argc, char *argv[])
err(1, NULL);
for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
+ int atflag;
+
+ if ((fts_options & FTS_LOGICAL) ||
+ ((fts_options & FTS_COMFOLLOW) &&
+ p->fts_level == FTS_ROOTLEVEL))
+ atflag = 0;
+ else
+ atflag = AT_SYMLINK_NOFOLLOW;
+
switch (p->fts_info) {
case FTS_D: /* Change it at FTS_DP if we're recursive. */
if (!Rflag)
fts_set(ftsp, p, FTS_SKIP);
continue;
- case FTS_DNR: /* Warn, chflag, continue. */
+ case FTS_DNR: /* Warn, chflags. */
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
rval = 1;
break;
@@ -156,16 +168,6 @@ main(int argc, char *argv[])
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
rval = 1;
continue;
- case FTS_SL: /* Ignore. */
- case FTS_SLNONE:
- /*
- * The only symlinks that end up here are ones that
- * don't point to anything and ones that we found
- * doing a physical walk.
- */
- if (!hflag)
- continue;
- /* FALLTHROUGH */
default:
break;
}
@@ -175,7 +177,8 @@ main(int argc, char *argv[])
newflags = (p->fts_statp->st_flags | set) & clear;
if (newflags == p->fts_statp->st_flags)
continue;
- if ((*change_flags)(p->fts_accpath, newflags) && !fflag) {
+ if (chflagsat(AT_FDCWD, p->fts_accpath, newflags,
+ atflag) == -1 && !fflag) {
warn("%s", p->fts_path);
rval = 1;
} else if (vflag) {
diff --git a/bin/chmod/chmod.1 b/bin/chmod/chmod.1
index 34a1ff018d9f..7efaabcdefcf 100644
--- a/bin/chmod/chmod.1
+++ b/bin/chmod/chmod.1
@@ -32,7 +32,7 @@
.\" @(#)chmod.1 8.4 (Berkeley) 3/31/94
.\" $FreeBSD$
.\"
-.Dd January 26, 2009
+.Dd April 20, 2015
.Dt CHMOD 1
.Os
.Sh NAME
@@ -63,9 +63,9 @@ nor modify the exit status to reflect such failures.
.It Fl H
If the
.Fl R
-option is specified, symbolic links on the command line are followed.
-(Symbolic links encountered in the tree traversal are not followed by
-default.)
+option is specified, symbolic links on the command line are followed
+and hence unaffected by the command.
+(Symbolic links encountered during tree traversal are not followed.)
.It Fl h
If the file is a symbolic link, change the mode of the link itself
rather than the file that the link points to.
@@ -79,8 +79,12 @@ If the
option is specified, no symbolic links are followed.
This is the default.
.It Fl R
-Change the modes of the file hierarchies rooted in the files
+Change the modes of the file hierarchies rooted in the files,
instead of just the files themselves.
+Beware of unintentionally matching the
+.Dq Pa ".."
+hard link to the parent directory when using wildcards like
+.Dq Li ".*" .
.It Fl v
Cause
.Nm
diff --git a/bin/chmod/chmod.c b/bin/chmod/chmod.c
index dc51faa39b01..9b801576efa7 100644
--- a/bin/chmod/chmod.c
+++ b/bin/chmod/chmod.c
@@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <fts.h>
#include <limits.h>
#include <stdio.h>
@@ -62,7 +63,7 @@ main(int argc, char *argv[])
FTS *ftsp;
FTSENT *p;
mode_t *set;
- int Hflag, Lflag, Rflag, ch, error, fflag, fts_options, hflag, rval;
+ int Hflag, Lflag, Rflag, ch, fflag, fts_options, hflag, rval;
int vflag;
char *mode;
mode_t newmode;
@@ -126,18 +127,23 @@ done: argv += optind;
usage();
if (Rflag) {
- fts_options = FTS_PHYSICAL;
if (hflag)
- errx(1,
- "the -R and -h options may not be specified together.");
- if (Hflag)
- fts_options |= FTS_COMFOLLOW;
+ errx(1, "the -R and -h options may not be "
+ "specified together.");
if (Lflag) {
- fts_options &= ~FTS_PHYSICAL;
- fts_options |= FTS_LOGICAL;
+ fts_options = FTS_LOGICAL;
+ } else {
+ fts_options = FTS_PHYSICAL;
+
+ if (Hflag) {
+ fts_options |= FTS_COMFOLLOW;
+ }
}
- } else
- fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL;
+ } else if (hflag) {
+ fts_options = FTS_PHYSICAL;
+ } else {
+ fts_options = FTS_LOGICAL;
+ }
mode = *argv;
if ((set = setmode(mode)) == NULL)
@@ -146,12 +152,21 @@ done: argv += optind;
if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL)
err(1, "fts_open");
for (rval = 0; (p = fts_read(ftsp)) != NULL;) {
+ int atflag;
+
+ if ((fts_options & FTS_LOGICAL) ||
+ ((fts_options & FTS_COMFOLLOW) &&
+ p->fts_level == FTS_ROOTLEVEL))
+ atflag = 0;
+ else
+ atflag = AT_SYMLINK_NOFOLLOW;
+
switch (p->fts_info) {
case FTS_D: /* Change it at FTS_DP. */
if (!Rflag)
fts_set(ftsp, p, FTS_SKIP);
continue;
- case FTS_DNR: /* Warn, chmod, continue. */
+ case FTS_DNR: /* Warn, chmod. */
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
rval = 1;
break;
@@ -160,16 +175,6 @@ done: argv += optind;
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
rval = 1;
continue;
- case FTS_SL: /* Ignore. */
- case FTS_SLNONE:
- /*
- * The only symlinks that end up here are ones that
- * don't point to anything and ones that we found
- * doing a physical walk.
- */
- if (!hflag)
- continue;
- /* FALLTHROUGH */
default:
break;
}
@@ -182,32 +187,25 @@ done: argv += optind;
if (may_have_nfs4acl(p, hflag) == 0 &&
(newmode & ALLPERMS) == (p->fts_statp->st_mode & ALLPERMS))
continue;
- if (hflag)
- error = lchmod(p->fts_accpath, newmode);
- else
- error = chmod(p->fts_accpath, newmode);
- if (error) {
- if (!fflag) {
- warn("%s", p->fts_path);
- rval = 1;
- }
- } else {
- if (vflag) {
- (void)printf("%s", p->fts_path);
-
- if (vflag > 1) {
- char m1[12], m2[12];
-
- strmode(p->fts_statp->st_mode, m1);
- strmode((p->fts_statp->st_mode &
- S_IFMT) | newmode, m2);
- (void)printf(": 0%o [%s] -> 0%o [%s]",
- p->fts_statp->st_mode, m1,
- (p->fts_statp->st_mode & S_IFMT) |
- newmode, m2);
- }
- (void)printf("\n");
+ if (fchmodat(AT_FDCWD, p->fts_accpath, newmode, atflag) == -1
+ && !fflag) {
+ warn("%s", p->fts_path);
+ rval = 1;
+ } else if (vflag) {
+ (void)printf("%s", p->fts_path);
+
+ if (vflag > 1) {
+ char m1[12], m2[12];
+
+ strmode(p->fts_statp->st_mode, m1);
+ strmode((p->fts_statp->st_mode &
+ S_IFMT) | newmode, m2);
+ (void)printf(": 0%o [%s] -> 0%o [%s]",
+ p->fts_statp->st_mode, m1,
+ (p->fts_statp->st_mode & S_IFMT) |
+ newmode, m2);
}
+ (void)printf("\n");
}
}
if (errno)
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index b83eeadc86ae..2ad5f4a43414 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -90,7 +90,6 @@ volatile sig_atomic_t info;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
static int copy(char *[], enum op, int);
-static int mastercmp(const FTSENT * const *, const FTSENT * const *);
static void siginfo(int __unused);
int
@@ -274,7 +273,7 @@ copy(char *argv[], enum op type, int fts_options)
mask = ~umask(0777);
umask(~mask);
- if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL)
+ if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL)
err(1, "fts_open");
for (badcp = rval = 0; (curr = fts_read(ftsp)) != NULL; badcp = 0) {
switch (curr->fts_info) {
@@ -488,32 +487,6 @@ copy(char *argv[], enum op type, int fts_options)
return (rval);
}
-/*
- * mastercmp --
- * The comparison function for the copy order. The order is to copy
- * non-directory files before directory files. The reason for this
- * is because files tend to be in the same cylinder group as their
- * parent directory, whereas directories tend not to be. Copying the
- * files first reduces seeking.
- */
-static int
-mastercmp(const FTSENT * const *a, const FTSENT * const *b)
-{
- int a_info, b_info;
-
- a_info = (*a)->fts_info;
- if (a_info == FTS_ERR || a_info == FTS_NS || a_info == FTS_DNR)
- return (0);
- b_info = (*b)->fts_info;
- if (b_info == FTS_ERR || b_info == FTS_NS || b_info == FTS_DNR)
- return (0);
- if (a_info == FTS_D)
- return (-1);
- if (b_info == FTS_D)
- return (1);
- return (0);
-}
-
static void
siginfo(int sig __unused)
{
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index ad9695c08a13..f58ed7a96f9b 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -330,7 +330,7 @@ copy_special(struct stat *from_stat, int exists)
int
setfile(struct stat *fs, int fd)
{
- static struct timeval tv[2];
+ static struct timespec tspec[2];
struct stat ts;
int rval, gotstat, islink, fdval;
@@ -340,10 +340,11 @@ setfile(struct stat *fs, int fd)
fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
S_IRWXU | S_IRWXG | S_IRWXO;
- TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atim);
- TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtim);
- if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
- warn("%sutimes: %s", islink ? "l" : "", to.p_path);
+ tspec[0] = fs->st_atim;
+ tspec[1] = fs->st_mtim;
+ if (fdval ? futimens(fd, tspec) : utimensat(AT_FDCWD, to.p_path, tspec,
+ islink ? AT_SYMLINK_NOFOLLOW : 0)) {
+ warn("utimensat: %s", to.p_path);
rval = 1;
}
if (fdval ? fstat(fd, &ts) :
diff --git a/bin/csh/Makefile b/bin/csh/Makefile
index fd345245eb0b..51ef3dd9c306 100644
--- a/bin/csh/Makefile
+++ b/bin/csh/Makefile
@@ -40,8 +40,7 @@ MLINKS= csh.1 tcsh.1
# utilities of the same name are handled with the associated manpage,
# builtin.1 in share/man/man1/.
-DPADD= ${LIBTERMCAPW} ${LIBCRYPT}
-LDADD= -ltermcapw -lcrypt
+LIBADD= termcapw crypt
LINKS= ${BINDIR}/csh ${BINDIR}/tcsh
@@ -94,7 +93,7 @@ GENHDRS+= iconv.h
SRCS+= iconv_stub.c
iconv.h: ${.CURDIR}/iconv_stub.h
- cp -f ${.CURDIR}/iconv_stub.h ${.TARGET}
+ ${CP} ${.CURDIR}/iconv_stub.h ${.TARGET}
.endif
.endif
diff --git a/bin/csh/config.h b/bin/csh/config.h
index 99f7d0b6a118..99aed5f7c64e 100644
--- a/bin/csh/config.h
+++ b/bin/csh/config.h
@@ -198,7 +198,7 @@
#define HAVE_WCWIDTH 1
/* Define as const if the declaration of iconv() needs const. */
-#define ICONV_CONST const
+#define ICONV_CONST
/* Support NLS. */
#define NLS 1
diff --git a/bin/csh/iconv_stub.h b/bin/csh/iconv_stub.h
index 89e9d0db59ac..a3e069a06e31 100644
--- a/bin/csh/iconv_stub.h
+++ b/bin/csh/iconv_stub.h
@@ -30,7 +30,7 @@
#define _ICONV_H_
typedef void *iconv_t;
-typedef size_t dl_iconv_t(iconv_t, const char **, size_t *, char **, size_t *);
+typedef size_t dl_iconv_t(iconv_t, char **, size_t *, char **, size_t *);
typedef int dl_iconv_close_t(iconv_t);
extern iconv_t dl_iconv_open(const char *, const char *);
diff --git a/bin/date/date.1 b/bin/date/date.1
index 5e9e6648d6d0..dd791ec7b78f 100644
--- a/bin/date/date.1
+++ b/bin/date/date.1
@@ -32,7 +32,7 @@
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
.\" $FreeBSD$
.\"
-.Dd April 26, 2014
+.Dd May 7, 2015
.Dt DATE 1
.Os
.Sh NAME
@@ -41,7 +41,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl jRu
-.Op Fl r Ar seconds
+.Op Fl r Ar seconds | Ar filename
.Oo
.Fl v
.Sm off
@@ -150,6 +150,9 @@ is the number of seconds since the Epoch
see
.Xr time 3 ) ,
and can be specified in decimal, octal, or hex.
+.It Fl r Ar filename
+Print the date and time of the last modification of
+.Ar filename .
.It Fl t Ar minutes_west
Set the system's value for minutes west of
.Tn GMT .
diff --git a/bin/date/date.c b/bin/date/date.c
index 2c09848a151e..9ae6502e2a7e 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/time.h>
+#include <sys/stat.h>
#include <ctype.h>
#include <err.h>
@@ -85,6 +86,7 @@ main(int argc, char *argv[])
struct vary *v;
const struct vary *badv;
struct tm lt;
+ struct stat sb;
v = NULL;
fmt = NULL;
@@ -116,8 +118,12 @@ main(int argc, char *argv[])
case 'r': /* user specified seconds */
rflag = 1;
tval = strtoq(optarg, &tmp, 0);
- if (*tmp != 0)
- usage();
+ if (*tmp != 0) {
+ if (stat(optarg, &sb) == 0)
+ tval = sb.st_mtim.tv_sec;
+ else
+ usage();
+ }
break;
case 't': /* minutes west of UTC */
/* error check; don't allow "PST" */
diff --git a/bin/df/Makefile b/bin/df/Makefile
index fb7b09a6ffe8..5cdae9ed7d2b 100644
--- a/bin/df/Makefile
+++ b/bin/df/Makefile
@@ -9,7 +9,6 @@ SRCS= df.c vfslist.c
CFLAGS+= -I${MOUNT}
-DPADD= ${LIBUTIL} ${LIBXO}
-LDADD= -lutil -lxo
+LIBADD= xo util
.include <bsd.prog.mk>
diff --git a/bin/ed/Makefile b/bin/ed/Makefile
index cc47a4271e92..bef3ff1ad5ef 100644
--- a/bin/ed/Makefile
+++ b/bin/ed/Makefile
@@ -9,8 +9,7 @@ MLINKS= ed.1 red.1
.if ${MK_OPENSSL} != "no" && ${MK_ED_CRYPTO} != "no"
CFLAGS+=-DDES
-DPADD= ${LIBCRYPTO}
-LDADD= -lcrypto
+LIBADD= crypto
.endif
.include <bsd.prog.mk>
diff --git a/bin/ed/ed.1 b/bin/ed/ed.1
index 8342645997c9..335dbd80ac7d 100644
--- a/bin/ed/ed.1
+++ b/bin/ed/ed.1
@@ -738,7 +738,7 @@ It is an error if no substitutions are performed on any of the addressed
lines.
The current address is set the last line affected.
.Pp
-.Ar Re
+.Ar \&Re
and
.Ar replacement
may be delimited by any character other than space and newline
diff --git a/bin/ed/glbl.c b/bin/ed/glbl.c
index 5524700983e8..dfb44d28ca0d 100644
--- a/bin/ed/glbl.c
+++ b/bin/ed/glbl.c
@@ -60,7 +60,7 @@ build_active_list(int isgcmd)
return ERR;
if (isbinary)
NUL_TO_NEWLINE(s, lp->len);
- if (!regexec(pat, s, 0, NULL, 0) == isgcmd &&
+ if (!(regexec(pat, s, 0, NULL, 0) == isgcmd) &&
set_active_node(lp) < 0)
return ERR;
}
@@ -153,7 +153,7 @@ set_active_node(line_t *lp)
if (active_list != NULL) {
#endif
if ((ts = (line_t **) realloc(active_list,
- (ti += MINBUFSZ) * sizeof(line_t **))) == NULL) {
+ (ti += MINBUFSZ) * sizeof(line_t *))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
errmsg = "out of memory";
SPL0();
diff --git a/bin/expr/Makefile b/bin/expr/Makefile
index b86cf6686ab0..1d741b7e0b6d 100644
--- a/bin/expr/Makefile
+++ b/bin/expr/Makefile
@@ -1,9 +1,18 @@
# $FreeBSD$
+.include <src.opts.mk>
+
PROG= expr
SRCS= expr.y
YFLAGS=
+# expr relies on signed integer wrapping
+CFLAGS+= -fwrapv
+
NO_WMISSING_VARIABLE_DECLARATIONS=
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
diff --git a/bin/expr/expr.1 b/bin/expr/expr.1
index 34be0b8fa9de..d02105561fde 100644
--- a/bin/expr/expr.1
+++ b/bin/expr/expr.1
@@ -90,17 +90,17 @@ Return the evaluation of
.Ar expr1
if neither expression evaluates to an empty string or zero;
otherwise, returns zero.
-.It Ar expr1 Li "{=, >, >=, <, <=, !=}" Ar expr2
+.It Ar expr1 Bro =, >, >=, <, <=, != Brc Ar expr2
Return the results of integer comparison if both arguments are integers;
otherwise, returns the results of string comparison using the locale-specific
collation sequence.
The result of each comparison is 1 if the specified relation is true,
or 0 if the relation is false.
-.It Ar expr1 Li "{+, -}" Ar expr2
+.It Ar expr1 Bro +, - Brc Ar expr2
Return the results of addition or subtraction of integer-valued arguments.
-.It Ar expr1 Li "{*, /, %}" Ar expr2
+.It Ar expr1 Bro *, /, % Brc Ar expr2
Return the results of multiplication, integer division, or remainder of integer-valued arguments.
-.It Ar expr1 Li : Ar expr2
+.It Ar expr1 Li \&: Ar expr2
The
.Dq Li \&:
operator matches
diff --git a/bin/expr/expr.y b/bin/expr/expr.y
index 1856ec84d0f7..0ddf3990d2a8 100644
--- a/bin/expr/expr.y
+++ b/bin/expr/expr.y
@@ -444,14 +444,26 @@ op_minus(struct val *a, struct val *b)
return (r);
}
+/*
+ * We depend on undefined behaviour giving a result (in r).
+ * To test this result, pass it as volatile. This prevents
+ * optimizing away of the test based on the undefined behaviour.
+ */
void
-assert_times(intmax_t a, intmax_t b, intmax_t r)
+assert_times(intmax_t a, intmax_t b, volatile intmax_t r)
{
/*
- * if first operand is 0, no overflow is possible,
- * else result of division test must match second operand
+ * If the first operand is 0, no overflow is possible,
+ * else the result of the division test must match the
+ * second operand.
+ *
+ * Be careful to avoid overflow in the overflow test, as
+ * in assert_div(). Overflow in division would kill us
+ * with a SIGFPE before getting the test wrong. In old
+ * buggy versions, optimization used to give a null test
+ * instead of a SIGFPE.
*/
- if (a != 0 && r / a != b)
+ if ((a == -1 && b == INTMAX_MIN) || (a != 0 && r / a != b))
errx(ERR_EXIT, "overflow");
}
diff --git a/bin/expr/tests/Makefile b/bin/expr/tests/Makefile
new file mode 100644
index 000000000000..80c130c3df20
--- /dev/null
+++ b/bin/expr/tests/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+OBJTOP= ${.OBJDIR}/../../..
+SRCTOP= ${.CURDIR}/../../..
+TESTSRC= ${SRCTOP}/contrib/netbsd-tests/bin/expr
+
+TESTSDIR= ${TESTSBASE}/bin/expr
+
+NETBSD_ATF_TESTS_SH= expr_test
+
+ATF_TESTS_SH_SED_expr_test+= -e 's/eval expr/eval expr --/g'
+ATF_TESTS_SH_SED_expr_test+= -e 's/"expr: integer overflow or underflow occurred for operation.*"/"expr: overflow"/g'
+
+.include <netbsd-tests.test.mk>
+
+.include <bsd.test.mk>
diff --git a/bin/freebsd-version/Makefile b/bin/freebsd-version/Makefile
index 0fe730860c22..e515d0c225d5 100644
--- a/bin/freebsd-version/Makefile
+++ b/bin/freebsd-version/Makefile
@@ -5,14 +5,13 @@ MAN = freebsd-version.1
CLEANFILES = freebsd-version.sh
NEWVERS = ${.CURDIR}/../../sys/conf/newvers.sh
-freebsd-version.sh.in: ${NEWVERS}
-freebsd-version.sh: ${.CURDIR}/freebsd-version.sh.in
+freebsd-version.sh: ${.CURDIR}/freebsd-version.sh.in ${NEWVERS}
eval $$(egrep '^(TYPE|REVISION|BRANCH)=' ${NEWVERS}) ; \
if ! sed -e "\
s/@@TYPE@@/$${TYPE}/g; \
s/@@REVISION@@/$${REVISION}/g; \
s/@@BRANCH@@/$${BRANCH}/g; \
- " ${.ALLSRC} >${.TARGET} ; then \
+ " ${.CURDIR}/freebsd-version.sh.in >${.TARGET} ; then \
rm -f ${.TARGET} ; \
exit 1 ; \
fi
diff --git a/bin/kill/kill.c b/bin/kill/kill.c
index b23c00acf21c..bfa274bc129c 100644
--- a/bin/kill/kill.c
+++ b/bin/kill/kill.c
@@ -56,7 +56,6 @@ __FBSDID("$FreeBSD$");
#ifdef SHELL
#define main killcmd
#include "bltin/bltin.h"
-#include "error.h"
#endif
static void nosig(const char *);
diff --git a/bin/ln/symlink.7 b/bin/ln/symlink.7
index 8c09f281a515..089c0103aad2 100644
--- a/bin/ln/symlink.7
+++ b/bin/ln/symlink.7
@@ -29,7 +29,7 @@
.\" @(#)symlink.7 8.3 (Berkeley) 3/31/94
.\" $FreeBSD$
.\"
-.Dd April 25, 2010
+.Dd February 16, 2015
.Dt SYMLINK 7
.Os
.Sh NAME
@@ -146,10 +146,12 @@ The following system calls follow symbolic links
unless given the
.Dv AT_SYMLINK_NOFOLLOW
flag:
+.Xr chflagsat 2 ,
.Xr fchmodat 2 ,
-.Xr fchownat 2
+.Xr fchownat 2 ,
+.Xr fstatat 2
and
-.Xr fstatat 2 .
+.Xr utimensat 2 .
.Pp
The owner and group of an existing symbolic link can be changed by
means of the
@@ -219,7 +221,7 @@ would change the ownership of
.Dq Li slink
itself.
.Pp
-There are four exceptions to this rule.
+There are five exceptions to this rule.
The
.Xr mv 1
and
@@ -262,13 +264,12 @@ a file tree.)
.Pp
The
.Xr file 1
-command is also an exception to this rule.
-The
-.Xr file 1
-command does not follow symbolic links named as argument by default.
-The
-.Xr file 1
-command does follow symbolic links named as argument if
+and
+.Xr stat 1
+commands are also exceptions to this rule.
+These
+commands do not follow symbolic links named as argument by default,
+but do follow symbolic links named as argument if the
.Fl L
option is specified.
.Pp
diff --git a/bin/ls/Makefile b/bin/ls/Makefile
index dce204655be0..58206e0884cc 100644
--- a/bin/ls/Makefile
+++ b/bin/ls/Makefile
@@ -5,14 +5,12 @@
PROG= ls
SRCS= cmp.c ls.c print.c util.c
-DPADD= ${LIBUTIL}
-LDADD= -lutil
+LIBADD= util
.if !defined(RELEASE_CRUNCH) && \
${MK_LS_COLORS} != no
CFLAGS+= -DCOLORLS
-DPADD+= ${LIBTERMCAPW}
-LDADD+= -ltermcapw
+LIBADD+= termcapw
.endif
.include <bsd.prog.mk>
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index 3e832acbfdf0..a95b07a288b0 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -273,7 +273,7 @@ do_move(const char *from, const char *to)
static int
fastcopy(const char *from, const char *to, struct stat *sbp)
{
- struct timeval tval[2];
+ struct timespec ts[2];
static u_int blen = MAXPHYS;
static char *bp = NULL;
mode_t oldmode;
@@ -350,10 +350,9 @@ err: if (unlink(to))
} else
warn("%s: cannot stat", to);
- tval[0].tv_sec = sbp->st_atime;
- tval[1].tv_sec = sbp->st_mtime;
- tval[0].tv_usec = tval[1].tv_usec = 0;
- if (utimes(to, tval))
+ ts[0] = sbp->st_atim;
+ ts[1] = sbp->st_mtim;
+ if (futimens(to_fd, ts))
warn("%s: set times", to);
if (close(to_fd)) {
diff --git a/bin/pax/ar_io.c b/bin/pax/ar_io.c
index 4914c8527439..57aa46d92e1c 100644
--- a/bin/pax/ar_io.c
+++ b/bin/pax/ar_io.c
@@ -82,7 +82,7 @@ static int wr_trail = 1; /* trailer was rewritten in append */
static int can_unlnk = 0; /* do we unlink null archives? */
const char *arcname; /* printable name of archive */
const char *gzip_program; /* name of gzip program */
-static pid_t zpid = -1; /* pid of child process */
+static pid_t zpid = -1; /* pid of child process */
static int get_phys(void);
static void ar_start_gzip(int, const char *, int);
@@ -1123,7 +1123,7 @@ ar_next(void)
if (sigprocmask(SIG_SETMASK, &o_mask, NULL) < 0)
syswarn(0, errno, "Unable to restore signal mask");
- if (done || !wr_trail || strcmp(NM_TAR, argv0) == 0)
+ if (done || !wr_trail || Oflag || strcmp(NM_TAR, argv0) == 0)
return(-1);
tty_prnt("\nATTENTION! %s archive volume change required.\n", argv0);
diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c
index 4a3e5e7b01c4..bcab2fce24cb 100644
--- a/bin/pax/ar_subs.c
+++ b/bin/pax/ar_subs.c
@@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$");
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
-#include <stdlib.h>
#include "pax.h"
#include "extern.h"
diff --git a/bin/pax/buf_subs.c b/bin/pax/buf_subs.c
index 995e34c88809..4922fc80ffa0 100644
--- a/bin/pax/buf_subs.c
+++ b/bin/pax/buf_subs.c
@@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include "pax.h"
#include "extern.h"
diff --git a/bin/pax/cache.c b/bin/pax/cache.c
index 358707d362c3..f6e52b49378e 100644
--- a/bin/pax/cache.c
+++ b/bin/pax/cache.c
@@ -45,7 +45,6 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <pwd.h>
#include <grp.h>
-#include <unistd.h>
#include <stdlib.h>
#include "pax.h"
#include "cache.h"
diff --git a/bin/pax/cpio.c b/bin/pax/cpio.c
index 0d9cc9fdc326..f385a5988313 100644
--- a/bin/pax/cpio.c
+++ b/bin/pax/cpio.c
@@ -45,8 +45,6 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <stdint.h>
#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
#include "pax.h"
#include "cpio.h"
#include "extern.h"
diff --git a/bin/pax/extern.h b/bin/pax/extern.h
index 4375694cc151..dc99e643b140 100644
--- a/bin/pax/extern.h
+++ b/bin/pax/extern.h
@@ -217,6 +217,7 @@ extern int vflag;
extern int Dflag;
extern int Hflag;
extern int Lflag;
+extern int Oflag;
extern int Xflag;
extern int Yflag;
extern int Zflag;
diff --git a/bin/pax/file_subs.c b/bin/pax/file_subs.c
index 5e4cce151a0b..f18227e40b6a 100644
--- a/bin/pax/file_subs.c
+++ b/bin/pax/file_subs.c
@@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <errno.h>
#include <sys/uio.h>
-#include <stdlib.h>
#include "pax.h"
#include "options.h"
#include "extern.h"
diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c
index 708e8af5ba29..232ee779e489 100644
--- a/bin/pax/gen_subs.c
+++ b/bin/pax/gen_subs.c
@@ -45,8 +45,6 @@ __FBSDID("$FreeBSD$");
#include <langinfo.h>
#include <stdint.h>
#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
#include <string.h>
#include "pax.h"
#include "extern.h"
diff --git a/bin/pax/getoldopt.c b/bin/pax/getoldopt.c
index 28717215aec0..838ff54d4a88 100644
--- a/bin/pax/getoldopt.c
+++ b/bin/pax/getoldopt.c
@@ -19,8 +19,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
-#include "pax.h"
-#include "extern.h"
+int getoldopt(int, char **, const char *);
int
getoldopt(int argc, char **argv, const char *optstring)
diff --git a/bin/pax/options.c b/bin/pax/options.c
index c6ebea28cefc..06e487c9c776 100644
--- a/bin/pax/options.c
+++ b/bin/pax/options.c
@@ -194,7 +194,7 @@ pax_options(int argc, char **argv)
/*
* process option flags
*/
- while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLPT:U:XYZ"))
+ while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ"))
!= -1) {
switch (c) {
case 'a':
@@ -447,6 +447,12 @@ pax_options(int argc, char **argv)
Lflag = 1;
flg |= CLF;
break;
+ case 'O':
+ /*
+ * Force one volume. Non standard option.
+ */
+ Oflag = 1;
+ break;
case 'P':
/*
* do NOT follow symlinks (default)
@@ -584,7 +590,7 @@ tar_options(int argc, char **argv)
{
int c;
int fstdin = 0;
- int Oflag = 0;
+ int tar_Oflag = 0;
int nincfiles = 0;
int incfiles_max = 0;
struct incfile {
@@ -664,7 +670,7 @@ tar_options(int argc, char **argv)
if (opt_add("write_opt=nodir") < 0)
tar_usage();
case 'O':
- Oflag = 1;
+ tar_Oflag = 1;
break;
case 'p':
/*
@@ -820,8 +826,8 @@ tar_options(int argc, char **argv)
* (unless -o specified)
*/
if (act == ARCHIVE || act == APPND)
- frmt = &(fsub[Oflag ? F_OTAR : F_TAR]);
- else if (Oflag) {
+ frmt = &(fsub[tar_Oflag ? F_OTAR : F_TAR]);
+ else if (tar_Oflag) {
paxwarn(1, "The -O/-o options are only valid when writing an archive");
tar_usage(); /* only valid when writing */
}
@@ -1526,25 +1532,25 @@ no_op(void)
void
pax_usage(void)
{
- (void)fputs("usage: pax [-cdnvz] [-E limit] [-f archive] ", stderr);
+ (void)fputs("usage: pax [-cdnOvz] [-E limit] [-f archive] ", stderr);
(void)fputs("[-s replstr] ... [-U user] ...", stderr);
(void)fputs("\n [-G group] ... ", stderr);
(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
(void)fputs("[pattern ...]\n", stderr);
- (void)fputs(" pax -r [-cdiknuvzDYZ] [-E limit] ", stderr);
+ (void)fputs(" pax -r [-cdiknOuvzDYZ] [-E limit] ", stderr);
(void)fputs("[-f archive] [-o options] ... \n", stderr);
(void)fputs(" [-p string] ... [-s replstr] ... ", stderr);
(void)fputs("[-U user] ... [-G group] ...\n ", stderr);
(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
(void)fputs(" [pattern ...]\n", stderr);
- (void)fputs(" pax -w [-dituvzHLPX] [-b blocksize] ", stderr);
+ (void)fputs(" pax -w [-dituvzHLOPX] [-b blocksize] ", stderr);
(void)fputs("[ [-a] [-f archive] ] [-x format] \n", stderr);
(void)fputs(" [-B bytes] [-s replstr] ... ", stderr);
(void)fputs("[-o options] ... [-U user] ...", stderr);
(void)fputs("\n [-G group] ... ", stderr);
(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);
(void)fputs("[file ...]\n", stderr);
- (void)fputs(" pax -r -w [-diklntuvDHLPXYZ] ", stderr);
+ (void)fputs(" pax -r -w [-diklntuvDHLOPXYZ] ", stderr);
(void)fputs("[-p string] ... [-s replstr] ...", stderr);
(void)fputs("\n [-U user] ... [-G group] ... ", stderr);
(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);
diff --git a/bin/pax/pat_rep.c b/bin/pax/pat_rep.c
index 7b0797525745..e8d17db363be 100644
--- a/bin/pax/pat_rep.c
+++ b/bin/pax/pat_rep.c
@@ -43,9 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
-#include <unistd.h>
#include <stdlib.h>
-#include <errno.h>
#ifdef NET2_REGEX
#include <regexp.h>
#else
diff --git a/bin/pax/pax.1 b/bin/pax/pax.1
index aa3025a13100..c2e1731bdba6 100644
--- a/bin/pax/pax.1
+++ b/bin/pax/pax.1
@@ -33,7 +33,7 @@
.\" @(#)pax.1 8.4 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
-.Dd December 21, 2013
+.Dd March 17, 2015
.Dt PAX 1
.Os
.Sh NAME
@@ -41,7 +41,7 @@
.Nd read and write file archives and copy directory hierarchies
.Sh SYNOPSIS
.Nm
-.Op Fl cdnvz
+.Op Fl cdnvzO
.Bk -words
.Op Fl f Ar archive
.Ek
@@ -68,7 +68,7 @@
.Op Ar pattern ...\&
.Nm
.Fl r
-.Op Fl cdiknuvzDYZ
+.Op Fl cdiknuvzDOYZ
.Bk -words
.Op Fl f Ar archive
.Ek
@@ -104,7 +104,7 @@
.Op Ar pattern ...\&
.Nm
.Fl w
-.Op Fl dituvzHLPX
+.Op Fl dituvzHLOPX
.Bk -words
.Op Fl b Ar blocksize
.Ek
@@ -147,7 +147,7 @@
.Nm
.Fl r
.Fl w
-.Op Fl diklntuvDHLPXYZ
+.Op Fl diklntuvDHLOPXYZ
.Bk -words
.Op Fl p Ar string
.Ar ...\&
@@ -853,6 +853,13 @@ Follow only command line symbolic links while performing a physical file
system traversal.
.It Fl L
Follow all symbolic links to perform a logical file system traversal.
+.It Fl O
+Force the archive to be one volume.
+If a volume ends prematurely,
+.Nm
+will not prompt for a new volume.
+This option can be useful for
+automated tasks where error recovery cannot be performed by a human.
.It Fl P
Do not follow symbolic links, perform a physical file system traversal.
This is the default mode.
@@ -1176,6 +1183,7 @@ The options
.Fl G ,
.Fl H ,
.Fl L ,
+.Fl O ,
.Fl P ,
.Fl T ,
.Fl U ,
diff --git a/bin/pax/pax.c b/bin/pax/pax.c
index 040db744c5b1..4e97610e954a 100644
--- a/bin/pax/pax.c
+++ b/bin/pax/pax.c
@@ -58,7 +58,6 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include "pax.h"
#include "extern.h"
static int gen_init(void);
@@ -85,6 +84,7 @@ int vflag; /* produce verbose output */
int Dflag; /* same as uflag except inode change time */
int Hflag; /* follow command line symlinks (write only) */
int Lflag; /* follow symlinks when writing */
+int Oflag; /* limit to single volume */
int Xflag; /* archive files with same device id only */
int Yflag; /* same as Dflg except after name mode */
int Zflag; /* same as uflg except after name mode */
diff --git a/bin/pax/sel_subs.c b/bin/pax/sel_subs.c
index fe131f7329ca..e9cc759e2403 100644
--- a/bin/pax/sel_subs.c
+++ b/bin/pax/sel_subs.c
@@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <string.h>
#include <strings.h>
-#include <unistd.h>
#include <stdlib.h>
#include "pax.h"
#include "sel_subs.h"
diff --git a/bin/pax/tar.c b/bin/pax/tar.c
index 4ee2786a8082..32bdd6e1ad0e 100644
--- a/bin/pax/tar.c
+++ b/bin/pax/tar.c
@@ -44,8 +44,6 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
#include "pax.h"
#include "extern.h"
#include "tar.h"
diff --git a/bin/pax/tty_subs.c b/bin/pax/tty_subs.c
index b3d140eb41cc..b63da86eb8db 100644
--- a/bin/pax/tty_subs.c
+++ b/bin/pax/tty_subs.c
@@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$");
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
-#include <stdlib.h>
#include <string.h>
#include "pax.h"
#include "extern.h"
diff --git a/bin/pkill/Makefile b/bin/pkill/Makefile
index 11bfbe329596..84a5af71ddf3 100644
--- a/bin/pkill/Makefile
+++ b/bin/pkill/Makefile
@@ -5,8 +5,7 @@
PROG= pkill
-DPADD= ${LIBKVM}
-LDADD= -lkvm
+LIBADD= kvm
LINKS= ${BINDIR}/pkill ${BINDIR}/pgrep
MLINKS= pkill.1 pgrep.1
diff --git a/bin/pkill/tests/pgrep-j_test.sh b/bin/pkill/tests/pgrep-j_test.sh
index 6acfb4be35ad..e24e5c2ff5fe 100644
--- a/bin/pkill/tests/pgrep-j_test.sh
+++ b/bin/pkill/tests/pgrep-j_test.sh
@@ -4,94 +4,88 @@
jail_name_to_jid()
{
local check_name="$1"
- (
- line="$(jls -n 2> /dev/null | grep name=$check_name )"
- for nv in $line; do
- local name="${nv%=*}"
- if [ "${name}" = "jid" ]; then
- eval $nv
- echo $jid
- break
- fi
- done
- )
+ jls -j "$check_name" -s | tr ' ' '\n' | grep jid= | sed -e 's/.*=//g'
}
base=pgrep_j_test
+if [ `id -u` -ne 0 ]; then
+ echo "1..0 # skip Test needs uid 0."
+ exit 0
+fi
+
echo "1..3"
+sleep=$(pwd)/sleep.txt
+ln -sf /bin/sleep $sleep
+
name="pgrep -j <jid>"
-if [ `id -u` -eq 0 ]; then
- sleep=$(pwd)/sleep.txt
- ln -sf /bin/sleep $sleep
- jail -c path=/ name=${base}_1_1 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_1_1.pid $sleep 5 &
+sleep_amount=5
+jail -c path=/ name=${base}_1_1 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_1_1.pid $sleep $sleep_amount &
- jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_1_2.pid $sleep 5 &
+jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_1_2.pid $sleep $sleep_amount &
+for i in `seq 1 10`; do
jid1=$(jail_name_to_jid ${base}_1_1)
jid2=$(jail_name_to_jid ${base}_1_2)
jid="${jid1},${jid2}"
- pid1="$(pgrep -f -x -j $jid "$sleep 5" | sort)"
- pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_1_1.pid)" \
- $(cat ${PWD}/${base}_1_2.pid) | sort)
- if [ "$pid1" = "$pid2" ]; then
- echo "ok 1 - $name"
- else
- echo "not ok 1 - $name"
- fi
- [ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid)
- [ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid)
- rm -f $sleep
+ case "$jid" in
+ [0-9]+,[0-9]+)
+ break
+ ;;
+ esac
+ sleep 0.1
+done
+sleep 0.5
+
+pid1="$(pgrep -f -x -j "$jid" "$sleep $sleep_amount" | sort)"
+pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_1_1.pid)" \
+ $(cat ${PWD}/${base}_1_2.pid) | sort)
+if [ "$pid1" = "$pid2" ]; then
+ echo "ok 1 - $name"
else
- echo "ok 1 - $name # skip Test needs uid 0."
+ echo "not ok 1 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
fi
+[ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid)
+[ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid)
+wait
name="pgrep -j any"
-if [ `id -u` -eq 0 ]; then
- sleep=$(pwd)/sleep.txt
- ln -sf /bin/sleep $sleep
- jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_2_1.pid $sleep 5 &
+sleep_amount=6
+jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_2_1.pid $sleep $sleep_amount &
- jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_2_2.pid $sleep 5 &
+jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_2_2.pid $sleep $sleep_amount &
- sleep 2
- pid1="$(pgrep -f -x -j any "$sleep 5" | sort)"
- pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_2_1.pid)" \
- $(cat ${PWD}/${base}_2_2.pid) | sort)
- if [ "$pid1" = "$pid2" ]; then
- echo "ok 2 - $name"
- else
- echo "not ok 2 - $name"
- fi
- [ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid)
- [ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid)
- rm -f $sleep
+sleep 2
+pid1="$(pgrep -f -x -j any "$sleep $sleep_amount" | sort)"
+pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_2_1.pid)" \
+ $(cat ${PWD}/${base}_2_2.pid) | sort)
+if [ "$pid1" = "$pid2" ]; then
+ echo "ok 2 - $name"
else
- echo "ok 2 - $name # skip Test needs uid 0."
+ echo "not ok 2 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
fi
+[ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid)
+[ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid)
+wait
name="pgrep -j none"
-if [ `id -u` -eq 0 ]; then
- sleep=$(pwd)/sleep.txt
- ln -sf /bin/sleep $sleep
- daemon -p ${PWD}/${base}_3_1.pid $sleep 5 &
- jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_3_2.pid $sleep 5 &
- sleep 2
- pid="$(pgrep -f -x -j none "$sleep 5")"
- if [ "$pid" = "$(cat ${PWD}/${base}_3_1.pid)" ]; then
- echo "ok 3 - $name"
- else
- echo "not ok 3 - $name"
- fi
- rm -f $sleep
- [ -f ${PWD}/${base}_3_1.pid ] && kill $(cat $PWD/${base}_3_1.pid)
- [ -f ${PWD}/${base}_3_2.pid ] && kill $(cat $PWD/${base}_3_2.pid)
+sleep_amount=7
+daemon -p ${PWD}/${base}_3_1.pid $sleep $sleep_amount &
+jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_3_2.pid $sleep $sleep_amount &
+sleep 2
+pid="$(pgrep -f -x -j none "$sleep $sleep_amount")"
+if [ "$pid" = "$(cat ${PWD}/${base}_3_1.pid)" ]; then
+ echo "ok 3 - $name"
else
- echo "ok 3 - $name # skip Test needs uid 0."
+ echo "not ok 3 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
fi
+[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat $PWD/${base}_3_1.pid)
+[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat $PWD/${base}_3_2.pid)
+
+rm -f $sleep
diff --git a/bin/pkill/tests/pkill-j_test.sh b/bin/pkill/tests/pkill-j_test.sh
index a844149cedb0..26e185fc8988 100644
--- a/bin/pkill/tests/pkill-j_test.sh
+++ b/bin/pkill/tests/pkill-j_test.sh
@@ -4,99 +4,91 @@
jail_name_to_jid()
{
local check_name="$1"
- (
- line="$(jls -n 2> /dev/null | grep name=$check_name )"
- for nv in $line; do
- local name="${nv%=*}"
- if [ "${name}" = "jid" ]; then
- eval $nv
- echo $jid
- break
- fi
- done
- )
+ jls -j "$check_name" -s | tr ' ' '\n' | grep jid= | sed -e 's/.*=//g'
}
base=pkill_j_test
+if [ `id -u` -ne 0 ]; then
+ echo "1..0 # skip Test needs uid 0."
+ exit 0
+fi
+
echo "1..3"
+sleep=$(pwd)/sleep.txt
+ln -sf /bin/sleep $sleep
+
name="pkill -j <jid>"
-if [ `id -u` -eq 0 ]; then
- sleep=$(pwd)/sleep.txt
- ln -sf /bin/sleep $sleep
- jail -c path=/ name=${base}_1_1 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_1_1.pid $sleep 5 &
+sleep_amount=5
+jail -c path=/ name=${base}_1_1 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_1_1.pid $sleep $sleep_amount &
- jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_1_2.pid $sleep 5 &
+jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_1_2.pid $sleep $sleep_amount &
- $sleep 5 &
- sleep 0.5
+$sleep $sleep_amount &
+
+for i in `seq 1 10`; do
jid1=$(jail_name_to_jid ${base}_1_1)
jid2=$(jail_name_to_jid ${base}_1_2)
jid="${jid1},${jid2}"
- if pkill -f -j "$jid" $sleep && sleep 0.5 &&
- ! -f ${PWD}/${base}_1_1.pid &&
- ! -f ${PWD}/${base}_1_2.pid ; then
- echo "ok 1 - $name"
- else
- echo "not ok 1 - $name"
- fi 2>/dev/null
- rm -f $sleep
- [ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid)
- [ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid)
- wait
+ case "$jid" in
+ [0-9]+,[0-9]+)
+ break
+ ;;
+ esac
+ sleep 0.1
+done
+sleep 0.5
+
+if pkill -f -j "$jid" $sleep && sleep 0.5 &&
+ ! -f ${PWD}/${base}_1_1.pid &&
+ ! -f ${PWD}/${base}_1_2.pid ; then
+ echo "ok 1 - $name"
else
- echo "ok 1 - $name # skip Test needs uid 0."
-fi
+ echo "not ok 1 - $name"
+fi 2>/dev/null
+[ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid)
+[ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid)
+wait
name="pkill -j any"
-if [ `id -u` -eq 0 ]; then
- sleep=$(pwd)/sleep.txt
- ln -sf /bin/sleep $sleep
- jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_2_1.pid $sleep 5 &
+sleep_amount=6
+jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_2_1.pid $sleep $sleep_amount &
- jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_2_2.pid $sleep 5 &
+jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_2_2.pid $sleep $sleep_amount &
- $sleep 5 &
- sleep 0.5
- chpid3=$!
- if pkill -f -j any $sleep && sleep 0.5 &&
- [ ! -f ${PWD}/${base}_2_1.pid -a
- ! -f ${PWD}/${base}_2_2.pid ] && kill $chpid3; then
- echo "ok 2 - $name"
- else
- echo "not ok 2 - $name"
- fi 2>/dev/null
- rm -f $sleep
- [ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid)
- [ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid)
- wait
+$sleep $sleep_amount &
+chpid3=$!
+sleep 0.5
+if pkill -f -j any $sleep && sleep 0.5 &&
+ [ ! -f ${PWD}/${base}_2_1.pid -a
+ ! -f ${PWD}/${base}_2_2.pid ] && kill $chpid3; then
+ echo "ok 2 - $name"
else
- echo "ok 2 - $name # skip Test needs uid 0."
-fi
+ echo "not ok 2 - $name"
+fi 2>/dev/null
+[ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid)
+[ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid)
+wait
name="pkill -j none"
-if [ `id -u` -eq 0 ]; then
- sleep=$(pwd)/sleep.txt
- ln -sf /bin/sleep $sleep
- daemon -p ${PWD}/${base}_3_1.pid $sleep 5
- jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_3_2.pid $sleep 5 &
- sleep 1
- if pkill -f -j none "$sleep 5" && sleep 1 &&
- [ ! -f ${PWD}/${base}_3_1.pid -a -f ${PWD}/${base}_3_2.pid ] ; then
- echo "ok 3 - $name"
- else
- ls ${PWD}/*.pid
- echo "not ok 3 - $name"
- fi 2>/dev/null
- rm -f $sleep
- [ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid)
- [ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid)
+sleep_amount=7
+daemon -p ${PWD}/${base}_3_1.pid $sleep $sleep_amount
+jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_3_2.pid $sleep $sleep_amount &
+sleep 1
+if pkill -f -j none "$sleep $sleep_amount" && sleep 1 &&
+ [ ! -f ${PWD}/${base}_3_1.pid -a -f ${PWD}/${base}_3_2.pid ] ; then
+ echo "ok 3 - $name"
else
- echo "ok 3 - $name # skip Test needs uid 0."
-fi
+ ls ${PWD}/*.pid
+ echo "not ok 3 - $name"
+fi 2>/dev/null
+[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid)
+[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid)
+
+rm -f $sleep
diff --git a/bin/ps/Makefile b/bin/ps/Makefile
index 5ba4f2fa705b..79e9fc6cf0ec 100644
--- a/bin/ps/Makefile
+++ b/bin/ps/Makefile
@@ -11,7 +11,6 @@ SRCS= fmt.c keyword.c nlist.c print.c ps.c
# on large systems.
#
CFLAGS+=-DLAZY_PS
-DPADD= ${LIBM} ${LIBKVM} ${LIBJAIL}
-LDADD= -lm -lkvm -ljail
+LIBADD= m kvm jail xo
.include <bsd.prog.mk>
diff --git a/bin/ps/Makefile.depend b/bin/ps/Makefile.depend
index a1b416dc3b7c..b98c059d8b87 100644
--- a/bin/ps/Makefile.depend
+++ b/bin/ps/Makefile.depend
@@ -12,6 +12,7 @@ DIRDEPS = \
lib/libcompiler_rt \
lib/libjail \
lib/libkvm \
+ lib/libxo \
lib/msun \
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index 38a993475401..b802c37143ea 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <libxo/xo.h>
#include "ps.h"
@@ -64,116 +65,170 @@ static int vcmp(const void *, const void *);
/* PLEASE KEEP THE TABLE BELOW SORTED ALPHABETICALLY!!! */
static VAR var[] = {
- {"%cpu", "%CPU", NULL, 0, pcpu, 0, CHAR, NULL, 0},
- {"%mem", "%MEM", NULL, 0, pmem, 0, CHAR, NULL, 0},
- {"acflag", "ACFLG", NULL, 0, kvar, KOFF(ki_acflag), USHORT, "x", 0},
- {"acflg", "", "acflag", 0, NULL, 0, CHAR, NULL, 0},
- {"args", "COMMAND", NULL, COMM|LJUST|USER, arguments, 0,
- CHAR, NULL, 0},
- {"blocked", "", "sigmask", 0, NULL, 0, CHAR, NULL, 0},
- {"caught", "", "sigcatch", 0, NULL, 0, CHAR, NULL, 0},
- {"class", "CLASS", NULL, LJUST, loginclass, 0, CHAR, NULL, 0},
- {"comm", "COMMAND", NULL, LJUST, ucomm, 0, CHAR, NULL, 0},
- {"command", "COMMAND", NULL, COMM|LJUST|USER, command, 0,
- CHAR, NULL, 0},
- {"cow", "COW", NULL, 0, kvar, KOFF(ki_cow), UINT, "u", 0},
- {"cpu", "CPU", NULL, 0, kvar, KOFF(ki_estcpu), UINT, "d", 0},
- {"cputime", "", "time", 0, NULL, 0, CHAR, NULL, 0},
- {"dsiz", "DSIZ", NULL, 0, kvar, KOFF(ki_dsize), PGTOK, "ld", 0},
- {"egid", "", "gid", 0, NULL, 0, CHAR, NULL, 0},
- {"egroup", "", "group", 0, NULL, 0, CHAR, NULL, 0},
- {"emul", "EMUL", NULL, LJUST, emulname, 0, CHAR, NULL, 0},
- {"etime", "ELAPSED", NULL, USER, elapsed, 0, CHAR, NULL, 0},
- {"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},
- {"inblk", "INBLK", NULL, USER, rvar, ROFF(ru_inblock), LONG, "ld", 0},
- {"inblock", "", "inblk", 0, NULL, 0, CHAR, NULL, 0},
- {"jid", "JID", NULL, 0, kvar, KOFF(ki_jid), INT, "d", 0},
- {"jobc", "JOBC", NULL, 0, kvar, KOFF(ki_jobc), SHORT, "d", 0},
- {"ktrace", "KTRACE", NULL, 0, kvar, KOFF(ki_traceflag), INT, "x", 0},
- {"label", "LABEL", NULL, LJUST, label, 0, CHAR, NULL, 0},
- {"lim", "LIM", NULL, 0, maxrss, 0, CHAR, NULL, 0},
- {"lockname", "LOCK", NULL, LJUST, lockname, 0, CHAR, NULL, 0},
- {"login", "LOGIN", NULL, LJUST, logname, 0, CHAR, NULL, 0},
- {"logname", "", "login", 0, NULL, 0, CHAR, NULL, 0},
- {"lstart", "STARTED", NULL, LJUST|USER, lstarted, 0, CHAR, NULL, 0},
- {"lwp", "LWP", NULL, 0, kvar, KOFF(ki_tid), UINT, LWPFMT, 0},
- {"majflt", "MAJFLT", NULL, USER, rvar, ROFF(ru_majflt), LONG, "ld", 0},
- {"minflt", "MINFLT", NULL, USER, rvar, ROFF(ru_minflt), LONG, "ld", 0},
- {"msgrcv", "MSGRCV", NULL, USER, rvar, ROFF(ru_msgrcv), LONG, "ld", 0},
- {"msgsnd", "MSGSND", NULL, USER, rvar, ROFF(ru_msgsnd), LONG, "ld", 0},
- {"mwchan", "MWCHAN", NULL, LJUST, mwchan, 0, CHAR, NULL, 0},
- {"ni", "", "nice", 0, NULL, 0, CHAR, NULL, 0},
- {"nice", "NI", NULL, 0, kvar, KOFF(ki_nice), CHAR, "d", 0},
- {"nivcsw", "NIVCSW", NULL, USER, rvar, ROFF(ru_nivcsw), LONG, "ld", 0},
- {"nlwp", "NLWP", NULL, 0, kvar, KOFF(ki_numthreads), UINT, NLWPFMT, 0},
- {"nsignals", "", "nsigs", 0, NULL, 0, CHAR, NULL, 0},
- {"nsigs", "NSIGS", NULL, USER, rvar, ROFF(ru_nsignals), LONG, "ld", 0},
- {"nswap", "NSWAP", NULL, USER, rvar, ROFF(ru_nswap), LONG, "ld", 0},
- {"nvcsw", "NVCSW", NULL, USER, rvar, ROFF(ru_nvcsw), LONG, "ld", 0},
- {"nwchan", "NWCHAN", NULL, LJUST, nwchan, 0, CHAR, NULL, 0},
- {"oublk", "OUBLK", NULL, USER, rvar, ROFF(ru_oublock), LONG, "ld", 0},
- {"oublock", "", "oublk", 0, NULL, 0, CHAR, NULL, 0},
- {"paddr", "PADDR", NULL, 0, kvar, KOFF(ki_paddr), KPTR, "lx", 0},
- {"pagein", "PAGEIN", NULL, USER, pagein, 0, CHAR, NULL, 0},
- {"pcpu", "", "%cpu", 0, NULL, 0, CHAR, NULL, 0},
- {"pending", "", "sig", 0, NULL, 0, CHAR, NULL, 0},
- {"pgid", "PGID", NULL, 0, kvar, KOFF(ki_pgid), UINT, PIDFMT, 0},
- {"pid", "PID", NULL, 0, kvar, KOFF(ki_pid), UINT, PIDFMT, 0},
- {"pmem", "", "%mem", 0, NULL, 0, CHAR, NULL, 0},
- {"ppid", "PPID", NULL, 0, kvar, KOFF(ki_ppid), UINT, PIDFMT, 0},
- {"pri", "PRI", NULL, 0, pri, 0, CHAR, NULL, 0},
- {"re", "RE", NULL, INF127, kvar, KOFF(ki_swtime), UINT, "d", 0},
- {"rgid", "RGID", NULL, 0, kvar, KOFF(ki_rgid), UINT, UIDFMT, 0},
- {"rgroup", "RGROUP", NULL, LJUST, rgroupname, 0, CHAR, NULL, 0},
- {"rss", "RSS", NULL, 0, kvar, KOFF(ki_rssize), PGTOK, "ld", 0},
- {"rtprio", "RTPRIO", NULL, 0, priorityr, KOFF(ki_pri), CHAR, NULL, 0},
- {"ruid", "RUID", NULL, 0, kvar, KOFF(ki_ruid), UINT, UIDFMT, 0},
- {"ruser", "RUSER", NULL, LJUST, runame, 0, CHAR, NULL, 0},
- {"sid", "SID", NULL, 0, kvar, KOFF(ki_sid), UINT, PIDFMT, 0},
- {"sig", "PENDING", NULL, 0, kvar, KOFF(ki_siglist), INT, "x", 0},
- {"sigcatch", "CAUGHT", NULL, 0, kvar, KOFF(ki_sigcatch), UINT, "x", 0},
- {"sigignore", "IGNORED", NULL, 0, kvar, KOFF(ki_sigignore),
- UINT, "x", 0},
- {"sigmask", "BLOCKED", NULL, 0, kvar, KOFF(ki_sigmask), UINT, "x", 0},
- {"sl", "SL", NULL, INF127, kvar, KOFF(ki_slptime), UINT, "d", 0},
- {"ssiz", "SSIZ", NULL, 0, kvar, KOFF(ki_ssize), PGTOK, "ld", 0},
- {"start", "STARTED", NULL, LJUST|USER, started, 0, CHAR, NULL, 0},
- {"stat", "", "state", 0, NULL, 0, CHAR, NULL, 0},
- {"state", "STAT", NULL, LJUST, state, 0, CHAR, NULL, 0},
- {"svgid", "SVGID", NULL, 0, kvar, KOFF(ki_svgid), UINT, UIDFMT, 0},
- {"svuid", "SVUID", NULL, 0, kvar, KOFF(ki_svuid), UINT, UIDFMT, 0},
- {"systime", "SYSTIME", NULL, USER, systime, 0, CHAR, NULL, 0},
- {"tdaddr", "TDADDR", NULL, 0, kvar, KOFF(ki_tdaddr), KPTR, "lx", 0},
- {"tdev", "TDEV", NULL, 0, tdev, 0, CHAR, NULL, 0},
- {"tdnam", "TDNAM", NULL, LJUST, tdnam, 0, CHAR, NULL, 0},
- {"time", "TIME", NULL, USER, cputime, 0, CHAR, NULL, 0},
- {"tpgid", "TPGID", NULL, 0, kvar, KOFF(ki_tpgid), UINT, PIDFMT, 0},
- {"tracer", "TRACER", NULL, 0, kvar, KOFF(ki_tracer), UINT, PIDFMT, 0},
- {"tsid", "TSID", NULL, 0, kvar, KOFF(ki_tsid), UINT, PIDFMT, 0},
- {"tsiz", "TSIZ", NULL, 0, kvar, KOFF(ki_tsize), PGTOK, "ld", 0},
- {"tt", "TT ", NULL, 0, tname, 0, CHAR, NULL, 0},
- {"tty", "TTY", NULL, LJUST, longtname, 0, CHAR, NULL, 0},
- {"ucomm", "UCOMM", NULL, LJUST, ucomm, 0, CHAR, NULL, 0},
- {"uid", "UID", NULL, 0, kvar, KOFF(ki_uid), UINT, UIDFMT, 0},
- {"upr", "UPR", NULL, 0, upr, 0, CHAR, NULL, 0},
- {"uprocp", "UPROCP", NULL, 0, kvar, KOFF(ki_paddr), KPTR, "lx", 0},
- {"user", "USER", NULL, LJUST, uname, 0, CHAR, NULL, 0},
- {"usertime", "USERTIME", NULL, USER, usertime, 0, CHAR, NULL, 0},
- {"usrpri", "", "upr", 0, NULL, 0, CHAR, NULL, 0},
- {"vsize", "", "vsz", 0, NULL, 0, CHAR, NULL, 0},
- {"vsz", "VSZ", NULL, 0, vsize, 0, CHAR, NULL, 0},
- {"wchan", "WCHAN", NULL, LJUST, wchan, 0, CHAR, NULL, 0},
- {"xstat", "XSTAT", NULL, 0, kvar, KOFF(ki_xstat), USHORT, "x", 0},
- {"", NULL, NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"%cpu", "%CPU", NULL, "percent-cpu", 0, pcpu, 0, CHAR, NULL, 0},
+ {"%mem", "%MEM", NULL, "percent-memory", 0, pmem, 0, CHAR, NULL, 0},
+ {"acflag", "ACFLG", NULL, "accounting-flag", 0, kvar, KOFF(ki_acflag),
+ USHORT, "x", 0},
+ {"acflg", "", "acflag", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"args", "COMMAND", NULL, "arguments", COMM|LJUST|USER, arguments, 0,
+ CHAR, NULL, 0},
+ {"blocked", "", "sigmask", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"caught", "", "sigcatch", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"class", "CLASS", NULL, "login-class", LJUST, loginclass, 0, CHAR,
+ NULL, 0},
+ {"comm", "COMMAND", NULL, "command", LJUST, ucomm, 0, CHAR, NULL, 0},
+ {"command", "COMMAND", NULL, "command", COMM|LJUST|USER, command, 0,
+ CHAR, NULL, 0},
+ {"cow", "COW", NULL, "copy-on-write-faults", 0, kvar, KOFF(ki_cow),
+ UINT, "u", 0},
+ {"cpu", "CPU", NULL, "cpu-usage", 0, kvar, KOFF(ki_estcpu), UINT, "d",
+ 0},
+ {"cputime", "", "time", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"dsiz", "DSIZ", NULL, "data-size", 0, kvar, KOFF(ki_dsize), PGTOK,
+ "ld", 0},
+ {"egid", "", "gid", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"egroup", "", "group", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"emul", "EMUL", NULL, "emulation-envirnment", LJUST, emulname, 0,
+ CHAR, NULL, 0},
+ {"etime", "ELAPSED", NULL, "elapsed-time", USER, elapsed, 0, CHAR,
+ NULL, 0},
+ {"etimes", "ELAPSED", NULL, "elapsed-times", USER, elapseds, 0, CHAR,
+ NULL, 0},
+ {"euid", "", "uid", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"f", "F", NULL, "flags", 0, kvar, KOFF(ki_flag), INT, "x", 0},
+ {"f2", "F2", NULL, "flags2", 0, kvar, KOFF(ki_flag2), INT, "08x", 0},
+ {"fib", "FIB", NULL, "fib", 0, kvar, KOFF(ki_fibnum), INT, "d", 0},
+ {"flags", "", "f", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"flags2", "", "f2", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"gid", "GID", NULL, "gid", 0, kvar, KOFF(ki_groups), UINT, UIDFMT, 0},
+ {"group", "GROUP", NULL, "group", LJUST, egroupname, 0, CHAR, NULL, 0},
+ {"ignored", "", "sigignore", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"inblk", "INBLK", NULL, "read-blocks", USER, rvar, ROFF(ru_inblock),
+ LONG, "ld", 0},
+ {"inblock", "", "inblk", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"jid", "JID", NULL, "jail-id", 0, kvar, KOFF(ki_jid), INT, "d", 0},
+ {"jobc", "JOBC", NULL, "job-control-count", 0, kvar, KOFF(ki_jobc),
+ SHORT, "d", 0},
+ {"ktrace", "KTRACE", NULL, "ktrace", 0, kvar, KOFF(ki_traceflag), INT,
+ "x", 0},
+ {"label", "LABEL", NULL, "label", LJUST, label, 0, CHAR, NULL, 0},
+ {"lim", "LIM", NULL, "memory-limit", 0, maxrss, 0, CHAR, NULL, 0},
+ {"lockname", "LOCK", NULL, "lock-name", LJUST, lockname, 0, CHAR, NULL,
+ 0},
+ {"login", "LOGIN", NULL, "login-name", LJUST, logname, 0, CHAR, NULL,
+ 0},
+ {"logname", "", "login", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"lstart", "STARTED", NULL, "start-time", LJUST|USER, lstarted, 0,
+ CHAR, NULL, 0},
+ {"lwp", "LWP", NULL, "process-thread-id", 0, kvar, KOFF(ki_tid), UINT,
+ LWPFMT, 0},
+ {"majflt", "MAJFLT", NULL, "major-faults", USER, rvar, ROFF(ru_majflt),
+ LONG, "ld", 0},
+ {"minflt", "MINFLT", NULL, "minor-faults", USER, rvar, ROFF(ru_minflt),
+ LONG, "ld", 0},
+ {"msgrcv", "MSGRCV", NULL, "received-messages", USER, rvar,
+ ROFF(ru_msgrcv), LONG, "ld", 0},
+ {"msgsnd", "MSGSND", NULL, "sent-messages", USER, rvar,
+ ROFF(ru_msgsnd), LONG, "ld", 0},
+ {"mwchan", "MWCHAN", NULL, "wait-channel", LJUST, mwchan, 0, CHAR,
+ NULL, 0},
+ {"ni", "", "nice", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"nice", "NI", NULL, "nice", 0, kvar, KOFF(ki_nice), CHAR, "d", 0},
+ {"nivcsw", "NIVCSW", NULL, "involuntary-context-switches", USER, rvar,
+ ROFF(ru_nivcsw), LONG, "ld", 0},
+ {"nlwp", "NLWP", NULL, "threads", 0, kvar, KOFF(ki_numthreads), UINT,
+ NLWPFMT, 0},
+ {"nsignals", "", "nsigs", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"nsigs", "NSIGS", NULL, "signals-taken", USER, rvar,
+ ROFF(ru_nsignals), LONG, "ld", 0},
+ {"nswap", "NSWAP", NULL, "swaps", USER, rvar, ROFF(ru_nswap), LONG,
+ "ld", 0},
+ {"nvcsw", "NVCSW", NULL, "voluntary-context-switches", USER, rvar,
+ ROFF(ru_nvcsw), LONG, "ld", 0},
+ {"nwchan", "NWCHAN", NULL, "wait-channel-address", LJUST, nwchan, 0,
+ CHAR, NULL, 0},
+ {"oublk", "OUBLK", NULL, "written-blocks", USER, rvar,
+ ROFF(ru_oublock), LONG, "ld", 0},
+ {"oublock", "", "oublk", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"paddr", "PADDR", NULL, "process-address", 0, kvar, KOFF(ki_paddr),
+ KPTR, "lx", 0},
+ {"pagein", "PAGEIN", NULL, "pageins", USER, pagein, 0, CHAR, NULL, 0},
+ {"pcpu", "", "%cpu", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"pending", "", "sig", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"pgid", "PGID", NULL, "process-group", 0, kvar, KOFF(ki_pgid), UINT,
+ PIDFMT, 0},
+ {"pid", "PID", NULL, "pid", 0, kvar, KOFF(ki_pid), UINT, PIDFMT, 0},
+ {"pmem", "", "%mem", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"ppid", "PPID", NULL, "ppid", 0, kvar, KOFF(ki_ppid), UINT, PIDFMT, 0},
+ {"pri", "PRI", NULL, "priority", 0, pri, 0, CHAR, NULL, 0},
+ {"re", "RE", NULL, "residency-time", INF127, kvar, KOFF(ki_swtime),
+ UINT, "d", 0},
+ {"rgid", "RGID", NULL, "real-gid", 0, kvar, KOFF(ki_rgid), UINT,
+ UIDFMT, 0},
+ {"rgroup", "RGROUP", NULL, "real-group", LJUST, rgroupname, 0, CHAR,
+ NULL, 0},
+ {"rss", "RSS", NULL, "rss", 0, kvar, KOFF(ki_rssize), PGTOK, "ld", 0},
+ {"rtprio", "RTPRIO", NULL, "realtime-priority", 0, priorityr,
+ KOFF(ki_pri), CHAR, NULL, 0},
+ {"ruid", "RUID", NULL, "real-uid", 0, kvar, KOFF(ki_ruid), UINT,
+ UIDFMT, 0},
+ {"ruser", "RUSER", NULL, "real-user", LJUST, runame, 0, CHAR, NULL, 0},
+ {"sid", "SID", NULL, "sid", 0, kvar, KOFF(ki_sid), UINT, PIDFMT, 0},
+ {"sig", "PENDING", NULL, "signals-pending", 0, kvar, KOFF(ki_siglist),
+ INT, "x", 0},
+ {"sigcatch", "CAUGHT", NULL, "signals-caught", 0, kvar,
+ KOFF(ki_sigcatch), UINT, "x", 0},
+ {"sigignore", "IGNORED", NULL, "signals-ignored", 0, kvar,
+ KOFF(ki_sigignore), UINT, "x", 0},
+ {"sigmask", "BLOCKED", NULL, "signal-mask", 0, kvar, KOFF(ki_sigmask),
+ UINT, "x", 0},
+ {"sl", "SL", NULL, "sleep-time", INF127, kvar, KOFF(ki_slptime), UINT,
+ "d", 0},
+ {"ssiz", "SSIZ", NULL, "stack-size", 0, kvar, KOFF(ki_ssize), PGTOK,
+ "ld", 0},
+ {"start", "STARTED", NULL, "start-time", LJUST|USER, started, 0, CHAR,
+ NULL, 0},
+ {"stat", "", "state", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"state", "STAT", NULL, "state", LJUST, state, 0, CHAR, NULL, 0},
+ {"svgid", "SVGID", NULL, "saved-gid", 0, kvar, KOFF(ki_svgid), UINT,
+ UIDFMT, 0},
+ {"svuid", "SVUID", NULL, "saved-uid", 0, kvar, KOFF(ki_svuid), UINT,
+ UIDFMT, 0},
+ {"systime", "SYSTIME", NULL, "system-time", USER, systime, 0, CHAR,
+ NULL, 0},
+ {"tdaddr", "TDADDR", NULL, "thread-address", 0, kvar, KOFF(ki_tdaddr),
+ KPTR, "lx", 0},
+ {"tdev", "TDEV", NULL, "terminal-device", 0, tdev, 0, CHAR, NULL, 0},
+ {"tdnam", "TDNAM", NULL, "terminal-device-name", LJUST, tdnam, 0, CHAR,
+ NULL, 0},
+ {"time", "TIME", NULL, "cpu-time", USER, cputime, 0, CHAR, NULL, 0},
+ {"tpgid", "TPGID", NULL, "terminal-process-gid", 0, kvar,
+ KOFF(ki_tpgid), UINT, PIDFMT, 0},
+ {"tracer", "TRACER", NULL, "tracer", 0, kvar, KOFF(ki_tracer), UINT,
+ PIDFMT, 0},
+ {"tsid", "TSID", NULL, "terminal-sid", 0, kvar, KOFF(ki_tsid), UINT,
+ PIDFMT, 0},
+ {"tsiz", "TSIZ", NULL, "text-size", 0, kvar, KOFF(ki_tsize), PGTOK,
+ "ld", 0},
+ {"tt", "TT ", NULL, "terminal-name", 0, tname, 0, CHAR, NULL, 0},
+ {"tty", "TTY", NULL, "tty", LJUST, longtname, 0, CHAR, NULL, 0},
+ {"ucomm", "UCOMM", NULL, "accounting-name", LJUST, ucomm, 0, CHAR,
+ NULL, 0},
+ {"uid", "UID", NULL, "uid", 0, kvar, KOFF(ki_uid), UINT, UIDFMT, 0},
+ {"upr", "UPR", NULL, "user-priority", 0, upr, 0, CHAR, NULL, 0},
+ {"uprocp", "UPROCP", NULL, "process-address", 0, kvar, KOFF(ki_paddr),
+ KPTR, "lx", 0},
+ {"user", "USER", NULL, "user", LJUST, uname, 0, CHAR, NULL, 0},
+ {"usertime", "USERTIME", NULL, "user-time", USER, usertime, 0, CHAR,
+ NULL, 0},
+ {"usrpri", "", "upr", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"vsize", "", "vsz", NULL, 0, NULL, 0, CHAR, NULL, 0},
+ {"vsz", "VSZ", NULL, "virtual-size", 0, vsize, 0, CHAR, NULL, 0},
+ {"wchan", "WCHAN", NULL, "wait-channel", LJUST, wchan, 0, CHAR, NULL,
+ 0},
+ {"xstat", "XSTAT", NULL, "exit-status", 0, kvar, KOFF(ki_xstat),
+ USHORT, "x", 0},
+ {"", NULL, NULL, NULL, 0, NULL, 0, CHAR, NULL, 0},
};
void
@@ -185,16 +240,19 @@ showkey(void)
i = 0;
sep = "";
+ xo_open_list("key");
for (v = var; *(p = v->name); ++v) {
int len = strlen(p);
if (termwidth && (i += len + 1) > termwidth) {
i = len;
sep = "\n";
}
- (void) printf("%s%s", sep, p);
+ xo_emit("{P:/%s}{l:key/%s}", sep, p);
sep = " ";
}
- (void) printf("\n");
+ xo_emit("\n");
+ xo_close_list("key");
+ xo_finish();
}
void
diff --git a/bin/ps/print.c b/bin/ps/print.c
index bcd451e1fb59..91daa444e03f 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
#include <vis.h>
+#include <libxo/xo.h>
#include "ps.h"
@@ -85,15 +86,15 @@ printheader(void)
v = vent->var;
if (v->flag & LJUST) {
if (STAILQ_NEXT(vent, next_ve) == NULL) /* last one */
- (void)printf("%s", vent->header);
+ xo_emit("{T:/%s}", vent->header);
else
- (void)printf("%-*s", v->width, vent->header);
+ xo_emit("{T:/%-*s}", v->width, vent->header);
} else
- (void)printf("%*s", v->width, vent->header);
+ xo_emit("{T:/%*s}", v->width, vent->header);
if (STAILQ_NEXT(vent, next_ve) != NULL)
- (void)putchar(' ');
+ xo_emit("{P: }");
}
- (void)putchar('\n');
+ xo_emit("\n");
}
char *
@@ -102,7 +103,7 @@ arguments(KINFO *k, VARENT *ve)
char *vis_args;
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
if (STAILQ_NEXT(ve, next_ve) != NULL && strlen(vis_args) > ARGUMENTS_WIDTH)
@@ -130,7 +131,7 @@ command(KINFO *k, VARENT *ve)
return (str);
}
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
if (STAILQ_NEXT(ve, next_ve) == NULL) {
@@ -139,7 +140,7 @@ command(KINFO *k, VARENT *ve)
if (k->ki_env) {
if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1))
== NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
strvis(vis_env, k->ki_env,
VIS_TAB | VIS_NL | VIS_NOSLASH);
} else
@@ -215,7 +216,7 @@ state(KINFO *k, VARENT *ve __unused)
buf = malloc(16);
if (buf == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
flag = k->ki_p->ki_flag;
tdflags = k->ki_p->ki_tdflags; /* XXXKSE */
@@ -383,7 +384,6 @@ started(KINFO *k, VARENT *ve __unused)
{
time_t then;
struct tm *tp;
- static int use_ampm = -1;
size_t buflen = 100;
char *buf;
@@ -392,18 +392,14 @@ started(KINFO *k, VARENT *ve __unused)
buf = malloc(buflen);
if (buf == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
- if (use_ampm < 0)
- use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
then = k->ki_p->ki_start.tv_sec;
tp = localtime(&then);
if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
- (void)strftime(buf, buflen,
- use_ampm ? "%l:%M%p" : "%k:%M ", tp);
+ (void)strftime(buf, buflen, "%H:%M ", tp);
} else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) {
- (void)strftime(buf, buflen,
- use_ampm ? "%a%I%p" : "%a%H ", tp);
+ (void)strftime(buf, buflen, "%a%H ", tp);
} else
(void)strftime(buf, buflen, "%e%b%y", tp);
return (buf);
@@ -421,7 +417,7 @@ lstarted(KINFO *k, VARENT *ve __unused)
buf = malloc(buflen);
if (buf == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
then = k->ki_p->ki_start.tv_sec;
(void)strftime(buf, buflen, "%c", localtime(&then));
@@ -767,7 +763,7 @@ printval(void *bp, VAR *v)
(void)asprintf(&str, ofmt, ps_pgtok(*(u_long *)bp));
break;
default:
- errx(1, "unknown type %d", v->type);
+ xo_errx(1, "unknown type %d", v->type);
}
return (str);
@@ -809,7 +805,7 @@ label(KINFO *k, VARENT *ve __unused)
string = NULL;
if (mac_prepare_process_label(&proclabel) == -1) {
- warn("mac_prepare_process_label");
+ xo_warn("mac_prepare_process_label");
goto out;
}
error = mac_get_pid(k->ki_p->ki_pid, proclabel);
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index 294ecf939dbc..369e1d72b56a 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 August 27, 2014
+.Dd May 22, 2015
.Dt PS 1
.Os
.Sh NAME
@@ -37,6 +37,7 @@
.Nd process status
.Sh SYNOPSIS
.Nm
+.Op Fl -libxo
.Op Fl aCcdefHhjlmrSTuvwXxZ
.Op Fl O Ar fmt | Fl o Ar fmt
.Op Fl G Ar gid Ns Op , Ns Ar gid Ns Ar ...
@@ -47,6 +48,7 @@
.Op Fl t Ar tty Ns Op , Ns Ar tty Ns Ar ...
.Op Fl U Ar user Ns Op , Ns Ar user Ns Ar ...
.Nm
+.Op Fl -libxo
.Op Fl L
.Sh DESCRIPTION
The
@@ -332,6 +334,7 @@ the include file
.It Dv "P_SINGLE_BOUNDARY" Ta No "0x400000" Ta "Threads should suspend at user boundary"
.It Dv "P_HWPMC" Ta No "0x800000" Ta "Process is using HWPMCs"
.It Dv "P_JAILED" Ta No "0x1000000" Ta "Process is in jail"
+.It Dv "P_TOTAL_STOP" Ta No "0x2000000" Ta "Stopped for system suspend"
.It Dv "P_INEXEC" Ta No "0x4000000" Ta "Process is in execve()"
.It Dv "P_STATCHILD" Ta No "0x8000000" Ta "Child process stopped or exited"
.It Dv "P_INMEM" Ta No "0x10000000" Ta "Loaded into memory"
@@ -380,12 +383,12 @@ the real memory (resident set) size of the process (in 1024 byte units).
The time the command started.
If the command started less than 24 hours ago, the start time is
displayed using the
-.Dq Li %l:ps.1p
+.Dq Li %H:%M
format described in
.Xr strftime 3 .
If the command started less than 7 days ago, the start time is
displayed using the
-.Dq Li %a6.15p
+.Dq Li %a%H
format.
Otherwise, the start time is displayed using the
.Dq Li %e%b%y
@@ -732,7 +735,9 @@ Display information on all system processes:
.Xr procstat 1 ,
.Xr w 1 ,
.Xr kvm 3 ,
+.Xr libxo 3
.Xr strftime 3 ,
+.Xr xo_parse_args 3
.Xr mac 4 ,
.Xr procfs 5 ,
.Xr pstat 8 ,
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 9d14a72c9a60..0e5dd5622fc9 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <libxo/xo.h>
#include "ps.h"
@@ -178,13 +179,15 @@ main(int argc, char *argv[])
KINFO *kinfo = NULL, *next_KINFO;
KINFO_STR *ks;
struct varent *vent;
- struct winsize ws;
+ struct winsize ws = { .ws_row = 0 };
const char *nlistf, *memf, *fmtstr, *str;
char *cols;
int all, ch, elem, flag, _fmt, i, lineno, linelen, left;
int descendancy, nentries, nkept, nselectors;
int prtheader, wflag, what, xkeep, xkeep_implied;
+ int fwidthmin, fwidthmax;
char errbuf[_POSIX2_LINE_MAX];
+ char fmtbuf[_POSIX2_LINE_MAX];
(void) setlocale(LC_ALL, "");
time(&now); /* Used by routines in print.c. */
@@ -221,6 +224,11 @@ main(int argc, char *argv[])
init_list(&uidlist, addelem_uid, sizeof(uid_t), "user");
memf = _PATH_DEVNULL;
nlistf = NULL;
+
+ argc = xo_parse_args(argc, argv);
+ if (argc < 0)
+ exit(1);
+
while ((ch = getopt(argc, argv, PS_ARGS)) != -1)
switch (ch) {
case 'A':
@@ -363,7 +371,7 @@ main(int argc, char *argv[])
#endif
case 'T':
if ((optarg = ttyname(STDIN_FILENO)) == NULL)
- errx(1, "stdin: not a terminal");
+ xo_errx(1, "stdin: not a terminal");
/* FALLTHROUGH */
case 't':
add_list(&ttylist, optarg);
@@ -434,8 +442,7 @@ main(int argc, char *argv[])
argv++;
}
if (*argv) {
- fprintf(stderr, "%s: illegal argument: %s\n",
- getprogname(), *argv);
+ xo_warnx("illegal argument: %s\n", *argv);
usage();
}
if (optfatal)
@@ -445,7 +452,7 @@ main(int argc, char *argv[])
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
if (kd == 0)
- errx(1, "%s", errbuf);
+ xo_errx(1, "%s", errbuf);
if (!_fmt)
parsefmt(dfmt, 0);
@@ -453,7 +460,7 @@ main(int argc, char *argv[])
if (nselectors == 0) {
uidlist.l.ptr = malloc(sizeof(uid_t));
if (uidlist.l.ptr == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
nselectors = 1;
uidlist.count = uidlist.maxcount = 1;
*uidlist.l.uids = getuid();
@@ -515,11 +522,11 @@ main(int argc, char *argv[])
nentries = -1;
kp = kvm_getprocs(kd, what, flag, &nentries);
if ((kp == NULL && nentries > 0) || (kp != NULL && nentries < 0))
- errx(1, "%s", kvm_geterr(kd));
+ xo_errx(1, "%s", kvm_geterr(kd));
nkept = 0;
if (nentries > 0) {
if ((kinfo = malloc(nentries * sizeof(*kinfo))) == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
for (i = nentries; --i >= 0; ++kp) {
/*
* If the user specified multiple selection-criteria,
@@ -629,13 +636,18 @@ main(int argc, char *argv[])
/*
* Print header.
*/
+ xo_open_container("process-information");
printheader();
+ if (xo_get_style(NULL) != XO_STYLE_TEXT)
+ termwidth = UNLIMITED;
/*
* Output formatted lines.
*/
+ xo_open_list("process");
for (i = lineno = 0; i < nkept; i++) {
linelen = 0;
+ xo_open_instance("process");
STAILQ_FOREACH(vent, &varlist, next_ve) {
if (vent->var->flag & LJUST)
fmtstr = "%-*s";
@@ -645,21 +657,27 @@ main(int argc, char *argv[])
ks = STAILQ_FIRST(&kinfo[i].ki_ks);
STAILQ_REMOVE_HEAD(&kinfo[i].ki_ks, ks_next);
/* Truncate rightmost column if necessary. */
+ fwidthmax = _POSIX2_LINE_MAX;
if (STAILQ_NEXT(vent, next_ve) == NULL &&
termwidth != UNLIMITED && ks->ks_str != NULL) {
left = termwidth - linelen;
if (left > 0 && left < (int)strlen(ks->ks_str))
- ks->ks_str[left] = '\0';
+ fwidthmax = left;
}
+
str = ks->ks_str;
if (str == NULL)
str = "-";
/* No padding for the last column, if it's LJUST. */
- if (STAILQ_NEXT(vent, next_ve) == NULL &&
- vent->var->flag & LJUST)
- linelen += printf(fmtstr, 0, str);
- else
- linelen += printf(fmtstr, vent->var->width, str);
+ fwidthmin = (xo_get_style(NULL) != XO_STYLE_TEXT ||
+ (STAILQ_NEXT(vent, next_ve) == NULL &&
+ (vent->var->flag & LJUST))) ? 0 : vent->var->width;
+ snprintf(fmtbuf, sizeof(fmtbuf), "{:%s/%%%s%d..%ds}",
+ vent->var->field ?: vent->var->name,
+ (vent->var->flag & LJUST) ? "-" : "",
+ fwidthmin, fwidthmax);
+ xo_emit(fmtbuf, str);
+ linelen += fwidthmin;
if (ks->ks_str != NULL) {
free(ks->ks_str);
@@ -669,17 +687,22 @@ main(int argc, char *argv[])
ks = NULL;
if (STAILQ_NEXT(vent, next_ve) != NULL) {
- (void)putchar(' ');
+ xo_emit("{P: }");
linelen++;
}
}
- (void)putchar('\n');
+ xo_emit("\n");
+ xo_close_instance("process");
if (prtheader && lineno++ == prtheader - 4) {
- (void)putchar('\n');
+ xo_emit("\n");
printheader();
lineno = 0;
}
}
+ xo_close_list("process");
+ xo_close_container("process-information");
+ xo_finish();
+
free_list(&gidlist);
free_list(&jidlist);
free_list(&pidlist);
@@ -705,9 +728,9 @@ addelem_gid(struct listinfo *inf, const char *elem)
if (*elem == '\0' || strlen(elem) >= MAXLOGNAME) {
if (*elem == '\0')
- warnx("Invalid (zero-length) %s name", inf->lname);
+ xo_warnx("Invalid (zero-length) %s name", inf->lname);
else
- warnx("%s name too long: %s", inf->lname, elem);
+ xo_warnx("%s name too long: %s", inf->lname, elem);
optfatal = 1;
return (0); /* Do not add this value. */
}
@@ -732,7 +755,7 @@ addelem_gid(struct listinfo *inf, const char *elem)
if (grp == NULL)
grp = getgrnam(elem);
if (grp == NULL) {
- warnx("No %s %s '%s'", inf->lname, nameorID, elem);
+ xo_warnx("No %s %s '%s'", inf->lname, nameorID, elem);
optfatal = 1;
return (0);
}
@@ -773,7 +796,7 @@ addelem_pid(struct listinfo *inf, const char *elem)
long tempid;
if (*elem == '\0') {
- warnx("Invalid (zero-length) process id");
+ xo_warnx("Invalid (zero-length) process id");
optfatal = 1;
return (0); /* Do not add this value. */
}
@@ -781,10 +804,10 @@ addelem_pid(struct listinfo *inf, const char *elem)
errno = 0;
tempid = strtol(elem, &endp, 10);
if (*endp != '\0' || tempid < 0 || elem == endp) {
- warnx("Invalid %s: %s", inf->lname, elem);
+ xo_warnx("Invalid %s: %s", inf->lname, elem);
errno = ERANGE;
} else if (errno != 0 || tempid > pid_max) {
- warnx("%s too large: %s", inf->lname, elem);
+ xo_warnx("%s too large: %s", inf->lname, elem);
errno = ERANGE;
}
if (errno == ERANGE) {
@@ -855,19 +878,19 @@ addelem_tty(struct listinfo *inf, const char *elem)
if (ttypath) {
if (stat(ttypath, &sb) == -1) {
if (pathbuf3[0] != '\0')
- warn("%s, %s, and %s", pathbuf3, pathbuf2,
+ xo_warn("%s, %s, and %s", pathbuf3, pathbuf2,
ttypath);
else
- warn("%s", ttypath);
+ xo_warn("%s", ttypath);
optfatal = 1;
return (0);
}
if (!S_ISCHR(sb.st_mode)) {
if (pathbuf3[0] != '\0')
- warnx("%s, %s, and %s: Not a terminal",
+ xo_warnx("%s, %s, and %s: Not a terminal",
pathbuf3, pathbuf2, ttypath);
else
- warnx("%s: Not a terminal", ttypath);
+ xo_warnx("%s: Not a terminal", ttypath);
optfatal = 1;
return (0);
}
@@ -887,9 +910,9 @@ addelem_uid(struct listinfo *inf, const char *elem)
if (*elem == '\0' || strlen(elem) >= MAXLOGNAME) {
if (*elem == '\0')
- warnx("Invalid (zero-length) %s name", inf->lname);
+ xo_warnx("Invalid (zero-length) %s name", inf->lname);
else
- warnx("%s name too long: %s", inf->lname, elem);
+ xo_warnx("%s name too long: %s", inf->lname, elem);
optfatal = 1;
return (0); /* Do not add this value. */
}
@@ -899,12 +922,12 @@ addelem_uid(struct listinfo *inf, const char *elem)
errno = 0;
bigtemp = strtoul(elem, &endp, 10);
if (errno != 0 || *endp != '\0' || bigtemp > UID_MAX)
- warnx("No %s named '%s'", inf->lname, elem);
+ xo_warnx("No %s named '%s'", inf->lname, elem);
else {
/* The string is all digits, so it might be a userID. */
pwd = getpwuid((uid_t)bigtemp);
if (pwd == NULL)
- warnx("No %s name or ID matches '%s'",
+ xo_warnx("No %s name or ID matches '%s'",
inf->lname, elem);
}
}
@@ -961,7 +984,7 @@ add_list(struct listinfo *inf, const char *argp)
while (*argp != '\0' && strchr(W_SEP T_SEP,
*argp) == NULL)
argp++;
- warnx("Value too long: %.*s", (int)(argp - savep),
+ xo_warnx("Value too long: %.*s", (int)(argp - savep),
savep);
optfatal = 1;
}
@@ -1062,7 +1085,7 @@ descendant_sort(KINFO *ki, int items)
continue;
}
if ((ki[src].ki_d.prefix = malloc(lvl * 2 + 1)) == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
for (n = 0; n < lvl - 2; n++) {
ki[src].ki_d.prefix[n * 2] =
path[n / 8] & 1 << (n % 8) ? '|' : ' ';
@@ -1100,7 +1123,7 @@ expand_list(struct listinfo *inf)
newlist = realloc(inf->l.ptr, newmax * inf->elemsize);
if (newlist == NULL) {
free(inf->l.ptr);
- errx(1, "realloc to %d %ss failed", newmax, inf->lname);
+ xo_errx(1, "realloc to %d %ss failed", newmax, inf->lname);
}
inf->maxcount = newmax;
inf->l.ptr = newlist;
@@ -1174,7 +1197,7 @@ format_output(KINFO *ki)
str = (v->oproc)(ki, vent);
ks = malloc(sizeof(*ks));
if (ks == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
ks->ks_str = str;
STAILQ_INSERT_TAIL(&ki->ki_ks, ks, ks_next);
if (str != NULL) {
@@ -1240,7 +1263,7 @@ saveuser(KINFO *ki)
else
asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm);
if (ki->ki_args == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
} else {
ki->ki_args = NULL;
}
@@ -1251,7 +1274,7 @@ saveuser(KINFO *ki)
else
ki->ki_env = strdup("()");
if (ki->ki_env == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
} else {
ki->ki_env = NULL;
}
@@ -1372,7 +1395,7 @@ kludge_oldps_options(const char *optlist, char *origval, const char *nextarg)
* original value.
*/
if ((newopts = ns = malloc(len + 3)) == NULL)
- errx(1, "malloc failed");
+ xo_errx(1, "malloc failed");
if (*origval != '-')
*ns++ = '-'; /* add option flag */
@@ -1401,7 +1424,7 @@ pidmax_init(void)
intsize = sizeof(pid_max);
if (sysctlbyname("kern.pid_max", &pid_max, &intsize, NULL, 0) < 0) {
- warn("unable to read kern.pid_max");
+ xo_warn("unable to read kern.pid_max");
pid_max = 99999;
}
}
@@ -1411,7 +1434,7 @@ usage(void)
{
#define SINGLE_OPTS "[-aCcde" OPT_LAZY_f "HhjlmrSTuvwXxZ]"
- (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
+ (void)xo_error("%s\n%s\n%s\n%s\n",
"usage: ps " SINGLE_OPTS " [-O fmt | -o fmt] [-G gid[,gid...]]",
" [-J jid[,jid...]] [-M core] [-N system]",
" [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]",
diff --git a/bin/ps/ps.h b/bin/ps/ps.h
index 86aaeb0fe652..314fbf276994 100644
--- a/bin/ps/ps.h
+++ b/bin/ps/ps.h
@@ -65,6 +65,7 @@ typedef struct var {
const char *name; /* name(s) of variable */
const char *header; /* default header */
const char *alias; /* aliases */
+ const char *field; /* xo field name */
#define COMM 0x01 /* needs exec arguments and environment (XXX) */
#define LJUST 0x02 /* left adjust on output (trailing blanks) */
#define USER 0x04 /* needs user structure */
diff --git a/bin/rcp/Makefile b/bin/rcp/Makefile
index 1c156a236d11..886ec01ca0d0 100644
--- a/bin/rcp/Makefile
+++ b/bin/rcp/Makefile
@@ -7,6 +7,5 @@ CFLAGS+=-DBINDIR=${BINDIR}
BINOWN= root
BINMODE=4555
-PRECIOUSPROG=
.include <bsd.prog.mk>
diff --git a/bin/rmail/Makefile b/bin/rmail/Makefile
index ad788a4745a8..a74898f853c7 100644
--- a/bin/rmail/Makefile
+++ b/bin/rmail/Makefile
@@ -14,11 +14,7 @@ MAN= rmail.8
WARNS?= 2
CFLAGS+=-I${SENDMAIL_DIR}/include -I.
-LIBSMDIR= ${.OBJDIR}/../../lib/libsm
-LIBSM= ${LIBSMDIR}/libsm.a
-
-DPADD= ${LIBSM}
-LDADD= ${LIBSM}
+LIBADD= sm
SRCS+= sm_os.h
CLEANFILES+=sm_os.h
diff --git a/bin/sh/Makefile b/bin/sh/Makefile
index ad43d33e6c3c..3f28a1231fd3 100644
--- a/bin/sh/Makefile
+++ b/bin/sh/Makefile
@@ -18,8 +18,7 @@ SRCS= ${SHSRCS} ${GENSRCS} ${GENHDRS}
# utilities of the same name are handled with the associated manpage,
# builtin.1 in share/man/man1/.
-DPADD= ${LIBEDIT} ${LIBTERMCAPW}
-LDADD= -ledit -ltermcapw
+LIBADD= edit
CFLAGS+=-DSHELL -I. -I${.CURDIR}
# for debug:
diff --git a/bin/sh/arith_yacc.h b/bin/sh/arith_yacc.h
index 5d8354fa2a16..ca92e6f7fa17 100644
--- a/bin/sh/arith_yacc.h
+++ b/bin/sh/arith_yacc.h
@@ -81,6 +81,8 @@
#define ARITH_QMARK 37
#define ARITH_COLON 38
+extern const char *arith_buf;
+
union yystype {
arith_t val;
char *name;
diff --git a/bin/sh/arith_yylex.c b/bin/sh/arith_yylex.c
index ad0818426de5..f7eaf3e3fa6d 100644
--- a/bin/sh/arith_yylex.c
+++ b/bin/sh/arith_yylex.c
@@ -50,8 +50,6 @@ __FBSDID("$FreeBSD$");
#error Arithmetic tokens are out of order.
#endif
-extern const char *arith_buf;
-
int
yylex(void)
{
diff --git a/bin/sh/bltin/bltin.h b/bin/sh/bltin/bltin.h
index bbf55f1ae79f..a530ab78b2a5 100644
--- a/bin/sh/bltin/bltin.h
+++ b/bin/sh/bltin/bltin.h
@@ -42,6 +42,7 @@
#include "../shell.h"
#include "../mystring.h"
#ifdef SHELL
+#include "../error.h"
#include "../output.h"
#include "builtins.h"
#define FILE struct output
@@ -73,7 +74,6 @@
#include <unistd.h>
pointer stalloc(int);
-void error(const char *, ...) __printf0like(1, 2);
int killjob(const char *, int);
extern char *commandname;
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index 7720fad7d64c..88f03f57d73b 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -122,7 +122,7 @@ cdcmd(int argc __unused, char **argv __unused)
(dest[0] == '.' && (dest[1] == '/' || dest[1] == '\0')) ||
(dest[0] == '.' && dest[1] == '.' && (dest[2] == '/' || dest[2] == '\0')) ||
(path = bltinlookup("CDPATH", 1)) == NULL)
- path = nullstr;
+ path = "";
while ((p = padvance(&path, dest)) != NULL) {
if (stat(p, &statb) < 0) {
if (errno != ENOENT)
@@ -182,7 +182,6 @@ cdlogical(char *dest)
struct stat statb;
int first;
int badstat;
- size_t len;
/*
* Check each component of the path. If we find a symlink or
@@ -190,9 +189,7 @@ cdlogical(char *dest)
* next time we get the value of the current directory.
*/
badstat = 0;
- len = strlen(dest);
- cdcomppath = stalloc(len + 1);
- memcpy(cdcomppath, dest, len + 1);
+ cdcomppath = stsavestr(dest);
STARTSTACKSTR(p);
if (*dest == '/') {
STPUTC('/', p);
@@ -277,7 +274,6 @@ findcwd(char *dir)
{
char *new;
char *p;
- size_t len;
/*
* If our argument is NULL, we don't know the current directory
@@ -286,9 +282,7 @@ findcwd(char *dir)
*/
if (dir == NULL || curdir == NULL)
return getpwd2();
- len = strlen(dir);
- cdcomppath = stalloc(len + 1);
- memcpy(cdcomppath, dir, len + 1);
+ cdcomppath = stsavestr(dir);
STARTSTACKSTR(new);
if (*dir != '/') {
STPUTS(curdir, new);
diff --git a/bin/sh/error.c b/bin/sh/error.c
index c76a9dc65768..605722669549 100644
--- a/bin/sh/error.c
+++ b/bin/sh/error.c
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
*/
#include "shell.h"
+#include "eval.h"
#include "main.h"
#include "options.h"
#include "output.h"
@@ -64,7 +65,6 @@ struct jmploc *handler;
volatile sig_atomic_t exception;
volatile sig_atomic_t suppressint;
volatile sig_atomic_t intpending;
-char *commandname;
static void exverror(int, const char *, va_list) __printf0like(2, 0) __dead2;
@@ -90,13 +90,14 @@ exraise(int e)
/*
- * Called from trap.c when a SIGINT is received. (If the user specifies
- * that SIGINT is to be trapped or ignored using the trap builtin, then
- * this routine is not called.) Suppressint is nonzero when interrupts
- * are held using the INTOFF macro. If SIGINTs are not suppressed and
- * the shell is not a root shell, then we want to be terminated if we
- * get here, as if we were terminated directly by a SIGINT. Arrange for
- * this here.
+ * Called from trap.c when a SIGINT is received and not suppressed, or when
+ * an interrupt is pending and interrupts are re-enabled using INTON.
+ * (If the user specifies that SIGINT is to be trapped or ignored using the
+ * trap builtin, then this routine is not called.) Suppressint is nonzero
+ * when interrupts are held using the INTOFF macro. If SIGINTs are not
+ * suppressed and the shell is not a root shell, then we want to be
+ * terminated if we get here, as if we were terminated directly by a SIGINT.
+ * Arrange for this here.
*/
void
@@ -104,16 +105,6 @@ onint(void)
{
sigset_t sigs;
- /*
- * The !in_dotrap here is safe. The only way we can arrive here
- * with in_dotrap set is that a trap handler set SIGINT to SIG_DFL
- * and killed itself.
- */
-
- if (suppressint && !in_dotrap) {
- intpending++;
- return;
- }
intpending = 0;
sigemptyset(&sigs);
sigprocmask(SIG_SETMASK, &sigs, NULL);
@@ -130,6 +121,7 @@ onint(void)
else {
signal(SIGINT, SIG_DFL);
kill(getpid(), SIGINT);
+ _exit(128 + SIGINT);
}
}
@@ -139,6 +131,8 @@ vwarning(const char *msg, va_list ap)
{
if (commandname)
outfmt(out2, "%s: ", commandname);
+ else if (arg0)
+ outfmt(out2, "%s: ", arg0);
doformat(out2, msg, ap);
out2fmt_flush("\n");
}
diff --git a/bin/sh/error.h b/bin/sh/error.h
index d0a4bca7477f..a60b1fa1767f 100644
--- a/bin/sh/error.h
+++ b/bin/sh/error.h
@@ -75,11 +75,12 @@ extern volatile sig_atomic_t intpending;
#define is_int_on() suppressint
#define SETINTON(s) suppressint = (s)
#define FORCEINTON {suppressint = 0; if (intpending) onint();}
+#define SET_PENDING_INT intpending = 1
#define CLEAR_PENDING_INT intpending = 0
#define int_pending() intpending
void exraise(int) __dead2;
-void onint(void);
+void onint(void) __dead2;
void warning(const char *, ...) __printflike(1, 2);
void error(const char *, ...) __printf0like(1, 2) __dead2;
void exerror(int, const char *, ...) __printf0like(2, 3) __dead2;
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index c1a9cdbfcd93..51206d931874 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -149,7 +149,7 @@ evalcmd(int argc, char **argv)
*/
void
-evalstring(char *s, int flags)
+evalstring(const char *s, int flags)
{
union node *n;
struct stackmark smark;
@@ -498,7 +498,7 @@ exphere(union node *redir, struct arglist *fn)
struct localvar *savelocalvars;
int need_longjmp = 0;
- redir->nhere.expdoc = nullstr;
+ redir->nhere.expdoc = "";
savelocalvars = localvars;
localvars = NULL;
forcelocal++;
@@ -539,13 +539,13 @@ expredir(union node *n)
case NFROMTO:
case NAPPEND:
case NCLOBBER:
- expandarg(redir->nfile.fname, &fn, EXP_TILDE | EXP_REDIR);
+ expandarg(redir->nfile.fname, &fn, EXP_TILDE);
redir->nfile.expfname = fn.list->text;
break;
case NFROMFD:
case NTOFD:
if (redir->ndup.vname) {
- expandarg(redir->ndup.vname, &fn, EXP_TILDE | EXP_REDIR);
+ expandarg(redir->ndup.vname, &fn, EXP_TILDE);
fixredir(redir, fn.list->text, 1);
}
break;
@@ -774,15 +774,7 @@ xtracecommand(struct arglist *varlist, struct arglist *arglist)
for (sp = arglist->list ; sp ; sp = sp->next) {
if (sep != 0)
out2c(' ');
- /* Disambiguate command looking like assignment. */
- if (sp == arglist->list &&
- strchr(sp->text, '=') != NULL &&
- strchr(sp->text, '\'') == NULL) {
- out2c('\'');
- out2str(sp->text);
- out2c('\'');
- } else
- out2qstr(sp->text);
+ out2qstr(sp->text);
sep = ' ';
}
out2c('\n');
diff --git a/bin/sh/eval.h b/bin/sh/eval.h
index 4129757e9f01..d4092be45137 100644
--- a/bin/sh/eval.h
+++ b/bin/sh/eval.h
@@ -53,7 +53,7 @@ void reseteval(void);
#define EV_TESTED 02 /* exit status is checked; ignore -e flag */
#define EV_BACKCMD 04 /* command executing within back quotes */
-void evalstring(char *, int);
+void evalstring(const char *, int);
union node; /* BLETCH for ansi C */
void evaltree(union node *, int);
void evalbackcmd(union node *, struct backcmd *);
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index d4c4c5a5d518..193d65177e74 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -105,11 +105,12 @@ static void expbackq(union node *, int, int);
static int subevalvar(char *, char *, int, int, int, int, int);
static char *evalvar(char *, int);
static int varisset(const char *, int);
+static void strtodest(const char *, int, int, int);
static void varvalue(const char *, int, int, int);
static void recordregion(int, int, int);
static void removerecordregions(int);
static void ifsbreakup(char *, struct arglist *);
-static void expandmeta(struct strlist *, int);
+static void expandmeta(struct strlist *);
static void expmeta(char *, char *);
static void addfname(char *);
static struct strlist *expsort(struct strlist *);
@@ -171,17 +172,12 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
STPUTC('\0', expdest);
p = grabstackstr(expdest);
exparg.lastp = &exparg.list;
- /*
- * TODO - EXP_REDIR
- */
if (flag & EXP_FULL) {
ifsbreakup(p, &exparg);
*exparg.lastp = NULL;
exparg.lastp = &exparg.list;
- expandmeta(exparg.list, flag);
+ expandmeta(exparg.list);
} else {
- if (flag & EXP_REDIR) /*XXX - for now, just remove escapes */
- rmescapes(p);
sp = (struct strlist *)stalloc(sizeof (struct strlist));
sp->text = p;
*exparg.lastp = sp;
@@ -209,7 +205,7 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
* expansion, and tilde expansion if requested via EXP_TILDE/EXP_VARTILDE.
* Processing ends at a CTLENDVAR or CTLENDARI character as well as '\0'.
* This is used to expand word in ${var+word} etc.
- * If EXP_FULL, EXP_CASE or EXP_REDIR are set, keep and/or generate CTLESC
+ * If EXP_FULL or EXP_CASE are set, keep and/or generate CTLESC
* characters to allow for further processing.
* If EXP_FULL is set, also preserve CTLQUOTEMARK characters.
*/
@@ -217,7 +213,7 @@ static char *
argstr(char *p, int flag)
{
char c;
- int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR); /* do CTLESC */
+ int quotes = flag & (EXP_FULL | EXP_CASE); /* do CTLESC */
int firsteq = 1;
int split_lit;
int lit_quoted;
@@ -303,9 +299,9 @@ exptilde(char *p, int flag)
char c, *startp = p;
struct passwd *pw;
char *home;
- int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR);
- while ((c = *p) != '\0') {
+ for (;;) {
+ c = *p;
switch(c) {
case CTLESC: /* This means CTL* are always considered quoted. */
case CTLVAR:
@@ -316,31 +312,27 @@ exptilde(char *p, int flag)
case CTLQUOTEMARK:
return (startp);
case ':':
- if (flag & EXP_VARTILDE)
- goto done;
- break;
+ if ((flag & EXP_VARTILDE) == 0)
+ break;
+ /* FALLTHROUGH */
+ case '\0':
case '/':
case CTLENDVAR:
- goto done;
+ *p = '\0';
+ if (*(startp+1) == '\0') {
+ home = lookupvar("HOME");
+ } else {
+ pw = getpwnam(startp+1);
+ home = pw != NULL ? pw->pw_dir : NULL;
+ }
+ *p = c;
+ if (home == NULL || *home == '\0')
+ return (startp);
+ strtodest(home, flag, VSNORMAL, 1);
+ return (p);
}
p++;
}
-done:
- *p = '\0';
- if (*(startp+1) == '\0') {
- home = lookupvar("HOME");
- } else {
- pw = getpwnam(startp+1);
- home = pw != NULL ? pw->pw_dir : NULL;
- }
- *p = c;
- if (home == NULL || *home == '\0')
- return (startp);
- if (quotes)
- STPUTS_QUOTES(home, SQSYNTAX, expdest);
- else
- STPUTS(home, expdest);
- return (p);
}
@@ -437,7 +429,7 @@ expbackq(union node *cmd, int quoted, int flag)
char lastc;
int startloc = dest - stackblock();
char const *syntax = quoted? DQSYNTAX : BASESYNTAX;
- int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR);
+ int quotes = flag & (EXP_FULL | EXP_CASE);
size_t nnl;
INTOFF;
@@ -501,6 +493,17 @@ expbackq(union node *cmd, int quoted, int flag)
+static void
+recordleft(const char *str, const char *loc, char *startp)
+{
+ int amount;
+
+ amount = ((str - 1) - (loc - startp)) - expdest;
+ STADJUST(amount, expdest);
+ while (loc != str - 1)
+ *startp++ = *loc++;
+}
+
static int
subevalvar(char *p, char *str, int strloc, int subtype, int startloc,
int varflags, int quotes)
@@ -535,8 +538,7 @@ subevalvar(char *p, char *str, int strloc, int subtype, int startloc,
error((char *)NULL);
}
error("%.*s: parameter %snot set", (int)(p - str - 1),
- str, (varflags & VSNUL) ? "null or "
- : nullstr);
+ str, (varflags & VSNUL) ? "null or " : "");
return 0;
case VSTRIMLEFT:
@@ -545,7 +547,8 @@ subevalvar(char *p, char *str, int strloc, int subtype, int startloc,
*loc = '\0';
if (patmatch(str, startp, quotes)) {
*loc = c;
- goto recordleft;
+ recordleft(str, loc, startp);
+ return 1;
}
*loc = c;
if (quotes && *loc == CTLESC)
@@ -559,7 +562,8 @@ subevalvar(char *p, char *str, int strloc, int subtype, int startloc,
*loc = '\0';
if (patmatch(str, startp, quotes)) {
*loc = c;
- goto recordleft;
+ recordleft(str, loc, startp);
+ return 1;
}
*loc = c;
loc--;
@@ -607,13 +611,6 @@ subevalvar(char *p, char *str, int strloc, int subtype, int startloc,
default:
abort();
}
-
-recordleft:
- amount = ((str - 1) - (loc - startp)) - expdest;
- STADJUST(amount, expdest);
- while (loc != str - 1)
- *startp++ = *loc++;
- return 1;
}
@@ -637,7 +634,8 @@ evalvar(char *p, int flag)
int varlen;
int varlenb;
int easy;
- int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR);
+ int quotes = flag & (EXP_FULL | EXP_CASE);
+ int record = 0;
varflags = (unsigned char)*p++;
subtype = varflags & VSTYPE;
@@ -695,22 +693,15 @@ again: /* jump here after setting a variable with ${var=text} */
STADJUST(-varlenb, expdest);
}
} else {
- char const *syntax = (varflags & VSQUOTE) ? DQSYNTAX
- : BASESYNTAX;
-
if (subtype == VSLENGTH) {
for (;*val; val++)
if (!localeisutf8 ||
(*val & 0xC0) != 0x80)
varlen++;
}
- else {
- if (quotes)
- STPUTS_QUOTES(val, syntax, expdest);
- else
- STPUTS(val, expdest);
-
- }
+ else
+ strtodest(val, flag, subtype,
+ varflags & VSQUOTE);
}
}
@@ -724,15 +715,11 @@ again: /* jump here after setting a variable with ${var=text} */
switch (subtype) {
case VSLENGTH:
expdest = cvtnum(varlen, expdest);
- goto record;
+ record = 1;
+ break;
case VSNORMAL:
- if (!easy)
- break;
-record:
- recordregion(startloc, expdest - stackblock(),
- varflags & VSQUOTE || (ifsset() && ifsval()[0] == '\0' &&
- (*var == '@' || *var == '*')));
+ record = easy;
break;
case VSPLUS:
@@ -742,8 +729,7 @@ record:
(varflags & VSQUOTE ? EXP_LIT_QUOTED : 0));
break;
}
- if (easy)
- goto record;
+ record = easy;
break;
case VSTRIMLEFT:
@@ -765,7 +751,8 @@ record:
}
/* Remove any recorded regions beyond start of variable */
removerecordregions(startloc);
- goto record;
+ record = 1;
+ break;
case VSASSIGN:
case VSQUESTION:
@@ -782,8 +769,7 @@ record:
}
break;
}
- if (easy)
- goto record;
+ record = easy;
break;
case VSERROR:
@@ -795,6 +781,11 @@ record:
abort();
}
+ if (record)
+ recordregion(startloc, expdest - stackblock(),
+ varflags & VSQUOTE || (ifsset() && ifsval()[0] == '\0' &&
+ (*var == '@' || *var == '*')));
+
if (subtype != VSNORMAL) { /* skip to end of alternative */
int nesting = 1;
for (;;) {
@@ -862,7 +853,7 @@ varisset(const char *name, int nulok)
static void
strtodest(const char *p, int flag, int subtype, int quoted)
{
- if (flag & (EXP_FULL | EXP_CASE | EXP_REDIR) && subtype != VSLENGTH)
+ if (flag & (EXP_FULL | EXP_CASE) && subtype != VSLENGTH)
STPUTS_QUOTES(p, quoted ? DQSYNTAX : BASESYNTAX, expdest);
else
STPUTS(p, expdest);
@@ -1098,13 +1089,12 @@ static char expdir[PATH_MAX];
* The results are stored in the list exparg.
*/
static void
-expandmeta(struct strlist *str, int flag __unused)
+expandmeta(struct strlist *str)
{
char *p;
struct strlist **savelastp;
struct strlist *sp;
char c;
- /* TODO - EXP_REDIR */
while (str) {
savelastp = exparg.lastp;
@@ -1290,11 +1280,8 @@ addfname(char *name)
{
char *p;
struct strlist *sp;
- size_t len;
- len = strlen(name);
- p = stalloc(len + 1);
- memcpy(p, name, len + 1);
+ p = stsavestr(name);
sp = (struct strlist *)stalloc(sizeof *sp);
sp->text = p;
*exparg.lastp = sp;
@@ -1484,16 +1471,14 @@ patmatch(const char *pattern, const char *string, int squoted)
endp = p;
if (*endp == '!' || *endp == '^')
endp++;
- for (;;) {
+ do {
while (*endp == CTLQUOTEMARK)
endp++;
if (*endp == 0)
goto dft; /* no matching ] */
if (*endp == CTLESC)
endp++;
- if (*++endp == ']')
- break;
- }
+ } while (*++endp != ']');
invert = 0;
if (*p == '!' || *p == '^') {
invert++;
diff --git a/bin/sh/expand.h b/bin/sh/expand.h
index 7495a633ef40..93c80f3013e3 100644
--- a/bin/sh/expand.h
+++ b/bin/sh/expand.h
@@ -50,7 +50,6 @@ struct arglist {
#define EXP_FULL 0x1 /* perform word splitting & file globbing */
#define EXP_TILDE 0x2 /* do normal tilde expansion */
#define EXP_VARTILDE 0x4 /* expand tildes in an assignment */
-#define EXP_REDIR 0x8 /* file glob for a redirection (1 match only) */
#define EXP_CASE 0x10 /* keeps quotes around for CASE pattern */
#define EXP_SPLIT_LIT 0x20 /* IFS split literal text ${v+-a b c} */
#define EXP_LIT_QUOTED 0x40 /* for EXP_SPLIT_LIT, start off quoted */
diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c
index c65d1c7134e5..7295c3f003c9 100644
--- a/bin/sh/histedit.c
+++ b/bin/sh/histedit.c
@@ -338,8 +338,8 @@ histcmd(int argc, char **argv __unused)
out1fmt("%5d ", he.num);
out1str(he.str);
} else {
- char *s = pat ?
- fc_replace(he.str, pat, repl) : (char *)he.str;
+ const char *s = pat ?
+ fc_replace(he.str, pat, repl) : he.str;
if (sflg) {
if (displayhist) {
@@ -477,7 +477,7 @@ bindcmd(int argc, char **argv)
if (el == NULL)
error("line editing is disabled");
- return (el_parse(el, argc, (const char **)argv));
+ return (el_parse(el, argc, __DECONST(const char **, argv)));
}
#else
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c
index 765e6a2ed3aa..b531231e4a59 100644
--- a/bin/sh/jobs.c
+++ b/bin/sh/jobs.c
@@ -87,8 +87,8 @@ static int ttyfd = -1;
/* mode flags for dowait */
#define DOWAIT_BLOCK 0x1 /* wait until a child exits */
-#define DOWAIT_SIG 0x2 /* if DOWAIT_BLOCK, abort on SIGINT/SIGQUIT */
-#define DOWAIT_SIG_ANY 0x4 /* if DOWAIT_SIG, abort on any signal */
+#define DOWAIT_SIG 0x2 /* if DOWAIT_BLOCK, abort on signal */
+#define DOWAIT_SIG_TRAP 0x4 /* if DOWAIT_SIG, abort on trapped signal only */
#if JOBS
static void restartjob(struct job *);
@@ -232,7 +232,7 @@ fgcmd(int argc __unused, char **argv __unused)
int
-bgcmd(int argc, char **argv)
+bgcmd(int argc __unused, char **argv __unused)
{
struct job *jp;
@@ -1028,7 +1028,7 @@ waitforjob(struct job *jp, int *origstatus)
TRACE(("waitforjob(%%%td) called\n", jp - jobtab + 1));
while (jp->state == 0)
if (dowait(DOWAIT_BLOCK | (Tflag ? DOWAIT_SIG |
- DOWAIT_SIG_ANY : 0), jp) == -1)
+ DOWAIT_SIG_TRAP : 0), jp) == -1)
dotrap();
#if JOBS
if (jp->jobctl) {
@@ -1057,7 +1057,7 @@ waitforjob(struct job *jp, int *origstatus)
CLEAR_PENDING_INT;
}
#if JOBS
- else if (rootshell && iflag && propagate_int &&
+ else if (rootshell && propagate_int &&
WIFSIGNALED(status) && WTERMSIG(status) == SIGINT)
kill(getpid(), SIGINT);
#endif
@@ -1120,7 +1120,7 @@ dowait(int mode, struct job *job)
TRACE(("wait returns %d, status=%d\n", (int)pid, status));
if (pid == 0 && (mode & DOWAIT_SIG) != 0) {
pid = -1;
- if (((mode & DOWAIT_SIG_ANY) != 0 ?
+ if (((mode & DOWAIT_SIG_TRAP) != 0 ?
pendingsig : pendingsig_waitcmd) != 0) {
errno = EINTR;
break;
diff --git a/bin/sh/mail.c b/bin/sh/mail.c
index 597e73370e86..720cab032abf 100644
--- a/bin/sh/mail.c
+++ b/bin/sh/mail.c
@@ -85,7 +85,7 @@ chkmail(int silent)
setstackmark(&smark);
mpath = mpathset()? mpathval() : mailval();
for (i = 0 ; i < nmboxes ; i++) {
- p = padvance(&mpath, nullstr);
+ p = padvance(&mpath, "");
if (p == NULL)
break;
if (*p == '\0')
diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c
index 119f12e9fc74..a04020f80c97 100644
--- a/bin/sh/memalloc.c
+++ b/bin/sh/memalloc.c
@@ -180,6 +180,18 @@ stunalloc(pointer p)
}
+char *
+stsavestr(const char *s)
+{
+ char *p;
+ size_t len;
+
+ len = strlen(s);
+ p = stalloc(len + 1);
+ memcpy(p, s, len + 1);
+ return p;
+}
+
void
setstackmark(struct stackmark *mark)
diff --git a/bin/sh/memalloc.h b/bin/sh/memalloc.h
index a22fa3919872..e8df7cb1c0b9 100644
--- a/bin/sh/memalloc.h
+++ b/bin/sh/memalloc.h
@@ -52,6 +52,7 @@ void ckfree(pointer);
char *savestr(const char *);
pointer stalloc(int);
void stunalloc(pointer);
+char *stsavestr(const char *);
void setstackmark(struct stackmark *);
void popstackmark(struct stackmark *);
char *growstackstr(void);
diff --git a/bin/sh/miscbltin.c b/bin/sh/miscbltin.c
index 027d8ae3faf4..715e324c6832 100644
--- a/bin/sh/miscbltin.c
+++ b/bin/sh/miscbltin.c
@@ -265,7 +265,7 @@ readcmd(int argc __unused, char **argv __unused)
/* Set any remaining args to "" */
while (*++ap != NULL)
- setvar(*ap, nullstr, 0);
+ setvar(*ap, "", 0);
return status;
}
diff --git a/bin/sh/mknodes.c b/bin/sh/mknodes.c
index 1a177f89531b..cb8830130dc0 100644
--- a/bin/sh/mknodes.c
+++ b/bin/sh/mknodes.c
@@ -204,7 +204,7 @@ parsefield(void)
}
-char writer[] = "\
+static const char writer[] = "\
/*\n\
* This file was generated by the mknodes program.\n\
*/\n\
diff --git a/bin/sh/mksyntax.c b/bin/sh/mksyntax.c
index c6bf480a2893..1f81828e5a69 100644
--- a/bin/sh/mksyntax.c
+++ b/bin/sh/mksyntax.c
@@ -60,7 +60,7 @@ struct synclass {
};
/* Syntax classes */
-struct synclass synclass[] = {
+static const struct synclass synclass[] = {
{ "CWORD", "character is nothing special" },
{ "CNL", "newline character" },
{ "CBACK", "a backslash character" },
@@ -85,7 +85,7 @@ struct synclass synclass[] = {
* Syntax classes for is_ functions. Warning: if you add new classes
* you may have to change the definition of the is_in_name macro.
*/
-struct synclass is_entry[] = {
+static const struct synclass is_entry[] = {
{ "ISDIGIT", "a digit" },
{ "ISUPPER", "an upper case letter" },
{ "ISLOWER", "a lower case letter" },
@@ -94,7 +94,7 @@ struct synclass is_entry[] = {
{ NULL, NULL }
};
-static char writer[] = "\
+static const char writer[] = "\
/*\n\
* This file was generated by the mksyntax program.\n\
*/\n\
diff --git a/bin/sh/mktokens b/bin/sh/mktokens
index 82d7cd7b2d5a..b6f5f97638a1 100644
--- a/bin/sh/mktokens
+++ b/bin/sh/mktokens
@@ -74,11 +74,11 @@ exec > token.h
awk '{print "#define " $1 " " NR-1}' $temp
echo '
/* Array indicating which tokens mark the end of a list */
-const char tokendlist[] = {'
+static const char tokendlist[] = {'
awk '{print "\t" $2 ","}' $temp
echo '};
-const char *const tokname[] = {'
+static const char *const tokname[] = {'
sed -e 's/"/\\"/g' \
-e 's/[^ ]*[ ][ ]*[^ ]*[ ][ ]*\(.*\)/ "\1",/' \
$temp
diff --git a/bin/sh/nodetypes b/bin/sh/nodetypes
index 603c77707f20..d480093a8a32 100644
--- a/bin/sh/nodetypes
+++ b/bin/sh/nodetypes
@@ -138,7 +138,7 @@ NXHERE nhere # fd<<!
fd int # file descriptor being redirected
next nodeptr # next redirection in list
doc nodeptr # input to command (NARG node)
- expdoc temp char *expdoc # actual document (for NXHERE)
+ expdoc temp const char *expdoc # actual document (for NXHERE)
NNOT nnot # ! command (actually pipeline)
type int
diff --git a/bin/sh/options.c b/bin/sh/options.c
index 860cf6c645bb..2d0ddce5a3de 100644
--- a/bin/sh/options.c
+++ b/bin/sh/options.c
@@ -465,7 +465,7 @@ getopts(char *optstr, char *optvar, char **optfirst, char ***optnext,
int ind = 0;
int err = 0;
char s[10];
- const char *optarg = NULL;
+ const char *newoptarg = NULL;
if ((p = *optptr) == NULL || *p == '\0') {
/* Current word is done, advance */
@@ -491,7 +491,7 @@ atend:
if (optstr[0] == ':') {
s[0] = c;
s[1] = '\0';
- optarg = s;
+ newoptarg = s;
}
else
out2fmt_flush("Illegal option -%c\n", c);
@@ -507,7 +507,7 @@ atend:
if (optstr[0] == ':') {
s[0] = c;
s[1] = '\0';
- optarg = s;
+ newoptarg = s;
c = ':';
}
else {
@@ -519,7 +519,7 @@ atend:
if (p == **optnext)
(*optnext)++;
- optarg = p;
+ newoptarg = p;
p = NULL;
}
@@ -527,8 +527,8 @@ out:
if (*optnext != NULL)
ind = *optnext - optfirst + 1;
*optptr = p;
- if (optarg != NULL)
- err |= setvarsafe("OPTARG", optarg, 0);
+ if (newoptarg != NULL)
+ err |= setvarsafe("OPTARG", newoptarg, 0);
else {
INTOFF;
err |= unsetvar("OPTARG");
diff --git a/bin/sh/options.h b/bin/sh/options.h
index 09948628197d..2048a354b6e5 100644
--- a/bin/sh/options.h
+++ b/bin/sh/options.h
@@ -73,6 +73,7 @@ struct optent {
char val;
};
+extern struct optent optlist[NOPTS];
#ifdef DEFINE_OPTIONS
struct optent optlist[NOPTS] = {
{ "errexit", 'e', 0 },
@@ -95,8 +96,6 @@ struct optent optlist[NOPTS] = {
{ "physical", 'P', 0 },
{ "trackall", 'h', 0 },
};
-#else
-extern struct optent optlist[NOPTS];
#endif
diff --git a/bin/sh/output.c b/bin/sh/output.c
index bf8e17d97ece..39b722fdba23 100644
--- a/bin/sh/output.c
+++ b/bin/sh/output.c
@@ -54,6 +54,8 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
#include "shell.h"
#include "syntax.h"
@@ -111,43 +113,86 @@ outstr(const char *p, struct output *file)
outbin(p, strlen(p), file);
}
+static void
+byteseq(int ch, struct output *file)
+{
+ char seq[4];
+
+ seq[0] = '\\';
+ seq[1] = (ch >> 6 & 0x3) + '0';
+ seq[2] = (ch >> 3 & 0x7) + '0';
+ seq[3] = (ch & 0x7) + '0';
+ outbin(seq, 4, file);
+}
+
+static void
+outdqstr(const char *p, struct output *file)
+{
+ const char *end;
+ mbstate_t mbs;
+ size_t clen;
+ wchar_t wc;
+
+ memset(&mbs, '\0', sizeof(mbs));
+ end = p + strlen(p);
+ outstr("$'", file);
+ while ((clen = mbrtowc(&wc, p, end - p + 1, &mbs)) != 0) {
+ if (clen == (size_t)-2) {
+ while (p < end)
+ byteseq(*p++, file);
+ break;
+ }
+ if (clen == (size_t)-1) {
+ memset(&mbs, '\0', sizeof(mbs));
+ byteseq(*p++, file);
+ continue;
+ }
+ if (wc == L'\n')
+ outcslow('\n', file), p++;
+ else if (wc == L'\r')
+ outstr("\\r", file), p++;
+ else if (wc == L'\t')
+ outstr("\\t", file), p++;
+ else if (!iswprint(wc)) {
+ for (; clen > 0; clen--)
+ byteseq(*p++, file);
+ } else {
+ if (wc == L'\'' || wc == L'\\')
+ outcslow('\\', file);
+ outbin(p, clen, file);
+ p += clen;
+ }
+ }
+ outcslow('\'', file);
+}
+
/* Like outstr(), but quote for re-input into the shell. */
void
outqstr(const char *p, struct output *file)
{
- char ch;
- int inquotes;
+ int i;
if (p[0] == '\0') {
outstr("''", file);
return;
}
- /* Caller will handle '=' if necessary */
- if (p[strcspn(p, "|&;<>()$`\\\"' \t\n*?[~#")] == '\0' ||
+ for (i = 0; p[i] != '\0'; i++) {
+ if ((p[i] > '\0' && p[i] < ' ' && p[i] != '\n') ||
+ (p[i] & 0x80) != 0 || p[i] == '\'') {
+ outdqstr(p, file);
+ return;
+ }
+ }
+
+ if (p[strcspn(p, "|&;<>()$`\\\" \n*?[~#=")] == '\0' ||
strcmp(p, "[") == 0) {
outstr(p, file);
return;
}
- inquotes = 0;
- while ((ch = *p++) != '\0') {
- switch (ch) {
- case '\'':
- /* Can't quote single quotes inside single quotes. */
- if (inquotes)
- outcslow('\'', file);
- inquotes = 0;
- outstr("\\'", file);
- break;
- default:
- if (!inquotes)
- outcslow('\'', file);
- inquotes = 1;
- outc(ch, file);
- }
- }
- if (inquotes)
- outcslow('\'', file);
+ outcslow('\'', file);
+ outstr(p, file);
+ outcslow('\'', file);
}
void
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index 7fae29eb7c5f..2bba84eb9136 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -1879,6 +1879,8 @@ synerror(const char *msg)
{
if (commandname)
outfmt(out2, "%s: %d: ", commandname, startlinno);
+ else if (arg0)
+ outfmt(out2, "%s: ", arg0);
outfmt(out2, "Syntax error: %s\n", msg);
error((char *)NULL);
}
@@ -1938,7 +1940,7 @@ getprompt(void *unused __unused)
*/
switch (whichprompt) {
case 0:
- fmt = nullstr;
+ fmt = "";
break;
case 1:
fmt = ps1val();
diff --git a/bin/sh/sh.1 b/bin/sh/sh.1
index fa6872017ca3..e5707c0ff721 100644
--- a/bin/sh/sh.1
+++ b/bin/sh/sh.1
@@ -32,7 +32,7 @@
.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95
.\" $FreeBSD$
.\"
-.Dd November 14, 2014
+.Dd April 18, 2015
.Dt SH 1
.Os
.Sh NAME
@@ -1196,17 +1196,18 @@ command is implemented as a special built-in command.
.Ss Variables and Parameters
The shell maintains a set of parameters.
A parameter
-denoted by a name is called a variable.
+denoted by a name
+(consisting solely
+of alphabetics, numerics, and underscores,
+and starting with an alphabetic or an underscore)
+is called a variable.
When starting up,
-the shell turns all the environment variables into shell
+the shell turns all environment variables with valid names into shell
variables.
New variables can be set using the form
.Pp
.D1 Ar name Ns = Ns Ar value
.Pp
-Variables set by the user must have a name consisting solely
-of alphabetics, numerics, and underscores.
-The first letter of a variable name must not be numeric.
A parameter can also be denoted by a number
or a special character as explained below.
.Pp
@@ -1369,6 +1370,10 @@ This variable overrides the
.Va MAIL
setting.
There is a maximum of 10 mailboxes that can be monitored at once.
+.It Va OPTIND
+The index of the next argument to be processed by
+.Ic getopts .
+This is initialized to 1 at startup.
.It Va PATH
The default search path for executables.
See the
@@ -2297,6 +2302,8 @@ If an invalid option is encountered,
is set to
.Ql \&? .
It returns a false value (1) when it encounters the end of the options.
+A new set of arguments may be parsed by assigning
+.Li OPTIND=1 .
.It Ic hash Oo Fl rv Oc Op Ar command ...
The shell maintains a hash table which remembers the locations of commands.
With no arguments whatsoever, the
@@ -2567,8 +2574,7 @@ the former causes the specified signal to be ignored
and the latter causes the default action to be taken.
Omitting the
.Ar action
-is another way to request the default action, for compatibility reasons this
-usage is not recommended though.
+and using only signal numbers is another way to request the default action.
In a subshell or utility environment,
the shell resets trapped (but not ignored) signals to the default action.
The
@@ -2771,7 +2777,7 @@ This is inherited by children of the shell, and is used in the history
editing modes.
.El
.Pp
-Additionally, all environment variables are turned into shell variables
+Additionally, environment variables are turned into shell variables
at startup,
which may affect the shell as described under
.Sx Special Variables .
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile
index 5f5da4a89077..ad39aacf1be5 100644
--- a/bin/sh/tests/builtins/Makefile
+++ b/bin/sh/tests/builtins/Makefile
@@ -137,6 +137,8 @@ FILES+= trap11.0
FILES+= trap12.0
FILES+= trap13.0
FILES+= trap14.0
+FILES+= trap15.0
+FILES+= trap16.0
FILES+= trap2.0
FILES+= trap3.0
FILES+= trap4.0
diff --git a/bin/sh/tests/builtins/trap15.0 b/bin/sh/tests/builtins/trap15.0
new file mode 100644
index 000000000000..6b9857df3d1a
--- /dev/null
+++ b/bin/sh/tests/builtins/trap15.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+(${SH} -c 'term(){ exit 5;}; trap term TERM; kill -TERM $$') &
+wait >/dev/null 2>&1 $!
+[ $? -eq 5 ]
diff --git a/bin/sh/tests/builtins/trap16.0 b/bin/sh/tests/builtins/trap16.0
new file mode 100644
index 000000000000..3d70cce8a721
--- /dev/null
+++ b/bin/sh/tests/builtins/trap16.0
@@ -0,0 +1,20 @@
+# $FreeBSD$
+
+traps=$(${SH} -c 'trap "echo bad" 0; trap - 0; trap')
+[ -z "$traps" ] || exit 1
+traps=$(${SH} -c 'trap "echo bad" 0; trap "" 0; trap')
+expected_traps=$(${SH} -c 'trap "" EXIT; trap')
+[ "$traps" = "$expected_traps" ] || exit 2
+traps=$(${SH} -c 'trap "echo bad" 0; trap 0; trap')
+[ -z "$traps" ] || exit 3
+traps=$(${SH} -c 'trap "echo bad" 0; trap -- 0; trap')
+[ -z "$traps" ] || exit 4
+traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap - 0 1 2; trap')
+[ -z "$traps" ] || exit 5
+traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap "" 0 1 2; trap')
+expected_traps=$(${SH} -c 'trap "" EXIT HUP INT; trap')
+[ "$traps" = "$expected_traps" ] || exit 6
+traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap 0 1 2; trap')
+[ -z "$traps" ] || exit 7
+traps=$(${SH} -c 'trap "echo bad" 0 1 2; trap -- 0 1 2; trap')
+[ -z "$traps" ] || exit 8
diff --git a/bin/sh/tests/execution/Makefile b/bin/sh/tests/execution/Makefile
index 2653d5ffe799..638492bb96ad 100644
--- a/bin/sh/tests/execution/Makefile
+++ b/bin/sh/tests/execution/Makefile
@@ -44,6 +44,7 @@ FILES+= set-n4.0
FILES+= set-x1.0
FILES+= set-x2.0
FILES+= set-x3.0
+FILES+= set-x4.0
FILES+= shellproc1.0
FILES+= subshell1.0 subshell1.0.stdout
FILES+= subshell2.0
diff --git a/bin/sh/tests/execution/set-x4.0 b/bin/sh/tests/execution/set-x4.0
new file mode 100644
index 000000000000..0904766ccdd1
--- /dev/null
+++ b/bin/sh/tests/execution/set-x4.0
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+key=`printf '\r\t\001\200\300'`
+r=`{ set -x; : "$key"; } 2>&1 >/dev/null`
+case $r in
+*[![:print:]]*) echo fail; exit 3
+esac
diff --git a/bin/sh/tests/expansion/Makefile b/bin/sh/tests/expansion/Makefile
index 027bc95f5f8d..e359ae7ee014 100644
--- a/bin/sh/tests/expansion/Makefile
+++ b/bin/sh/tests/expansion/Makefile
@@ -48,6 +48,9 @@ FILES+= ifs1.0
FILES+= ifs2.0
FILES+= ifs3.0
FILES+= ifs4.0
+FILES+= ifs5.0
+FILES+= ifs6.0
+FILES+= ifs7.0
FILES+= length1.0
FILES+= length2.0
FILES+= length3.0
@@ -62,6 +65,7 @@ FILES+= pathname1.0
FILES+= pathname2.0
FILES+= pathname3.0
FILES+= pathname4.0
+FILES+= pathname5.0
FILES+= plus-minus1.0
FILES+= plus-minus2.0
FILES+= plus-minus3.0
diff --git a/bin/sh/tests/expansion/ifs5.0 b/bin/sh/tests/expansion/ifs5.0
new file mode 100644
index 000000000000..ab0e64662fdf
--- /dev/null
+++ b/bin/sh/tests/expansion/ifs5.0
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+set -- $(echo a b c d)
+[ "$#" = 4 ]
diff --git a/bin/sh/tests/expansion/ifs6.0 b/bin/sh/tests/expansion/ifs6.0
new file mode 100644
index 000000000000..be7794563085
--- /dev/null
+++ b/bin/sh/tests/expansion/ifs6.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+IFS=': '
+x=': :'
+set -- $x
+[ "$#|$1|$2|$3" = "2|||" ]
diff --git a/bin/sh/tests/expansion/ifs7.0 b/bin/sh/tests/expansion/ifs7.0
new file mode 100644
index 000000000000..0cc08348c04a
--- /dev/null
+++ b/bin/sh/tests/expansion/ifs7.0
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+IFS=2
+set -- $((123))
+[ "$#|$1|$2|$3" = "2|1|3|" ]
diff --git a/bin/sh/tests/expansion/pathname5.0 b/bin/sh/tests/expansion/pathname5.0
new file mode 100644
index 000000000000..bc278124de4f
--- /dev/null
+++ b/bin/sh/tests/expansion/pathname5.0
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+[ `echo '/[e]tc'` = /etc ]
diff --git a/bin/sh/trap.c b/bin/sh/trap.c
index 8ea3b126e1b1..f562e2785a58 100644
--- a/bin/sh/trap.c
+++ b/bin/sh/trap.c
@@ -74,8 +74,8 @@ __FBSDID("$FreeBSD$");
static char sigmode[NSIG]; /* current value of signal */
volatile sig_atomic_t pendingsig; /* indicates some signal received */
-volatile sig_atomic_t pendingsig_waitcmd; /* indicates SIGINT/SIGQUIT received */
-int in_dotrap; /* do we execute in a trap handler? */
+volatile sig_atomic_t pendingsig_waitcmd; /* indicates wait builtin should be interrupted */
+static int in_dotrap; /* do we execute in a trap handler? */
static char *volatile trap[NSIG]; /* trap handler commands */
static volatile sig_atomic_t gotsig[NSIG];
/* indicates specified signal received */
@@ -183,7 +183,7 @@ trapcmd(int argc __unused, char **argv)
return 0;
}
action = NULL;
- if (*argv && sigstring_to_signum(*argv) == -1) {
+ if (*argv && !is_number(*argv)) {
if (strcmp(*argv, "-") == 0)
argv++;
else {
@@ -380,7 +380,15 @@ onsig(int signo)
{
if (signo == SIGINT && trap[SIGINT] == NULL) {
- onint();
+ /*
+ * The !in_dotrap here is safe. The only way we can arrive
+ * here with in_dotrap set is that a trap handler set SIGINT to
+ * SIG_DFL and killed itself.
+ */
+ if (suppressint && !in_dotrap)
+ SET_PENDING_INT;
+ else
+ onint();
return;
}
@@ -392,6 +400,7 @@ onsig(int signo)
(signo != SIGCHLD || !ignore_sigchld)) {
gotsig[signo] = 1;
pendingsig = signo;
+ pendingsig_waitcmd = signo;
}
}
diff --git a/bin/sh/trap.h b/bin/sh/trap.h
index 541b9b149a8d..a27283926997 100644
--- a/bin/sh/trap.h
+++ b/bin/sh/trap.h
@@ -35,7 +35,6 @@
extern volatile sig_atomic_t pendingsig;
extern volatile sig_atomic_t pendingsig_waitcmd;
-extern int in_dotrap;
void clear_traps(void);
int have_traps(void);
diff --git a/bin/sh/var.c b/bin/sh/var.c
index ebeff16635fb..f60dea16dfdf 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -94,6 +94,7 @@ struct var vps4;
static struct var voptind;
struct var vdisvfork;
+struct localvar *localvars;
int forcelocal;
static const struct varinit varinit[] = {
@@ -141,6 +142,7 @@ static const int locale_categories[7] = {
static int varequal(const char *, const char *);
static struct var *find_var(const char *, struct var ***, int *);
static int localevar(const char *);
+static void setvareq_const(const char *s, int flags);
extern char **environ;
@@ -183,7 +185,7 @@ initvar(void)
setvareq(*envp, VEXPORT|VTEXTFIXED);
}
}
- setvareq("OPTIND=1", VTEXTFIXED);
+ setvareq_const("OPTIND=1", 0);
}
/*
@@ -389,6 +391,12 @@ setvareq(char *s, int flags)
}
+static void
+setvareq_const(const char *s, int flags)
+{
+ setvareq(__DECONST(char *, s), flags | VTEXTFIXED);
+}
+
/*
* Process a linked list of variable assignments.
@@ -872,7 +880,7 @@ unsetvar(const char *s)
if (vp->flags & VREADONLY)
return (1);
if (vp->text[vp->name_len + 1] != '\0')
- setvar(s, nullstr, 0);
+ setvar(s, "", 0);
if ((vp->flags & VEXPORT) && localevar(vp->text)) {
change_env(s, 0);
setlocale(LC_ALL, "");
diff --git a/bin/sh/var.h b/bin/sh/var.h
index 6ce5b24e0312..6e831aef3fb0 100644
--- a/bin/sh/var.h
+++ b/bin/sh/var.h
@@ -68,7 +68,7 @@ struct localvar {
};
-struct localvar *localvars;
+extern struct localvar *localvars;
extern int forcelocal;
extern struct var vifs;