summaryrefslogtreecommitdiff
path: root/ext/socket/lib/socket.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket/lib/socket.rb')
-rw-r--r--ext/socket/lib/socket.rb26
1 files changed, 19 insertions, 7 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 10ab13b..981b937 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -791,12 +791,14 @@ class Socket < BasicSocket
# }
#
def self.unix_server_socket(path)
- begin
- st = File.lstat(path)
- rescue Errno::ENOENT
- end
- if st && st.socket? && st.owned?
- File.unlink path
+ if !unix_socket_abstract_name?(path)
+ begin
+ st = File.lstat(path)
+ rescue Errno::ENOENT
+ end
+ if st && st.socket? && st.owned?
+ File.unlink path
+ end
end
s = Addrinfo.unix(path).listen
if block_given?
@@ -804,13 +806,23 @@ class Socket < BasicSocket
yield s
ensure
s.close if !s.closed?
- File.unlink path
+ if !unix_socket_abstract_name?(path)
+ File.unlink path
+ end
end
else
s
end
end
+ class << self
+ private
+
+ def unix_socket_abstract_name?(path)
+ /linux/ =~ RUBY_PLATFORM && /\A\0/ =~ path
+ end
+ end
+
# creates a UNIX socket server on _path_.
# It calls the block for each socket accepted.
#