From: Brian Corrigan <brian@genexp.me>
To: raindrops@librelist.org
Subject: [PATCH] Raindrops currently fails when provided a symlink to a socket. As this is a common practice for many deployment tools (Vlad, etc.) this patch adds support for finding the realpath prior to looking the socket up in /proc/net/unix
Date: Tue, 5 Jun 2012 11:46:34 -0400 [thread overview]
Message-ID: <CALO9HP2n2s47Nuj+7zjS=nHSTjvr=eONS2+EXnd7erCoorbigQ@mail.gmail.com> (raw)
In-Reply-To: <CALO9HP2n2s47Nuj+7zjS=nHSTjvr=eONS2+EXnd7erCoorbigQ@mail.gmail.com>
---
lib/raindrops/linux.rb | 3 +++
test/test_linux.rb | 26 ++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/lib/raindrops/linux.rb b/lib/raindrops/linux.rb
index fe2af09..a198253 100644
--- a/lib/raindrops/linux.rb
+++ b/lib/raindrops/linux.rb
@@ -8,6 +8,8 @@
# Instead of snapshotting, Raindrops::Aggregate::LastDataRecv may be used
# to aggregate statistics from +all+ accepted sockets as they arrive
# based on the +last_data_recv+ field in Raindrops::TCP_Info
+require 'pathname'
+
module Raindrops::Linux
# The standard proc path for active UNIX domain sockets, feel free to call
@@ -41,6 +43,7 @@ module Raindrops::Linux
else
paths = paths.map do |path|
path = path.dup
+ path = Pathname.new(path).realpath.to_s
path.force_encoding(Encoding::BINARY) if defined?(Encoding)
rv[path]
Regexp.escape(path)
diff --git a/test/test_linux.rb b/test/test_linux.rb
index 65f25e0..81463c9 100644
--- a/test/test_linux.rb
+++ b/test/test_linux.rb
@@ -67,6 +67,32 @@ class TestLinux < Test::Unit::TestCase
assert_equal 1, stats[tmp.path].queued
end
+ def test_unix_resolves_symlinks
+ tmp = Tempfile.new("\xde\xad\xbe\xef") # valid path, really :)
+ File.unlink(tmp.path)
+ us = UNIXServer.new(tmp.path)
+
+ # Create a symlink
+ destination = Tempfile.new("somethingelse")
+ destination.unlink # We need an available name, not an actual file
+ link = File.symlink(tmp, destination)
+
+ @to_close << UNIXSocket.new(tmp.path)
+ stats = unix_listener_stats
+ assert_equal 0, stats[link.path].active
+ assert_equal 1, stats[link.path].queued
+
+ @to_close << UNIXSocket.new(tmp.path)
+ stats = unix_listener_stats
+ assert_equal 0, stats[link.path].active
+ assert_equal 2, stats[link.path].queued
+
+ @to_close << us.accept
+ stats = unix_listener_stats
+ assert_equal 1, stats[link.path].active
+ assert_equal 1, stats[link.path].queued
+ end
+
def test_tcp
s = TCPServer.new(TEST_ADDR, 0)
port = s.addr[1]
--
1.7.0.4
next parent reply other threads:[~2012-06-05 15:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-05 15:46 Brian Corrigan [this message]
2012-06-05 17:57 ` [PATCH] Eric Wong
2012-06-05 23:59 ` [PATCH] Brian Corrigan
2012-06-06 0:15 ` [PATCH] Eric Wong
2012-06-06 0:49 ` [PATCH] Eric Wong
2012-06-06 0:50 ` [PATCH] Brian Corrigan
2012-06-06 0:56 ` [PATCH] unix_listener_stats follows and remembers symlinks Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/raindrops/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALO9HP2n2s47Nuj+7zjS=nHSTjvr=eONS2+EXnd7erCoorbigQ@mail.gmail.com' \
--to=brian@genexp.me \
--cc=raindrops@librelist.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/raindrops.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).