git: 838c356b1752 - main - lang/ghc: Pull a patch from upstream fixing a forking bug

From: Gleb Popov <arrowd_at_FreeBSD.org>
Date: Mon, 23 Sep 2024 08:28:49 UTC
The branch main has been updated by arrowd:

URL: https://cgit.FreeBSD.org/ports/commit/?id=838c356b1752e1cb73bb21bfa7710e1dcbc22b2b

commit 838c356b1752e1cb73bb21bfa7710e1dcbc22b2b
Author:     Gleb Popov <arrowd@FreeBSD.org>
AuthorDate: 2024-09-23 08:27:34 +0000
Commit:     Gleb Popov <arrowd@FreeBSD.org>
CommitDate: 2024-09-23 08:28:44 +0000

    lang/ghc: Pull a patch from upstream fixing a forking bug
---
 lang/ghc/Makefile                                  |  2 +-
 .../patch-libraries_base_GHC_Event_KQueue.hsc      | 45 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/lang/ghc/Makefile b/lang/ghc/Makefile
index ff93d9d2b7a7..a61a0477f0e3 100644
--- a/lang/ghc/Makefile
+++ b/lang/ghc/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	ghc
 PORTVERSION=	${GHC_VERSION}
-PORTREVISION?=	0
+PORTREVISION?=	1
 CATEGORIES=	lang haskell
 MASTER_SITES=	https://www.haskell.org/ghc/dist/${PORTVERSION}/:source \
 		LOCAL/arrowd/:boot
diff --git a/lang/ghc/files/patch-libraries_base_GHC_Event_KQueue.hsc b/lang/ghc/files/patch-libraries_base_GHC_Event_KQueue.hsc
new file mode 100644
index 000000000000..1413a39d9705
--- /dev/null
+++ b/lang/ghc/files/patch-libraries_base_GHC_Event_KQueue.hsc
@@ -0,0 +1,45 @@
+https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13276
+
+--- libraries/base/GHC/Event/KQueue.hsc.orig	2024-06-30 22:49:26 UTC
++++ libraries/base/GHC/Event/KQueue.hsc
+@@ -44,8 +44,8 @@ import GHC.Event.Internal (Timeout(..))
+ import GHC.Real (quotRem, fromIntegral)
+ import GHC.Show (Show(show))
+ import GHC.Event.Internal (Timeout(..))
+-import System.Posix.Internals (c_close)
+-import System.Posix.Types (Fd(..))
++import System.Posix.Internals (c_close, c_getpid)
++import System.Posix.Types (Fd(..), CPid)
+ import qualified GHC.Event.Array as A
+ 
+ #if defined(netbsd_HOST_OS)
+@@ -73,19 +73,26 @@ data KQueue = KQueue {
+ data KQueue = KQueue {
+       kqueueFd     :: {-# UNPACK #-} !KQueueFd
+     , kqueueEvents :: {-# UNPACK #-} !(A.Array Event)
++    , kqueuePid    :: {-# UNPACK #-} !CPid -- ^ pid, used to detect forks
+     }
+ 
+ new :: IO E.Backend
+ new = do
+   kqfd <- kqueue
+   events <- A.new 64
+-  let !be = E.backend poll modifyFd modifyFdOnce delete (KQueue kqfd events)
++  pid <- c_getpid
++  let !be = E.backend poll modifyFd modifyFdOnce delete (KQueue kqfd events pid)
+   return be
+ 
+ delete :: KQueue -> IO ()
+ delete kq = do
+-  _ <- c_close . fromKQueueFd . kqueueFd $ kq
+-  return ()
++  -- detect forks: the queue isn't inherited by a child process created with
++  -- fork. Hence we mustn't try to close the old fd or we might close a random
++  -- one (e.g. the one used by timerfd, cf #24672).
++  pid <- c_getpid
++  when (pid == kqueuePid kq) $ do
++    _ <- c_close . fromKQueueFd . kqueueFd $ kq
++    return ()
+ 
+ modifyFd :: KQueue -> Fd -> E.Event -> E.Event -> IO Bool
+ modifyFd kq fd oevt nevt = do