View | Details | Raw Unified | Return to bug 201588 | Differences between
and this patch

Collapse All | Expand All

(-)Makefile (-1 / +1 lines)
Lines 5-11 Link Here
5
5
6
PROG=	pkill
6
PROG=	pkill
7
7
8
LIBADD=	kvm
8
LIBADD=	kvm jail
9
9
10
LINKS=	${BINDIR}/pkill ${BINDIR}/pgrep
10
LINKS=	${BINDIR}/pkill ${BINDIR}/pgrep
11
MLINKS=	pkill.1 pgrep.1
11
MLINKS=	pkill.1 pgrep.1
(-)Makefile.depend (+1 lines)
Lines 9-14 DIRDEPS = \ Link Here
9
	lib/${CSU_DIR} \
9
	lib/${CSU_DIR} \
10
	lib/libc \
10
	lib/libc \
11
	lib/libcompiler_rt \
11
	lib/libcompiler_rt \
12
	lib/libjail \
12
	lib/libkvm \
13
	lib/libkvm \
13
14
14
15
(-)pkill.1 (-10 / +11 lines)
Lines 47-53 Link Here
47
.Op Fl c Ar class
47
.Op Fl c Ar class
48
.Op Fl d Ar delim
48
.Op Fl d Ar delim
49
.Op Fl g Ar pgrp
49
.Op Fl g Ar pgrp
50
.Op Fl j Ar jid
50
.Op Fl j Ar jail
51
.Op Fl s Ar sid
51
.Op Fl s Ar sid
52
.Op Fl t Ar tty
52
.Op Fl t Ar tty
53
.Op Fl u Ar euid
53
.Op Fl u Ar euid
Lines 63-69 Link Here
63
.Op Fl U Ar uid
63
.Op Fl U Ar uid
64
.Op Fl c Ar class
64
.Op Fl c Ar class
65
.Op Fl g Ar pgrp
65
.Op Fl g Ar pgrp
66
.Op Fl j Ar jid
66
.Op Fl j Ar jail
67
.Op Fl s Ar sid
67
.Op Fl s Ar sid
68
.Op Fl t Ar tty
68
.Op Fl t Ar tty
69
.Op Fl u Ar euid
69
.Op Fl u Ar euid
Lines 149-164 or Link Here
149
command.
149
command.
150
.It Fl i
150
.It Fl i
151
Ignore case distinctions in both the process table and the supplied pattern.
151
Ignore case distinctions in both the process table and the supplied pattern.
152
.It Fl j Ar jid
152
.It Fl j Ar jail
153
Restrict matches to processes inside jails with a jail ID in the comma-separated
153
Restrict matches to processes inside the specified jails.
154
list
154
The argument
155
.Ar jid .
155
.Ar jail
156
The value
156
may be
157
.Dq Li any
157
.Dq Li any
158
matches processes in any jail.
158
to match processes in any jail,
159
The value
160
.Dq Li none
159
.Dq Li none
161
matches processes not in jail.
160
to match processes not in jail,
161
or
162
a comma-separated list of jail IDs or names.
162
.It Fl l
163
.It Fl l
163
Long output.
164
Long output.
164
For
165
For
(-)pkill.c (-4 / +10 lines)
Lines 41-46 __FBSDID("$FreeBSD$"); Link Here
41
#include <sys/stat.h>
41
#include <sys/stat.h>
42
#include <sys/time.h>
42
#include <sys/time.h>
43
#include <sys/user.h>
43
#include <sys/user.h>
44
#include <sys/jail.h>
44
45
45
#include <assert.h>
46
#include <assert.h>
46
#include <stdio.h>
47
#include <stdio.h>
Lines 59-64 __FBSDID("$FreeBSD$"); Link Here
59
#include <grp.h>
60
#include <grp.h>
60
#include <errno.h>
61
#include <errno.h>
61
#include <locale.h>
62
#include <locale.h>
63
#include <jail.h>
62
64
63
#define	STATUS_MATCH	0
65
#define	STATUS_MATCH	0
64
#define	STATUS_NOMATCH	1
66
#define	STATUS_NOMATCH	1
Lines 78-84 enum listtype { Link Here
78
	LT_GROUP,
80
	LT_GROUP,
79
	LT_TTY,
81
	LT_TTY,
80
	LT_PGRP,
82
	LT_PGRP,
81
	LT_JID,
83
	LT_JID, /* jid or jname */
82
	LT_SID,
84
	LT_SID,
83
	LT_CLASS
85
	LT_CLASS
84
};
86
};
Lines 585-591 usage(void) Link Here
585
587
586
	fprintf(stderr,
588
	fprintf(stderr,
587
		"usage: %s %s [-F pidfile] [-G gid] [-M core] [-N system]\n"
589
		"usage: %s %s [-F pidfile] [-G gid] [-M core] [-N system]\n"
588
		"             [-P ppid] [-U uid] [-c class] [-g pgrp] [-j jid]\n"
590
		"             [-P ppid] [-U uid] [-c class] [-g pgrp] [-j jail]\n"
589
		"             [-s sid] [-t tty] [-u euid] pattern ...\n",
591
		"             [-s sid] [-t tty] [-u euid] pattern ...\n",
590
		getprogname(), ustr);
592
		getprogname(), ustr);
591
593
Lines 766-780 foundtty: if ((st.st_mode & S_IFCHR) == 0) Link Here
766
768
767
			li->li_number = st.st_rdev;
