blob: 9943d30ae57fa33045a4e1693ad9898be0dde2ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
module Process (
Process(..),
ProcName(..),
textProcName, unpackProcName,
send,
) where
import Control.Concurrent.STM
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import System.IO
import System.Posix.Signals
import System.Process
data Process = Process
{ procName :: ProcName
, procHandle :: ProcessHandle
, procStdin :: Handle
, procOutput :: TVar [Text]
, procKillWith :: Maybe Signal
}
data ProcName = ProcName Text
| ProcNameTcpdump
| ProcNameGDB
deriving (Eq, Ord)
textProcName :: ProcName -> Text
textProcName (ProcName name) = name
textProcName ProcNameTcpdump = T.pack "tcpdump"
textProcName ProcNameGDB = T.pack "gdb"
unpackProcName :: ProcName -> String
unpackProcName = T.unpack . textProcName
send :: Process -> Text -> IO ()
send p line = do
T.hPutStrLn (procStdin p) line
hFlush (procStdin p)
|