From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 02 11:46:56 2010 Received: (at submit) by debbugs.gnu.org; 2 Jun 2010 15:46:56 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJq9f-0003q8-5y for submit@debbugs.gnu.org; Wed, 02 Jun 2010 11:46:55 -0400 Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJksM-0000r2-8J for submit@debbugs.gnu.org; Wed, 02 Jun 2010 06:08:42 -0400 Received: from lists.gnu.org ([199.232.76.165]:54290) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1OJksJ-0004DH-Cf for submit@debbugs.gnu.org; Wed, 02 Jun 2010 06:08:39 -0400 Received: from [140.186.70.92] (port=34096 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJksH-0001q6-Qf for bug-coreutils@gnu.org; Wed, 02 Jun 2010 06:08:38 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE, T_DKIM_INVALID, T_TO_NO_BRKTS_FREEMAIL autolearn=unavailable version=3.3.1 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJksG-0006mZ-Ea for bug-coreutils@gnu.org; Wed, 02 Jun 2010 06:08:37 -0400 Received: from mail-ww0-f41.google.com ([74.125.82.41]:55323) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJksG-0006mQ-Ae for bug-coreutils@gnu.org; Wed, 02 Jun 2010 06:08:36 -0400 Received: by wwb24 with SMTP id 24so2401998wwb.0 for ; Wed, 02 Jun 2010 03:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=HplcAAbNI5O6oWmkn7492mqtCaDBOuGijFCYI2YAbkk=; b=mduMoIT4L5XSn6OtaSDoBM8KjL5m2nR196W6dzghqID7Imvb5cHA+shKlf8qDqTPRB 4aLF8CgfAmcftrm50GuVGvqutvoJrNpUX2aVucM5SI1b3U9ZJNYBBsDaGq7qu07gcOWn oiMB4LMRsi9DU/r0MOzFvlUCI++x4U9MBgU44= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=jnBkmzk61rJQzfhSWZUtAhOmWVRAKA+8zIOD2sjvAXv5haY8xaMe1cI1IGKVjkLByi E3TE/PJ7aBKaF105fwy9O1EqcQuiPcqM7cbl5j/6eF16c+rMOyOAfeBXFmv9BaMItEuX rvtynMFlLvFJSdjtlrRQAucgwsG0COUXyL9HQ= MIME-Version: 1.0 Received: by 10.216.85.74 with SMTP id t52mr718873wee.99.1275473314280; Wed, 02 Jun 2010 03:08:34 -0700 (PDT) Received: by 10.216.15.142 with HTTP; Wed, 2 Jun 2010 03:08:34 -0700 (PDT) Date: Wed, 2 Jun 2010 12:08:34 +0200 X-Google-Sender-Auth: ZhBSZaeQHiwMFUE0X7f1NxEhyLM Message-ID: Subject: Feature request: mktemp creates named pipes From: Sebastien Andre To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary=0016e6db24d1d174280488094500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -5.9 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 02 Jun 2010 11:46:53 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) --0016e6db24d1d174280488094500 Content-Type: text/plain; charset=UTF-8 Hello guys! When needing a temporary named pipe in shell scripts, I've often been writing the following function: mktempfifo() { local path=$(mktemp -t) rm "$path" mkfifo -m 0600 "$path" echo "$path" } I was wondering if anybody would be interested in having an option -p --pipe (or -f --fifo since -p is deprecated) to create temporary named pipes? Example: $ file $(mktemp -tp) /tmp/tmp.24665457: fifo (named pipe) PS: I can try to provide a patch if my bug is accepted Thanks, Sebastien --0016e6db24d1d174280488094500 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello guys!

When needing a temporary named pipe in shell scripts, I&= #39;ve often been writing the following function:

mktempfifo() {
= =C2=A0=C2=A0=C2=A0 local path=3D$(mktemp -t)
=C2=A0=C2=A0=C2=A0 rm "= ;$path"
=C2=A0=C2=A0=C2=A0 mkfifo -m 0600 "$path"
=C2=A0=C2=A0=C2=A0 echo "$path"
}

I was wondering if an= ybody would be interested in having an option -p --pipe (or -f --fifo since= -p is deprecated)
to create temporary named pipes?

Example:
= =C2=A0=C2=A0 $ file $(mktemp -tp)
=C2=A0=C2=A0 /tmp/tmp.24665457: fifo (named pipe)


PS: I can try = to provide a patch if my bug is accepted

