ng_pipe: Remove node when all hooks are disconnected

This is the behavior described in the man page.

Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>

Discussed with:	glebius
Reviewed by:	markj
MFC after:	2 weeks
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1181
This commit is contained in:
Martin Vahlensieck 2024-04-17 20:51:40 +02:00 committed by Mark Johnston
parent 8512311fb5
commit bb2ab7a374

View file

@ -936,6 +936,7 @@ ngp_disconnect(hook_p hook)
struct hookinfo *const hinfo = NG_HOOK_PRIVATE(hook);
struct ngp_fifo *ngp_f;
struct ngp_hdr *ngp_h;
priv_p priv;
KASSERT(hinfo != NULL, ("%s: null info", __FUNCTION__));
hinfo->hook = NULL;
@ -962,6 +963,12 @@ ngp_disconnect(hook_p hook)
if (hinfo->ber_p)
free(hinfo->ber_p, M_NG_PIPE);
/* Destroy the node if all hooks are disconnected */
priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
if (priv->upper.hook == NULL && priv->lower.hook == NULL)
ng_rmnode_self(NG_HOOK_NODE(hook));
return (0);
}