FreeBSD/usr.sbin/jail/command.c
/*
 * Run the next command associated with a jail.
 */
Run the next command associated with a jail.
Run the next command associated with a jail .
int
next_command(struct cfjail *j)
{
	enum intparam comparam;
	int create_failed, stopping;
	if (paralimit == 0) {
		if (j->flags & JF_FROM_RUNQ)
			requeue_head(j, &runnable);
		else
			requeue(j, &runnable);
		return 1;
	}
	j->flags &= ~JF_FROM_RUNQ;
	create_failed = (j->flags & (JF_STOP | JF_FAILED)) == JF_FAILED;
	stopping = (j->flags & JF_STOP) != 0;
	comparam = *j->comparam;
	for (;;) {
		if (j->comstring == NULL) {
			j->comparam += create_failed ? -1 : 1;
			switch ((comparam = *j->comparam)) {
			case IP__NULL:
				return 0;
			case IP_MOUNT_DEVFS:
				if (!bool_param(j->intparams[IP_MOUNT_DEVFS]))
					continue;
				j->comstring = &dummystring;
				break;
			case IP_MOUNT_FDESCFS:
				if (!bool_param(j->intparams[IP_MOUNT_FDESCFS]))
					continue;
				j->comstring = &dummystring;
				break;
			case IP_MOUNT_PROCFS:
				if (!bool_param(j->intparams[IP_MOUNT_PROCFS]))
					continue;
				j->comstring = &dummystring;
				break;
			case IP__OP:
			case IP_STOP_TIMEOUT:
				j->comstring = &dummystring;
				break;
			default:
				if (j->intparams[comparam] == NULL)
					continue;
				j->comstring = create_failed || (stopping &&
				    (j->intparams[comparam]->flags & PF_REV))
				    ? TAILQ_LAST(&j->intparams[comparam]->val,
					cfstrings)
				    : TAILQ_FIRST(&j->intparams[comparam]->val);
			}
		} else {
			j->comstring = j->comstring == &dummystring ? NULL :
			    create_failed || (stopping &&
			    (j->intparams[comparam]->flags & PF_REV))
			    ? TAILQ_PREV(j->comstring, cfstrings, tq)
			    : TAILQ_NEXT(j->comstring, tq);
		}
		if (j->comstring == NULL || j->comstring->len == 0 ||
		    (create_failed && (comparam == IP_EXEC_PRESTART ||
		    comparam == IP_EXEC_START || comparam == IP_COMMAND ||
		    comparam == IP_EXEC_POSTSTART)))
			continue;
		switch (run_command(j)) {
		case -1:
			failed(j);
		case 1:
			return 1;
		}
	}
}
int next_command ( struct cfjail * j ) { enum intparam comparam ; int create_failed , stopping ; if ( paralimit == 0 ) { if ( j -> flags & JF_FROM_RUNQ ) requeue_head ( j , & runnable ) ; else requeue ( j , & runnable ) ; return 1 ; } j -> flags &= ~ JF_FROM_RUNQ ; create_failed = ( j -> flags & ( JF_STOP | JF_FAILED ) ) == JF_FAILED ; stopping = ( j -> flags & JF_STOP ) != 0 ; comparam = * j -> comparam ; for ( ; ; ) { if ( j -> comstring == NULL ) { j -> comparam += create_failed ? -1 : 1 ; switch ( ( comparam = * j -> comparam ) ) { case IP__NULL : return 0 ; case IP_MOUNT_DEVFS : if ( ! bool_param ( j -> intparams [ IP_MOUNT_DEVFS ] ) ) continue ; j -> comstring = & dummystring ; break ; case IP_MOUNT_FDESCFS : if ( ! bool_param ( j -> intparams [ IP_MOUNT_FDESCFS ] ) ) continue ; j -> comstring = & dummystring ; break ; case IP_MOUNT_PROCFS : if ( ! bool_param ( j -> intparams [ IP_MOUNT_PROCFS ] ) ) continue ; j -> comstring = & dummystring ; break ; case IP__OP : case IP_STOP_TIMEOUT : j -> comstring = & dummystring ; break ; default : if ( j -> intparams [ comparam ] == NULL ) continue ; j -> comstring = create_failed || ( stopping && ( j -> intparams [ comparam ] -> flags & PF_REV ) ) ? TAILQ_LAST ( & j -> intparams [ comparam ] -> val , cfstrings ) : TAILQ_FIRST ( & j -> intparams [ comparam ] -> val ) ; } } else { j -> comstring = j -> comstring == & dummystring ? NULL : create_failed || ( stopping && ( j -> intparams [ comparam ] -> flags & PF_REV ) ) ? TAILQ_PREV ( j -> comstring , cfstrings , tq ) : TAILQ_NEXT ( j -> comstring , tq ) ; } if ( j -> comstring == NULL || j -> comstring -> len == 0 || ( create_failed && ( comparam == IP_EXEC_PRESTART || comparam == IP_EXEC_START || comparam == IP_COMMAND || comparam == IP_EXEC_POSTSTART ) ) ) continue ; switch ( run_command ( j ) ) { case -1 : failed ( j ) ; case 1 : return 1 ; } } }
Run the next command associated with a jail.
Run the next command associated with a jail .
/* FALLTHROUGH */