Qt DBus unable to detect an exit status of zero



  • 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


  • Lifetime Qt Champion

    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 ?



  • 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


  • Lifetime Qt Champion

    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 ?



  • Hi @SGaist,

    Yes you got it right.

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


  • Qt Champions 2016

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



  • 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();

  • Qt Champions 2016

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



  • 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;
        }
    }
    

  • Qt Champions 2016

    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.



  • 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.)


  • Qt Champions 2016

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


Log in to reply
 

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