From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 208.118.235.0/24 X-Spam-Status: No, score=-5.0 required=3.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: dtas-all@80x24.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 6BE5363386C for ; Mon, 7 Sep 2015 21:40:45 +0000 (UTC) Received: from localhost ([::1]:58889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZ49c-000685-Ih for dtas-all@80x24.org; Mon, 07 Sep 2015 17:40:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZ49a-00067Q-F6 for dtas-all@nongnu.org; Mon, 07 Sep 2015 17:40:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZ49Y-0001Tv-QU for dtas-all@nongnu.org; Mon, 07 Sep 2015 17:40:42 -0400 Received: from dcvr.yhbt.net ([64.71.152.64]:39405) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZ49Y-0001Tr-Hv for dtas-all@nongnu.org; Mon, 07 Sep 2015 17:40:40 -0400 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 45EC463386B for ; Mon, 7 Sep 2015 21:40:37 +0000 (UTC) From: Eric Wong To: Subject: [PATCH 1/2] use a common /dev/null Date: Mon, 7 Sep 2015 21:40:33 +0000 Message-Id: <20150907214034.28039-2-e@80x24.org> In-Reply-To: <20150907214034.28039-1-e@80x24.org> References: <20150907214034.28039-1-e@80x24.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.71.152.64 X-BeenThere: dtas-all@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dtas-all-bounces+dtas-all=80x24.org@nongnu.org Sender: dtas-all-bounces+dtas-all=80x24.org@nongnu.org This allows us to avoid wasting time reopening the same device over and over again. --- lib/dtas.rb | 5 +++++ lib/dtas/buffer/splice.rb | 3 +-- lib/dtas/format.rb | 4 ++-- lib/dtas/player.rb | 2 +- lib/dtas/sink.rb | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/dtas.rb b/lib/dtas.rb index f11d549..0b704ca 100644 --- a/lib/dtas.rb +++ b/lib/dtas.rb @@ -13,6 +13,11 @@ module DTAS # :nodoc: Time.now.to_f end end + + @null = nil + def self.null + @null ||= File.open('/dev/null', 'r+') + end end require_relative 'dtas/compat_onenine' diff --git a/lib/dtas/buffer/splice.rb b/lib/dtas/buffer/splice.rb index 02ce877..be40881 100644 --- a/lib/dtas/buffer/splice.rb +++ b/lib/dtas/buffer/splice.rb @@ -10,7 +10,6 @@ module DTAS::Buffer::Splice # :nodoc: MAX_AT_ONCE = 4096 # page size in Linux MAX_AT_ONCE_1 = 65536 MAX_SIZE = File.read("/proc/sys/fs/pipe-max-size").to_i - DEVNULL = File.open("/dev/null", "r+") F_MOVE = IO::Splice::F_MOVE def buffer_size @@ -25,7 +24,7 @@ module DTAS::Buffer::Splice # :nodoc: # be sure to only call this with nil when all writers to @wr are done def discard(bytes) - IO.splice(@to_io, nil, DEVNULL, nil, bytes) + IO.splice(@to_io, nil, DTAS.null, nil, bytes) end def broadcast_one(targets, limit = nil) diff --git a/lib/dtas/format.rb b/lib/dtas/format.rb index a6314bd..cfcec64 100644 --- a/lib/dtas/format.rb +++ b/lib/dtas/format.rb @@ -44,9 +44,9 @@ class DTAS::Format # :nodoc: def self.precision(env, infile) # sox.git f4562efd0aa3 - qx(env, %W(soxi -p #{infile}), err: "/dev/null").to_i + qx(env, %W(soxi -p #{infile}), err: DTAS.null).to_i rescue # fallback to parsing the whole output - s = qx(env, %W(soxi #{infile}), err: "/dev/null") + s = qx(env, %W(soxi #{infile}), err: DTAS.null) s =~ /Precision\s+:\s*(\d+)-bit/n v = $1.to_i return v if v > 0 diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb index cdf1265..a102618 100644 --- a/lib/dtas/player.rb +++ b/lib/dtas/player.rb @@ -426,7 +426,7 @@ class DTAS::Player # :nodoc: dst = @sink_buf pending.dst_assoc(dst) - pending.src_spawn(@format, @rg, out: dst.wr, in: "/dev/null") + pending.src_spawn(@format, @rg, out: dst.wr, in: DTAS.null) # watch and restart on modifications pending.respond_to?(:watch_begin) and diff --git a/lib/dtas/sink.rb b/lib/dtas/sink.rb index 70d6861..0bf49f4 100644 --- a/lib/dtas/sink.rb +++ b/lib/dtas/sink.rb @@ -91,7 +91,7 @@ class DTAS::Sink # :nodoc: w.sink = self rv << w end - opts[:in] = "/dev/null" + opts[:in] = DTAS.null # map to real /dev/fd/* values and setup proper redirects cmd = cmd.gsub(DEVFD_RE) do -- EW