Getting a name for a mkfifo
David Faure
faure at kde.org
Sun Aug 7 00:16:31 CEST 2005
On Saturday 06 August 2005 18:45, Rafał Rzepecki wrote:
> On Saturday, 6 of August 2005 17:15, David Faure wrote:
> > On Saturday 06 August 2005 16:21, Tomas Mecir wrote:
> > > On 8/6/05, Piotr Szymański <niedakh at gmail.com> wrote:
> > > > Hi,
> > > > What class in KDE do I need to get a decent not taken name for a
> > > > mkfifo, i'd use KTempFile, but it creates a file there right? Any
> > > > ideas?
> > >
> > > man 3 tmpnam
> > > man 3 tempnam
> >
> > Both say:
> > BUGS
> > Never use this function.
> >
> > so don't. Use the name provided by a KTempFile. It still leaves a small
> > race condition though, since you have to let it delete the file before you
> > can create the fifo, but well, we do that already in KDE (e.g.
> > KParts::ReadWritePart::prepareSaving).
>
> I think that man 3 tmpnam says never to use it because of the inherent danger
> posed by generating a filename and only then creating the file in an
> non-atomic operation, possibly doing something in-between. Since you will be
> doing effectively the same thing with creating a tempfile and deleting it and
> placing a fifo, I think it's better to just go ahead and use the tmpnam and
> _immediately_ create the fifo (taking proper precautions of possible error
> conditions).
Well, nowadays you even get a warning from ld when linking a program that uses tmpnam....
--
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
More information about the Kde-soc
mailing list