Qt Forum

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

    Call for Presentations - Qt World Summit

    Solved QSystemSemaphore location on linux

    General and Desktop
    2
    7
    1428
    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

      I'm developing two applications on linux that have to be synchronized.
      One application is regular C++ and a second is Qt.
      The C++ application opens Posix named semaphore as sem_open(...), and the Qt opens QSystemSemaphore.
      Tere is no strict order in opening the apps. Each one configured to connect to the existing semaphore in case it started as a second.
      The C++ semaphore i can see at /dev/shm, but the Qt semaphore i can't found.
      Where is it stored ?
      If it's system resource, why it is not stored in standard place ?

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

        @alexsho
        Hello,
        If both applications are going to be synchronized through the same semaphore, then you have to pass the same name both for the the Qt app and your C++ program. Doing that will open only one semaphore, so why would you expect to see two separate primitives?

        Kind regards.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply Reply Quote 0
        • A
          alexsho last edited by alexsho

          I do define the same name. I know that QT adds prefix and SHA hash to the name.
          The problem that the applications still don't open same semaphore.
          When i tested the applications as stand alone, to check where it creates (or looks for ) the semaphore, the C++ app creates its semaphore at the defined place: /dev/shm/, but the Qt app don't , or it is created in some another place.
          As i understand, if i want the apps to open the same semaphore - it should be pointed to the same place.
          When Qt app runs alone, the QSystemSemaphore object is creared without errors, but i can't found it in the system.

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

            @alexsho

            Suppose you've given key to Qt for the semaphore, then the file path is:

            QDir::tempPath() + "/qipc_systemsem_" + keyStripped + QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Sha1).toHex()
            

            Where keyStripped is the key variable but every character that is not in the range a-z, A-Z is removed.

            Does that help?

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply Reply Quote 0
            • A
              alexsho last edited by

              I know that, this is the way the semaphore name is build on Qt.
              I did the same on the C++ app, using external SHA1 function, and i get the same name.
              The problem is that the default location of the Qt semaphore is probably differ from default system location.
              I believe that two Qt applications will found each other, but in my case one app is general C++.
              I solved the similar problem with QSharedMemory, but
              in QSharedMemory there is a possibility to set NativeKey, then this will be the exact name of the created object. What i did is - i added the path prefix /dev/shm/ to the name and set it as Native.
              That way i forced Qt to create (or found) the shared object in system standard place where the C++ app creates it.
              In QSystemSemaphore there is no possibility to set Native Key, the Qt always adds its prefix, so i can't control the location of the object (i hope i'm wrong).
              I must then try to change the location of the C++ semaphore.

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

                @alexsho

                The problem is that the default location of the Qt semaphore is probably differ from default system location.

                The location Qt uses is QDir::tempPath() as written in my previous post.

                That way i forced Qt to create (or found) the shared object in system standard place where the C++ app creates it.
                In QSystemSemaphore there is no possibility to set Native Key, the Qt always adds its prefix, so i can't control the location of the object (i hope i'm wrong).

                Not to my knowledge.

                Kind regards.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply Reply Quote 0
                • A
                  alexsho last edited by

                  Sorry i missed that.
                  That is the point.
                  Thank you.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post