Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't create Posix semaphore in the location where the Qt creates QSystemSemaphore

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alexsho
    wrote on last edited by
    #1

    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++ ?

    kshegunovK 1 Reply Last reply
    0
    • A alexsho

      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++ ?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexsho
        wrote on last edited by alexsho
        #3

        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.

        kshegunovK 1 Reply Last reply
        0
        • A alexsho

          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.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @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.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved