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: Sebastien Andre
Subject: bug#6330: Feature request: mktemp creates named pipes
Date: Thu, 3 Jun 2010 12:04:34 +0200

On Wed, Jun 2, 2010 at 6:13 PM, Bob Proulx <address@hidden> 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


reply via email to

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