FreeBSD/contrib/nvi/ex/ex_cscope.c
/*
 * terminate --
 *	Detach from a cscope process.
 */
terminate
Detach from a cscope process.
terminate Detach from a cscope process .
static int
terminate(SCR *sp, CSC *csc, int n)
{
	EX_PRIVATE *exp;
	int i = 0, pstat;
	CSC *cp, *pre_cp = NULL;
	exp = EXP(sp);
	if (csc == NULL && n < 1)
		goto badno;
	SLIST_FOREACH(cp, exp->cscq, q) {
		++i;
		if (csc == NULL ? i != n : cp != csc) {
			pre_cp = cp;
			continue;
		}
		if (cp == SLIST_FIRST(exp->cscq))
			SLIST_REMOVE_HEAD(exp->cscq, q);
		else
			SLIST_REMOVE_AFTER(pre_cp, q);
		csc = cp;
		break;
	}
	if (csc == NULL) {
badno:		msgq(sp, M_ERR, "312|%d: no such cscope session", n);
		return (1);
	}
	if (csc->from_fp != NULL)
		(void)fclose(csc->from_fp);
	if (csc->to_fp != NULL)
		(void)fclose(csc->to_fp);
	if (i > 1)
		(void)kill(csc->pid, SIGTERM);
	(void)waitpid(csc->pid, &pstat, 0);
	if (csc->pbuf != NULL)
		free(csc->pbuf);
	if (csc->paths != NULL)
		free(csc->paths);
	free(csc);
	return (0);
}
static int terminate ( SCR * sp , CSC * csc , int n ) { EX_PRIVATE * exp ; int i = 0 , pstat ; CSC * cp , * pre_cp = NULL ; exp = EXP ( sp ) ; if ( csc == NULL && n < 1 ) goto badno ; SLIST_FOREACH ( cp , exp -> cscq , q ) { ++ i ; if ( csc == NULL ? i != n : cp != csc ) { pre_cp = cp ; continue ; } if ( cp == SLIST_FIRST ( exp -> cscq ) ) SLIST_REMOVE_HEAD ( exp -> cscq , q ) ; else SLIST_REMOVE_AFTER ( pre_cp , q ) ; csc = cp ; break ; } if ( csc == NULL ) { badno : msgq ( sp , M_ERR , " " , n ) ; return ( 1 ) ; } if ( csc -> from_fp != NULL ) ( void ) fclose ( csc -> from_fp ) ; if ( csc -> to_fp != NULL ) ( void ) fclose ( csc -> to_fp ) ; if ( i > 1 ) ( void ) kill ( csc -> pid , SIGTERM ) ; ( void ) waitpid ( csc -> pid , & pstat , 0 ) ; if ( csc -> pbuf != NULL ) free ( csc -> pbuf ) ; if ( csc -> paths != NULL ) free ( csc -> paths ) ; free ( csc ) ; return ( 0 ) ; }
terminate
      Detach from a cscope process.
terminate Detach from a cscope process .
/*
	 * We either get a csc structure or a number.  Locate and remove
	 * the candidate which matches the structure or the number.
	 */ /*
	 * XXX
	 * Theoretically, we have the only file descriptors to the process,
	 * so closing them should let it exit gracefully, deleting temporary
	 * files, etc.  However, the earlier created cscope processes seems
	 * to refuse to quit unless we send a SIGTERM signal.
	 */ /* Discard cscope connection information. */