Date: Sat, 29 Aug 2015 02:42:00 +0000 (UTC) From: Jamie Gritton <jamie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287269 - in stable/10/bin/pkill: . tests Message-ID: <201508290242.t7T2g0t5029130@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jamie Date: Sat Aug 29 02:41:59 2015 New Revision: 287269 URL: https://svnweb.freebsd.org/changeset/base/287269 Log: MFC r287012: Make pkill/pgrep -j ARG take jname, not just jid. PR: 201588 Submitted by: Daniel Shahaf <danielsh at apache.org> Modified: stable/10/bin/pkill/Makefile stable/10/bin/pkill/pkill.1 stable/10/bin/pkill/pkill.c stable/10/bin/pkill/tests/pgrep-j_test.sh stable/10/bin/pkill/tests/pkill-j_test.sh Directory Properties: stable/10/ (props changed) Modified: stable/10/bin/pkill/Makefile ============================================================================== --- stable/10/bin/pkill/Makefile Sat Aug 29 00:05:39 2015 (r287268) +++ stable/10/bin/pkill/Makefile Sat Aug 29 02:41:59 2015 (r287269) @@ -5,8 +5,8 @@ PROG= pkill -DPADD= ${LIBKVM} -LDADD= -lkvm +DPADD= ${LIBKVM} ${LIBJAIL} +LDADD= -lkvm -ljail LINKS= ${BINDIR}/pkill ${BINDIR}/pgrep MLINKS= pkill.1 pgrep.1 Modified: stable/10/bin/pkill/pkill.1 ============================================================================== --- stable/10/bin/pkill/pkill.1 Sat Aug 29 00:05:39 2015 (r287268) +++ stable/10/bin/pkill/pkill.1 Sat Aug 29 02:41:59 2015 (r287269) @@ -29,7 +29,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd August 9, 2013 +.Dd August 21, 2015 .Dt PKILL 1 .Os .Sh NAME @@ -47,7 +47,7 @@ .Op Fl c Ar class .Op Fl d Ar delim .Op Fl g Ar pgrp -.Op Fl j Ar jid +.Op Fl j Ar jail .Op Fl s Ar sid .Op Fl t Ar tty .Op Fl u Ar euid @@ -63,7 +63,7 @@ .Op Fl U Ar uid .Op Fl c Ar class .Op Fl g Ar pgrp -.Op Fl j Ar jid +.Op Fl j Ar jail .Op Fl s Ar sid .Op Fl t Ar tty .Op Fl u Ar euid @@ -149,16 +149,16 @@ or command. .It Fl i Ignore case distinctions in both the process table and the supplied pattern. -.It Fl j Ar jid -Restrict matches to processes inside jails with a jail ID in the comma-separated -list -.Ar jid . -The value +.It Fl j Ar jail +Restrict matches to processes inside the specified jails. +The argument +.Ar jail +may be .Dq Li any -matches processes in any jail. -The value +to match processes in any jail, .Dq Li none -matches processes not in jail. +to match processes not in jail, +or a comma-separated list of jail IDs or names. .It Fl l Long output. For Modified: stable/10/bin/pkill/pkill.c ============================================================================== --- stable/10/bin/pkill/pkill.c Sat Aug 29 00:05:39 2015 (r287268) +++ stable/10/bin/pkill/pkill.c Sat Aug 29 02:41:59 2015 (r287269) @@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$"); #include <grp.h> #include <errno.h> #include <locale.h> +#include <jail.h> #define STATUS_MATCH 0 #define STATUS_NOMATCH 1 @@ -78,7 +79,7 @@ enum listtype { LT_GROUP, LT_TTY, LT_PGRP, - LT_JID, + LT_JAIL, LT_SID, LT_CLASS }; @@ -245,7 +246,7 @@ main(int argc, char **argv) cflags |= REG_ICASE; break; case 'j': - makelist(&jidlist, LT_JID, optarg); + makelist(&jidlist, LT_JAIL, optarg); criteria = 1; break; case 'l': @@ -582,7 +583,7 @@ usage(void) fprintf(stderr, "usage: %s %s [-F pidfile] [-G gid] [-M core] [-N system]\n" - " [-P ppid] [-U uid] [-c class] [-g pgrp] [-j jid]\n" + " [-P ppid] [-U uid] [-c class] [-g pgrp] [-j jail]\n" " [-s sid] [-t tty] [-u euid] pattern ...\n", getprogname(), ustr); @@ -697,7 +698,7 @@ makelist(struct listhead *head, enum lis if (li->li_number == 0) li->li_number = getsid(mypid); break; - case LT_JID: + case LT_JAIL: if (li->li_number < 0) errx(STATUS_BADUSAGE, "Negative jail ID `%s'", sp); @@ -763,15 +764,20 @@ foundtty: if ((st.st_mode & S_IFCHR) == li->li_number = st.st_rdev; break; - case LT_JID: + case LT_JAIL: { + int jid; + if (strcmp(sp, "none") == 0) li->li_number = 0; else if (strcmp(sp, "any") == 0) li->li_number = -1; + else if ((jid = jail_getid(sp)) != -1) + li->li_number = jid; else if (*ep != '\0') errx(STATUS_BADUSAGE, - "Invalid jail ID `%s'", sp); + "Invalid jail ID or name `%s'", sp); break; + } case LT_CLASS: li->li_number = -1; li->li_name = strdup(sp); Modified: stable/10/bin/pkill/tests/pgrep-j_test.sh ============================================================================== --- stable/10/bin/pkill/tests/pgrep-j_test.sh Sat Aug 29 00:05:39 2015 (r287268) +++ stable/10/bin/pkill/tests/pgrep-j_test.sh Sat Aug 29 02:41:59 2015 (r287269) @@ -14,7 +14,7 @@ if [ `id -u` -ne 0 ]; then exit 0 fi -echo "1..3" +echo "1..4" sleep=$(pwd)/sleep.txt ln -sf /bin/sleep $sleep @@ -87,5 +87,30 @@ else 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) +wait + +# test 4 is like test 1 except with jname instead of jid. +name="pgrep -j <jname>" +sleep_amount=8 +jail -c path=/ name=${base}_4_1 ip4.addr=127.0.0.1 \ + command=daemon -p ${PWD}/${base}_4_1.pid $sleep $sleep_amount & + +jail -c path=/ name=${base}_4_2 ip4.addr=127.0.0.1 \ + command=daemon -p ${PWD}/${base}_4_2.pid $sleep $sleep_amount & + +sleep 0.5 + +jname="${base}_4_1,${base}_4_2" +pid1="$(pgrep -f -x -j "$jname" "$sleep $sleep_amount" | sort)" +pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_4_1.pid)" \ + $(cat ${PWD}/${base}_4_2.pid) | sort) +if [ "$pid1" = "$pid2" ]; then + echo "ok 4 - $name" +else + echo "not ok 4 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'" +fi +[ -f ${PWD}/${base}_4_1.pid ] && kill $(cat ${PWD}/${base}_4_1.pid) +[ -f ${PWD}/${base}_4_2.pid ] && kill $(cat ${PWD}/${base}_4_2.pid) +wait rm -f $sleep Modified: stable/10/bin/pkill/tests/pkill-j_test.sh ============================================================================== --- stable/10/bin/pkill/tests/pkill-j_test.sh Sat Aug 29 00:05:39 2015 (r287268) +++ stable/10/bin/pkill/tests/pkill-j_test.sh Sat Aug 29 02:41:59 2015 (r287269) @@ -14,7 +14,7 @@ if [ `id -u` -ne 0 ]; then exit 0 fi -echo "1..3" +echo "1..4" sleep=$(pwd)/sleep.txt ln -sf /bin/sleep $sleep @@ -90,5 +90,31 @@ else 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) +wait + +# test 4 is like test 1 except with jname instead of jid. +name="pkill -j <jname>" +sleep_amount=8 +jail -c path=/ name=${base}_4_1 ip4.addr=127.0.0.1 \ + command=daemon -p ${PWD}/${base}_4_1.pid $sleep $sleep_amount & + +jail -c path=/ name=${base}_4_2 ip4.addr=127.0.0.1 \ + command=daemon -p ${PWD}/${base}_4_2.pid $sleep $sleep_amount & + +$sleep $sleep_amount & + +sleep 0.5 + +jname="${base}_4_1,${base}_4_2" +if pkill -f -j "$jname" $sleep && sleep 0.5 && + ! -f ${PWD}/${base}_4_1.pid && + ! -f ${PWD}/${base}_4_2.pid ; then + echo "ok 4 - $name" +else + echo "not ok 4 - $name" +fi 2>/dev/null +[ -f ${PWD}/${base}_4_1.pid ] && kill $(cat ${PWD}/${base}_4_1.pid) +[ -f ${PWD}/${base}_4_2.pid ] && kill $(cat ${PWD}/${base}_4_2.pid) +wait rm -f $sleep
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508290242.t7T2g0t5029130>