2012년 6월 20일 수요일

When got os error no 38, function not implemented, on emulation environment

I had got an os error no 38, function not implemented, on emulation environment. This was about shared memory. For this, I made a simple test program.

[test.cpp]

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

extern int errno;

int main()
{
    int fd;

    fd = shm_open("/Test/123456789", O_CREAT | O_CLOEXEC | O_RDWR, S_IRUSR | S_IWUSR);

    if (fd == -1)
        fprintf(stderr, "errno[%d] \n", errno);

    return 0;
}

$ gcc test.cpp -lrt
$ ./a.out
errno[38] // usually return 2, path problem

I first thought it is absurd because shm_open function is really basic function provided by glibc. Later, I got realized this was from emulation environment specifically mount problem.

There was '/dev/shm' linked to '/run/...' but actually '/run/...' path wasn't existed. So I mounted '/run' to virtual path on emulator like '/var/tmp/blahblah/run' and solved the problem. You can do like this 'sudo mount -o bind /run /var/tmp/blahblah/run'.

Hope this might help.