The idea is that the joiner
will run as a master daemon, watching tshark
and the processor
which here is
represented by std-reader
. If either process is to die, the daemon will restart and re-join the FDs; this isn't
implemented yet, but would be the end goal.
Last active
December 13, 2015 23:29
-
-
Save cupakromer/4991880 to your computer and use it in GitHub Desktop.
For some reason tshark is buffering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def kill_all_children(children, signal) | |
children.each{ |wpid| Process.kill(signal, wpid) } | |
end | |
worker_pids = {} | |
[:INT, :QUIT].each do |signal| | |
Signal.trap(signal) { kill_all_children worker_pids.values, signal } | |
end | |
reader, writer = IO.pipe | |
interface = ARGV.shift | |
tshark_cmd = %W[tshark -i #{interface} -R http -T fields -e http.user_agent] | |
# Neither the Process.spawn nor the direct fork + exec seem to solve the buffer issue | |
writer.sync = true | |
worker_pids[:tshark] = Process.spawn *tshark_cmd, out: writer | |
#fork do | |
# reader.close | |
# writer.sync = true | |
# STDOUT.reopen writer | |
# exec *tshark_cmd | |
#end | |
writer.close | |
worker_pids[:processor] = Process.spawn "std-reader", in: reader | |
reader.close | |
Process.waitall # Dumb run loop. Just wait until all children are dead |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
$stdin.sync = true | |
$stdout.sync = true | |
$stdin.each_line do |line| | |
$stdout.puts line | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So very frustratingly if I change the pipes to use
PTY
andraw
things work 😖 😬