Commit 29ad7223 authored by Aaron Quint's avatar Aaron Quint

Ensure that the path to the socket is cleaned up when detaching

Currently the path to the socket was only cleaned up on exit
parent 2e105674
......@@ -43,12 +43,11 @@ class RBTracer
raise ArgumentError, 'could not signal process, are you running as root?'
end
path = "/tmp/rbtrace-#{@pid}.sock"
@sock = Socket.new Socket::AF_UNIX, Socket::SOCK_DGRAM, 0
@sockaddr = Socket.pack_sockaddr_un(path)
@sockaddr = Socket.pack_sockaddr_un(socket_path)
@sock.bind(@sockaddr)
FileUtils.chmod 0666, path
at_exit{ FileUtils.rm(path) if File.exists?(path) }
FileUtils.chmod 0666, socket_path
at_exit { clean_socket_path }
5.times do
signal
......@@ -92,6 +91,14 @@ class RBTracer
attach
end
def socket_path
"/tmp/rbtrace-#{@pid}.sock"
end
def clean_socket_path
FileUtils.rm(socket_path) if File.exists?(socket_path)
end
# Watch for method calls slower than a threshold.
#
# msec - The Fixnum threshold in milliseconds
......@@ -233,6 +240,8 @@ class RBTracer
# STDERR.puts $!.backtrace.join("\n ")
rescue Interrupt, SignalException
retry
ensure
clean_socket_path
end
# Process events from the traced process.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment