GNU bug report logs - #6330
Feature request: mktemp creates named pipes

Previous Next

Package: coreutils;

Reported by: Sebastien Andre <wayana <at> users.sourceforge.net>

Date: Wed, 2 Jun 2010 15:47:02 UTC

Severity: normal

Tags: notabug

Merged with 6900

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 6330 <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Sebastien Andre <wayana <at> users.sourceforge.net>
Cc: 6330 <at> debbugs.gnu.org
Subject: Re: bug#6330: Feature request: mktemp creates named pipes
Date: Wed, 2 Jun 2010 10:13:27 -0600
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




This bug report was last modified 13 years and 352 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.