summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authoryar <yar@FreeBSD.org>2006-11-23 11:55:17 +0000
committeryar <yar@FreeBSD.org>2006-11-23 11:55:17 +0000
commitaf6cce5172606f7b47cb3d610fc2b8c9fa08b79c (patch)
tree8ccb68474bfd6de2bc2eaba6ee731a4e44618f92 /usr.bin
parent75d7b09c83861e14ce15d3c488d180f094455382 (diff)
downloadFreeBSD-src-af6cce5172606f7b47cb3d610fc2b8c9fa08b79c.zip
FreeBSD-src-af6cce5172606f7b47cb3d610fc2b8c9fa08b79c.tar.gz
Fix and extend the -j option to pkill/pgrep WRT the jail
wildcard specifications. Earlier the only wildcard syntax was "-j 0" for "any jail". There were at least two shortcomings in it: First, jail ID 0 was abused; it meant "no jail" in other utils, e.g., ps(1). Second, it was impossible to match processed not in jail, which could be useful to rc.d developers. Therefore a new syntax is introduced: "-j any" means any jail while "-j none" means out of jail. The old syntax is preserved for compatibility, but now it's deprecated because it's limited and confusing. Update the respective regression tests. While I'm here, make the tests more complex but sensitive: Start several processes, some in jail and some out of jail, so we can detect that only the right processes are killed by pkill or matched by pgrep. Reviewed by: gad, pjd MFC after: 1 week
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/pkill/pkill.121
-rw-r--r--usr.bin/pkill/pkill.c32
2 files changed, 44 insertions, 9 deletions
diff --git a/usr.bin/pkill/pkill.1 b/usr.bin/pkill/pkill.1
index 7db3307..cf202fd 100644
--- a/usr.bin/pkill/pkill.1
+++ b/usr.bin/pkill/pkill.1
@@ -36,7 +36,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd November 16, 2005
+.Dd November 23, 2006
.Dt PKILL 1
.Os
.Sh NAME
@@ -146,7 +146,12 @@ Ignore case distinctions in both the process table and the supplied pattern.
Restrict matches to processes inside jails with a jail ID in the comma-separated
list
.Ar jid .
-The value zero is taken to mean any jail ID.
+The value
+.Dq Li any
+matches processes in any jail.
+The value
+.Dq Li none
+matches processes not in jail.
.It Fl l
Long output.
Print the process name in addition to the process ID for each matching
@@ -240,6 +245,18 @@ Invalid options were specified on the command line.
.It 3
An internal error occurred.
.El
+.Sh COMPATIBILITY
+Historically the option
+.Dq Fl j Li 0
+means any jail, although in other utilities such as
+.Xr ps 1
+jail ID
+.Li 0
+has the opposite meaning, not in jail.
+Therefore
+.Dq Fl j Li 0
+is deprecated, and its use is discouraged in favor of
+.Dq Fl j Li any .
.Sh SEE ALSO
.Xr kill 1 ,
.Xr killall 1 ,
diff --git a/usr.bin/pkill/pkill.c b/usr.bin/pkill/pkill.c
index 94bc70c..2547744 100644
--- a/usr.bin/pkill/pkill.c
+++ b/usr.bin/pkill/pkill.c
@@ -84,6 +84,7 @@ enum listtype {
LT_GROUP,
LT_TTY,
LT_PGRP,
+ LT_JID,
LT_SID
};
@@ -235,7 +236,7 @@ main(int argc, char **argv)
cflags |= REG_ICASE;
break;
case 'j':
- makelist(&jidlist, LT_GENERIC, optarg);
+ makelist(&jidlist, LT_JID, optarg);
criteria = 1;
break;
case 'l':
@@ -451,12 +452,12 @@ main(int argc, char **argv)
}
SLIST_FOREACH(li, &jidlist, li_chain) {
- if (kp->ki_jid > 0) {
- if (li->li_number == 0)
- break;
- if (kp->ki_jid == (int)li->li_number)
- break;
- }
+ /* A particular jail ID, including 0 (not in jail) */
+ if (kp->ki_jid == (int)li->li_number)
+ break;
+ /* Any jail */
+ if (kp->ki_jid > 0 && li->li_number == -1)
+ break;
}
if (SLIST_FIRST(&jidlist) != NULL && li == NULL) {
selected[i] = 0;
@@ -636,6 +637,14 @@ makelist(struct listhead *head, enum listtype type, char *src)
if (li->li_number == 0)
li->li_number = getsid(mypid);
break;
+ case LT_JID:
+ if (li->li_number < 0)
+ errx(STATUS_BADUSAGE,
+ "Negative jail ID `%s'", sp);
+ /* For compatibility with old -j */
+ if (li->li_number == 0)
+ li->li_number = -1; /* any jail */
+ break;
case LT_TTY:
usage();
/* NOTREACHED */
@@ -683,6 +692,15 @@ makelist(struct listhead *head, enum listtype type, char *src)
li->li_number = st.st_rdev;
break;
+ case LT_JID:
+ if (strcmp(sp, "none") == 0)
+ li->li_number = 0;
+ else if (strcmp(sp, "any") == 0)
+ li->li_number = -1;
+ else if (*ep != '\0')
+ errx(STATUS_BADUSAGE,
+ "Invalid jail ID `%s'", sp);
+ break;
default:
usage();
}
OpenPOWER on IntegriCloud