Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    4
    1110
    Loading More Posts
    • 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
      alexsho last edited by

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

      kshegunov 1 Reply Last reply Reply Quote 0
      • kshegunov
        kshegunov Moderators @alexsho last edited by

        @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 Reply Quote 0
        • A
          alexsho last edited by 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.

          kshegunov 1 Reply Last reply Reply Quote 0
          • kshegunov
            kshegunov Moderators @alexsho last edited by kshegunov

            @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 Reply Quote 0
            • First post
              Last post