raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: raindrops@librelist.org
Subject: [PATCH] unix_listener_stats follows and remembers symlinks
Date: Wed, 6 Jun 2012 00:56:21 +0000	[thread overview]
Message-ID: <20120606005621.GA32222@dcvr.yhbt.net> (raw)
In-Reply-To: <20120606004911.GA31736@dcvr.yhbt.net>

Eric Wong <normalperson@yhbt.net> wrote:
> However, I think the way unix_listener_stats behaves can pose
> some confusing usability problems with symlinks

I think the following patch should improve usability with
symlinks and unix_listener_stats:

>From bd7236fe23c4388d2fa42a4f836aca3c796dabab Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Tue, 5 Jun 2012 17:49:43 -0700
Subject: [PATCH] unix_listener_stats follows and remembers symlinks

Teach unix_listener_stats to remember the symlink path
it followed and have it point to the same object as the
resolved (real) socket path.

This allows the case where looking up stats by symlinks
works if the symlink is given to unix_listener_stats:

  File.symlink("/real/path/of.sock", "/path/to/link.sock")
  stats = unix_listener_stats(["/path/to/link.sock"])
  stats["/path/to/link.sock"] => # same as stats["/real/path/of.sock"]
---
 lib/raindrops/linux.rb |  9 +++++++--
 test/test_linux.rb     | 20 +++++++++++---------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/lib/raindrops/linux.rb b/lib/raindrops/linux.rb
index a198253..1752b8a 100644
--- a/lib/raindrops/linux.rb
+++ b/lib/raindrops/linux.rb
@@ -43,9 +43,14 @@ 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]
+        if File.symlink?(path)
+          link = path
+          path = Pathname.new(link).realpath.to_s
+          rv[link] = rv[path] # vivify ListenerStats
+        else
+          rv[path] # vivify ListenerStats
+        end
         Regexp.escape(path)
       end
     end
diff --git a/test/test_linux.rb b/test/test_linux.rb
index 81463c9..a84eecf 100644
--- a/test/test_linux.rb
+++ b/test/test_linux.rb
@@ -73,24 +73,26 @@ class TestLinux < Test::Unit::TestCase
     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)
+    link = Tempfile.new("somethingelse")
+    File.unlink(link.path) # We need an available name, not an actual file
+    File.symlink(tmp.path, link.path)
 
     @to_close << UNIXSocket.new(tmp.path)
     stats = unix_listener_stats
-    assert_equal 0, stats[link.path].active
-    assert_equal 1, stats[link.path].queued
+    assert_equal 0, stats[tmp.path].active
+    assert_equal 1, stats[tmp.path].queued
 
-    @to_close << UNIXSocket.new(tmp.path)
-    stats = unix_listener_stats
+    @to_close << UNIXSocket.new(link.path)
+    stats = unix_listener_stats([link.path])
     assert_equal 0, stats[link.path].active
     assert_equal 2, stats[link.path].queued
 
+    assert_equal stats[link.path].object_id, stats[tmp.path].object_id
+
     @to_close << us.accept
     stats = unix_listener_stats
-    assert_equal 1, stats[link.path].active
-    assert_equal 1, stats[link.path].queued
+    assert_equal 1, stats[tmp.path].active
+    assert_equal 1, stats[tmp.path].queued
   end
 
   def test_tcp
-- 


      parent reply	other threads:[~2012-06-06  0:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-05 15:46 [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 Brian Corrigan
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         ` Eric Wong [this message]

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=20120606005621.GA32222@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=raindrops@librelist.org \
    --subject='Re: [PATCH] unix_listener_stats follows and remembers symlinks' \
    /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

Code repositories for project(s) associated with this inbox:

	../../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).