-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.rb
54 lines (49 loc) · 1.07 KB
/
common.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
module Libtrusterd
class Util
def Util.ldd
path = Getprocpath.get
lddcmd = `which ldd`
if lddcmd.length == 0
# sorry for windows
lddcmd = "otool -L"
else
lddcmd="ldd"
end
rtn = `#{lddcmd} #{path}`
return rtn
end
def Util.write_pid
f = File.open('libtrusterd.pid','w')
f.write Process.pid
f.close
end
def Util.kill_children
pid = Process.pid
childrenPid = `pgrep -P #{pid}`
childrenPid = childrenPid.split("\n")
puts "children pid : " + childrenPid.to_s
childrenPid.each{|pid|
begin
Process.kill('SIGTERM',pid.to_i)
Process.waitpid(pid.to_i)
rescue => e
p e
p "but we continue"
end
}
end
def Util.set_sigterm
pid = Process.pid
pr = Proc.new { |signo|
puts "SIGTERM!"
kill_children
exit(0)
}
Signal.trap(:TERM, pr)
end
end
end
#Libtrusterd::Util.write_pid
#Libtrusterd::Util.set_sigterm
#sleep(1000)
#puts Libtrusterd::Util.ldd