{-# OPTIONS_GHC -fglasgow-exts -fallow-overlapping-instances #-}

-- Copyright (C) 2006 Benedikt Schmidt
-- see LICENSE.BSD3 for license

module Main where

import Shim.Shim
import Shim.Utils
import IO
import System (getArgs)
import System.Exit
import GHC.IOBase

main :: IO ExitCode
main = do
  args <- getArgs
  case args of
    socketfile:logfile:rest -> do
      hSetBuffering stdin NoBuffering
      hSetBuffering stdout NoBuffering
      setLogfile logfile
      setLogAction appendFile
      let ghcProgram = safeHead "ghc" rest
      startServer socketfile ghcProgram
    _ -> do
      usage
      exitFailure

usage :: IO ()
usage = putStrLn $ unlines
        ["shim socketfile logfile [ghc program]",
         "the default for ghc program is ``ghc''",
         "make sure to restrict access to the file e.g. by placing it in a",
         "directory with restricted executable permissions"]
