mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 00:13:12 +03:00
king: wtf use getExecutablePath
This commit is contained in:
parent
fc92fd3611
commit
1e995e8f11
@ -25,6 +25,8 @@ import Urbit.King.App
|
||||
import Urbit.Vere.Pier.Types
|
||||
|
||||
import Control.Monad.STM (retry)
|
||||
import System.Environment (getExecutablePath)
|
||||
import System.FilePath (splitFileName, (</>))
|
||||
import System.Posix.Files (ownerModes, setFileMode)
|
||||
import Urbit.EventLog.LMDB (EventLog)
|
||||
import Urbit.King.API (TermConn)
|
||||
@ -122,24 +124,25 @@ runSerf
|
||||
-> RAcquire e Serf
|
||||
runSerf vSlog pax = do
|
||||
env <- ask
|
||||
heuSerf <- heuristicallyFindSerf
|
||||
Serf.withSerf (config env heuSerf)
|
||||
serfProg <- io getSerfProg
|
||||
Serf.withSerf (config env serfProg)
|
||||
where
|
||||
slog txt = atomically (readTVar vSlog) >>= (\f -> f txt)
|
||||
config env heuSerf = Serf.Config
|
||||
{ scSerf = env ^. pierConfigL . pcSerfExe . to (unpack . fromMaybe heuSerf)
|
||||
config env serfProg = Serf.Config
|
||||
{ scSerf = env ^. pierConfigL . pcSerfExe . to (maybe serfProg unpack)
|
||||
, scPier = pax
|
||||
, scFlag = env ^. pierConfigL . pcSerfFlags
|
||||
, scSlog = \(pri, tank) -> printTank slog pri tank
|
||||
, scStdr = \txt -> slog (txt <> "\r\n")
|
||||
, scDead = pure () -- TODO: What can be done?
|
||||
}
|
||||
heuristicallyFindSerf = serfPrgm <$> listToMaybe <$> getArgs
|
||||
serfPrgm = \case
|
||||
Just (stripSuffix "urbit" -> Just pfix) -> pfix <> "urbit-worker"
|
||||
Just (stripSuffix "urbit-king" -> Just pfix) -> pfix <> "urbit-worker"
|
||||
_ -> "urbit-worker"
|
||||
|
||||
getSerfProg :: IO FilePath
|
||||
getSerfProg = do
|
||||
(path, filename) <- splitFileName <$> getExecutablePath
|
||||
pure $ case filename of
|
||||
"urbit" -> path </> "urbit-worker"
|
||||
"urbit-king" -> path </> "urbit-worker"
|
||||
_ -> "urbit-worker"
|
||||
|
||||
|
||||
-- Boot a new ship. ------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user