FreeBSD/usr.sbin/jail/command.c
/*
 * Send SIGTERM to all processes in a jail and wait for them to die.
 */
Send SIGTERM to all processes in a jail and wait for them to die.
Send SIGTERM to all processes in a jail and wait for them to die .
static int
term_procs(struct cfjail *j)
{
	struct kinfo_proc *ki;
	int i, noted, pcnt, timeout;
	static kvm_t *kd;
	if (!int_param(j->intparams[IP_STOP_TIMEOUT], &timeout))
		timeout = DEFAULT_STOP_TIMEOUT;
	else if (timeout == 0)
		return 0;
	if (kd == NULL) {
		kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
		if (kd == NULL)
			return 0;
	}
	ki = kvm_getprocs(kd, KERN_PROC_PROC, 0, &pcnt);
	if (ki == NULL)
		return 0;
	noted = 0;
	for (i = 0; i < pcnt; i++)
		if (ki[i].ki_jid == j->jid &&
		    kill(ki[i].ki_pid, SIGTERM) == 0) {
			(void)add_proc(j, ki[i].ki_pid);
			if (verbose > 0) {
				if (!noted) {
					noted = 1;
					jail_note(j, "sent SIGTERM to:");
				}
				printf(" %d", ki[i].ki_pid);
			}
		}
	if (noted)
		printf("\n");
	if (j->nprocs > 0) {
		clock_gettime(CLOCK_REALTIME, &j->timeout);
		j->timeout.tv_sec += timeout;
		return 1;
	}
	return 0;
}
static int term_procs ( struct cfjail * j ) { struct kinfo_proc * ki ; int i , noted , pcnt , timeout ; static kvm_t * kd ; if ( ! int_param ( j -> intparams [ IP_STOP_TIMEOUT ] , & timeout ) ) timeout = DEFAULT_STOP_TIMEOUT ; else if ( timeout == 0 ) return 0 ; if ( kd == NULL ) { kd = kvm_open ( NULL , NULL , NULL , O_RDONLY , NULL ) ; if ( kd == NULL ) return 0 ; } ki = kvm_getprocs ( kd , KERN_PROC_PROC , 0 , & pcnt ) ; if ( ki == NULL ) return 0 ; noted = 0 ; for ( i = 0 ; i < pcnt ; i ++ ) if ( ki [ i ] . ki_jid == j -> jid && kill ( ki [ i ] . ki_pid , SIGTERM ) == 0 ) { ( void ) add_proc ( j , ki [ i ] . ki_pid ) ; if ( verbose > 0 ) { if ( ! noted ) { noted = 1 ; jail_note ( j , " " ) ; } printf ( " " , ki [ i ] . ki_pid ) ; } } if ( noted ) printf ( " \n " ) ; if ( j -> nprocs > 0 ) { clock_gettime ( CLOCK_REALTIME , & j -> timeout ) ; j -> timeout . tv_sec += timeout ; return 1 ; } return 0 ; }
Send SIGTERM to all processes in a jail and wait for them to die.
Send SIGTERM to all processes in a jail and wait for them to die .