aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2012-11-04 02:52:03 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2012-11-04 02:52:03 +0000
commit23090366f729c56cab62de74c7a51792357e98a9 (patch)
treec511c885796e28ec571b5267e8f11f3b103d35e9 /bin
parent7750ad47a9a7dbc83f87158464170c8640723293 (diff)
parent22ff74b2f44234d31540b1f7fd6c91489c37cad3 (diff)
downloadsrc-23090366f729c56cab62de74c7a51792357e98a9.tar.gz
src-23090366f729c56cab62de74c7a51792357e98a9.zip
Sync from head
Notes
Notes: svn path=/projects/bmake/; revision=242545
Diffstat (limited to 'bin')
-rw-r--r--bin/cat/cat.12
-rw-r--r--bin/cat/cat.c37
-rw-r--r--bin/cp/cp.14
-rw-r--r--bin/date/date.c8
-rw-r--r--bin/date/extern.h2
-rw-r--r--bin/date/netdate.c2
-rw-r--r--bin/dd/conv_tab.c5
-rw-r--r--bin/dd/dd.c4
-rw-r--r--bin/dd/misc.c2
-rw-r--r--bin/ed/buf.c15
-rw-r--r--bin/ed/cbc.c20
-rw-r--r--bin/ed/ed.h6
-rw-r--r--bin/ed/glbl.c10
-rw-r--r--bin/ed/io.c13
-rw-r--r--bin/ed/main.c31
-rw-r--r--bin/ed/re.c3
-rw-r--r--bin/ed/sub.c10
-rw-r--r--bin/ed/undo.c6
-rw-r--r--bin/getfacl/getfacl.14
-rw-r--r--bin/getfacl/getfacl.c2
-rw-r--r--bin/ln/ln.166
-rw-r--r--bin/ls/ls.c12
-rw-r--r--bin/ls/print.c6
-rw-r--r--bin/mv/mv.122
-rw-r--r--bin/mv/mv.c20
-rw-r--r--bin/pax/ar_io.c1
-rw-r--r--bin/pax/ar_subs.c1
-rw-r--r--bin/pax/extern.h3
-rw-r--r--bin/pax/options.c1
-rw-r--r--bin/ps/keyword.c2
-rw-r--r--bin/ps/print.c10
-rw-r--r--bin/ps/ps.16
-rw-r--r--bin/ps/ps.c4
-rw-r--r--bin/rcp/rcp.16
-rw-r--r--bin/rcp/rcp.c15
-rw-r--r--bin/rm/rm.c26
-rw-r--r--bin/setfacl/merge.c7
-rw-r--r--bin/setfacl/setfacl.14
-rw-r--r--bin/setfacl/setfacl.c55
-rw-r--r--bin/setfacl/setfacl.h32
-rw-r--r--bin/sh/cd.c26
-rw-r--r--bin/sh/eval.c70
-rw-r--r--bin/sh/exec.c13
-rw-r--r--bin/sh/exec.h1
-rw-r--r--bin/sh/histedit.c44
-rw-r--r--bin/sh/input.c2
-rw-r--r--bin/sh/jobs.c101
-rw-r--r--bin/sh/jobs.h1
-rw-r--r--bin/sh/main.c9
-rw-r--r--bin/sh/options.c4
-rw-r--r--bin/sh/sh.123
-rw-r--r--bin/sh/trap.c10
-rw-r--r--bin/sh/trap.h1
-rw-r--r--bin/sh/var.c18
-rw-r--r--bin/stty/extern.h2
55 files changed, 504 insertions, 306 deletions
diff --git a/bin/cat/cat.1 b/bin/cat/cat.1
index 1f0f6b60a31c..4fdff3ae6df4 100644
--- a/bin/cat/cat.1
+++ b/bin/cat/cat.1
@@ -127,7 +127,7 @@ to the file
truncating
.Pa file3
if it already exists.
-See the manual page for your shell (i.e.,
+See the manual page for your shell (e.g.,
.Xr sh 1 )
for more information on redirection.
.Pp
diff --git a/bin/cat/cat.c b/bin/cat/cat.c
index 437c01379faf..69c56c0af224 100644
--- a/bin/cat/cat.c
+++ b/bin/cat/cat.c
@@ -58,11 +58,11 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <fcntl.h>
#include <locale.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <stddef.h>
static int bflag, eflag, nflag, sflag, tflag, vflag;
static int rval;
@@ -77,16 +77,20 @@ static void raw_cat(int);
static int udom_open(const char *path, int flags);
#endif
-/* Memory strategy threshold, in pages: if physmem is larger then this, use a
- * large buffer */
-#define PHYSPAGES_THRESHOLD (32*1024)
+/*
+ * Memory strategy threshold, in pages: if physmem is larger than this,
+ * use a large buffer.
+ */
+#define PHYSPAGES_THRESHOLD (32 * 1024)
-/* Maximum buffer size in bytes - do not allow it to grow larger than this */
-#define BUFSIZE_MAX (2*1024*1024)
+/* Maximum buffer size in bytes - do not allow it to grow larger than this. */
+#define BUFSIZE_MAX (2 * 1024 * 1024)
-/* Small (default) buffer size in bytes. It's inefficient for this to be
- * smaller than MAXPHYS */
-#define BUFSIZE_SMALL (MAXPHYS)
+/*
+ * Small (default) buffer size in bytes. It's inefficient for this to be
+ * smaller than MAXPHYS.
+ */
+#define BUFSIZE_SMALL (MAXPHYS)
int
main(int argc, char *argv[])
@@ -144,13 +148,12 @@ usage(void)
static void
scanfiles(char *argv[], int cooked)
{
- int i = 0;
+ int fd, i;
char *path;
FILE *fp;
+ i = 0;
while ((path = argv[i]) != NULL || i == 0) {
- int fd;
-
if (path == NULL || strcmp(path, "-") == 0) {
filename = "stdin";
fd = STDIN_FILENO;
@@ -257,16 +260,16 @@ raw_cat(int rfd)
wfd = fileno(stdout);
if (buf == NULL) {
if (fstat(wfd, &sbuf))
- err(1, "%s", filename);
+ err(1, "stdout");
if (S_ISREG(sbuf.st_mode)) {
/* If there's plenty of RAM, use a large copy buffer */
if (sysconf(_SC_PHYS_PAGES) > PHYSPAGES_THRESHOLD)
- bsize = MIN(BUFSIZE_MAX, MAXPHYS*8);
+ bsize = MIN(BUFSIZE_MAX, MAXPHYS * 8);
else
bsize = BUFSIZE_SMALL;
} else
- bsize = MAX(sbuf.st_blksize,
- (blksize_t)sysconf(_SC_PAGESIZE));
+ bsize = MAX(sbuf.st_blksize,
+ (blksize_t)sysconf(_SC_PAGESIZE));
if ((buf = malloc(bsize)) == NULL)
err(1, "malloc() failure of IO buffer");
}
@@ -327,7 +330,7 @@ udom_open(const char *path, int flags)
break;
}
}
- return(fd);
+ return (fd);
}
#endif
diff --git a/bin/cp/cp.1 b/bin/cp/cp.1
index fc5a9f73ad65..8c014b437e51 100644
--- a/bin/cp/cp.1
+++ b/bin/cp/cp.1
@@ -32,7 +32,7 @@
.\" @(#)cp.1 8.3 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
-.Dd January 17, 2010
+.Dd September 4, 2012
.Dt CP 1
.Os
.Sh NAME
@@ -164,7 +164,7 @@ Cause
.Nm
to preserve the following attributes of each source
file in the copy: modification time, access time,
-file flags, file mode, user ID, and group ID, as allowed by permissions.
+file flags, file mode, ACL, user ID, and group ID, as allowed by permissions.
.Pp
If the user ID and group ID cannot be preserved, no error message
is displayed and the exit value is not altered.
diff --git a/bin/date/date.c b/bin/date/date.c
index 1e9f281bc8a7..58a9afb0d0fc 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -137,7 +137,7 @@ main(int argc, char *argv[])
* If -d or -t, set the timezone or daylight savings time; this
* doesn't belong here; the kernel should not know about either.
*/
- if (set_timezone && settimeofday((struct timeval *)NULL, &tz))
+ if (set_timezone && settimeofday(NULL, &tz) != 0)
err(1, "settimeofday (timezone)");
if (!rflag && time(&tval) == -1)
@@ -273,14 +273,14 @@ setthetime(const char *fmt, const char *p, int jflag, int nflag)
/* set the time */
if (nflag || netsettime(tval)) {
utx.ut_type = OLD_TIME;
- gettimeofday(&utx.ut_tv, NULL);
+ (void)gettimeofday(&utx.ut_tv, NULL);
pututxline(&utx);
tv.tv_sec = tval;
tv.tv_usec = 0;
- if (settimeofday(&tv, (struct timezone *)NULL))
+ if (settimeofday(&tv, NULL) != 0)
err(1, "settimeofday (timeval)");
utx.ut_type = NEW_TIME;
- gettimeofday(&utx.ut_tv, NULL);
+ (void)gettimeofday(&utx.ut_tv, NULL);
pututxline(&utx);
}
diff --git a/bin/date/extern.h b/bin/date/extern.h
index 76b8d5e16105..91aeab2e07e1 100644
--- a/bin/date/extern.h
+++ b/bin/date/extern.h
@@ -30,4 +30,6 @@
* $FreeBSD$
*/
+extern int retval;
+
int netsettime(time_t);
diff --git a/bin/date/netdate.c b/bin/date/netdate.c
index b8441068eadf..b085be4db68f 100644
--- a/bin/date/netdate.c
+++ b/bin/date/netdate.c
@@ -55,8 +55,6 @@ __FBSDID("$FreeBSD$");
#define WAITACK 2 /* seconds */
#define WAITDATEACK 5 /* seconds */
-extern int retval;
-
/*
* Set the date in the machines controlled by timedaemons by communicating the
* new date to the local timedaemon. If the timedaemon is in the master state,
diff --git a/bin/dd/conv_tab.c b/bin/dd/conv_tab.c
index 9bfd10921823..07449fd0f572 100644
--- a/bin/dd/conv_tab.c
+++ b/bin/dd/conv_tab.c
@@ -41,6 +41,11 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
+#include <stdint.h>
+
+#include "dd.h"
+#include "extern.h"
+
/*
* There are currently six tables:
*
diff --git a/bin/dd/dd.c b/bin/dd/dd.c
index 0bb43f789b1a..637e0cc6cdcf 100644
--- a/bin/dd/dd.c
+++ b/bin/dd/dd.c
@@ -232,8 +232,8 @@ setup(void)
ctab = casetab;
}
- (void)gettimeofday(&tv, (struct timezone *)NULL);
- st.start = tv.tv_sec + tv.tv_usec * 1e-6;
+ (void)gettimeofday(&tv, NULL);
+ st.start = tv.tv_sec + tv.tv_usec * 1e-6;
}
static void
diff --git a/bin/dd/misc.c b/bin/dd/misc.c
index 4f538bc4bfbd..8edc5a534c63 100644
--- a/bin/dd/misc.c
+++ b/bin/dd/misc.c
@@ -59,7 +59,7 @@ summary(void)
double secs;
char buf[100];
- (void)gettimeofday(&tv, (struct timezone *)NULL);
+ (void)gettimeofday(&tv, NULL);
secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
if (secs < 1e-6)
secs = 1e-6;
diff --git a/bin/ed/buf.c b/bin/ed/buf.c
index b4b78a5565b5..6d8a6ed4f559 100644
--- a/bin/ed/buf.c
+++ b/bin/ed/buf.c
@@ -35,10 +35,10 @@ __FBSDID("$FreeBSD$");
#include "ed.h"
-FILE *sfp; /* scratch file pointer */
-off_t sfseek; /* scratch file position */
-int seek_write; /* seek before writing */
-line_t buffer_head; /* incore buffer */
+static FILE *sfp; /* scratch file pointer */
+static off_t sfseek; /* scratch file position */
+static int seek_write; /* seek before writing */
+static line_t buffer_head; /* incore buffer */
/* get_sbuf_line: get a line of text from the scratch file; return pointer
to the text */
@@ -185,10 +185,7 @@ get_addressed_line_node(long n)
return lp;
}
-
-extern int newline_added;
-
-char sfn[15] = ""; /* scratch file name */
+static char sfn[15] = ""; /* scratch file name */
/* open_sbuf: open scratch file */
int
@@ -244,7 +241,7 @@ quit(int n)
}
-unsigned char ctab[256]; /* character translation table */
+static unsigned char ctab[256]; /* character translation table */
/* init_buffers: open scratch buffer; initialize line queue */
void
diff --git a/bin/ed/cbc.c b/bin/ed/cbc.c
index 52e99998d67c..08e48cd0544d 100644
--- a/bin/ed/cbc.c
+++ b/bin/ed/cbc.c
@@ -68,28 +68,24 @@ __FBSDID("$FreeBSD$");
* global variables and related macros
*/
-enum { /* encrypt, decrypt, authenticate */
- MODE_ENCRYPT, MODE_DECRYPT, MODE_AUTHENTICATE
-} mode = MODE_ENCRYPT;
-
#ifdef DES
-DES_cblock ivec; /* initialization vector */
-DES_cblock pvec; /* padding vector */
+static DES_cblock ivec; /* initialization vector */
+static DES_cblock pvec; /* padding vector */
#endif
-char bits[] = { /* used to extract bits from a char */
+static char bits[] = { /* used to extract bits from a char */
'\200', '\100', '\040', '\020', '\010', '\004', '\002', '\001'
};
-int pflag; /* 1 to preserve parity bits */
+static int pflag; /* 1 to preserve parity bits */
#ifdef DES
-DES_key_schedule schedule; /* expanded DES key */
+static DES_key_schedule schedule; /* expanded DES key */
#endif
-unsigned char des_buf[8]; /* shared buffer for get_des_char/put_des_char */
-int des_ct = 0; /* count for get_des_char/put_des_char */
-int des_n = 0; /* index for put_des_char/get_des_char */
+static unsigned char des_buf[8];/* shared buffer for get_des_char/put_des_char */
+static int des_ct = 0; /* count for get_des_char/put_des_char */
+static int des_n = 0; /* index for put_des_char/get_des_char */
/* init_des_cipher: initialize DES */
void
diff --git a/bin/ed/ed.h b/bin/ed/ed.h
index 2021232c0490..8cb8cec731ef 100644
--- a/bin/ed/ed.h
+++ b/bin/ed/ed.h
@@ -277,3 +277,9 @@ extern int lineno;
extern long second_addr;
extern long u_addr_last;
extern long u_current_addr;
+extern long rows;
+extern int cols;
+extern int newline_added;
+extern int des;
+extern int scripted;
+extern int patlock;
diff --git a/bin/ed/glbl.c b/bin/ed/glbl.c
index 11dcc19fcc85..5524700983e8 100644
--- a/bin/ed/glbl.c
+++ b/bin/ed/glbl.c
@@ -135,11 +135,11 @@ exec_global(int interact, int gflag)
}
-line_t **active_list; /* list of lines active in a global command */
-long active_last; /* index of last active line in active_list */
-long active_size; /* size of active_list */
-long active_ptr; /* active_list index (non-decreasing) */
-long active_ndx; /* active_list index (modulo active_last) */
+static line_t **active_list; /* list of lines active in a global command */
+static long active_last; /* index of last active line in active_list */
+static long active_size; /* size of active_list */
+static long active_ptr; /* active_list index (non-decreasing) */
+static long active_ndx; /* active_list index (modulo active_last) */
/* set_active_node: add a line node to the global-active list */
int
diff --git a/bin/ed/io.c b/bin/ed/io.c
index 63fe10c489eb..cf2e95906c1f 100644
--- a/bin/ed/io.c
+++ b/bin/ed/io.c
@@ -30,9 +30,6 @@ __FBSDID("$FreeBSD$");
#include "ed.h"
-
-extern int scripted;
-
/* read_file: read a named file/pipe into the buffer; return line count */
long
read_file(char *fn, long n)
@@ -58,11 +55,8 @@ read_file(char *fn, long n)
return current_addr - n;
}
-
-extern int des;
-
-char *sbuf; /* file i/o buffer */
-int sbufsz; /* file i/o buffer size */
+static char *sbuf; /* file i/o buffer */
+static int sbufsz; /* file i/o buffer size */
int newline_added; /* if set, newline appended to input file */
/* read_stream: read a stream into the editor buffer; return status */
@@ -298,9 +292,6 @@ get_tty_line(void)
#define ESCAPES "\a\b\f\n\r\t\v\\"
#define ESCCHARS "abfnrtv\\"
-extern int rows;
-extern int cols;
-
/* put_tty_line: print text to stdout */
int
put_tty_line(const char *s, int l, long n, int gflag)
diff --git a/bin/ed/main.c b/bin/ed/main.c
index f414d40f17d2..98bb300fe623 100644
--- a/bin/ed/main.c
+++ b/bin/ed/main.c
@@ -66,40 +66,40 @@ __FBSDID("$FreeBSD$");
#ifdef _POSIX_SOURCE
-sigjmp_buf env;
+static sigjmp_buf env;
#else
-jmp_buf env;
+static jmp_buf env;
#endif
/* static buffers */
char stdinbuf[1]; /* stdin buffer */
-char *shcmd; /* shell command buffer */
-int shcmdsz; /* shell command buffer size */
-int shcmdi; /* shell command buffer index */
+static char *shcmd; /* shell command buffer */
+static int shcmdsz; /* shell command buffer size */
+static int shcmdi; /* shell command buffer index */
char *ibuf; /* ed command-line buffer */
int ibufsz; /* ed command-line buffer size */
char *ibufp; /* pointer to ed command-line buffer */
/* global flags */
int des = 0; /* if set, use crypt(3) for i/o */
-int garrulous = 0; /* if set, print all error messages */
+static int garrulous = 0; /* if set, print all error messages */
int isbinary; /* if set, buffer contains ASCII NULs */
int isglobal; /* if set, doing a global command */
int modified; /* if set, buffer modified since last write */
int mutex = 0; /* if set, signals set "sigflags" */
-int red = 0; /* if set, restrict shell/directory access */
+static int red = 0; /* if set, restrict shell/directory access */
int scripted = 0; /* if set, suppress diagnostics */
int sigflags = 0; /* if set, signals received while mutex set */
-int sigactive = 0; /* if set, signal handlers are enabled */
+static int sigactive = 0; /* if set, signal handlers are enabled */
-char old_filename[PATH_MAX] = ""; /* default filename */
+static char old_filename[PATH_MAX] = ""; /* default filename */
long current_addr; /* current address in editor buffer */
long addr_last; /* last address in editor buffer */
int lineno; /* script line number */
-const char *prompt; /* command-line prompt */
-const char *dps = "*"; /* default command-line prompt */
+static const char *prompt; /* command-line prompt */
+static const char *dps = "*"; /* default command-line prompt */
-const char usage[] = "usage: %s [-] [-sx] [-p string] [file]\n";
+static const char *usage = "usage: %s [-] [-sx] [-p string] [file]\n";
/* ed: line editor */
int
@@ -254,7 +254,8 @@ top:
/*NOTREACHED*/
}
-long first_addr, second_addr, addr_cnt;
+long first_addr, second_addr;
+static long addr_cnt;
/* extract_addr_range: get line addresses from the command buffer until an
illegal address is seen; return status */
@@ -1241,8 +1242,8 @@ display_lines(long from, long to, int gflag)
#define MAXMARK 26 /* max number of marks */
-line_t *mark[MAXMARK]; /* line markers */
-int markno; /* line marker count */
+static line_t *mark[MAXMARK]; /* line markers */
+static int markno; /* line marker count */
/* mark_line_node: set a line node mark */
int
diff --git a/bin/ed/re.c b/bin/ed/re.c
index f89ecf94cd6b..08a330de3f87 100644
--- a/bin/ed/re.c
+++ b/bin/ed/re.c
@@ -31,9 +31,6 @@ __FBSDID("$FreeBSD$");
#include "ed.h"
-
-extern int patlock;
-
const char *errmsg = "";
/* get_compiled_pattern: return pointer to compiled pattern from command
diff --git a/bin/ed/sub.c b/bin/ed/sub.c
index 1c44328cc79c..d12a5c9e1402 100644
--- a/bin/ed/sub.c
+++ b/bin/ed/sub.c
@@ -32,9 +32,9 @@ __FBSDID("$FreeBSD$");
#include "ed.h"
-char *rhbuf; /* rhs substitution buffer */
-int rhbufsz; /* rhs substitution buffer size */
-int rhbufi; /* rhs substitution buffer index */
+static char *rhbuf; /* rhs substitution buffer */
+static int rhbufsz; /* rhs substitution buffer size */
+static int rhbufi; /* rhs substitution buffer index */
/* extract_subst_tail: extract substitution tail from the command buffer */
int
@@ -105,8 +105,8 @@ extract_subst_template(void)
}
-char *rbuf; /* substitute_matching_text buffer */
-int rbufsz; /* substitute_matching_text buffer size */
+static char *rbuf; /* substitute_matching_text buffer */
+static int rbufsz; /* substitute_matching_text buffer size */
/* search_and_replace: for each line in a range, change text matching a pattern
according to a substitution template; return status */
diff --git a/bin/ed/undo.c b/bin/ed/undo.c
index 6a8ca9e90137..603e39f1ca53 100644
--- a/bin/ed/undo.c
+++ b/bin/ed/undo.c
@@ -32,9 +32,9 @@ __FBSDID("$FreeBSD$");
#define USIZE 100 /* undo stack size */
-undo_t *ustack = NULL; /* undo stack */
-long usize = 0; /* stack size variable */
-long u_p = 0; /* undo stack pointer */
+static undo_t *ustack = NULL; /* undo stack */
+static long usize = 0; /* stack size variable */
+static long u_p = 0; /* undo stack pointer */
/* push_undo_stack: return pointer to initialized undo node */
undo_t *
diff --git a/bin/getfacl/getfacl.1 b/bin/getfacl/getfacl.1
index 8f46857ed46d..c44974128be3 100644
--- a/bin/getfacl/getfacl.1
+++ b/bin/getfacl/getfacl.1
@@ -97,6 +97,10 @@ then
reads a list of pathnames, each terminated by one newline character,
from the standard input.
.El
+.Pp
+For an explanation of the ACL syntax, see the
+.Xr setfacl 1
+manual page.
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
diff --git a/bin/getfacl/getfacl.c b/bin/getfacl/getfacl.c
index ea376c78f0ef..45d6b451c67e 100644
--- a/bin/getfacl/getfacl.c
+++ b/bin/getfacl/getfacl.c
@@ -48,7 +48,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
-int more_than_one = 0;
+static int more_than_one = 0;
static void
usage(void)
diff --git a/bin/ln/ln.1 b/bin/ln/ln.1
index c180123b6f12..fcf97dad68c1 100644
--- a/bin/ln/ln.1
+++ b/bin/ln/ln.1
@@ -32,7 +32,7 @@
.\" @(#)ln.1 8.2 (Berkeley) 12/30/93
.\" $FreeBSD$
.\"
-.Dd July 17, 2009
+.Dd November 2, 2012
.Dt LN 1
.Os
.Sh NAME
@@ -212,6 +212,70 @@ No options may be supplied in this simple mode of operation,
which performs a
.Xr link 2
operation using the two passed arguments.
+.Sh EXAMPLES
+Create a symbolic link named
+.Pa /home/src
+and point it to
+.Pa /usr/src :
+.Pp
+.Dl # ln -s /usr/src /home/src
+.Pp
+Hard link
+.Pa /usr/local/bin/fooprog
+to file
+.Pa /usr/local/bin/fooprog-1.0 :
+.Pp
+.Dl # ln /usr/local/bin/fooprog-1.0 /usr/local/bin/fooprog
+.Pp
+As an exercise, try the following commands:
+.Bd -literal -offset indent
+# ls -i /bin/[
+11553 /bin/[
+# ls -i /bin/test
+11553 /bin/test
+.Ed
+.Pp
+Note that both files have the same inode; that is,
+.Pa /bin/[
+is essentially an alias for the
+.Xr test 1
+command.
+This hard link exists so
+.Xr test 1
+may be invoked from shell scripts, for example, using the
+.Li "if [ ]"
+construct.
+.Pp
+In the next example, the second call to
+.Nm
+removes the original
+.Pa foo
+and creates a replacement pointing to
+.Pa baz :
+.Bd -literal -offset indent
+# mkdir bar baz
+# ln -s bar foo
+# ln -shf baz foo
+.Ed
+.Pp
+Without the
+.Fl h
+option, this would instead leave
+.Pa foo
+pointing to
+.Pa bar
+and inside
+.Pa foo
+create a new symlink
+.Pa baz
+pointing to itself.
+This results from directory-walking.
+.Pp
+An easy rule to remember is that the argument order for
+.Nm
+is the same as for
+.Xr cp 1 :
+The first argument needs to exist, the second one is created.
.Sh COMPATIBILITY
The
.Fl h ,
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index b6373e20c1f5..b96d18bd5785 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -561,7 +561,8 @@ display(const FTSENT *p, FTSENT *list, int options)
NAMES *np;
off_t maxsize;
long maxblock;
- u_long btotal, labelstrlen, maxinode, maxlen, maxnlink;
+ uintmax_t maxinode;
+ u_long btotal, labelstrlen, maxlen, maxnlink;
u_long maxlabelstr;
u_int sizelen;
int maxflags;
@@ -580,8 +581,9 @@ display(const FTSENT *p, FTSENT *list, int options)
btotal = 0;
initmax = getenv("LS_COLWIDTHS");
/* Fields match -lios order. New ones should be added at the end. */
- maxlabelstr = maxblock = maxinode = maxlen = maxnlink =
- maxuser = maxgroup = maxflags = maxsize = 0;
+ maxlabelstr = maxblock = maxlen = maxnlink = 0;
+ maxuser = maxgroup = maxflags = maxsize = 0;
+ maxinode = 0;
if (initmax != NULL && *initmax != '\0') {
char *initmax2, *jinitmax;
int ninitmax;
@@ -609,7 +611,7 @@ display(const FTSENT *p, FTSENT *list, int options)
strcpy(initmax2, "0");
ninitmax = sscanf(jinitmax,
- " %lu : %ld : %lu : %u : %u : %i : %jd : %lu : %lu ",
+ " %ju : %ld : %lu : %u : %u : %i : %jd : %lu : %lu ",
&maxinode, &maxblock, &maxnlink, &maxuser,
&maxgroup, &maxflags, &maxsize, &maxlen, &maxlabelstr);
f_notabs = 1;
@@ -839,7 +841,7 @@ label_out:
d.s_flags = maxflags;
d.s_label = maxlabelstr;
d.s_group = maxgroup;
- d.s_inode = snprintf(NULL, 0, "%lu", maxinode);
+ d.s_inode = snprintf(NULL, 0, "%ju", maxinode);
d.s_nlink = snprintf(NULL, 0, "%lu", maxnlink);
sizelen = f_humanval ? HUMANVALSTR_LEN :
snprintf(NULL, 0, "%ju", maxsize);
diff --git a/bin/ls/print.c b/bin/ls/print.c
index a788042144bb..5a0fc86acde0 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -152,7 +152,8 @@ printlong(const DISPLAY *dp)
continue;
sp = p->fts_statp;
if (f_inode)
- (void)printf("%*lu ", dp->s_inode, (u_long)sp->st_ino);
+ (void)printf("%*ju ",
+ dp->s_inode, (uintmax_t)sp->st_ino);
if (f_size)
(void)printf("%*jd ",
dp->s_block, howmany(sp->st_blocks, blocksize));
@@ -328,7 +329,8 @@ printaname(const FTSENT *p, u_long inodefield, u_long sizefield)
sp = p->fts_statp;
chcnt = 0;
if (f_inode)
- chcnt += printf("%*lu ", (int)inodefield, (u_long)sp->st_ino);
+ chcnt += printf("%*ju ",
+ (int)inodefield, (uintmax_t)sp->st_ino);
if (f_size)
chcnt += printf("%*jd ",
(int)sizefield, howmany(sp->st_blocks, blocksize));
diff --git a/bin/mv/mv.1 b/bin/mv/mv.1
index 9e4d9ee0d4bd..5199f27bc068 100644
--- a/bin/mv/mv.1
+++ b/bin/mv/mv.1
@@ -32,7 +32,7 @@
.\" @(#)mv.1 8.1 (Berkeley) 5/31/93
.\" $FreeBSD$
.\"
-.Dd May 12, 2007
+.Dd August 28, 2012
.Dt MV 1
.Os
.Sh NAME
@@ -41,7 +41,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl f | i | n
-.Op Fl v
+.Op Fl hv
.Ar source target
.Nm
.Op Fl f | i | n
@@ -81,6 +81,21 @@ option overrides any previous
or
.Fl n
options.)
+.It Fl h
+If the
+.Ar target
+operand is a symbolic link to a directory,
+do not follow it.
+This causes the
+.Nm
+utility to rename the file
+.Ar source
+to the destination path
+.Ar target
+rather than moving
+.Ar source
+into the directory referenced by
+.Ar target .
.It Fl i
Cause
.Nm
@@ -142,7 +157,8 @@ rm -rf source_file
.Ex -std
.Sh COMPATIBILITY
The
-.Fl n
+.Fl h ,
+.Fl n ,
and
.Fl v
options are non-standard and their use in scripts is not recommended.
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index e4fe007323af..d33b28d5b7e5 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -68,7 +68,7 @@ __FBSDID("$FreeBSD$");
/* Exit code for a failed exec. */
#define EXEC_FAILED 127
-static int fflg, iflg, nflg, vflg;
+static int fflg, hflg, iflg, nflg, vflg;
static int copy(const char *, const char *);
static int do_move(const char *, const char *);
@@ -87,8 +87,11 @@ main(int argc, char *argv[])
int ch;
char path[PATH_MAX];
- while ((ch = getopt(argc, argv, "finv")) != -1)
+ while ((ch = getopt(argc, argv, "fhinv")) != -1)
switch (ch) {
+ case 'h':
+ hflg = 1;
+ break;
case 'i':
iflg = 1;
fflg = nflg = 0;
@@ -123,6 +126,17 @@ main(int argc, char *argv[])
exit(do_move(argv[0], argv[1]));
}
+ /*
+ * If -h was specified, treat the target as a symlink instead of
+ * directory.
+ */
+ if (hflg) {
+ if (argc > 2)
+ usage();
+ if (lstat(argv[1], &sb) == 0 && S_ISLNK(sb.st_mode))
+ exit(do_move(argv[0], argv[1]));
+ }
+
/* It's a directory, move each file into it. */
if (strlen(argv[argc - 1]) > sizeof(path) - 1)
errx(1, "%s: destination pathname too long", *argv);
@@ -483,7 +497,7 @@ usage(void)
{
(void)fprintf(stderr, "%s\n%s\n",
- "usage: mv [-f | -i | -n] [-v] source target",
+ "usage: mv [-f | -i | -n] [-hv] source target",
" mv [-f | -i | -n] [-v] source ... directory");
exit(EX_USAGE);
}
diff --git a/bin/pax/ar_io.c b/bin/pax/ar_io.c
index c3b35a7d4836..4914c8527439 100644
--- a/bin/pax/ar_io.c
+++ b/bin/pax/ar_io.c
@@ -85,7 +85,6 @@ const char *gzip_program; /* name of gzip program */
static pid_t zpid = -1; /* pid of child process */
static int get_phys(void);
-extern sigset_t s_mask;
static void ar_start_gzip(int, const char *, int);
/*
diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c
index bc808ab45bf9..4a3e5e7b01c4 100644
--- a/bin/pax/ar_subs.c
+++ b/bin/pax/ar_subs.c
@@ -55,7 +55,6 @@ __FBSDID("$FreeBSD$");
static void wr_archive(ARCHD *, int is_app);
static int get_arc(void);
static int next_head(ARCHD *);
-extern sigset_t s_mask;
/*
* Routines which control the overall operation modes of pax as specified by
diff --git a/bin/pax/extern.h b/bin/pax/extern.h
index e7167928e2f9..4375694cc151 100644
--- a/bin/pax/extern.h
+++ b/bin/pax/extern.h
@@ -186,7 +186,7 @@ void options(int, char **);
OPLIST * opt_next(void);
int opt_add(const char *);
int bad_opt(void);
-char *chdname;
+extern char *chdname;
/*
* pat_rep.c
@@ -231,6 +231,7 @@ extern int exit_val;
extern int docrc;
extern char *dirptr;
extern const char *argv0;
+extern sigset_t s_mask;
extern FILE *listf;
extern char *tempfile;
extern char *tempbase;
diff --git a/bin/pax/options.c b/bin/pax/options.c
index 5fd641fc3088..32d967e1d857 100644
--- a/bin/pax/options.c
+++ b/bin/pax/options.c
@@ -81,6 +81,7 @@ static void cpio_usage(void);
#define GETLINE_OUT_OF_MEM 2
static int getline_error;
+char *chdname;
#define GZIP_CMD "gzip" /* command to run as gzip */
#define COMPRESS_CMD "compress" /* command to run as compress */
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index 6c380e8b8f15..5861129c82a8 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -79,6 +79,7 @@ static VAR var[] = {
{"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},
@@ -141,6 +142,7 @@ static VAR var[] = {
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},
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 5c9398d63514..f36411e786a9 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -387,12 +387,13 @@ started(KINFO *k, VARENT *ve __unused)
size_t buflen = 100;
char *buf;
+ if (!k->ki_valid)
+ return (NULL);
+
buf = malloc(buflen);
if (buf == NULL)
errx(1, "malloc failed");
- if (!k->ki_valid)
- return (NULL);
if (use_ampm < 0)
use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
then = k->ki_p->ki_start.tv_sec;
@@ -415,12 +416,13 @@ lstarted(KINFO *k, VARENT *ve __unused)
char *buf;
size_t buflen = 100;
+ if (!k->ki_valid)
+ return (NULL);
+
buf = malloc(buflen);
if (buf == NULL)
errx(1, "malloc failed");
- if (!k->ki_valid)
- return (NULL);
then = k->ki_p->ki_start.tv_sec;
(void)strftime(buf, buflen, "%c", localtime(&then));
return (buf);
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index d1627f640cd4..21e8eaf37cb6 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -29,7 +29,7 @@
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
.\" $FreeBSD$
.\"
-.Dd May 20, 2012
+.Dd September 18, 2012
.Dt PS 1
.Os
.Sh NAME
@@ -500,6 +500,8 @@ command and arguments
number of copy-on-write faults
.It Cm cpu
short-term CPU usage factor (for scheduling)
+.It Cm dsiz
+data size (in Kbytes)
.It Cm emul
system-call emulation environment
.It Cm etime
@@ -610,6 +612,8 @@ blocked signals (alias
.Cm blocked )
.It Cm sl
sleep time (in seconds; 127 = infinity)
+.It Cm ssiz
+stack size (in Kbytes)
.It Cm start
time started
.It Cm state
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index f507b6a028f3..ebabc1952fab 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -889,8 +889,8 @@ add_list(struct listinfo *inf, const char *argp)
int toolong;
char elemcopy[PATH_MAX];
- if (*argp == 0)
- inf->addelem(inf, elemcopy);
+ if (*argp == '\0')
+ inf->addelem(inf, argp);
while (*argp != '\0') {
while (*argp != '\0' && strchr(W_SEP, *argp) != NULL)
argp++;
diff --git a/bin/rcp/rcp.1 b/bin/rcp/rcp.1
index f3c3a8edd334..71bdab9887fc 100644
--- a/bin/rcp/rcp.1
+++ b/bin/rcp/rcp.1
@@ -116,17 +116,11 @@ The
.Nm
utility handles third party copies, where neither source nor target files
are on the current machine.
-.Sh FILES
-.Bl -tag -width ".Pa /etc/auth.conf" -compact
-.It Pa /etc/auth.conf
-configure authentication services
-.El
.Sh SEE ALSO
.Xr cp 1 ,
.Xr ftp 1 ,
.Xr rlogin 1 ,
.Xr rsh 1 ,
-.Xr auth.conf 5 ,
.Xr hosts.equiv 5
.Sh HISTORY
The
diff --git a/bin/rcp/rcp.c b/bin/rcp/rcp.c
index 335770540950..186dde6d5e20 100644
--- a/bin/rcp/rcp.c
+++ b/bin/rcp/rcp.c
@@ -76,12 +76,13 @@ __FBSDID("$FreeBSD$");
#define OPTIONS "46dfprt"
-struct passwd *pwd;
-u_short port;
-uid_t userid;
-int errs, rem;
-int pflag, iamremote, iamrecursive, targetshouldbedirectory;
-int family = PF_UNSPEC;
+static struct passwd *pwd;
+static u_short port;
+static uid_t userid;
+static int errs, rem;
+int iamremote;
+static int pflag, iamrecursive, targetshouldbedirectory;
+static int family = PF_UNSPEC;
static int argc_copy;
static const char **argv_copy;
@@ -89,7 +90,7 @@ static const char **argv_copy;
static char period[] = ".";
#define CMDNEEDS 64
-char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
+static char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
int response(void);
void rsource(char *, struct stat *);
diff --git a/bin/rm/rm.c b/bin/rm/rm.c
index 3c2ba61b3c54..a45005739de1 100644
--- a/bin/rm/rm.c
+++ b/bin/rm/rm.c
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
#include <fts.h>
#include <grp.h>
#include <pwd.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -301,10 +302,16 @@ rm_tree(char **argv)
if (fflag)
continue;
/* FALLTHROUGH */
- default:
+
+ case FTS_F:
+ case FTS_NSOK:
if (Pflag)
- if (!rm_overwrite(p->fts_accpath, NULL))
+ if (!rm_overwrite(p->fts_accpath, p->fts_info ==
+ FTS_NSOK ? NULL : p->fts_statp))
continue;
+ /* FALLTHROUGH */
+
+ default:
rval = unlink(p->fts_accpath);
if (rval == 0 || (fflag && errno == ENOENT)) {
if (rval == 0 && vflag)
@@ -408,7 +415,7 @@ rm_file(char **argv)
int
rm_overwrite(char *file, struct stat *sbp)
{
- struct stat sb;
+ struct stat sb, sb2;
struct statfs fsb;
off_t len;
int bsize, fd, wlen;
@@ -423,12 +430,19 @@ rm_overwrite(char *file, struct stat *sbp)
if (!S_ISREG(sbp->st_mode))
return (1);
if (sbp->st_nlink > 1 && !fflag) {
- warnx("%s (inode %u): not overwritten due to multiple links",
- file, sbp->st_ino);
+ warnx("%s (inode %ju): not overwritten due to multiple links",
+ file, (uintmax_t)sbp->st_ino);
return (0);
}
- if ((fd = open(file, O_WRONLY, 0)) == -1)
+ if ((fd = open(file, O_WRONLY|O_NONBLOCK|O_NOFOLLOW, 0)) == -1)
+ goto err;
+ if (fstat(fd, &sb2))
goto err;
+ if (sb2.st_dev != sbp->st_dev || sb2.st_ino != sbp->st_ino ||
+ !S_ISREG(sb2.st_mode)) {
+ errno = EPERM;
+ goto err;
+ }
if (fstatfs(fd, &fsb) == -1)
goto err;
bsize = MAX(fsb.f_iosize, 1024);
diff --git a/bin/setfacl/merge.c b/bin/setfacl/merge.c
index 9d8e67a66235..8c359d5e6690 100644
--- a/bin/setfacl/merge.c
+++ b/bin/setfacl/merge.c
@@ -94,7 +94,7 @@ merge_acl(acl_t acl, acl_t *prev_acl, const char *filename)
acl_tag_t tag, tag_new;
acl_entry_type_t entry_type, entry_type_new;
acl_flagset_t flagset;
- int entry_id, entry_id_new, have_entry, entry_number = 0;
+ int entry_id, entry_id_new, have_entry, had_entry, entry_number = 0;
int acl_brand, prev_acl_brand;
acl_get_brand_np(acl, &acl_brand);
@@ -116,6 +116,7 @@ merge_acl(acl_t acl, acl_t *prev_acl, const char *filename)
while (acl_get_entry(acl, entry_id, &entry) == 1) {
entry_id = ACL_NEXT_ENTRY;
have_entry = 0;
+ had_entry = 0;
/* keep track of existing ACL_MASK entries */
if (acl_get_tag_type(entry, &tag) == -1)
@@ -187,7 +188,7 @@ merge_acl(acl_t acl, acl_t *prev_acl, const char *filename)
err(1, "%s: acl_set_flagset_np() failed",
filename);
}
- have_entry = 1;
+ had_entry = have_entry = 1;
break;
default:
/* should never be here */
@@ -197,7 +198,7 @@ merge_acl(acl_t acl, acl_t *prev_acl, const char *filename)
}
/* if this entry has not been found, it must be new */
- if (have_entry == 0) {
+ if (had_entry == 0) {
/*
* NFSv4 ACL entries must be prepended to the ACL.
diff --git a/bin/setfacl/setfacl.1 b/bin/setfacl/setfacl.1
index f501c2c5131e..3d7b517a3417 100644
--- a/bin/setfacl/setfacl.1
+++ b/bin/setfacl/setfacl.1
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd April 9, 2011
+.Dd September 2, 2012
.Dt SETFACL 1
.Os
.Sh NAME
@@ -337,7 +337,7 @@ read_acl
write_acl
.It o
write_owner
-.It S
+.It s
synchronize
.El
.Pp
diff --git a/bin/setfacl/setfacl.c b/bin/setfacl/setfacl.c
index 75347945f7ba..c69f0baf6f1f 100644
--- a/bin/setfacl/setfacl.c
+++ b/bin/setfacl/setfacl.c
@@ -42,6 +42,35 @@ __FBSDID("$FreeBSD$");
#include "setfacl.h"
+/* file operations */
+#define OP_MERGE_ACL 0x00 /* merge acl's (-mM) */
+#define OP_REMOVE_DEF 0x01 /* remove default acl's (-k) */
+#define OP_REMOVE_EXT 0x02 /* remove extended acl's (-b) */
+#define OP_REMOVE_ACL 0x03 /* remove acl's (-xX) */
+#define OP_REMOVE_BY_NUMBER 0x04 /* remove acl's (-xX) by acl entry number */
+#define OP_ADD_ACL 0x05 /* add acls entries at a given position */
+
+/* TAILQ entry for acl operations */
+struct sf_entry {
+ uint op;
+ acl_t acl;
+ uint entry_number;
+ TAILQ_ENTRY(sf_entry) next;
+};
+static TAILQ_HEAD(, sf_entry) entrylist;
+
+/* TAILQ entry for files */
+struct sf_file {
+ const char *filename;
+ TAILQ_ENTRY(sf_file) next;
+};
+static TAILQ_HEAD(, sf_file) filelist;
+
+uint have_mask;
+uint need_mask;
+uint have_stdin;
+uint n_flag;
+
static void add_filename(const char *filename);
static void usage(void);
@@ -73,6 +102,7 @@ main(int argc, char *argv[])
{
acl_t acl;
acl_type_t acl_type;
+ acl_entry_t unused_entry;
char filename[PATH_MAX];
int local_error, carried_error, ch, i, entry_number, ret;
int h_flag;
@@ -263,6 +293,17 @@ main(int argc, char *argv[])
need_mask = 1;
break;
case OP_REMOVE_EXT:
+ /*
+ * Don't try to call remove_ext() for empty
+ * default ACL.
+ */
+ if (acl_type == ACL_TYPE_DEFAULT &&
+ acl_get_entry(acl, ACL_FIRST_ENTRY,
+ &unused_entry) == 0) {
+ local_error += remove_default(&acl,
+ file->filename);
+ break;
+ }
remove_ext(&acl, file->filename);
need_mask = 0;
break;
@@ -296,6 +337,20 @@ main(int argc, char *argv[])
}
}
+ /*
+ * Don't try to set an empty default ACL; it will always fail.
+ * Use acl_delete_def_file(3) instead.
+ */
+ if (acl_type == ACL_TYPE_DEFAULT &&
+ acl_get_entry(acl, ACL_FIRST_ENTRY, &unused_entry) == 0) {
+ if (acl_delete_def_file(file->filename) == -1) {
+ warn("%s: acl_delete_def_file() failed",
+ file->filename);
+ carried_error++;
+ }
+ continue;
+ }
+
/* don't bother setting the ACL if something is broken */
if (local_error) {
carried_error++;
diff --git a/bin/setfacl/setfacl.h b/bin/setfacl/setfacl.h
index 84fdd9249d0a..c4afbfc1e88e 100644
--- a/bin/setfacl/setfacl.h
+++ b/bin/setfacl/setfacl.h
@@ -33,30 +33,6 @@
#include <sys/acl.h>
#include <sys/queue.h>
-/* file operations */
-#define OP_MERGE_ACL 0x00 /* merge acl's (-mM) */
-#define OP_REMOVE_DEF 0x01 /* remove default acl's (-k) */
-#define OP_REMOVE_EXT 0x02 /* remove extended acl's (-b) */
-#define OP_REMOVE_ACL 0x03 /* remove acl's (-xX) */
-#define OP_REMOVE_BY_NUMBER 0x04 /* remove acl's (-xX) by acl entry number */
-#define OP_ADD_ACL 0x05 /* add acls entries at a given position */
-
-/* TAILQ entry for acl operations */
-struct sf_entry {
- uint op;
- acl_t acl;
- uint entry_number;
- TAILQ_ENTRY(sf_entry) next;
-};
-TAILQ_HEAD(, sf_entry) entrylist;
-
-/* TAILQ entry for files */
-struct sf_file {
- const char *filename;
- TAILQ_ENTRY(sf_file) next;
-};
-TAILQ_HEAD(, sf_file) filelist;
-
/* files.c */
acl_t get_acl_from_file(const char *filename);
/* merge.c */
@@ -74,9 +50,9 @@ void *zmalloc(size_t size);
const char *brand_name(int brand);
int branding_mismatch(int brand1, int brand2);
-uint have_mask;
-uint need_mask;
-uint have_stdin;
-uint n_flag;
+extern uint have_mask;
+extern uint need_mask;
+extern uint have_stdin;
+extern uint n_flag;
#endif /* _SETFACL_H */
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index 1330c850c7fb..fa6f4925acee 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -79,7 +79,7 @@ static char *prevdir; /* previous working directory */
static char *cdcomppath;
int
-cdcmd(int argc, char **argv)
+cdcmd(int argc __unused, char **argv __unused)
{
const char *dest;
const char *path;
@@ -89,9 +89,8 @@ cdcmd(int argc, char **argv)
int rc;
int errno1 = ENOENT;
- optreset = 1; optind = 1; opterr = 0; /* initialize getopt */
phys = Pflag;
- while ((ch = getopt(argc, argv, "eLP")) != -1) {
+ while ((ch = nextopt("eLP")) != '\0') {
switch (ch) {
case 'e':
getcwderr = 1;
@@ -102,18 +101,13 @@ cdcmd(int argc, char **argv)
case 'P':
phys = 1;
break;
- default:
- error("unknown option: -%c", optopt);
- break;
}
}
- argc -= optind;
- argv += optind;
- if (argc > 1)
+ if (*argptr != NULL && argptr[1] != NULL)
error("too many arguments");
- if ((dest = *argv) == NULL && (dest = bltinlookup("HOME", 1)) == NULL)
+ if ((dest = *argptr) == NULL && (dest = bltinlookup("HOME", 1)) == NULL)
error("HOME not set");
if (*dest == '\0')
dest = ".";
@@ -330,14 +324,13 @@ updatepwd(char *dir)
}
int
-pwdcmd(int argc, char **argv)
+pwdcmd(int argc __unused, char **argv __unused)
{
char *p;
int ch, phys;
- optreset = 1; optind = 1; opterr = 0; /* initialize getopt */
phys = Pflag;
- while ((ch = getopt(argc, argv, "LP")) != -1) {
+ while ((ch = nextopt("LP")) != '\0') {
switch (ch) {
case 'L':
phys = 0;
@@ -345,15 +338,10 @@ pwdcmd(int argc, char **argv)
case 'P':
phys = 1;
break;
- default:
- error("unknown option: -%c", optopt);
- break;
}
}
- argc -= optind;
- argv += optind;
- if (argc != 0)
+ if (*argptr != NULL)
error("too many arguments");
if (!phys && getpwd()) {
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 2d90921aa206..8973f699f039 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -672,6 +672,52 @@ out:
result->fd, result->buf, result->nleft, result->jp));
}
+static int
+mustexpandto(const char *argtext, const char *mask)
+{
+ for (;;) {
+ if (*argtext == CTLQUOTEMARK || *argtext == CTLQUOTEEND) {
+ argtext++;
+ continue;
+ }
+ if (*argtext == CTLESC)
+ argtext++;
+ else if (BASESYNTAX[(int)*argtext] == CCTL)
+ return (0);
+ if (*argtext != *mask)
+ return (0);
+ if (*argtext == '\0')
+ return (1);
+ argtext++;
+ mask++;
+ }
+}
+
+static int
+isdeclarationcmd(struct narg *arg)
+{
+ int have_command = 0;
+
+ if (arg == NULL)
+ return (0);
+ while (mustexpandto(arg->text, "command")) {
+ have_command = 1;
+ arg = &arg->next->narg;
+ if (arg == NULL)
+ return (0);
+ /*
+ * To also allow "command -p" and "command --" as part of
+ * a declaration command, add code here.
+ * We do not do this, as ksh does not do it either and it
+ * is not required by POSIX.
+ */
+ }
+ return (mustexpandto(arg->text, "export") ||
+ mustexpandto(arg->text, "readonly") ||
+ (mustexpandto(arg->text, "local") &&
+ (have_command || !isfunc("local"))));
+}
+
/*
* Check if a builtin can safely be executed in the same process,
* even though it should be in a subshell (command substitution).
@@ -743,11 +789,12 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
exitstatus = 0;
for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) {
if (varflag && isassignment(argp->narg.text)) {
- expandarg(argp, &varlist, EXP_VARTILDE);
+ expandarg(argp, varflag == 1 ? &varlist : &arglist,
+ EXP_VARTILDE);
continue;
- }
+ } else if (varflag == 1)
+ varflag = isdeclarationcmd(&argp->narg) ? 2 : 0;
expandarg(argp, &arglist, EXP_FULL | EXP_TILDE);
- varflag = 0;
}
*arglist.lastp = NULL;
*varlist.lastp = NULL;
@@ -1176,7 +1223,7 @@ breakcmd(int argc, char **argv)
* The `command' command.
*/
int
-commandcmd(int argc, char **argv)
+commandcmd(int argc __unused, char **argv __unused)
{
const char *path;
int ch;
@@ -1184,9 +1231,7 @@ commandcmd(int argc, char **argv)
path = bltinlookup("PATH", 1);
- optind = optreset = 1;
- opterr = 0;
- while ((ch = getopt(argc, argv, "pvV")) != -1) {
+ while ((ch = nextopt("pvV")) != '\0') {
switch (ch) {
case 'p':
path = _PATH_STDPATH;
@@ -1197,20 +1242,15 @@ commandcmd(int argc, char **argv)
case 'V':
cmd = TYPECMD_BIGV;
break;
- case '?':
- default:
- error("unknown option: -%c", optopt);
}
}
- argc -= optind;
- argv += optind;
if (cmd != -1) {
- if (argc != 1)
+ if (*argptr == NULL || argptr[1] != NULL)
error("wrong number of arguments");
- return typecmd_impl(2, argv - 1, cmd, path);
+ return typecmd_impl(2, argptr - 1, cmd, path);
}
- if (argc != 0)
+ if (*argptr != NULL)
error("commandcmd bad call");
/*
diff --git a/bin/sh/exec.c b/bin/sh/exec.c
index f2e4c1db75ec..cd495895e03d 100644
--- a/bin/sh/exec.c
+++ b/bin/sh/exec.c
@@ -648,6 +648,19 @@ unsetfunc(const char *name)
return (0);
}
+
+/*
+ * Check if a function by a certain name exists.
+ */
+int
+isfunc(const char *name)
+{
+ struct tblentry *cmdp;
+ cmdp = cmdlookup(name, 0);
+ return (cmdp != NULL && cmdp->cmdtype == CMDFUNCTION);
+}
+
+
/*
* Shared code for the following builtin commands:
* type, command -v, command -V
diff --git a/bin/sh/exec.h b/bin/sh/exec.h
index 0948421f40be..b57b2d5b270e 100644
--- a/bin/sh/exec.h
+++ b/bin/sh/exec.h
@@ -72,5 +72,6 @@ void hashcd(void);
void changepath(const char *);
void defun(const char *, union node *);
int unsetfunc(const char *);
+int isfunc(const char *);
int typecmd_impl(int, char **, int, const char *);
void clearcmdentry(void);
diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c
index 6371599e3b23..a8c376a295fe 100644
--- a/bin/sh/histedit.c
+++ b/bin/sh/histedit.c
@@ -182,7 +182,7 @@ setterm(const char *term)
}
int
-histcmd(int argc, char **argv)
+histcmd(int argc, char **argv __unused)
{
int ch;
const char *editor = NULL;
@@ -206,13 +206,10 @@ histcmd(int argc, char **argv)
if (argc == 1)
error("missing history argument");
- optreset = 1; optind = 1; /* initialize getopt */
- opterr = 0;
- while (not_fcnumber(argv[optind]) &&
- (ch = getopt(argc, argv, ":e:lnrs")) != -1)
+ while (not_fcnumber(*argptr) && (ch = nextopt("e:lnrs")) != '\0')
switch ((char)ch) {
case 'e':
- editor = optarg;
+ editor = shoptarg;
break;
case 'l':
lflg = 1;
@@ -226,13 +223,7 @@ histcmd(int argc, char **argv)
case 's':
sflg = 1;
break;
- case ':':
- error("option -%c expects argument", optopt);
- case '?':
- default:
- error("unknown option: -%c", optopt);
}
- argc -= optind, argv += optind;
savehandler = handler;
/*
@@ -276,31 +267,26 @@ histcmd(int argc, char **argv)
/*
* If executing, parse [old=new] now
*/
- if (lflg == 0 && argc > 0 &&
- ((repl = strchr(argv[0], '=')) != NULL)) {
- pat = argv[0];
+ if (lflg == 0 && *argptr != NULL &&
+ ((repl = strchr(*argptr, '=')) != NULL)) {
+ pat = *argptr;
*repl++ = '\0';
- argc--, argv++;
+ argptr++;
}
/*
* determine [first] and [last]
*/
- switch (argc) {
- case 0:
+ if (*argptr == NULL) {
firststr = lflg ? "-16" : "-1";
laststr = "-1";
- break;
- case 1:
- firststr = argv[0];
- laststr = lflg ? "-1" : argv[0];
- break;
- case 2:
- firststr = argv[0];
- laststr = argv[1];
- break;
- default:
+ } else if (argptr[1] == NULL) {
+ firststr = argptr[0];
+ laststr = lflg ? "-1" : argptr[0];
+ } else if (argptr[2] == NULL) {
+ firststr = argptr[0];
+ laststr = argptr[1];
+ } else
error("too many arguments");
- }
/*
* Turn into event numbers.
*/
diff --git a/bin/sh/input.c b/bin/sh/input.c
index 3ceaea40e39f..12f285f8b423 100644
--- a/bin/sh/input.c
+++ b/bin/sh/input.c
@@ -186,7 +186,7 @@ retry:
if (rl_cp == NULL)
rl_cp = el_gets(el, &el_len);
if (rl_cp == NULL)
- nr = 0;
+ nr = el_len == 0 ? 0 : -1;
else {
nr = el_len;
if (nr > BUFSIZ)
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c
index f6f66182473f..05e2e889239d 100644
--- a/bin/sh/jobs.c
+++ b/bin/sh/jobs.c
@@ -84,10 +84,13 @@ static struct job *jobmru; /* most recently used job list */
static pid_t initialpgrp; /* pgrp of shell on invocation */
#endif
int in_waitcmd = 0; /* are we in waitcmd()? */
-int in_dowait = 0; /* are we in dowait()? */
volatile sig_atomic_t breakwaitcmd = 0; /* should wait be terminated? */
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 signals */
+
#if JOBS
static void restartjob(struct job *);
#endif
@@ -95,7 +98,6 @@ static void freejob(struct job *);
static struct job *getjob(char *);
pid_t getjobpgrp(char *);
static pid_t dowait(int, struct job *);
-static pid_t waitproc(int, int *);
static void checkzombies(void);
static void cmdtxt(union node *);
static void cmdputs(const char *);
@@ -248,15 +250,13 @@ restartjob(struct job *jp)
int
-jobscmd(int argc, char *argv[])
+jobscmd(int argc __unused, char *argv[] __unused)
{
char *id;
int ch, mode;
- optind = optreset = 1;
- opterr = 0;
mode = SHOWJOBS_DEFAULT;
- while ((ch = getopt(argc, argv, "lps")) != -1) {
+ while ((ch = nextopt("lps")) != '\0') {
switch (ch) {
case 'l':
mode = SHOWJOBS_VERBOSE;
@@ -267,18 +267,13 @@ jobscmd(int argc, char *argv[])
case 's':
mode = SHOWJOBS_PIDS;
break;
- case '?':
- default:
- error("unknown option: -%c", optopt);
}
}
- argc -= optind;
- argv += optind;
- if (argc == 0)
+ if (*argptr == NULL)
showjobs(0, mode);
else
- while ((id = *argv++) != NULL)
+ while ((id = *argptr++) != NULL)
showjob(getjob(id), mode);
return (0);
@@ -520,7 +515,7 @@ waitcmd(int argc, char **argv)
break;
}
}
- } while (dowait(1, (struct job *)NULL) != -1);
+ } while (dowait(DOWAIT_BLOCK | DOWAIT_SIG, (struct job *)NULL) != -1);
in_waitcmd--;
return 0;
@@ -967,7 +962,7 @@ waitforjob(struct job *jp, int *origstatus)
INTOFF;
TRACE(("waitforjob(%%%td) called\n", jp - jobtab + 1));
while (jp->state == 0)
- if (dowait(1, jp) == -1)
+ if (dowait(DOWAIT_BLOCK | (Tflag ? DOWAIT_SIG : 0), jp) == -1)
dotrap();
#if JOBS
if (jp->jobctl) {
@@ -1005,14 +1000,20 @@ waitforjob(struct job *jp, int *origstatus)
}
+static void
+dummy_handler(int sig)
+{
+}
/*
* Wait for a process to terminate.
*/
static pid_t
-dowait(int block, struct job *job)
+dowait(int mode, struct job *job)
{
+ struct sigaction sa, osa;
+ sigset_t mask, omask;
pid_t pid;
int status;
struct procstat *sp;
@@ -1022,17 +1023,49 @@ dowait(int block, struct job *job)
int stopped;
int sig;
int coredump;
+ int wflags;
+ int restore_sigchld;
- in_dowait++;
TRACE(("dowait(%d) called\n", block));
+ restore_sigchld = 0;
+ if ((mode & DOWAIT_SIG) != 0) {
+ sigfillset(&mask);
+ sigprocmask(SIG_BLOCK, &mask, &omask);
+ INTOFF;
+ if (!issigchldtrapped()) {
+ restore_sigchld = 1;
+ sa.sa_handler = dummy_handler;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGCHLD, &sa, &osa);
+ }
+ }
do {
- pid = waitproc(block, &status);
+#if JOBS
+ if (iflag)
+ wflags = WUNTRACED | WCONTINUED;
+ else
+#endif
+ wflags = 0;
+ if ((mode & (DOWAIT_BLOCK | DOWAIT_SIG)) != DOWAIT_BLOCK)
+ wflags |= WNOHANG;
+ pid = wait3(&status, wflags, (struct rusage *)NULL);
TRACE(("wait returns %d, status=%d\n", (int)pid, status));
- } while ((pid == -1 && errno == EINTR && breakwaitcmd == 0) ||
- (pid > 0 && WIFSTOPPED(status) && !iflag));
- in_dowait--;
+ if (pid == 0 && (mode & DOWAIT_SIG) != 0) {
+ sigsuspend(&omask);
+ pid = -1;
+ if (int_pending())
+ break;
+ }
+ } while (pid == -1 && errno == EINTR && breakwaitcmd == 0);
if (pid == -1 && errno == ECHILD && job != NULL)
job->state = JOBDONE;
+ if ((mode & DOWAIT_SIG) != 0) {
+ if (restore_sigchld)
+ sigaction(SIGCHLD, &osa, NULL);
+ sigprocmask(SIG_SETMASK, &omask, NULL);
+ INTON;
+ }
if (breakwaitcmd != 0) {
breakwaitcmd = 0;
if (pid <= 0)
@@ -1053,7 +1086,11 @@ dowait(int block, struct job *job)
TRACE(("Changing status of proc %d from 0x%x to 0x%x\n",
(int)pid, sp->status,
status));
- sp->status = status;
+ if (WIFCONTINUED(status)) {
+ sp->status = -1;
+ jp->state = 0;
+ } else
+ sp->status = status;
thisjob = jp;
}
if (sp->status == -1)
@@ -1111,26 +1148,6 @@ dowait(int block, struct job *job)
/*
- * Do a wait system call. If job control is compiled in, we accept
- * stopped processes. If block is zero, we return a value of zero
- * rather than blocking.
- */
-static pid_t
-waitproc(int block, int *status)
-{
- int flags;
-
-#if JOBS
- flags = WUNTRACED;
-#else
- flags = 0;
-#endif
- if (block == 0)
- flags |= WNOHANG;
- return wait3(status, flags, (struct rusage *)NULL);
-}
-
-/*
* return 1 if there are stopped jobs, otherwise 0
*/
int job_warning = 0;
diff --git a/bin/sh/jobs.h b/bin/sh/jobs.h
index e741b2c0dfb1..1570b4695dad 100644
--- a/bin/sh/jobs.h
+++ b/bin/sh/jobs.h
@@ -84,7 +84,6 @@ enum {
extern int job_warning; /* user was warned about stopped jobs */
extern int in_waitcmd; /* are we in waitcmd()? */
-extern int in_dowait; /* are we in dowait()? */
extern volatile sig_atomic_t breakwaitcmd; /* break wait to process traps? */
void setjobctl(int);
diff --git a/bin/sh/main.c b/bin/sh/main.c
index 5eb12e07dacb..b93f04ee0581 100644
--- a/bin/sh/main.c
+++ b/bin/sh/main.c
@@ -266,14 +266,7 @@ read_profile(char *name)
void
readcmdfile(const char *name)
{
- int fd;
-
- INTOFF;
- if ((fd = open(name, O_RDONLY)) >= 0)
- setinputfd(fd, 1);
- else
- error("cannot open %s: %s", name, strerror(errno));
- INTON;
+ setinputfile(name, 1);
cmdloop(0);
popfile();
}
diff --git a/bin/sh/options.c b/bin/sh/options.c
index 4c2c8ab8e3ec..ad0291e73a39 100644
--- a/bin/sh/options.c
+++ b/bin/sh/options.c
@@ -531,10 +531,6 @@ out:
}
/*
- * XXX - should get rid of. have all builtins use getopt(3). the
- * library getopt must have the BSD extension static variable "optreset"
- * otherwise it can't be used within the shell safely.
- *
* Standard option processing (a la getopt) for builtin routines. The
* only argument that is passed to nextopt is the option string; the
* other arguments are unnecessary. It return the character, or '\0' on
diff --git a/bin/sh/sh.1 b/bin/sh/sh.1
index 34b6b2b8969e..175026746dfc 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 5, 2011
+.Dd July 15, 2012
.Dt SH 1
.Os
.Sh NAME
@@ -487,8 +487,9 @@ and backslash
The backslash inside double quotes is historically weird.
It remains literal unless it precedes the following characters,
which it serves to quote:
+.Pp
.Bl -column "XXX" "XXX" "XXX" "XXX" "XXX" -offset center -compact
-.It Li $ Ta Li ` Ta Li \&" Ta Li \e\ Ta Li \en
+.It Li $ Ta Li ` Ta Li \&" Ta Li \e Ta Li \en
.El
.It Backslash
A backslash preserves the literal meaning of the following
@@ -648,8 +649,8 @@ The following redirection is often called a
.Dq here-document .
.Bd -unfilled -offset indent
.Oo Ar n Oc Ns Li << Ar delimiter
-.D1 Ar here-doc-text
-.D1 ...
+.Ar here-doc-text
+.Ar ...
.Ar delimiter
.Ed
.Pp
@@ -1164,6 +1165,20 @@ Assignments are expanded differently from other words:
tilde expansion is also performed after the equals sign and after any colon
and usernames are also terminated by colons,
and field splitting and pathname expansion are not performed.
+.Pp
+This special expansion applies not only to assignments that form a simple
+command by themselves or precede a command word,
+but also to words passed to the
+.Ic export ,
+.Ic local
+or
+.Ic readonly
+built-in commands that have this form.
+For this, the builtin's name must be literal
+(not the result of an expansion)
+and may optionally be preceded by one or more literal instances of
+.Ic command
+without options.
.Ss Positional Parameters
A positional parameter is a parameter denoted by a number greater than zero.
The shell sets these initially to the values of its command line
diff --git a/bin/sh/trap.c b/bin/sh/trap.c
index 834992f01e1e..521c5110cb3c 100644
--- a/bin/sh/trap.c
+++ b/bin/sh/trap.c
@@ -368,6 +368,14 @@ ignoresig(int signo)
}
+int
+issigchldtrapped(void)
+{
+
+ return (trap[SIGCHLD] != NULL && *trap[SIGCHLD] != '\0');
+}
+
+
/*
* Signal handler.
*/
@@ -416,6 +424,7 @@ dotrap(void)
in_dotrap++;
for (;;) {
+ pendingsigs = 0;
for (i = 1; i < NSIG; i++) {
if (gotsig[i]) {
gotsig[i] = 0;
@@ -467,7 +476,6 @@ dotrap(void)
break;
}
in_dotrap--;
- pendingsigs = 0;
}
diff --git a/bin/sh/trap.h b/bin/sh/trap.h
index bf1250a85b87..61a17ec05174 100644
--- a/bin/sh/trap.h
+++ b/bin/sh/trap.h
@@ -41,6 +41,7 @@ void clear_traps(void);
int have_traps(void);
void setsignal(int);
void ignoresig(int);
+int issigchldtrapped(void);
void onsig(int);
void dotrap(void);
void setinteractive(int);
diff --git a/bin/sh/var.c b/bin/sh/var.c
index 6041459e6864..48a0dc5d3e25 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -640,10 +640,11 @@ showvarscmd(int argc __unused, char **argv __unused)
*/
int
-exportcmd(int argc, char **argv)
+exportcmd(int argc __unused, char **argv)
{
struct var **vpp;
struct var *vp;
+ char **ap;
char *name;
char *p;
char *cmdname;
@@ -651,26 +652,19 @@ exportcmd(int argc, char **argv)
int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
cmdname = argv[0];
- optreset = optind = 1;
- opterr = 0;
values = 0;
- while ((ch = getopt(argc, argv, "p")) != -1) {
+ while ((ch = nextopt("p")) != '\0') {
switch (ch) {
case 'p':
values = 1;
break;
- case '?':
- default:
- error("unknown option: -%c", optopt);
}
}
- argc -= optind;
- argv += optind;
- if (values && argc != 0)
+ if (values && *argptr != NULL)
error("-p requires no arguments");
- if (argc != 0) {
- while ((name = *argv++) != NULL) {
+ if (*argptr != NULL) {
+ for (ap = argptr; (name = *ap) != NULL; ap++) {
if ((p = strchr(name, '=')) != NULL) {
p++;
} else {
diff --git a/bin/stty/extern.h b/bin/stty/extern.h
index 8d0657cd0a9f..7c484a25159d 100644
--- a/bin/stty/extern.h
+++ b/bin/stty/extern.h
@@ -40,6 +40,6 @@ int ksearch(char ***, struct info *);
int msearch(char ***, struct info *);
void optlist(void);
void print(struct termios *, struct winsize *, int, enum FMT);
-void usage(void);
+void usage(void) __dead2;
extern struct cchar cchars1[], cchars2[];