I am having trouble in creating named pipe in Android and the example below illustrates my dilemma:
res = mkfifo("/sdcard/fifo9000", S_IRWXO);
if (res != 0)
{
LOG("Error while creating a pipe (return:%d, errno:%d)", res, errno);
}
The code always prints:
Error while creating a pipe (return:-1, errno:1)
I can’t figure out exactly why this fails. The application has android.permission.WRITE_EXTERNAL_STORAGE permissions. I can create normal files with exactly the same name in the same location, but pipe creation fails. The pipe in question should be accessible from multiple applications.
- I suspect that noone can create pipes in /sdcard. Where would it be the best location to do so?
- What mode mast should I set (2nd parameter)?
- Does application need any extra permissions?
Roosmaa’s answer is correct — mkfifo() just calls mknod() to create a special file, and FAT32 doesn’t support that.
As an alternative you may want to consider using Linux’s “abstract namespace” UNIX-domain sockets. They should be roughly equivalent to a named pipe. You can access them by name, but they’re not part of the filesystem, so you don’t have to deal with various permission issues. Note the socket is bi-directional.
Since it’s a socket, you may need INTERNET permission. Not sure about that.
Here’s a quick bit of client/server sample code: