king: wtf use getExecutablePath
@@ -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,26 +124,27 @@ 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"
+ 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. ------------------------------------------------------------
booted
