Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating temporary named fifo in *nix system

Tags:

linux

unix

fifo

I have some tasks requiring massive temporary named pipes to deal with.

Originally, I just simply think that generate random numbers, then append it as <number>.fifo be the name of named pipe.

However, I found this post: Create a temporary FIFO (named pipe) in Python?

It seems there is something I don't know that may cause some security issue there.

So my question here is that, what's the best way to generate a named pipe?

Notice that even though I am referencing a Python related post, I don't really mean to ask only in Python.

UPDATE:

Since I want to use a named pipe to connect unrelated processes, my plan is having process A call process B first via shell, and capture stdout to acquire the name of pipe, then both know what to open.

Here I am just worrying about whether leaking the name of pipe will become an issue. Before I never thought of it, until I read that Python post.

like image 290
Jason Hu Avatar asked Nov 03 '14 20:11

Jason Hu


1 Answers

If you have to use named FIFOs and need to ensure that overlap/overwriting cannot occur, your best bet is probably to use some combination of mktemp and mkfifo.

Although mktemp itself cannot create FIFOs, it can be used to create unique temporary directories, which you can then put your FIFOs into.

The GNU mktemp documentation has an example of this.

like image 151
yossarian Avatar answered Sep 19 '22 17:09

yossarian