FreeBSD/usr.sbin/jail/state.c
/*
 * Return if a jail has dependencies.
 */
Return if a jail has dependencies.
Return if a jail has dependencies .
int
dep_check(struct cfjail *j)
{
	int reset, depfrom, depto, ndeps, rev;
	struct cfjail *dj;
	struct cfdepend *d;
	static int bits[] = { 0, 1, 1, 2, 1, 2, 2, 3 };
	if (j->ndeps == 0)
		return 0;
	ndeps = 0;
	if ((rev = JF_DO_STOP(j->flags))) {
		depfrom = DEP_TO;
		depto = DEP_FROM;
	} else {
		depfrom = DEP_FROM;
		depto = DEP_TO;
	}
	STAILQ_FOREACH(d, &j->dep[depfrom], tq[depfrom]) {
		if (d->flags & DF_SEEN)
			continue;
		dj = d->j[depto];
		if (dj->flags & JF_FAILED) {
			if (!(j->flags & (JF_DEPEND | JF_FAILED)) &&
			    verbose >= 0)
				jail_warnx(j, "skipped");
			j->flags |= JF_FAILED;
			continue;
		}
		reset = 0;
		if (bits[dj->flags & JF_OP_MASK] <= 1) {
			if (!(dj->flags & JF_OP_MASK)) {
				reset = 1;
				dj->flags |= JF_DEPEND;
				requeue(dj, &ready);
			}
			switch (j->flags & JF_OP_MASK) {
			case JF_START:
				dj->flags |= JF_START;
				break;
			case JF_SET:
				if (!(dj->flags & JF_OP_MASK))
					dj->flags |= JF_SET;
				else if (dj->flags & JF_STOP)
					dj->flags |= JF_START;
				break;
			case JF_STOP:
			case JF_RESTART:
				if (!(dj->flags & JF_STOP))
					reset = 1;
				dj->flags |= JF_STOP;
				if (dj->flags & JF_SET)
					dj->flags ^= (JF_START | JF_SET);
				break;
			}
		}
		if (reset)
			dep_reset(dj);
		if (!((d->flags & DF_LIGHT) &&
		    (rev ? dj->jid < 0 : dj->jid > 0)))
			ndeps++;
	}
	if (ndeps == 0)
		return 0;
	requeue(j, &depend);
	return 1;
}
int dep_check ( struct cfjail * j ) { int reset , depfrom , depto , ndeps , rev ; struct cfjail * dj ; struct cfdepend * d ; static int bits [ ] = { 0 , 1 , 1 , 2 , 1 , 2 , 2 , 3 } ; if ( j -> ndeps == 0 ) return 0 ; ndeps = 0 ; if ( ( rev = JF_DO_STOP ( j -> flags ) ) ) { depfrom = DEP_TO ; depto = DEP_FROM ; } else { depfrom = DEP_FROM ; depto = DEP_TO ; } STAILQ_FOREACH ( d , & j -> dep [ depfrom ] , tq [ depfrom ] ) { if ( d -> flags & DF_SEEN ) continue ; dj = d -> j [ depto ] ; if ( dj -> flags & JF_FAILED ) { if ( ! ( j -> flags & ( JF_DEPEND | JF_FAILED ) ) && verbose >= 0 ) jail_warnx ( j , " " ) ; j -> flags |= JF_FAILED ; continue ; } reset = 0 ; if ( bits [ dj -> flags & JF_OP_MASK ] <= 1 ) { if ( ! ( dj -> flags & JF_OP_MASK ) ) { reset = 1 ; dj -> flags |= JF_DEPEND ; requeue ( dj , & ready ) ; } switch ( j -> flags & JF_OP_MASK ) { case JF_START : dj -> flags |= JF_START ; break ; case JF_SET : if ( ! ( dj -> flags & JF_OP_MASK ) ) dj -> flags |= JF_SET ; else if ( dj -> flags & JF_STOP ) dj -> flags |= JF_START ; break ; case JF_STOP : case JF_RESTART : if ( ! ( dj -> flags & JF_STOP ) ) reset = 1 ; dj -> flags |= JF_STOP ; if ( dj -> flags & JF_SET ) dj -> flags ^= ( JF_START | JF_SET ) ; break ; } } if ( reset ) dep_reset ( dj ) ; if ( ! ( ( d -> flags & DF_LIGHT ) && ( rev ? dj -> jid < 0 : dj -> jid > 0 ) ) ) ndeps ++ ; } if ( ndeps == 0 ) return 0 ; requeue ( j , & depend ) ; return 1 ; }
Return if a jail has dependencies.
Return if a jail has dependencies .
/*
		 * The dependee's state may be set (or changed) as a result of
		 * being in a dependency it wasn't in earlier.
		 */ /* Set or change the dependee's state. */