diff options
author | sjg <sjg@FreeBSD.org> | 2014-05-08 23:54:15 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2014-05-08 23:54:15 +0000 |
commit | ed3fc70bf5a8edaf648093b11acca450802244ef (patch) | |
tree | 8ce0ddd0e6f508bd20c77429c448969589170fae /bin | |
parent | d4e443e0426fee44056ba3c1123455666d083aef (diff) | |
parent | a2e6be0add027bf3e713c0d56ba9715b83a01144 (diff) | |
download | FreeBSD-src-ed3fc70bf5a8edaf648093b11acca450802244ef.zip FreeBSD-src-ed3fc70bf5a8edaf648093b11acca450802244ef.tar.gz |
Merge from head
Diffstat (limited to 'bin')
-rw-r--r-- | bin/Makefile | 2 | ||||
-rw-r--r-- | bin/Makefile.inc | 2 | ||||
-rw-r--r-- | bin/csh/Makefile | 2 | ||||
-rw-r--r-- | bin/date/Makefile | 2 | ||||
-rw-r--r-- | bin/dd/conv.c | 2 | ||||
-rw-r--r-- | bin/dd/dd.c | 74 | ||||
-rw-r--r-- | bin/dd/dd.h | 4 | ||||
-rw-r--r-- | bin/dd/misc.c | 20 | ||||
-rw-r--r-- | bin/ed/Makefile | 2 | ||||
-rw-r--r-- | bin/ls/Makefile | 2 | ||||
-rw-r--r-- | bin/mv/Makefile | 2 | ||||
-rw-r--r-- | bin/pax/Makefile | 2 | ||||
-rw-r--r-- | bin/pkill/Makefile | 2 | ||||
-rw-r--r-- | bin/ps/Makefile | 4 | ||||
-rw-r--r-- | bin/ps/ps.1 | 19 | ||||
-rw-r--r-- | bin/ps/ps.c | 46 | ||||
-rw-r--r-- | bin/sh/Makefile | 2 | ||||
-rw-r--r-- | bin/sh/tests/builtins/Makefile | 3 | ||||
-rw-r--r-- | bin/sh/tests/builtins/getopts3.0 | 6 | ||||
-rw-r--r-- | bin/sh/tests/builtins/getopts4.0 | 10 | ||||
-rw-r--r-- | bin/sh/tests/builtins/getopts5.0 | 10 | ||||
-rw-r--r-- | bin/test/Makefile | 2 |
22 files changed, 164 insertions, 56 deletions
diff --git a/bin/Makefile b/bin/Makefile index 63d96fe..ae509c4 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,7 +1,7 @@ # From: @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> SUBDIR= cat \ chflags \ diff --git a/bin/Makefile.inc b/bin/Makefile.inc index ec24a48..86141a1 100644 --- a/bin/Makefile.inc +++ b/bin/Makefile.inc @@ -1,7 +1,7 @@ # @(#)Makefile.inc 8.1 (Berkeley) 5/31/93 # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> BINDIR?= /bin WARNS?= 6 diff --git a/bin/csh/Makefile b/bin/csh/Makefile index 1fa24a1..c8845f9 100644 --- a/bin/csh/Makefile +++ b/bin/csh/Makefile @@ -6,7 +6,7 @@ # # To profile, put -DPROF in DEFS and -pg in CFLAGS, and recompile. -.include <bsd.own.mk> +.include <src.opts.mk> TCSHDIR= ${.CURDIR}/../../contrib/tcsh .PATH: ${TCSHDIR} diff --git a/bin/date/Makefile b/bin/date/Makefile index 6da5848..56ce33a 100644 --- a/bin/date/Makefile +++ b/bin/date/Makefile @@ -1,7 +1,7 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> PROG= date SRCS= date.c netdate.c vary.c diff --git a/bin/dd/conv.c b/bin/dd/conv.c index cd66258..2ffba1e 100644 --- a/bin/dd/conv.c +++ b/bin/dd/conv.c @@ -74,7 +74,7 @@ def(void) dd_out(0); /* - * Ddout copies the leftover output to the beginning of + * dd_out copies the leftover output to the beginning of * the buffer and resets the output buffer. Reset the * input buffer to match it. */ diff --git a/bin/dd/dd.c b/bin/dd/dd.c index 7e5bd91..8ae11a7 100644 --- a/bin/dd/dd.c +++ b/bin/dd/dd.c @@ -50,8 +50,8 @@ __FBSDID("$FreeBSD$"); #include <sys/conf.h> #include <sys/disklabel.h> #include <sys/filio.h> -#include <sys/time.h> +#include <assert.h> #include <ctype.h> #include <err.h> #include <errno.h> @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #include "dd.h" @@ -76,6 +77,7 @@ STAT st; /* statistics */ void (*cfunc)(void); /* conversion function */ uintmax_t cpy_cnt; /* # of blocks to copy */ static off_t pending = 0; /* pending seek if sparse */ +static off_t last_sp = 0; /* size of last added sparse block */ u_int ddflags = 0; /* conversion options */ size_t cbsz; /* conversion block size */ uintmax_t files_cnt = 1; /* # of files to copy */ @@ -123,7 +125,6 @@ static void setup(void) { u_int cnt; - struct timeval tv; if (in.name == NULL) { in.name = "stdin"; @@ -173,6 +174,8 @@ setup(void) } else if ((in.db = malloc(MAX(in.dbsz, cbsz) + cbsz)) == NULL || (out.db = malloc(out.dbsz + cbsz)) == NULL) err(1, "output buffer"); + + /* dbp is the first free position in each buffer. */ in.dbp = in.db; out.dbp = out.db; @@ -240,8 +243,8 @@ setup(void) ctab = casetab; } - (void)gettimeofday(&tv, NULL); - st.start = tv.tv_sec + tv.tv_usec * 1e-6; + if (clock_gettime(CLOCK_MONOTONIC, &st.start)) + err(1, "clock_gettime"); } static void @@ -434,8 +437,15 @@ dd_out(int force) * we play games with the buffer size, and it's usually a partial write. */ outp = out.db; + + /* + * If force, first try to write all pending data, else try to write + * just one block. Subsequently always write data one full block at + * a time at most. + */ for (n = force ? out.dbcnt : out.dbsz;; n = out.dbsz) { - for (cnt = n;; cnt -= nw) { + cnt = n; + do { sparse = 0; if (ddflags & C_SPARSE) { sparse = 1; /* Is buffer sparse? */ @@ -447,18 +457,24 @@ dd_out(int force) } if (sparse && !force) { pending += cnt; + last_sp = cnt; nw = cnt; } else { if (pending != 0) { - if (force) - pending--; + /* If forced to write, and we have no + * data left, we need to write the last + * sparse block explicitly. + */ + if (force && cnt == 0) { + pending -= last_sp; + assert(outp == out.db); + memset(outp, 0, cnt); + } if (lseek(out.fd, pending, SEEK_CUR) == -1) err(2, "%s: seek error creating sparse file", out.name); - if (force) - write(out.fd, outp, 1); - pending = 0; + pending = last_sp = 0; } if (cnt) nw = write(out.fd, outp, cnt); @@ -473,27 +489,29 @@ dd_out(int force) err(1, "%s", out.name); nw = 0; } + outp += nw; st.bytes += nw; - if ((size_t)nw == n) { - if (n != out.dbsz) - ++st.out_part; - else - ++st.out_full; - break; - } - ++st.out_part; - if ((size_t)nw == cnt) - break; - if (out.flags & ISTAPE) - errx(1, "%s: short write on tape device", - out.name); - if (out.flags & ISCHR && !warned) { - warned = 1; - warnx("%s: short write on character device", - out.name); + + if ((size_t)nw == n && n == out.dbsz) + ++st.out_full; + else + ++st.out_part; + + if ((size_t) nw != cnt) { + if (out.flags & ISTAPE) + errx(1, "%s: short write on tape device", + out.name); + if (out.flags & ISCHR && !warned) { + warned = 1; + warnx("%s: short write on character device", + out.name); + } } - } + + cnt -= nw; + } while (cnt != 0); + if ((out.dbcnt -= n) < out.dbsz) break; } diff --git a/bin/dd/dd.h b/bin/dd/dd.h index dace845..a8b45e5 100644 --- a/bin/dd/dd.h +++ b/bin/dd/dd.h @@ -41,7 +41,7 @@ typedef struct { /* XXX ssize_t? */ size_t dbcnt; /* current buffer byte count */ size_t dbrcnt; /* last read byte count */ - size_t dbsz; /* buffer size */ + size_t dbsz; /* block size */ #define ISCHR 0x01 /* character device (warn on short) */ #define ISPIPE 0x02 /* pipe-like (see position.c) */ @@ -64,7 +64,7 @@ typedef struct { uintmax_t trunc; /* # of truncated records */ uintmax_t swab; /* # of odd-length swab blocks */ uintmax_t bytes; /* # of bytes written */ - double start; /* start time of dd */ + struct timespec start; /* start time of dd */ } STAT; /* Flags (in ddflags). */ diff --git a/bin/dd/misc.c b/bin/dd/misc.c index 61f843b..eb1227b 100644 --- a/bin/dd/misc.c +++ b/bin/dd/misc.c @@ -40,14 +40,15 @@ static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; __FBSDID("$FreeBSD$"); #include <sys/types.h> -#include <sys/time.h> +#include <err.h> #include <errno.h> #include <inttypes.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #include "dd.h" @@ -56,16 +57,21 @@ __FBSDID("$FreeBSD$"); void summary(void) { - struct timeval tv; - double secs; + struct timespec end, ts_res; + double secs, res; if (ddflags & C_NOINFO) return; - (void)gettimeofday(&tv, NULL); - secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start; - if (secs < 1e-6) - secs = 1e-6; + if (clock_gettime(CLOCK_MONOTONIC, &end)) + err(1, "clock_gettime"); + if (clock_getres(CLOCK_MONOTONIC, &ts_res)) + err(1, "clock_getres"); + secs = (end.tv_sec - st.start.tv_sec) + \ + (end.tv_nsec - st.start.tv_nsec) * 1e-9; + res = ts_res.tv_sec + ts_res.tv_nsec * 1e-9; + if (secs < res) + secs = res; (void)fprintf(stderr, "%ju+%ju records in\n%ju+%ju records out\n", st.in_full, st.in_part, st.out_full, st.out_part); diff --git a/bin/ed/Makefile b/bin/ed/Makefile index 7c39e54..fb1c37d 100644 --- a/bin/ed/Makefile +++ b/bin/ed/Makefile @@ -1,6 +1,6 @@ # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> PROG= ed SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c diff --git a/bin/ls/Makefile b/bin/ls/Makefile index 4d02a7e..7149d91 100644 --- a/bin/ls/Makefile +++ b/bin/ls/Makefile @@ -1,7 +1,7 @@ # @(#)Makefile 8.1 (Berkeley) 6/2/93 # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> PROG= ls SRCS= cmp.c ls.c print.c util.c diff --git a/bin/mv/Makefile b/bin/mv/Makefile index ad8cc4f..02a5a48 100644 --- a/bin/mv/Makefile +++ b/bin/mv/Makefile @@ -1,7 +1,7 @@ # @(#)Makefile 8.2 (Berkeley) 4/2/94 # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> PROG= mv diff --git a/bin/pax/Makefile b/bin/pax/Makefile index 95f18bb..c00d52c 100644 --- a/bin/pax/Makefile +++ b/bin/pax/Makefile @@ -1,7 +1,7 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> # To install on versions prior to BSD 4.4 the following may have to be # defined with CFLAGS += diff --git a/bin/pkill/Makefile b/bin/pkill/Makefile index bb4d865..11bfbe3 100644 --- a/bin/pkill/Makefile +++ b/bin/pkill/Makefile @@ -1,7 +1,7 @@ # $NetBSD: Makefile,v 1.1 2002/03/01 11:21:58 ad Exp $ # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> PROG= pkill diff --git a/bin/ps/Makefile b/bin/ps/Makefile index 9be1979..5ba4f2f 100644 --- a/bin/ps/Makefile +++ b/bin/ps/Makefile @@ -11,7 +11,7 @@ SRCS= fmt.c keyword.c nlist.c print.c ps.c # on large systems. # CFLAGS+=-DLAZY_PS -DPADD= ${LIBM} ${LIBKVM} -LDADD= -lm -lkvm +DPADD= ${LIBM} ${LIBKVM} ${LIBJAIL} +LDADD= -lm -lkvm -ljail .include <bsd.prog.mk> diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 118e961..c4239ea 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 December 27, 2013 +.Dd May 2, 2014 .Dt PS 1 .Os .Sh NAME @@ -40,6 +40,7 @@ .Op Fl aCcdefHhjlmrSTuvwXxZ .Op Fl O Ar fmt | Fl o Ar fmt .Op Fl G Ar gid Ns Op , Ns Ar gid Ns Ar ... +.Op Fl J Ar jid Ns Op , Ns Ar jid Ns Ar ... .Op Fl M Ar core .Op Fl N Ar system .Op Fl p Ar pid Ns Op , Ns Ar pid Ns Ar ... @@ -62,7 +63,7 @@ will also display processes that do not have controlling terminals. .Pp A different set of processes can be selected for display by using any combination of the -.Fl a , G , p , T , t , +.Fl a , G , J , p , T , t , and .Fl U options. @@ -152,6 +153,20 @@ Print information associated with the following keywords: .Cm user , pid , ppid , pgid , sid , jobc , state , tt , time , and .Cm command . +.It Fl J +Display information about processes which match the specified jail IDs. +This may be either the +.Cm jid +or +.Cm name +of the jail. +Use +.Fl J +.Sy 0 +to display only host processes. +This flag implies +.Fl x +by default. .It Fl L List the set of keywords available for the .Fl O diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 7099cc0..9d14a72c 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -50,6 +50,7 @@ static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; __FBSDID("$FreeBSD$"); #include <sys/param.h> +#include <sys/jail.h> #include <sys/proc.h> #include <sys/user.h> #include <sys/stat.h> @@ -62,6 +63,7 @@ __FBSDID("$FreeBSD$"); #include <errno.h> #include <fcntl.h> #include <grp.h> +#include <jail.h> #include <kvm.h> #include <limits.h> #include <locale.h> @@ -124,6 +126,7 @@ struct listinfo { const char *lname; union { gid_t *gids; + int *jids; pid_t *pids; dev_t *ttys; uid_t *uids; @@ -132,6 +135,7 @@ struct listinfo { }; static int addelem_gid(struct listinfo *, const char *); +static int addelem_jid(struct listinfo *, const char *); static int addelem_pid(struct listinfo *, const char *); static int addelem_tty(struct listinfo *, const char *); static int addelem_uid(struct listinfo *, const char *); @@ -163,12 +167,12 @@ static char vfmt[] = "pid,state,time,sl,re,pagein,vsz,rss,lim,tsiz," "%cpu,%mem,command"; static char Zfmt[] = "label"; -#define PS_ARGS "AaCcde" OPT_LAZY_f "G:gHhjLlM:mN:O:o:p:rSTt:U:uvwXxZ" +#define PS_ARGS "AaCcde" OPT_LAZY_f "G:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ" int main(int argc, char *argv[]) { - struct listinfo gidlist, pgrplist, pidlist; + struct listinfo gidlist, jidlist, pgrplist, pidlist; struct listinfo ruidlist, sesslist, ttylist, uidlist; struct kinfo_proc *kp; KINFO *kinfo = NULL, *next_KINFO; @@ -208,6 +212,7 @@ main(int argc, char *argv[]) prtheader = showthreads = wflag = xkeep_implied = 0; xkeep = -1; /* Neither -x nor -X. */ init_list(&gidlist, addelem_gid, sizeof(gid_t), "group"); + init_list(&jidlist, addelem_jid, sizeof(int), "jail id"); init_list(&pgrplist, addelem_pid, sizeof(pid_t), "process group"); init_list(&pidlist, addelem_pid, sizeof(pid_t), "process id"); init_list(&ruidlist, addelem_uid, sizeof(uid_t), "ruser"); @@ -275,6 +280,11 @@ main(int argc, char *argv[]) case 'h': prtheader = ws.ws_row > 5 ? ws.ws_row : 22; break; + case 'J': + add_list(&jidlist, optarg); + xkeep_implied = 1; + nselectors++; + break; case 'j': parsefmt(jfmt, 0); _fmt = 1; @@ -538,6 +548,11 @@ main(int argc, char *argv[]) if (kp->ki_rgid == gidlist.l.gids[elem]) goto keepit; } + if (jidlist.count > 0) { + for (elem = 0; elem < jidlist.count; elem++) + if (kp->ki_jid == jidlist.l.jids[elem]) + goto keepit; + } if (pgrplist.count > 0) { for (elem = 0; elem < pgrplist.count; elem++) if (kp->ki_pgid == @@ -666,6 +681,7 @@ main(int argc, char *argv[]) } } free_list(&gidlist); + free_list(&jidlist); free_list(&pidlist); free_list(&pgrplist); free_list(&ruidlist); @@ -727,6 +743,30 @@ addelem_gid(struct listinfo *inf, const char *elem) } static int +addelem_jid(struct listinfo *inf, const char *elem) +{ + int tempid; + + if (*elem == '\0') { + warnx("Invalid (zero-length) jail id"); + optfatal = 1; + return (0); /* Do not add this value. */ + } + + tempid = jail_getid(elem); + if (tempid < 0) { + warnx("Invalid %s: %s", inf->lname, elem); + optfatal = 1; + return (0); + } + + if (inf->count >= inf->maxcount) + expand_list(inf); + inf->l.jids[(inf->count)++] = tempid; + return (1); +} + +static int addelem_pid(struct listinfo *inf, const char *elem) { char *endp; @@ -1373,7 +1413,7 @@ usage(void) (void)fprintf(stderr, "%s\n%s\n%s\n%s\n", "usage: ps " SINGLE_OPTS " [-O fmt | -o fmt] [-G gid[,gid...]]", - " [-M core] [-N system]", + " [-J jid[,jid...]] [-M core] [-N system]", " [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]", " ps [-L]"); exit(1); diff --git a/bin/sh/Makefile b/bin/sh/Makefile index e1ce5fe..6a982bc 100644 --- a/bin/sh/Makefile +++ b/bin/sh/Makefile @@ -1,7 +1,7 @@ # @(#)Makefile 8.4 (Berkeley) 5/5/95 # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> PROG= sh INSTALLFLAGS= -S diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile index 945a14d..c0b21dc 100644 --- a/bin/sh/tests/builtins/Makefile +++ b/bin/sh/tests/builtins/Makefile @@ -80,6 +80,9 @@ FILES+= for2.0 FILES+= for3.0 FILES+= getopts1.0 getopts1.0.stdout FILES+= getopts2.0 getopts2.0.stdout +FILES+= getopts3.0 +FILES+= getopts4.0 +FILES+= getopts5.0 FILES+= hash1.0 hash1.0.stdout FILES+= hash2.0 hash2.0.stdout FILES+= hash3.0 hash3.0.stdout diff --git a/bin/sh/tests/builtins/getopts3.0 b/bin/sh/tests/builtins/getopts3.0 new file mode 100644 index 0000000..d02469b --- /dev/null +++ b/bin/sh/tests/builtins/getopts3.0 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +shift $# +getopts x opt +r=$? +[ "$r" != 0 ] && [ "$OPTIND" = 1 ] diff --git a/bin/sh/tests/builtins/getopts4.0 b/bin/sh/tests/builtins/getopts4.0 new file mode 100644 index 0000000..61d5c2b --- /dev/null +++ b/bin/sh/tests/builtins/getopts4.0 @@ -0,0 +1,10 @@ +# $FreeBSD$ + +set -- -x +opt=not +getopts x opt +r1=$? OPTIND1=$OPTIND opt1=$opt +getopts x opt +r2=$? OPTIND2=$OPTIND +[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] && + [ "$OPTIND2" = 2 ] diff --git a/bin/sh/tests/builtins/getopts5.0 b/bin/sh/tests/builtins/getopts5.0 new file mode 100644 index 0000000..666ee76 --- /dev/null +++ b/bin/sh/tests/builtins/getopts5.0 @@ -0,0 +1,10 @@ +# $FreeBSD$ + +set -- -x arg +opt=not +getopts x opt +r1=$? OPTIND1=$OPTIND opt1=$opt +getopts x opt +r2=$? OPTIND2=$OPTIND +[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] && + [ "$OPTIND2" = 2 ] diff --git a/bin/test/Makefile b/bin/test/Makefile index e9a0507..8e3121b 100644 --- a/bin/test/Makefile +++ b/bin/test/Makefile @@ -1,7 +1,7 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD$ -.include <bsd.own.mk> +.include <src.opts.mk> PROG= test LINKS= ${BINDIR}/test ${BINDIR}/[ |