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.8 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: Brian Corrigan Newsgroups: gmane.comp.lang.ruby.raindrops.general 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 Message-ID: References: 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 1338911224 24771 80.91.229.3 (5 Jun 2012 15:47:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 5 Jun 2012 15:47:04 +0000 (UTC) To: raindrops@librelist.org Original-X-From: raindrops@librelist.org Tue Jun 05 17:47:03 2012 Return-path: Envelope-to: gclrrg-raindrops@m.gmane.org In-Reply-To: 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:78 Archived-At: Received: from zedshaw.xen.prgmr.com ([64.71.167.205]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SbvyE-0000KF-Ra for gclrrg-raindrops@m.gmane.org; Tue, 05 Jun 2012 17:46:59 +0200 Received: from zedshaw.xen.prgmr.com (localhost [IPv6:::1]) by zedshaw.xen.prgmr.com (Postfix) with ESMTP id 93FE121DDAD for ; Tue, 5 Jun 2012 15:54:59 +0000 (UTC) --- 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