From owner-svn-src-head@freebsd.org Thu Oct 18 14:20:17 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E5D1510DDDAB; Thu, 18 Oct 2018 14:20:16 +0000 (UTC) (envelope-from jtl@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 99EEE8D44D; Thu, 18 Oct 2018 14:20:16 +0000 (UTC) (envelope-from jtl@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 94EFA20EF5; Thu, 18 Oct 2018 14:20:16 +0000 (UTC) (envelope-from jtl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9IEKGxA008890; Thu, 18 Oct 2018 14:20:16 GMT (envelope-from jtl@FreeBSD.org) Received: (from jtl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9IEKGG7008889; Thu, 18 Oct 2018 14:20:16 GMT (envelope-from jtl@FreeBSD.org) Message-Id: <201810181420.w9IEKGG7008889@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jtl set sender to jtl@FreeBSD.org using -f From: "Jonathan T. Looney" Date: Thu, 18 Oct 2018 14:20:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339419 - in head: share/man/man9 sys/kern X-SVN-Group: head X-SVN-Commit-Author: jtl X-SVN-Commit-Paths: in head: share/man/man9 sys/kern X-SVN-Commit-Revision: 339419 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Oct 2018 14:20:17 -0000 Author: jtl Date: Thu Oct 18 14:20:15 2018 New Revision: 339419 URL: https://svnweb.freebsd.org/changeset/base/339419 Log: r334853 added a "socket destructor" callback. However, as implemented, it was really a "socket close" callback. Update the socket destructor functionality to run when a socket is destroyed (rather than when it is closed). The original submitter has confirmed that this change satisfies the intended use case. Suggested by: rwatson Submitted by: Michio Honda Tested by: Michio Honda Approved by: re (kib) Differential Revision: https://reviews.freebsd.org/D17590 Modified: head/share/man/man9/socket.9 head/sys/kern/uipc_socket.c Modified: head/share/man/man9/socket.9 ============================================================================== --- head/share/man/man9/socket.9 Thu Oct 18 04:36:25 2018 (r339418) +++ head/share/man/man9/socket.9 Thu Oct 18 14:20:15 2018 (r339419) @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 8, 2018 +.Dd October 18, 2018 .Dt SOCKET 9 .Os .Sh NAME @@ -378,8 +378,8 @@ or A kernel system can use the .Fn sodtor_set function to set a destructor for a socket. -The destructor is called when the socket is closed. -The destructor is called after the protocol close routine has completed. +The destructor is called when the socket is is about to be freed. +The destructor is called before the protocol detach routine. The destructor can serve as a callback to initiate additional cleanup actions. .Ss Socket I/O The Modified: head/sys/kern/uipc_socket.c ============================================================================== --- head/sys/kern/uipc_socket.c Thu Oct 18 04:36:25 2018 (r339418) +++ head/sys/kern/uipc_socket.c Thu Oct 18 14:20:15 2018 (r339419) @@ -1026,6 +1026,9 @@ sofree(struct socket *so) so->so_error = ECONNABORTED; SOCK_UNLOCK(so); + if (so->so_dtor != NULL) + so->so_dtor(so); + VNET_SO_ASSERT(so); if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose != NULL) (*pr->pr_domain->dom_dispose)(so); @@ -1102,8 +1105,6 @@ soclose(struct socket *so) drop: if (so->so_proto->pr_usrreqs->pru_close != NULL) (*so->so_proto->pr_usrreqs->pru_close)(so); - if (so->so_dtor != NULL) - so->so_dtor(so); SOCK_LOCK(so); if ((listening = (so->so_options & SO_ACCEPTCONN))) {