From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS6939 64.71.128.0/18 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.raindrops.general Subject: [PATCH] unix_listener_stats follows and remembers symlinks Date: Wed, 6 Jun 2012 00:56:21 +0000 Message-ID: <20120606005621.GA32222@dcvr.yhbt.net> References: <20120605175755.GA8749@dcvr.yhbt.net> <20120606001534.GA28607@dcvr.yhbt.net> <20120606004911.GA31736@dcvr.yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1338944204 19508 80.91.229.3 (6 Jun 2012 00:56:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 6 Jun 2012 00:56:44 +0000 (UTC) To: raindrops@librelist.org Original-X-From: raindrops@librelist.org Wed Jun 06 02:56:43 2012 Return-path: Envelope-to: gclrrg-raindrops@m.gmane.org List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: raindrops@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.raindrops.general:84 Archived-At: Received: from zedshaw.xen.prgmr.com ([64.71.167.205]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sc4YD-0004ps-7V for gclrrg-raindrops@m.gmane.org; Wed, 06 Jun 2012 02:56:41 +0200 Received: from zedshaw.xen.prgmr.com (localhost [IPv6:::1]) by zedshaw.xen.prgmr.com (Postfix) with ESMTP id 11E8821DDB7 for ; Wed, 6 Jun 2012 01:04:43 +0000 (UTC) Eric Wong 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 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 --