Deleted Added
sdiff udiff text old ( 302408 ) new ( 302954 )
full compact
1/*-
2 * Copyright (c) 2011 James Gritton
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/11/usr.sbin/jail/command.c 302954 2016-07-17 14:06:17Z jamie $");
29
30#include <sys/types.h>
31#include <sys/event.h>
32#include <sys/mount.h>
33#include <sys/stat.h>
34#include <sys/sysctl.h>
35#include <sys/user.h>
36#include <sys/wait.h>

--- 50 unchanged lines hidden (view full) ---

87 */
88int
89next_command(struct cfjail *j)
90{
91 enum intparam comparam;
92 int create_failed, stopping;
93
94 if (paralimit == 0) {
95 if (j->flags & JF_FROM_RUNQ)
96 requeue_head(j, &runnable);
97 else
98 requeue(j, &runnable);
99 return 1;
100 }
101 j->flags &= ~JF_FROM_RUNQ;
102 create_failed = (j->flags & (JF_STOP | JF_FAILED)) == JF_FAILED;
103 stopping = (j->flags & JF_STOP) != 0;
104 comparam = *j->comparam;
105 for (;;) {
106 if (j->comstring == NULL) {
107 j->comparam += create_failed ? -1 : 1;
108 switch ((comparam = *j->comparam)) {
109 case IP__NULL:

--- 49 unchanged lines hidden (view full) ---

159}
160
161/*
162 * Check command exit status
163 */
164int
165finish_command(struct cfjail *j)
166{
167 struct cfjail *rj;
168 int error;
169
170 if (!(j->flags & JF_SLEEPQ))
171 return 0;
172 j->flags &= ~JF_SLEEPQ;
173 if (*j->comparam == IP_STOP_TIMEOUT) {
174 j->flags &= ~JF_TIMEOUT;
175 j->pstatus = 0;
176 return 0;
177 }
178 paralimit++;
179 if (!TAILQ_EMPTY(&runnable)) {
180 rj = TAILQ_FIRST(&runnable);
181 rj->flags |= JF_FROM_RUNQ;
182 requeue(rj, &ready);
183 }
184 error = 0;
185 if (j->flags & JF_TIMEOUT) {
186 j->flags &= ~JF_TIMEOUT;
187 if (*j->comparam != IP_STOP_TIMEOUT) {
188 jail_warnx(j, "%s: timed out", j->comline);
189 failed(j);
190 error = -1;
191 } else if (verbose > 0)

--- 69 unchanged lines hidden (view full) ---

261 }
262 goto again;
263 }
264 }
265 return NULL;
266}
267
268/*
269 * Run a single command for a jail, possibly inside the jail.
270 */
271static int
272run_command(struct cfjail *j)
273{
274 const struct passwd *pwd;
275 const struct cfstring *comstring, *s;
276 login_cap_t *lcap;
277 const char **argv;

--- 717 unchanged lines hidden ---