Can't create Posix semaphore in the location where the Qt creates QSystemSemaphore



  • On Linux system QSystemSemaphore created in /tmp directory.
    I'd like to share the semaphore with C++ application.
    According to the Qt sources it uses Posix command sem_open().
    I did the same with my C++ and name: /tmp/qipc_systemsem_somehashtag but i got fail on wrong name.
    In C++, using sem_open, i'm able to create only at default location, means /dev/shm/, and the system always add sem. prefix.
    How is it possible ? It uses same API (sem_open(...) ).
    How can i recreate the Qt semaphore on C++ ?


  • Qt Champions 2016

    @alexsho
    What flags are you passing in your C++ code, and which process is starting first? Are you handling the sem_open errors accordingly?

    http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qsystemsemaphore_posix.cpp#n74
    http://man7.org/linux/man-pages/man3/sem_open.3.html

    If both O_CREAT and O_EXCL are specified in oflag, then an error is returned if a semaphore with the given name already exists.

    Kind regards.



  • Yes, i'm handling sem_open errors i similar way
    I'm trying to create the semaphore with O_CREAT only flag, which is mean that it first trys to open existing semaphore, and, if not available, it creates one.
    So From this point it should never get NULL.
    The name i set is, as i said, string /tmp/qipc_systemsem_somehashtag.
    I'm testing it when no semaphore with this name exists in both places.
    The errno i get is EINVAL (2) which means in my case - wrong name format.
    When i set the name without /tmp/ i get semaphore created successfully but at /dev/shm/.
    I read some info regarding this problem - it looks like problem in Qt.
    Somehow it uses different (wrong) implementation of sem_open, not according the Posix standard.


  • Qt Champions 2016

    @alexsho
    Unfortunately, I don't know what the problem might be. :|
    What about checking semget?
    Do you have available resources?
    Have you tried without the O_CREAT flag?
    Can you verify you have permissions for the file?

    Kind regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.