forked from dmayer/idb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpb_watcher_thread.rb
61 lines (48 loc) · 1.49 KB
/
pb_watcher_thread.rb
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class PBWatcherThread < Qt::Object
signals "new_entry(QString)"
def initialize *args
super *args
$terminate_pbwatcher_thread = false
end
def stop
$terminate_pbwatcher_thread = true
end
def start_pbwatcher_thread pbs
@pbwatcher_thread = Thread.new do
channel = $device.ssh.open_channel do |ch|
ch.request_pty do |ch, success|
cmd = "/var/root/pbwatcher 1 #{pbs}"
$log.info "Executing pbwatcher: #{cmd}"
ch.exec cmd do |ch, success|
$log.error "could not execute command" unless success
# "on_data" is called when the process writes something to stdout
ch.on_data do |c, data|
emit new_entry(data)
end
# "on_extended_data" is called when the process writes something to stderr
ch.on_extended_data do |c, type, data|
emit new_entry(data)
end
ch.on_close { |ch|
$log.info "pbwatcher terminated"
}
end
end
end
loop do
#TODO mutex to protect device?
#even better: make one central thread that calls process.
# and all functions using it call it to ensure its running. or auto start it.
sleep 0.5
$device.ssh.process
#$device.ssh.process 0
if $terminate_pbwatcher_thread
$log.info "Terminating pbwatcher"
channel.close
break
end
end
$log.info "Terminating thread"
end
end
end