Boost Interprocess named_mutex semaphore file permissions [duplicate]

佐手、 提交于 2020-01-17 00:41:56

问题


I am creating my shared memory using the below, trying either to open or create and setting unrestricted permissions.

void createMemory(const int numBytes)
{
    permissions perm;
    perm.set_unrestricted();

    segment.reset(new managed_shared_memory(open_or_create, memory_name, numBytes, 0, perm));

    // Exception throw on this line
    mutex.reset(new named_mutex(open_or_create, mutex_name, perm));

    cond_empty.reset(new named_condition(open_or_create, cv_name, perm));

    const ShmemAllocator alloc_inst(segment->get_segment_manager());
    vec = segment->find_or_construct<MyVector>(vector_name)(alloc_inst);
}

This creates two files for named_mutex, the shared memory and the (semaphore?) file:

mutex_name
sem.mutex_name

The first file has permissions which are fine, but the second file is created with restrictive permissions, preventing the second user from opening it.

I have configured user in the bashrc profile of the first user, but that doesn't seem to fix the problem. How else can I force this sem file to have relaxed permissions?


回答1:


This answers it:

POSIX shared memory and semaphores permissions set incorrectly by open calls

You set umask programatically to zero and then restore the previous umask value.



来源:https://stackoverflow.com/questions/50348027/boost-interprocess-named-mutex-semaphore-file-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!