bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#6330: Feature request: mktemp creates named pipes


From: Eric Blake
Subject: bug#6330: Feature request: mktemp creates named pipes
Date: Wed, 02 Jun 2010 10:14:41 -0600
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

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.

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

-- 
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]