0

I have the following code which I call from a Swift main program in Xcode and when running it in the Simulator in a virtual iPhone for example, it works. It creates /tmp/MYFIFO.

int32_t init_udpC(void) {

    static char *filename="/tmp/MYFIFO";

    umask(0);
    unlink(filename);
    if((mkfifo(filename, 0666)) == -1){
        perror("mkfifo");
        exit(2);
    }
    if((fd=open("/tmp/MYFIFO",O_RDWR|O_APPEND)) == -1) {
        perror("open");
        exit(2);
    }
    return fd;
}

Running it on the physical device the code fails with

mkfifo: Operation not permitted

Krischu
  • 1,024
  • 2
  • 15
  • 35
  • I found this link https://stackoverflow.com/questions/5328398/what-are-the-directory-locations-that-are-writable-on-ios serving as a helpful source of information. – Krischu Dec 27 '18 at 08:40

1 Answers1

2

It's because of iOS sandboxing. On iOS, your app isn't allowed to access /tmp/. It works in the simulator because you're running on macOS, where it's OK.

You need to use a path that's someplace where your app is allowed to access. One possibility is to replace the path with

const char *filename=[[NSTemporaryDirectory() stringByAppendingPathComponent:@"MYFIFO"] UTF8String];

There are other valid paths-- the key is that you have to be allowed to access the directory.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170