Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Qt DBus unable to detect an exit status of zero
Forum Updated to NodeBB v4.3 + New Features

Qt DBus unable to detect an exit status of zero

Scheduled Pinned Locked Moved Unsolved C++ Gurus
12 Posts 3 Posters 3.5k Views 3 Watching
  • 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.
  • J Offline
    J Offline
    josephdp
    wrote on last edited by A Former User
    #1

    Hi Qt community,

    I would like to ask for your help.

    I am developing a system using Qt Dbus.

    It was able to launch dbus-daemon's session bus and launch the specific service on demand.

    Problem:
    The problem is when the service exits as zero, it will wait until the QDBusPendingCall timeout is exhausted and will report a false positive error:
    "Failed to activate service 'com.example.foo': timed out.

    Other non-zero exit codes will be returned immediately (not waiting for the pending call timeout) and will be reported as:
    "Process com.example.foo exited with status 1"

    Goal:
    I wanted to trap a success (zero) exit code for the service activated without waiting for the timeout.

    Any suggestions is really appreciated.

    Set-up:
    OS: Widows 7 64 bit.
    Qt toolkit: Qt 5.5.1 MSVC2013 64 bit

    I look forward to your response.

    Sincerely,
    JosephDP

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      I'm not sure I'm following you. Do you mean that you have this problem if the dbus-daemon exits normally ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        josephdp
        wrote on last edited by josephdp
        #3

        Hi @SGaist,

        Thank you for your response and for the warm welcome.

        There's no problem with dbus-daemon since it will never exit and is always running.

        The problem is with the services launched and when it exits normally (exit code: 0).

        P.S. all services are running on the session bus

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          To be sure I understand correctly: you are doing a call to your service that results in it exiting normally but then you get a timeout error, right ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          J 1 Reply Last reply
          0
          • SGaistS SGaist

            To be sure I understand correctly: you are doing a call to your service that results in it exiting normally but then you get a timeout error, right ?

            J Offline
            J Offline
            josephdp
            wrote on last edited by
            #5

            Hi @SGaist,

            Yes you got it right.

            Do you happen to know if this is a bug in QT 5.5.1 DBus?

            kshegunovK 1 Reply Last reply
            0
            • J josephdp

              Hi @SGaist,

              Yes you got it right.

              Do you happen to know if this is a bug in QT 5.5.1 DBus?

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

              @josephdp
              How does your service exit? Can you provide a very minimal snippet illustrating the function you're calling?

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • J Offline
                J Offline
                josephdp
                wrote on last edited by
                #7

                Hi @kshegunov, @SGaist,

                My service exits with a exit code of 0 if successful and non-zero for error.

                The problem is QT DBus can't understand perhaps an exit code of 0 which means success?

                Please see minimal snippet:

                QDBusConnection session = QDBusConnection::sessionBus ();
                QDBusMessage msg = QDBusMessage::createMethodCall ("com.myservice.foo",
                                                                    "/com/myservice/foo",
                                                                    "com.myservice.foo",
                                                                    "mymethod");
                
                QDBusPendingCall call = session.asyncCall (msg,  120000);
                
                QDBusPendingCallWatcher * watcher = new QDBusPendingCallWatcher (call);
                
                QObject::connect(watcher,
                                 SIGNAL (finished(QDBusPendingCallWatcher*)),
                                 this,
                                 SLOT (onMethodFinished(QDBusPendingCallWatcher*)));
                

                and for the onMethodFinished ():

                QDBusPendingCall reply = * call;
                
                if (reply.isError()) {
                    QString text = reply.reply().errorMessage();
                    qDebug () << __FUNCTION__ << "Error: " << text;
                } else {
                    qDebug () << __FUNCTION__ << "OK";
                }
                call->deleteLater();
                
                kshegunovK 1 Reply Last reply
                0
                • J josephdp

                  Hi @kshegunov, @SGaist,

                  My service exits with a exit code of 0 if successful and non-zero for error.

                  The problem is QT DBus can't understand perhaps an exit code of 0 which means success?

                  Please see minimal snippet:

                  QDBusConnection session = QDBusConnection::sessionBus ();
                  QDBusMessage msg = QDBusMessage::createMethodCall ("com.myservice.foo",
                                                                      "/com/myservice/foo",
                                                                      "com.myservice.foo",
                                                                      "mymethod");
                  
                  QDBusPendingCall call = session.asyncCall (msg,  120000);
                  
                  QDBusPendingCallWatcher * watcher = new QDBusPendingCallWatcher (call);
                  
                  QObject::connect(watcher,
                                   SIGNAL (finished(QDBusPendingCallWatcher*)),
                                   this,
                                   SLOT (onMethodFinished(QDBusPendingCallWatcher*)));
                  

                  and for the onMethodFinished ():

                  QDBusPendingCall reply = * call;
                  
                  if (reply.isError()) {
                      QString text = reply.reply().errorMessage();
                      qDebug () << __FUNCTION__ << "Error: " << text;
                  } else {
                      qDebug () << __FUNCTION__ << "OK";
                  }
                  call->deleteLater();
                  
                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @josephdp
                  I meant the service's method you're calling - mymethod from /com/myservice/foo.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    josephdp
                    wrote on last edited by
                    #9

                    Hi @kshegunov

                    Basically it will just return 0 on success and 1 on failure.

                    mymethod ()
                    {
                        bool rc = do_something ();
                    
                        if (rc) {
                            // success
                            return 0;
                        } else {
                            // failure
                            return 1;
                        }
                    }
                    
                    kshegunovK 1 Reply Last reply
                    0
                    • J josephdp

                      Hi @kshegunov

                      Basically it will just return 0 on success and 1 on failure.

                      mymethod ()
                      {
                          bool rc = do_something ();
                      
                          if (rc) {
                              // success
                              return 0;
                          } else {
                              // failure
                              return 1;
                          }
                      }
                      
                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #10

                      What I was concerned about is if your application gives up before it's able to close the DBus connection cleanly. Meaning you calling ::exit() somewhere or having an unexpected SIGSEGV signal raised somewhere.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        josephdp
                        wrote on last edited by
                        #11

                        Hi @kshegunov

                        Basically this is the final sequence of the app.

                        It is able to return immediately if the app returns a non-zero value (which in this case is 1).
                        However, if it will return a zero value (success in this case), the caller will wait for the timeout set (120000) and will inform a false negative result (that "Failed to activate service 'com.myservice.foo': timed out.)

                        kshegunovK 1 Reply Last reply
                        0
                        • J josephdp

                          Hi @kshegunov

                          Basically this is the final sequence of the app.

                          It is able to return immediately if the app returns a non-zero value (which in this case is 1).
                          However, if it will return a zero value (success in this case), the caller will wait for the timeout set (120000) and will inform a false negative result (that "Failed to activate service 'com.myservice.foo': timed out.)

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

                          Is it possible you don't have an event loop running at this point? I don't see a good reason for that behavior, so I'm starting to guess now ...

                          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