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 d311eed28d..66ff548270 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -716,12 +716,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?
@@ -729,13 +731,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|\z)/ =~ path
+ end
+ end
+
# creates a UNIX socket server on _path_.
# It calls the block for each socket accepted.
#