Thanks,
Sebastien
--0016e6db24d1d174280488094500-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 02 12:13:35 2010 Received: (at 6330) by debbugs.gnu.org; 2 Jun 2010 16:13:35 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJqZT-00042V-3M for submit@debbugs.gnu.org; Wed, 02 Jun 2010 12:13:35 -0400 Received: from joseki.proulx.com ([216.17.153.58]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJqZQ-00042Q-Ol for 6330@debbugs.gnu.org; Wed, 02 Jun 2010 12:13:34 -0400 Received: from dementia.proulx.com (dementia.proulx.com [192.168.230.115]) by joseki.proulx.com (Postfix) with ESMTP id 3EC2D21378; Wed, 2 Jun 2010 10:13:27 -0600 (MDT) Received: by dementia.proulx.com (Postfix, from userid 1000) id 376F63CC204; Wed, 2 Jun 2010 10:13:27 -0600 (MDT) Date: Wed, 2 Jun 2010 10:13:27 -0600 From: Bob Proulx To: Sebastien Andre Subject: Re: bug#6330: Feature request: mktemp creates named pipes Message-ID: <20100602161327.GB14757@dementia.proulx.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: 6330 Cc: 6330@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.4 (--) Sebastien Andre wrote: > When needing a temporary named pipe in shell scripts, I've often been > writing the following function: > > mktempfifo() { > local path=$(mktemp -t) > rm "$path" > mkfifo -m 0600 "$path" > echo "$path" > } Ew... That isn't safe. There is a time gap between when you remove the temporary file and create the pipe. That isn't good. > I was wondering if anybody would be interested in having an option -p --pipe > (or -f --fifo since -p is deprecated) > to create temporary named pipes? > > Example: > $ file $(mktemp -tp) > /tmp/tmp.24665457: fifo (named pipe) The traditional way to deal with the entire range of issues such as this (creating files with different suffixes, whatever) is to have mktemp create a directory and then create your special files within the directory. It is fully safe that way. Because the directory is uniquely named the file within can have a fixed name. No race condition exists. This is off of the top of my head, untested, but you might try something like this example. This is a do-nothing but with enough to hopefully show you the technique. #!/bin/sh unset tmpdir trap 'cd / ; rm -rf "$tmpdir"' EXIT tmpdir=$(mktemp -d) || exit 1 tmppipe="$tmpdir/pipe" mknod "$tmppipe" p ls -log "$tmppipe" exit 0 Bob From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 02 12:15:25 2010 Received: (at 6330) by debbugs.gnu.org; 2 Jun 2010 16:15:25 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJqbF-00043o-BC for submit@debbugs.gnu.org; Wed, 02 Jun 2010 12:15:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJqbC-00043i-7y for 6330@debbugs.gnu.org; Wed, 02 Jun 2010 12:15:23 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o52GFFd3025063 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Jun 2010 12:15:16 -0400 Received: from [10.3.227.83] (vpn-227-83.phx2.redhat.com [10.3.227.83]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o52GFEFS017976; Wed, 2 Jun 2010 12:15:14 -0400 Message-ID: <4C068371.4090702@redhat.com> Date: Wed, 02 Jun 2010 10:14:41 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-3.fc13 Lightning/1.0b2pre Mnenhy/0.8.2 Thunderbird/3.0.4 MIME-Version: 1.0 To: Sebastien Andre Subject: Re: bug#6330: Feature request: mktemp creates named pipes References: In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigFCF57C7CFC3999B160BA5B8D" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Spam-Score: -10.1 (----------) X-Debbugs-Envelope-To: 6330 Cc: 6330@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.1 (----------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFCF57C7CFC3999B160BA5B8D Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/02/2010 04:08 AM, Sebastien Andre wrote: > Hello guys! >=20 > When needing a temporary named pipe in shell scripts, I've often been > writing the following function: >=20 > mktempfifo() { > local path=3D$(mktemp -t) > rm "$path" > mkfifo -m 0600 "$path" > echo "$path" > } First off, thanks for the suggestion. What's wrong with the example given in the manual (info coreutils mktemp), as adjusted to your usage pattern: mktempfifo() { local dir dir=3D$(mktemp -t -d) || return 1 mkfifo -m 0600 "$dir/fifo" || return 1 echo "$dir/fifo" } other than the fact that you have to remember to also remove the temporary directory? And if you need to create more than one secure temporary object, it becomes a much easier paradigm to create a single secure directory in which to place all the other objects, and use a simple 'rm -rf "$tmpdir"' in your cleanup paths. That's how coreutils 'make check' works - every test is run inside its own temporary directory, and within the body of the test, there is no need to worry about name collisions from external processes. >=20 > I was wondering if anybody would be interested in having an option -p -= -pipe > (or -f --fifo since -p is deprecated) > to create temporary named pipes? You are correct that a short option -p cannot be used. And I'm reluctant to burn -f unless there is another implementation that already does it. But you have a point that adding a long option --fifo may make sense. However, I thought about that same point the last time I touched mktemp(1), and did not implement it at that time because I felt that a temporary directory was enough. But I can be swayed if you can present good arguments why the addition is better than using existing tools. >=20 > PS: I can try to provide a patch if my bug is accepted Patches speak volumes, although by the time you add the code and the documentation, your contribution would probably be non-trivial and require copyright assignment to the FSF. Let us know if you'd like to start that process. --=20 Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org --------------enigFCF57C7CFC3999B160BA5B8D Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJMBoN2AAoJEKeha0olJ0NqZyEH/jgmdyIMXCgZI9IvdUWB1GcH hGALfI+F9SK+5qJHUulIRAYXJUFZXJJGNMcJ00d09eRh8a3KnUeSa+nKRBU6NVIf Rq3zh+GSzhMGiJOkiLRYar63QcODY2rkUrNh/okoppzS07JD4yDafD+mA+qkgLeN PyJGjDDaf14k1YWi69vvZymHXNrq5LNAAjxQyfnLV0MMyvJJP79ytY9ZTPyH3oVx OQErAhK4KUsRGeWX3e2+DGhxhdTIAwVBiMSRlAfayr6P7SWWn0nV+DQxaoxukz3U AmTkWsj1BGZc2TdoeG1a8FXNZ2jBLDwIpzVSS7TamCPSCqL2tiHjn40ZmiUkFgc= =/kYe -----END PGP SIGNATURE----- --------------enigFCF57C7CFC3999B160BA5B8D-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 03 06:04:40 2010 Received: (at 6330) by debbugs.gnu.org; 3 Jun 2010 10:04:40 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OK7I0-0002wV-8H for submit@debbugs.gnu.org; Thu, 03 Jun 2010 06:04:40 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OK7Hy-0002wQ-LN for 6330@debbugs.gnu.org; Thu, 03 Jun 2010 06:04:39 -0400 Received: by wwb39 with SMTP id 39so3317323wwb.3 for <6330@debbugs.gnu.org>; Thu, 03 Jun 2010 03:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=p14+klSwT52QpGb83bMUM7ZeNfV/aviJSZrPVmAqmEE=; b=PQKysPSW5m1BIRXxUfE6BrpDyAv5t+hduJr2mL0RzvJfEaaHqJZimat1jPJEw7hj9G SdTQKzqaBzit3bUJTKUG8pa0MZs+UXOriCff+IXpYBaSUT+ePQ54zSqxaIsgTsUjBWXe XJjsfBafTLfl4uaSKxf8ZGpRjab3f2kDZ//fM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=ibBfsepz/tmbulIzTTywzigC8HgJOWw7PB9/CGe8ufb61CjBIx3J5+2kremqnsqju9 g6DV2UUq6u2aciJ4Va/0vmdybC8WrRVigOH3s/yst7FfYIq4nZVbUijMlXC1+VViCR5k lJ+uTVZ0JGyrOQ+b8EioI6g44RP+hvGD2biNk= MIME-Version: 1.0 Received: by 10.227.128.129 with SMTP id k1mr9021767wbs.32.1275559475006; Thu, 03 Jun 2010 03:04:35 -0700 (PDT) Received: by 10.216.15.142 with HTTP; Thu, 3 Jun 2010 03:04:34 -0700 (PDT) In-Reply-To: <20100602161327.GB14757@dementia.proulx.com> References: <20100602161327.GB14757@dementia.proulx.com> Date: Thu, 3 Jun 2010 12:04:34 +0200 X-Google-Sender-Auth: DKn08T0XBKFjsOxiGrI_Ka72218 Message-ID: Subject: Re: bug#6330: Feature request: mktemp creates named pipes From: Sebastien Andre To: Bob Proulx Content-Type: multipart/alternative; boundary=001636456ff065cca704881d5526 X-Spam-Score: -3.3 (---) X-Debbugs-Envelope-To: 6330 Cc: 6330@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.4 (---) --001636456ff065cca704881d5526 Content-Type: text/plain; charset=UTF-8 On Wed, Jun 2, 2010 at 6:13 PM, Bob Proulx wrote: > Sebastien Andre wrote: > > When needing a temporary named pipe in shell scripts, I've often been > > writing the following function: > > > > mktempfifo() { > > local path=$(mktemp -t) > > rm "$path" > > mkfifo -m 0600 "$path" > > echo "$path" > > } > > Ew... That isn't safe. There is a time gap between when you remove > the temporary file and create the pipe. That isn't good. > > > I was wondering if anybody would be interested in having an option -p > --pipe > > (or -f --fifo since -p is deprecated) > > to create temporary named pipes? > > > > Example: > > $ file $(mktemp -tp) > > /tmp/tmp.24665457: fifo (named pipe) > > The traditional way to deal with the entire range of issues such as > this (creating files with different suffixes, whatever) is to have > mktemp create a directory and then create your special files within > the directory. It is fully safe that way. Because the directory is > uniquely named the file within can have a fixed name. No race > condition exists. > > This is off of the top of my head, untested, but you might try > something like this example. This is a do-nothing but with enough to > hopefully show you the technique. > > #!/bin/sh > unset tmpdir > trap 'cd / ; rm -rf "$tmpdir"' EXIT > tmpdir=$(mktemp -d) || exit 1 > tmppipe="$tmpdir/pipe" > mknod "$tmppipe" p > ls -log "$tmppipe" > exit 0 > > Bob > Thank you Bob for the suggestion I agree my example was bad, my goal was to show the hassle in creating a temporary named fifo in a shell script. The traditional way, with the directory safely created and removed on exit, is better but still not as convenient as a "mktemp -f" would be. Sebastien --001636456ff065cca704881d5526 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Wed, Jun 2, 2010 at 6:13 PM, Bob Proulx <bob@proulx.com> wrote:
Sebastien Andre wrote:
> When needing a temporary named pipe in shell scripts, I've often b= een
> writing the following function:
>
> mktempfifo() {
> =C2=A0 =C2=A0 local path=3D$(mktemp -t)
> =C2=A0 =C2=A0 rm "$path"
> =C2=A0 =C2=A0 mkfifo -m 0600 "$path"
> =C2=A0 =C2=A0 echo "$path"
> }

Ew... =C2=A0That isn't safe. =C2=A0There is a time gap between when you= remove
the temporary file and create the pipe. =C2=A0That isn't good.

> I was wondering if anybody would be interested in having an option -p = --pipe
> (or -f --fifo since -p is deprecated)
> to create temporary named pipes?
>
> Example:
> =C2=A0 =C2=A0$ file $(mktemp -tp)
> =C2=A0 =C2=A0/tmp/tmp.24665457: fifo (named pipe)

The traditional way to deal with the entire range of issues such as
this (creating files with different suffixes, whatever) is to have
mktemp create a directory and then create your special files within
the directory. =C2=A0It is fully safe that way. =C2=A0Because the directory= is
uniquely named the file within can have a fixed name. =C2=A0No race
condition exists.

This is off of the top of my head, untested, but you might try
something like this example. =C2=A0This is a do-nothing but with enough to<= br> hopefully show you the technique.

=C2=A0#!/bin/sh
=C2=A0unset tmpdir
=C2=A0trap 'cd / ; rm -rf "$tmpdir"' EXIT
=C2=A0tmpdir=3D$(mktemp -d) || exit 1
=C2=A0tmppipe=3D"$tmpdir/pipe"
=C2=A0mknod "$tmppipe" p
=C2=A0ls -log "$tmppipe"
=C2=A0exit 0

Bob

Thank you Bob for the suggestion

I agr= ee my example was bad, my goal was to show the hassle in creating a tempora= ry named fifo in a shell script.
The traditional way, with the directory= safely created and removed on exit, is better but still not as convenient = as a "mktemp -f" would be.

Sebastien


--001636456ff065cca704881d5526-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 03 15:10:04 2010 Received: (at 6330) by debbugs.gnu.org; 3 Jun 2010 19:10:04 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKFnn-0002Ko-DP for submit@debbugs.gnu.org; Thu, 03 Jun 2010 15:10:03 -0400 Received: from mail-wy0-f172.google.com ([74.125.82.172]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKFnj-0002KH-Jh for 6330@debbugs.gnu.org; Thu, 03 Jun 2010 15:10:01 -0400 Received: by wyf23 with SMTP id 23so306340wyf.3 for <6330@debbugs.gnu.org>; Thu, 03 Jun 2010 12:09:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=e8S0whfF9NWRkXCxnyXmvebY/rx+UTa9jvY9A/UPqNM=; b=Q4Sb2raFjw0LrbhGuUb9bswvpIF6sZHTSeb/H7Q3VQoMNpJN8IpfLU+nEwgvISBMlk RyVPgL4unl3mYG5zokN0YCPjJ6b5q67d1hRixBoo7vkjKRYFAx4227DFoJM/Zqu6vzRK iQUlzMb8fW6dMuT0E48UkwMxxlPmAjJQwYh5g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=bOrdCequOO6IYqtCXm23m4m8d7p+8DRBhxArOH+MlgRRcScCKki1NSUZzPQdh/3bdR z75yPW3Cek7HV+kwK3phsBExirHLAJ1VR9NmZm0DyTjemBzmkPl5suqEym+mJAO06BdD 5fyChICOUegF9FOfP2wJKgnwNPNH2vEr5G+tM= MIME-Version: 1.0 Received: by 10.216.164.20 with SMTP id b20mr1471578wel.101.1275592193979; Thu, 03 Jun 2010 12:09:53 -0700 (PDT) Received: by 10.216.15.142 with HTTP; Thu, 3 Jun 2010 12:09:53 -0700 (PDT) In-Reply-To: <4C068371.4090702@redhat.com> References: <4C068371.4090702@redhat.com> Date: Thu, 3 Jun 2010 21:09:53 +0200 X-Google-Sender-Auth: S8752CM3BP814PY5LyoxPbrjvco Message-ID: Subject: Re: bug#6330: Feature request: mktemp creates named pipes From: Sebastien Andre To: Eric Blake Content-Type: multipart/alternative; boundary=0016e64c1f4899b660048824f350 X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 6330 Cc: 6330@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.8 (--) --0016e64c1f4899b660048824f350 Content-Type: text/plain; charset=UTF-8 On Wed, Jun 2, 2010 at 6:14 PM, Eric Blake wrote: > On 06/02/2010 04:08 AM, Sebastien Andre wrote: > > Hello guys! > > > > When needing a temporary named pipe in shell scripts, I've often been > > writing the following function: > > > > mktempfifo() { > > local path=$(mktemp -t) > > rm "$path" > > mkfifo -m 0600 "$path" > > echo "$path" > > } > > First off, thanks for the suggestion. > > What's wrong with the example given in the manual (info coreutils > mktemp), as adjusted to your usage pattern: > > mktempfifo() { > local dir > dir=$(mktemp -t -d) || return 1 > mkfifo -m 0600 "$dir/fifo" || return 1 > echo "$dir/fifo" > } > > other than the fact that you have to remember to also remove the > temporary directory? And if you need to create more than one secure > temporary object, it becomes a much easier paradigm to create a single > secure directory in which to place all the other objects, and use a > simple 'rm -rf "$tmpdir"' in your cleanup paths. That's how coreutils > 'make check' works - every test is run inside its own temporary > directory, and within the body of the test, there is no need to worry > about name collisions from external processes. > > > > > I was wondering if anybody would be interested in having an option -p > --pipe > > (or -f --fifo since -p is deprecated) > > to create temporary named pipes? > > You are correct that a short option -p cannot be used. And I'm > reluctant to burn -f unless there is another implementation that already > does it. But you have a point that adding a long option --fifo may make > sense. However, I thought about that same point the last time I touched > mktemp(1), and did not implement it at that time because I felt that a > temporary directory was enough. But I can be swayed if you can present > good arguments why the addition is better than using existing tools. > > Thank you Eric for your answer, I see two reasons why the addition of a --fifo option is better than using existing tools: * Creating a temporary directory to finally create a pipe just because it is safe this way is kind of a trick. For the clarity of scripts, it would be better having mktemp to ensure the uniqueness of a fifo, even if it's created in / * mktemp is not only a tool to create unique files, it's also a name generator. The example given in the manual works for one or two fifos, but if the number of fifos is unknown there is no choice but implementing something to generate names, which is another potential source of bugs. Below is an example of two functions using temp fifos, with and without the -f option (code not tested): # merge the output of every given command, line by line (fifos are not removed for clarity) merge_output_mktempfifo() { local fifos=() if [ $# -gt 0 ]; then for cmd in "$@"; do local fifo=$(mktemp -tf) || return 1 ( $cmd > $fifo ) & fifos=( ${fifos[@]} $fifo ) done paste "${fifos[@]}" wait fi } merge_output_traditional() { local tmpdir=$(mktemp -td) || return 1 local i=0 if [ $# -gt 0 ]; then for cmd in "$@"; do i=$(expr $i + 1) mkfifo -m 0600 "$tmpdir/fifo$i" ( $cmd > "$tmpdir/fifo$i" ) & done paste $tmpdir/fifo* wait fi } The merge_output_traditional() function is more difficult to understand than merge_output_mktempfifo() because of the use of $i to ensure unicity of fifo names. If for any reason $tmpdir must be shared with other processes which use the exact same function it will lead to a mess, that's why I prefer merge_output_mktempfifo(). I think the "traditional way" to deal with named fifos is good and efficient but tricky. The -f option would be more straightforward. > > > PS: I can try to provide a patch if my bug is accepted > > Patches speak volumes, although by the time you add the code and the > documentation, your contribution would probably be non-trivial and > require copyright assignment to the FSF. Let us know if you'd like to > start that process. > > Yes, I'm interested in starting that process. > -- > Eric Blake eblake@redhat.com +1-801-349-2682 > Libvirt virtualization library http://libvirt.org > > --0016e64c1f4899b660048824f350 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Wed, Jun 2, 2010 at 6:14 PM, Eric Blake <ebl= ake@redhat.com> wrote:
On 06/02/2010 04:08 AM, Sebastien Andre wrote:
> Hello guys!
>
> When needing a temporary named pipe in shell scripts, I've often b= een
> writing the following function:
>
> mktempfifo() {
> =C2=A0 =C2=A0 local path=3D$(mktemp -t)
> =C2=A0 =C2=A0 rm "$path"
> =C2=A0 =C2=A0 mkfifo -m 0600 "$path"
> =C2=A0 =C2=A0 echo "$path"
> }

First off, thanks for the suggestion.

What's wrong with the example given in the manual (info coreutils
mktemp), as adjusted to your usage pattern:

mktempfifo() {
=C2=A0 =C2=A0local dir
=C2=A0 =C2=A0dir=3D$(mktemp -t -d) || return 1
=C2=A0 =C2=A0mkfifo -m 0600 "$dir/fifo" || return 1
=C2=A0 =C2=A0echo "$dir/fifo"
}

other than the fact that you have to remember to also remove the
temporary directory? =C2=A0And if you need to create more than one secure temporary object, it becomes a much easier paradigm to create a single
secure directory in which to place all the other objects, and use a
simple 'rm -rf "$tmpdir"' in your cleanup paths. =C2=A0Th= at's how coreutils
'make check' works - every test is run inside its own temporary
directory, and within the body of the test, there is no need to worry
about name collisions from external processes.

>
> I was wondering if anybody would be interested in having an option -p = --pipe
> (or -f --fifo since -p is deprecated)
> to create temporary named pipes?

You are correct that a short option -p cannot be used. =C2=A0And I= 9;m
reluctant to burn -f unless there is another implementation that already does it. =C2=A0But you have a point that adding a long option --fifo may ma= ke
sense. =C2=A0However, I thought about that same point the last time I touch= ed
mktemp(1), and did not implement it at that time because I felt that a
temporary directory was enough. =C2=A0But I can be swayed if you can presen= t
good arguments why the addition is better than using existing tools.


Thank you Eric for your answer,

I see two = reasons why the addition of a --fifo option is better than using existing t= ools:

=C2=A0=C2=A0=C2=A0 * Creating a temporary directory to finally= create a pipe just because it is safe this way is kind of a trick. For the= clarity of scripts, it would be better having mktemp to ensure the uniquen= ess of a fifo, even if it's created in /

=C2=A0=C2=A0=C2=A0 * mktemp is not only a tool to create unique files, = it's also a name generator. The example given in the manual works for o= ne or two fifos, but if the number of fifos is unknown there is no choice b= ut implementing something to generate names, which is another potential sou= rce of bugs.


Below is an example of two functions using temp fifos, with and wit= hout the -f option (code not tested):


# merge the output of ever= y given command, line by line (fifos are not removed for clarity)

merge_output_mktempfifo() {
=C2=A0=C2=A0=C2=A0 local fifos=3D()
=C2=A0=C2=A0=C2=A0 if [ $# -gt 0 ]; then
=C2=A0 =C2=A0=C2=A0 =C2=A0=C2= =A0 for cmd in "$@"; do
=C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0= =C2=A0=C2=A0 local fifo=3D$(mktemp -tf) || return 1
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ( $cmd > $fifo ) &<= br>=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fifos=3D( ${fif= os[@]} $fifo )
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 done
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 paste "${fifos[@]}"
=C2=A0 =C2=A0 =C2=A0= =C2=A0 wait
=C2=A0=C2=A0=C2=A0 fi
}

merge_output_traditional()= {
=C2=A0=C2=A0=C2=A0 local tmpdir=3D$(mktemp -td) || return 1
=C2=A0=C2=A0= =C2=A0 local i=3D0
=C2=A0=C2=A0=C2=A0 if [ $# -gt 0 ]; then
=C2=A0 = =C2=A0=C2=A0 =C2=A0=C2=A0 for cmd in "$@"; do
=C2=A0=C2=A0=C2= =A0 =C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 i=3D$(expr $i + 1)
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mkfifo -m 0600 "$t= mpdir/fifo$i"
=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ( $cmd > "= $tmpdir/fifo$i" ) &
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 done
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 paste $tmpdir/fifo*
=C2=A0 =C2=A0=C2=A0 =C2=A0=C2=A0 wait
=C2=A0=C2=A0=C2=A0 fi
}

The merge_output_traditional() function is more difficult to under= stand than merge_output_mktempfifo() because of the use
of $i to ensure = unicity of fifo names. If for any reason $tmpdir must be shared with other = processes which use the exact same function it will
lead to a mess, that's why I prefer merge_output_mktempfifo().

I= think the "traditional way" to deal with named fifos is good and= efficient but tricky. The -f option would be more straightforward.

>
> PS: I can try to provide a patch if my bug is accepted

Patches speak volumes, although by the time you add the code and the
documentation, your contribution would probably be non-trivial and
require copyright assignment to the FSF. =C2=A0Let us know if you'd lik= e to
start that process.


Yes, I'm inter= ested in starting that process.


=C2=A0
--
Eric Blake =C2=A0 eb= lake@redhat.com =C2=A0 =C2=A0+1-801-349-2682
Libvirt virtualization library http://libvirt.org


--0016e64c1f4899b660048824f350-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 05 03:25:38 2010 Received: (at 6330) by debbugs.gnu.org; 5 Jun 2010 07:25:38 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKnlB-0000A4-W6 for submit@debbugs.gnu.org; Sat, 05 Jun 2010 03:25:38 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKnl9-00009z-IQ for 6330@debbugs.gnu.org; Sat, 05 Jun 2010 03:25:36 -0400 Received: from mx.meyering.net (mx.meyering.net [82.230.74.64]) by smtp1-g21.free.fr (Postfix) with ESMTP id 15572940014; Sat, 5 Jun 2010 09:25:26 +0200 (CEST) Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 46F39E6CF; Sat, 5 Jun 2010 09:25:25 +0200 (CEST) From: Jim Meyering To: Sebastien Andre Subject: Re: bug#6330: Feature request: mktemp creates named pipes In-Reply-To: (Sebastien Andre's message of "Thu, 3 Jun 2010 21:09:53 +0200") References: <4C068371.4090702@redhat.com> Date: Sat, 05 Jun 2010 09:25:25 +0200 Message-ID: <87r5kmym8q.fsf@meyering.net> Lines: 26 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Score: -2.0 (--) X-Debbugs-Envelope-To: 6330 Cc: Eric Blake , 6330@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.3 (---) Sebastien Andre wrote: ... > I see two reasons why the addition of a --fifo option is better than using > existing tools: > > * Creating a temporary directory to finally create a pipe just because > it is safe this way is kind of a trick. For the clarity of scripts, it would > be better having mktemp to ensure the uniqueness of a fifo, even if it's > created in / "because it is safe" is often a good reason to learn and use a new idiom. When you first encounter such an idiom, it does indeed look like a "trick". > * mktemp is not only a tool to create unique files, it's also a name > generator. The example given in the manual works for one or two fifos, but > if the number of fifos is unknown there is no choice but implementing > something to generate names, which is another potential source of bugs. Any code addition is an opportunity to introduce bugs ;-) What if someone wants a uniquely-named symlink? New option? ... or a shared memory object? Add another? Wouldn't it be better to use the tried and true (safe) idiom that will work with all versions of mktemp? Then your script will work also on systems that use the version of mktemp that predated the one in coreutils. From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 07 20:42:29 2010 Received: (at 6330) by debbugs.gnu.org; 8 Jun 2010 00:42:29 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLmtg-00070i-PA for submit@debbugs.gnu.org; Mon, 07 Jun 2010 20:42:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLmte-00070b-7k for 6330@debbugs.gnu.org; Mon, 07 Jun 2010 20:42:27 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o580gGff013918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 7 Jun 2010 20:42:16 -0400 Received: from [10.11.10.218] (vpn-10-218.rdu.redhat.com [10.11.10.218]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o580gApD021400; Mon, 7 Jun 2010 20:42:11 -0400 Message-ID: <4C0D91C8.3020201@redhat.com> Date: Mon, 07 Jun 2010 18:41:44 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-3.fc13 Lightning/1.0b2pre Mnenhy/0.8.2 Thunderbird/3.0.4 MIME-Version: 1.0 To: Sebastien Andre Subject: Re: bug#6330: Feature request: mktemp creates named pipes References: <4C068371.4090702@redhat.com> In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigB3CF180915C77DABEA10ADFF" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-Spam-Score: -8.8 (--------) X-Debbugs-Envelope-To: 6330 Cc: 6330@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.1 (----------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigB3CF180915C77DABEA10ADFF Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/03/2010 01:09 PM, Sebastien Andre wrote: > I see two reasons why the addition of a --fifo option is better than us= ing > existing tools: >=20 > * Creating a temporary directory to finally create a pipe just beca= use > it is safe this way is kind of a trick. For the clarity of scripts, it = would > be better having mktemp to ensure the uniqueness of a fifo, even if it'= s > created in / Why do you need to create fifos directly in /? Unless you can prove that it is needed there, then what's wrong with creating it elsewhere? Maybe the real feature we should be asking for is a way to ensure that 'mv /path1/to/fifo /path2/to/fifo' is atomic, and fails if /path2/to/fifo is a dangling symlink rather than accidentally creating the fifo at an unintended location? >=20 > * mktemp is not only a tool to create unique files, it's also a nam= e > generator. The example given in the manual works for one or two fifos, = but > if the number of fifos is unknown there is no choice but implementing > something to generate names, which is another potential source of bugs.= If you are worried about creating lots of fifos, and want to avoid collisions, you can still use the existing semantics of unpatched mktemp to get that: merely make a secure directory with mktemp -d, then use mkfifo "$(mktemp -u -p "$dir")". That is, once you have a safe directory, then mktemp -u within that directory is no longer a security hole, and serves as a great way to create unique names without also creating files. > of $i to ensure unicity of fifo names. If for any reason $tmpdir must b= e > shared with other processes which use the exact same function it will > lead to a mess, that's why I prefer merge_output_mktempfifo(). As long as the multiple processes are closely cooperating, and all use the same secure temporary directory, then mktemp -u is an appropriate way for each of those processes to name their fifo. >> Patches speak volumes, although by the time you add the code and the >> documentation, your contribution would probably be non-trivial and >> require copyright assignment to the FSF. Let us know if you'd like to= >> start that process. >> >> > Yes, I'm interested in starting that process. I'm sending you some details off-list. --=20 Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org --------------enigB3CF180915C77DABEA10ADFF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJMDZHIAAoJEKeha0olJ0NqSs0H/2K4rFF3ZgUB8cqT1+XERIZ9 3fprDlgoaJBX0u19HvnV6HMHbBpRbCo1v8lw5Hs8RsA9NoFKYdwV9kTa6b8JSErb Y28lG5jS2hGAIgyfdvfScDYwdWZ8V5IPPa1ayypYNqnDAVOcdXqhCUMlBBozSCZ5 q5b51oQsONdD+KxBngufOI667QlnftY3oMYF/7FqeV1CixJef/VeFKNuCRFOwEYL zGx8KxQmnjHXoJajA4mRfL8qxVIQ5sTHJpbYEfdN6/OuwmWNXgrdLSTXTLkEr9FS SNcJ2BsfxEEtX/cbjr1rslFwP9j1CQ1T4iHqNevyvvScu14AQYHSE5bA0a/v7XA= =gFcS -----END PGP SIGNATURE----- --------------enigB3CF180915C77DABEA10ADFF-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 08 02:37:01 2010 Received: (at 6330) by debbugs.gnu.org; 8 Jun 2010 06:37:01 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLsQm-0000s7-0Z for submit@debbugs.gnu.org; Tue, 08 Jun 2010 02:37:00 -0400 Received: from mail-wy0-f172.google.com ([74.125.82.172]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLsQj-0000s0-Vy for 6330@debbugs.gnu.org; Tue, 08 Jun 2010 02:36:58 -0400 Received: by wyb32 with SMTP id 32so485744wyb.3 for <6330@debbugs.gnu.org>; Mon, 07 Jun 2010 23:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=w3LY7vI2M/5f2urgo4wKrrazb8n9UBQbod5F5QK4Wyg=; b=v+PMBEpgmJRkBNu+orauQeOtJtpjyxEM5OWn1L1mimbi+2o7J52rMf3hSb/Xg7R6ko XXMomTZwZSwuZmvyAqh66pXr2OCR4Xh74ljj6F1cJRpA28mzNEBAW89WkeshaJQTQqwK Rgyag1n7XWfT/nhvLEfXnth7/5fj09MdnRyz4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=QOt0IUXdyqZc5ludAby2zUx2d2KG/kY8W01PmXQENIRYv/t4lNODW9Krx5SJQ89H8q c02VgdRMIwu6WXLH3rvlfsTdRUQEsx+4mOCDCQ9hOi38gqAX3VWpGQih+4HyViZxp4nj U2IVuOFVqiCdDfneDBFfCvI5aWSSjtt5c1t8w= MIME-Version: 1.0 Received: by 10.227.143.205 with SMTP id w13mr395860wbu.162.1275979014139; Mon, 07 Jun 2010 23:36:54 -0700 (PDT) Received: by 10.216.182.203 with HTTP; Mon, 7 Jun 2010 23:36:53 -0700 (PDT) In-Reply-To: <87r5kmym8q.fsf@meyering.net> References: <4C068371.4090702@redhat.com> <87r5kmym8q.fsf@meyering.net> Date: Tue, 8 Jun 2010 08:36:53 +0200 X-Google-Sender-Auth: py6_FEIfvCpUoROjKqe8NT5LOsU Message-ID: Subject: Re: bug#6330: Feature request: mktemp creates named pipes From: Sebastien Andre To: Jim Meyering Content-Type: multipart/alternative; boundary=0016365ee90ae0efd304887f0372 X-Spam-Score: -2.8 (--) X-Debbugs-Envelope-To: 6330 Cc: Eric Blake , 6330@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.8 (--) --0016365ee90ae0efd304887f0372 Content-Type: text/plain; charset=UTF-8 On Sat, Jun 5, 2010 at 9:25 AM, Jim Meyering wrote: > Sebastien Andre wrote: > ... > > I see two reasons why the addition of a --fifo option is better than > using > > existing tools: > > > > * Creating a temporary directory to finally create a pipe just > because > > it is safe this way is kind of a trick. For the clarity of scripts, it > would > > be better having mktemp to ensure the uniqueness of a fifo, even if it's > > created in / > > "because it is safe" is often a good reason to learn and use a new idiom. > When you first encounter such an idiom, it does indeed look like a "trick". > > Well, after all an idiom might just be a "popular trick" > > * mktemp is not only a tool to create unique files, it's also a name > > generator. The example given in the manual works for one or two fifos, > but > > if the number of fifos is unknown there is no choice but implementing > > something to generate names, which is another potential source of bugs. > > Any code addition is an opportunity to introduce bugs ;-) > > What if someone wants a uniquely-named symlink? > New option? ... or a shared memory object? Add another? > Wouldn't it be better to use the tried and true (safe) idiom > that will work with all versions of mktemp? Then > your script will work also on systems that use the > version of mktemp that predated the one in coreutils. > Thank you for broadening the question. You made me realize that what I really want is to use the tempnam(3) function in shell scripts. But having a tempnam command in a shell script would be unsafe unless something is created atomically when invoked. If mktemp(1) is not the right place for this, how about adding a -t/--template option to the mkfifo(1) ? Wanting to get a unique name in a given directory according to a template doesn't sound too specific to me, maybe some other people need it? --0016365ee90ae0efd304887f0372 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Sat, Jun 5, 2010 at 9:25 AM, Jim Meyering= <jim@meyering.net= > wrote:
Sebastien Andre wrote:
...
> I see two reasons why the addition of a --fifo optio= n is better than using
> existing tools:
>
> =C2=A0 =C2=A0 * Creating a temporary directory to finally create a pip= e just because
> it is safe this way is kind of a trick. For the clarity of scripts, it= would
> be better having mktemp to ensure the uniqueness of a fifo, even if it= 's
> created in /

"because it is safe" is often a good reason to learn and us= e a new idiom.
When you first encounter such an idiom, it does indeed look like a "tr= ick".


Well, after all an idiom = might just be a "popular trick"

=C2=A0
> =C2=A0 =C2=A0 * mktemp is not only a tool to create unique files, it&#= 39;s also a name
> generator. The example given in the manual works for one or two fifos,= but
> if the number of fifos is unknown there is no choice but implementing<= br> > something to generate names, which is another potential source of bugs= .

Any code addition is an opportunity to introduce bugs ;-)

What if someone wants a uniquely-named symlink?
New option? =C2=A0... or a shared memory object? =C2=A0Add another?
Wouldn't it be better to use the tried and true (safe) idiom
that will work with all versions of mktemp? =C2=A0Then
your script will work also on systems that use the
version of mktemp that predated the one in coreutils.

Thank you for broadening the question.

You ma= de me realize that what I really want is to use the tempnam(3) function
= in shell scripts. But having a tempnam command in a shell script would be u= nsafe unless
something is created atomically when invoked. If mktemp(1) is not the right=
place for this, how about adding a -t/--template option to the mkfifo(1= ) ?

Wanting to get a unique name in a given directory according to a= template doesn't
sound too specific to me, maybe some other people need it?



<= br> --0016365ee90ae0efd304887f0372-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 08 05:07:37 2010 Received: (at 6330) by debbugs.gnu.org; 8 Jun 2010 09:07:37 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLumW-0001s3-VF for submit@debbugs.gnu.org; Tue, 08 Jun 2010 05:07:37 -0400 Received: from smtp1-g21.free.fr ([212.27.42.1]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLumU-0001rw-Df for 6330@debbugs.gnu.org; Tue, 08 Jun 2010 05:07:35 -0400 Received: from mx.meyering.net (mx.meyering.net [82.230.74.64]) by smtp1-g21.free.fr (Postfix) with ESMTP id 5994D940100; Tue, 8 Jun 2010 11:07:26 +0200 (CEST) Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 08BA3BD2; Tue, 8 Jun 2010 11:07:25 +0200 (CEST) From: Jim Meyering To: Sebastien Andre Subject: Re: bug#6330: Feature request: mktemp creates named pipes In-Reply-To: (Sebastien Andre's message of "Tue, 8 Jun 2010 08:36:53 +0200") References: <4C068371.4090702@redhat.com> <87r5kmym8q.fsf@meyering.net> Date: Tue, 08 Jun 2010 11:07:24 +0200 Message-ID: <87wru9uc37.fsf@meyering.net> Lines: 56 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.3 (---) X-Debbugs-Envelope-To: 6330 Cc: Eric Blake , 6330@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.3 (---) Sebastien Andre wrote: > On Sat, Jun 5, 2010 at 9:25 AM, Jim Meyering wrote: ... > "because it is safe" is often a good reason to learn and use a new id= iom. > When you first encounter such an idiom, it does indeed look like a "t= rick". > > Well, after all an idiom might just be a "popular trick" "Effective technique" is more accurate. This is the "unix way". > > =C2=A0 =C2=A0 * mktemp is not only a tool to create unique files, i= t's also a name > > generator. The example given in the manual works for one or two fif= os, > but > > if the number of fifos is unknown there is no choice but implementi= ng > > something to generate names, which is another potential source of b= ugs. > > Any code addition is an opportunity to introduce bugs ;-) > > What if someone wants a uniquely-named symlink? > New option? =C2=A0... or a shared memory object? =C2=A0Add another? > Wouldn't it be better to use the tried and true (safe) idiom > that will work with all versions of mktemp? =C2=A0Then > your script will work also on systems that use the > version of mktemp that predated the one in coreutils. > > Thank you for broadening the question. > > You made me realize that what I really want is to use the tempnam(3) func= tion > in shell scripts. But having a tempnam command in a shell script would be > unsafe unless > something is created atomically when invoked. If mktemp(1) is not the rig= ht > place for this, how about adding a -t/--template option to the mkfifo(1) ? And to mknod and to ln? > Wanting to get a unique name in a given directory according to a template > doesn't sound too specific to me, maybe some other people need it? If that given directory has only one writer, then using mktemp -u is fine. Other people use mktemp -d, and then can create names however they like (and safely) in the just-created directory. The point that someone might want to create an object of a type other than "fifo" (e.g., symlink, hard link, block dev., etc.) was to make you think about adding a more generic option, but then you'd have to consider how to specify the target of a symlink and major,minor numbers for a block device. I was hoping you would then conclude that this would lead to mktemp subsuming most of the functionality of tools like ln, mkfifo and mknod, and thus rethink your premise that it would be better to change mktemp than to use it the way everyone else does. From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 14 14:39:10 2010 Received: (at 6330) by debbugs.gnu.org; 14 Jun 2010 18:39:10 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOEYv-0001OW-Vz for submit@debbugs.gnu.org; Mon, 14 Jun 2010 14:39:10 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOEYt-0001OR-MS for 6330@debbugs.gnu.org; Mon, 14 Jun 2010 14:39:08 -0400 Received: by wwc33 with SMTP id 33so4183954wwc.3 for <6330@debbugs.gnu.org>; Mon, 14 Jun 2010 11:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=gn/MPVy9+WsZguxg1SAK5u5fSXFLYfmbC47M60HLb0A=; b=lVancvCSylBchptsu90V33v1l7lDXFJY0kDGE2t/8ht+9LIjX6tKTT59EHDReysUSY N1tLh/OMZf1TxZrcUP/xheRJE4w0cVzYWOir2XuoLJlVwTzqQrarg3MDqNCyEQ4kMWcY wDzcLk8ub3EHK2Y9ILNFnkQl51nL60tw8bRRw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=TtqYXoHSfLjyjHhqJ7uaHtvqDrRANkaxpX8ISfTWDGvIewCf4pi/pwxwI7+n5n9QXt v2P2BbX9ne6qAJ4PEVpg3UGqVOubRVWK6QGfzF+B433r+fD3vEyTJh6UMw4X8rEdaX2G T7ns6Fe0rqi19kXK9edbCidxUvxuNUQy8z4zQ= MIME-Version: 1.0 Received: by 10.216.87.5 with SMTP id x5mr2734819wee.90.1276540742676; Mon, 14 Jun 2010 11:39:02 -0700 (PDT) Received: by 10.216.182.203 with HTTP; Mon, 14 Jun 2010 11:39:02 -0700 (PDT) In-Reply-To: <4C0D91C8.3020201@redhat.com> References: <4C068371.4090702@redhat.com> <4C0D91C8.3020201@redhat.com> Date: Mon, 14 Jun 2010 20:39:02 +0200 X-Google-Sender-Auth: UoEtkaVEtS1OJTRZI0KadsIeBfI Message-ID: Subject: Re: bug#6330: Feature request: mktemp creates named pipes From: Sebastien Andre To: Eric Blake Content-Type: multipart/alternative; boundary=0016e6db2d7b823268048901cd94 X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: 6330 Cc: 6330@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) --0016e6db2d7b823268048901cd94 Content-Type: text/plain; charset=UTF-8 On Tue, Jun 8, 2010 at 2:41 AM, Eric Blake wrote: > On 06/03/2010 01:09 PM, Sebastien Andre wrote: > > I see two reasons why the addition of a --fifo option is better than > using > > existing tools: > > > > * Creating a temporary directory to finally create a pipe just > because > > it is safe this way is kind of a trick. For the clarity of scripts, it > would > > be better having mktemp to ensure the uniqueness of a fifo, even if it's > > created in / > > Why do you need to create fifos directly in /? Unless you can prove > that it is needed there, then what's wrong with creating it elsewhere? > Maybe the real feature we should be asking for is a way to ensure that > 'mv /path1/to/fifo /path2/to/fifo' is atomic, and fails if > /path2/to/fifo is a dangling symlink rather than accidentally creating > the fifo at an unintended location? > > > > > * mktemp is not only a tool to create unique files, it's also a name > > generator. The example given in the manual works for one or two fifos, > but > > if the number of fifos is unknown there is no choice but implementing > > something to generate names, which is another potential source of bugs. > > If you are worried about creating lots of fifos, and want to avoid > collisions, you can still use the existing semantics of unpatched mktemp > to get that: merely make a secure directory with mktemp -d, then use > mkfifo "$(mktemp -u -p "$dir")". That is, once you have a safe > directory, then mktemp -u within that directory is no longer a security > hole, and serves as a great way to create unique names without also > creating files. > > I don't really need to create temp fifos in /, just wanted it to be as convenient as creating temp files. Even if the 'dir=$(mktemp -td)' followed by 'mkfifo "$(mktemp -u -p "$dir")"' is not as straightforward as I would expect, it fits my need ~ > of $i to ensure unicity of fifo names. If for any reason $tmpdir must be > > shared with other processes which use the exact same function it will > > lead to a mess, that's why I prefer merge_output_mktempfifo(). > > As long as the multiple processes are closely cooperating, and all use > the same secure temporary directory, then mktemp -u is an appropriate > way for each of those processes to name their fifo. > > >> Patches speak volumes, although by the time you add the code and the > >> documentation, your contribution would probably be non-trivial and > >> require copyright assignment to the FSF. Let us know if you'd like to > >> start that process. > >> > >> > > Yes, I'm interested in starting that process. > > I'm sending you some details off-list. > > Thanks > -- > Eric Blake eblake@redhat.com +1-801-349-2682 > Libvirt virtualization library http://libvirt.org > > --0016e6db2d7b823268048901cd94 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Tue, Jun 8, 2010 at 2:41 AM, Eric Blake <= span dir=3D"ltr"><eblake@redhat.com= > wrote:
On 06/03/2010 01:09 PM, Sebastien Andre wrote:
> I see two reasons why the addition of a --fifo option is better than u= sing
> existing tools:
>
> =C2=A0 =C2=A0 * Creating a temporary directory to finally create a pip= e just because
> it is safe this way is kind of a trick. For the clarity of scripts, it= would
> be better having mktemp to ensure the uniqueness of a fifo, even if it= 's
> created in /

Why do you need to create fifos directly in /? =C2=A0Unless you can p= rove
that it is needed there, then what's wrong with creating it elsewhere?<= br> Maybe the real feature we should be asking for is a way to ensure that
'mv /path1/to/fifo /path2/to/fifo' is atomic, and fails if
/path2/to/fifo is a dangling symlink rather than accidentally creating
the fifo at an unintended location?

>
> =C2=A0 =C2=A0 * mktemp is not only a tool to create unique files, it&#= 39;s also a name
> generator. The example given in the manual works for one or two fifos,= but
> if the number of fifos is unknown there is no choice but implementing<= br> > something to generate names, which is another potential source of bugs= .

If you are worried about creating lots of fifos, and want to avoid collisions, you can still use the existing semantics of unpatched mktemp to get that: merely make a secure directory with mktemp -d, then use
mkfifo "$(mktemp -u -p "$dir")". =C2=A0That is, once yo= u have a safe
directory, then mktemp -u within that directory is no longer a security
hole, and serves as a great way to create unique names without also
creating files.


I don't really need to create temp fifos in /, just wanted it to be as = convenient as
creating temp files. Even if the 'dir=3D$(mktemp -td)= ' followed by 'mkfifo "$(mktemp -u -p "$dir")"&= #39;
is not as straightforward as I would expect, it fits my need ~


<= /div>
> of $i to ensure unicity of fifo names. If for any reason $tmpdir must = be
> shared with other processes which use the exact same function it will<= br> > lead to a mess, that's why I prefer merge_output_mktempfifo().

As long as the multiple processes are closely cooperating, and all us= e
the same secure temporary directory, then mktemp -u is an appropriate
way for each of those processes to name their fifo.

>> Patches speak volumes, although by the time you add the code and t= he
>> documentation, your contribution would probably be non-trivial and=
>> require copyright assignment to the FSF. =C2=A0Let us know if you&= #39;d like to
>> start that process.
>>
>>
> Yes, I'm interested in starting that process.

I'm sending you some details off-list.

Thanks
--
Eric Blake =C2=A0 eblake@redhat.com =C2=A0 =C2=A0+1-801-349-2682
Libvirt virtualization library http://libvirt.org


--0016e6db2d7b823268048901cd94-- From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 07 12:49:54 2011 Received: (at control) by debbugs.gnu.org; 7 Aug 2011 16:49:54 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qq6Xx-0003HY-VR for submit@debbugs.gnu.org; Sun, 07 Aug 2011 12:49:54 -0400 Received: from mx.meyering.net ([82.230.74.64]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qq6Xv-0003HM-4q for control@debbugs.gnu.org; Sun, 07 Aug 2011 12:49:52 -0400 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id CFEC460098 for ; Sun, 7 Aug 2011 18:48:52 +0200 (CEST) From: Jim Meyering To: control@debbugs.gnu.org Subject: merge and close Date: Sun, 07 Aug 2011 18:48:52 +0200 Message-ID: <87bow1i2vf.fsf@rho.meyering.net> Lines: 4 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -6.1 (------) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.1 (------) forcemerge 6900 6330 tags 6900 notabug close 6900 thanks From unknown Mon Aug 18 15:39:05 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 05 Sep 2011 11:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator