Permalink
Browse files

Initial release

And it's wrong already. I thought I might be able to
use inotify, but that does not work on procfs (does
not give errors either, but ok)
  • Loading branch information...
bneijt committed Jul 25, 2014
0 parents commit 5e63582a4456f70cdb94b752afc77af6a55bea26
Showing with 750 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +674 −0 LICENSE
  3. +9 −0 README.md
  4. +2 −0 Setup.hs
  5. +25 −0 after.cabal
  6. +18 −0 src/After.hs
  7. +20 −0 src/Main.hs
@@ -0,0 +1,2 @@
/cabal.sandbox.config
/dist
674 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,9 @@
After
=====

Simple program that will exit when another program exits.

It makes it easy to retroactively schedule a command after another command has started (without using Ctrl-Z, fg; new command)



@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
@@ -0,0 +1,25 @@
-- Initial after.cabal generated by cabal init. For further documentation,
-- see http://haskell.org/cabal/users-guide/

name: after
version: 0.1.0.0
-- synopsis:
-- description:
homepage: http://bneijt.nl
license: GPL-3
license-file: LICENSE
author: A. Bram Neijt
maintainer: bneijt@gmail.com
-- copyright:
category: System
build-type: Simple
extra-source-files: README
cabal-version: >=1.10

executable after
main-is: Main.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.7 && <4.8, options ==1.*, hinotify ==0.3.*
hs-source-dirs: src
default-language: Haskell2010
@@ -0,0 +1,18 @@
module After where

import System.INotify
import Control.Concurrent

justShowAndUnlock :: MVar String -> Event -> IO()
justShowAndUnlock mvar event = do
putStrLn (show event)
putMVar mvar "Yep, this is happening"

afterPid :: String -> IO ()
afterPid pid = do
inotifyHandle <- initINotify
unockedAfter <- newEmptyMVar
watchHandle <- addWatch inotifyHandle [DeleteSelf, MoveSelf, OnlyDir] ("/proc/" ++ pid) (justShowAndUnlock unockedAfter)
seen <- takeMVar unockedAfter
putStrLn seen

@@ -0,0 +1,20 @@
import Control.Applicative
import Options

import After (afterPid)

data MainOptions = MainOptions
{ optQuiet :: Bool
}

instance Options MainOptions where
defineOptions = pure MainOptions
<*> simpleOption "quiet" False
"Whether to be quiet."

main :: IO ()
main = runCommand $ \opts args -> do
if optQuiet opts
then return ()
else afterPid (head args)

0 comments on commit 5e63582

Please sign in to comment.