assistant: Fix a crash on startup by avoiding using forkProcess

ghc 8.8.4 seems to have changed something that broke code that has been
successfully using forkProcess since 2012. Likely a change to GC internals.

Since forkProcess has never had clear documentation about how to
use it safely, avoid using it at all. Instead, when git-annex needs to
daemonize itself, re-run the git-annex command, in a new process group
and session.

This commit was sponsored by Luke Shumaker on Patreon.
This commit is contained in:
Joey Hess 2021-05-12 15:08:03 -04:00
parent ba7598dbab
commit 947d2a10bc
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 84 additions and 41 deletions

View file

@ -12,6 +12,7 @@ module Command.RemoteDaemon where
import Command
import RemoteDaemon.Core
import Utility.Daemon
import Annex.Path
cmd :: Command
cmd = noCommit $
@ -25,8 +26,10 @@ run o
| foregroundDaemonOption o = liftIO runInteractive
| otherwise = do
#ifndef mingw32_HOST_OS
nullfd <- liftIO $ openFd "/dev/null" ReadOnly Nothing defaultFileFlags
liftIO $ daemonize nullfd Nothing False runNonInteractive
git_annex <- liftIO programPath
ps <- gitAnnexDaemonizeParams
let logfd = openFd "/dev/null" ReadOnly Nothing defaultFileFlags
liftIO $ daemonize git_annex ps logfd Nothing False runNonInteractive
#else
liftIO $ foreground Nothing runNonInteractive
#endif