769
			li->li_number = st.st_rdev;
768
			break;
770
			break;
769
		case LT_JID:
771
		case LT_JID: {
772
			int jid;
770
			if (strcmp(sp, "none") == 0)
773
			if (strcmp(sp, "none") == 0)
771
				li->li_number = 0;
774
				li->li_number = 0;
772
			else if (strcmp(sp, "any") == 0)
775
			else if (strcmp(sp, "any") == 0)
773
				li->li_number = -1;
776
				li->li_number = -1;
777
			else if ((jid = jail_getid(sp)) != -1)
778
				li->li_number = jid;
774
			else if (*ep != '\0')
779
			else if (*ep != '\0')
775
				errx(STATUS_BADUSAGE,
780
				errx(STATUS_BADUSAGE,
776
				     "Invalid jail ID `%s'", sp);
781
				     "Invalid jail ID or name `%s'", sp);
777
			break;
782
			break;
783
		}
778
		case LT_CLASS:
784
		case LT_CLASS:
779
			li->li_number = -1;
785
			li->li_number = -1;
780
			li->li_name = strdup(sp);
786
			li->li_name = strdup(sp);
(-)tests/pgrep-j_test.sh (-1 / +26 lines)
Lines 14-20 if [ `id -u` -ne 0 ]; then Link Here
14
	exit 0
14
	exit 0
15
fi
15
fi
16
16
17
echo "1..3"
17
echo "1..4"
18
18
19
sleep=$(pwd)/sleep.txt
19
sleep=$(pwd)/sleep.txt
20
ln -sf /bin/sleep $sleep
20
ln -sf /bin/sleep $sleep
Lines 87-91 else Link Here
87
fi
87
fi
88
[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat $PWD/${base}_3_1.pid) 
88
[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat $PWD/${base}_3_1.pid) 
89
[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat $PWD/${base}_3_2.pid) 
89
[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat $PWD/${base}_3_2.pid) 
90
wait
90
91
92
# test 4 is like test 1 except with jname instead of jid.
93
name="pgrep -j <jname>"
94
sleep_amount=8
95
jail -c path=/ name=${base}_4_1 ip4.addr=127.0.0.1 \
96
    command=daemon -p ${PWD}/${base}_4_1.pid $sleep $sleep_amount &
97
98
jail -c path=/ name=${base}_4_2 ip4.addr=127.0.0.1 \
99
    command=daemon -p ${PWD}/${base}_4_2.pid $sleep $sleep_amount &
100
101
sleep 0.5
102
103
jid="${base}_4_1,${base}_4_2"
104
pid1="$(pgrep -f -x -j "$jid" "$sleep $sleep_amount" | sort)"
105
pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_4_1.pid)" \
106
    $(cat ${PWD}/${base}_4_2.pid) | sort)
107
if [ "$pid1" = "$pid2" ]; then
108
	echo "ok 4 - $name"
109
else
110
	echo "not ok 4 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
111
fi
112
[ -f ${PWD}/${base}_4_1.pid ] && kill $(cat ${PWD}/${base}_4_1.pid)
113
[ -f ${PWD}/${base}_4_2.pid ] && kill $(cat ${PWD}/${base}_4_2.pid)
114
wait
115
91
rm -f $sleep
116
rm -f $sleep
(-)tests/pkill-j_test.sh (-1 / +27 lines)
Lines 14-20 if [ `id -u` -ne 0 ]; then Link Here
14
	exit 0
14
	exit 0
15
fi
15
fi
16
16
17
echo "1..3"
17
echo "1..4"
18
18
19
sleep=$(pwd)/sleep.txt
19
sleep=$(pwd)/sleep.txt
20
ln -sf /bin/sleep $sleep
20
ln -sf /bin/sleep $sleep
Lines 90-94 else Link Here
90
fi 2>/dev/null
90
fi 2>/dev/null
91
[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid)
91
[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat ${base}_3_1.pid)
92
[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid)
92
[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat ${base}_3_2.pid)
93
wait
93
94
95
# test 4 is like test 1 except with jname instead of jid.
96
name="pkill -j <jname>"
97
sleep_amount=8
98
jail -c path=/ name=${base}_4_1 ip4.addr=127.0.0.1 \
99
    command=daemon -p ${PWD}/${base}_4_1.pid $sleep $sleep_amount &
100
101
jail -c path=/ name=${base}_4_2 ip4.addr=127.0.0.1 \
102
    command=daemon -p ${PWD}/${base}_4_2.pid $sleep $sleep_amount &
103
104
$sleep $sleep_amount &
105
106
sleep 0.5
107
108
jid="${base}_4_1,${base}_4_2"
109
if pkill -f -j "$jid" $sleep && sleep 0.5 &&
110
    ! -f ${PWD}/${base}_4_1.pid &&
111
    ! -f ${PWD}/${base}_4_2.pid ; then
112
	echo "ok 4 - $name"
113
else
114
	echo "not ok 4 - $name"
115
fi 2>/dev/null
116
[ -f ${PWD}/${base}_4_1.pid ] && kill $(cat ${PWD}/${base}_4_1.pid)
117
[ -f ${PWD}/${base}_4_2.pid ] && kill $(cat ${PWD}/${base}_4_2.pid)
118
wait
119
94
rm -f $sleep
120
rm -f $sleep

Return to bug 201588