[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freedesktop-dbus
Subject:    Bug with dbus_pending_call_steal_reply?
From:       bitfxed <bitfxed () disroot ! org>
Date:       2023-08-18 2:10:17
Message-ID: 3bb1bb7a-2017-dac2-a95b-276a44a0a8e1 () disroot ! org
[Download RAW message or body]

I was trying to receive a reply from a method call I made using \
dbus_pending_call_steal_reply but the thing is it tells me I'm trying to use an \
incorrect argument during runtime.

This is the code I was using:

#include <stdio.h>
#include <dbus/dbus.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
         DBusError err;
         DBusConnection *con;
         DBusMessage *msg;
         DBusMessage *reply;
         DBusPendingCall *pending;

         dbus_error_init(&err);

         con = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
         if (dbus_error_is_set(&err)) {
                 fprintf(stderr, "ERROR: %s\n", err.message);
                 dbus_error_free(&err);
                 exit(EXIT_FAILURE);
         }

         msg = dbus_message_new_method_call("org.freedesktop.systemd1", \
"/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "GetUnit");  const \
char *msg_arg1 = "cron.service";  dbus_message_append_args(msg,
                                 DBUS_TYPE_STRING, &msg_arg1,
                                 DBUS_TYPE_INVALID);

         dbus_connection_send_with_reply(con, msg, &pending, \
DBUS_TIMEOUT_USE_DEFAULT);

         for (;;) {
                 if ((reply = dbus_pending_call_steal_reply(pending)) == NULL)
                         continue;
                 else
                         break;
         }

         return EXIT_SUCCESS;
}

And the error was:

dbus[6959]: arguments to dbus_pending_call_steal_reply() were incorrect, assertion \
"pending->completed" failed in file ../../../dbus/dbus-pending-call.c line 734. This \
is normally a bug in some application using the D-Bus library.

   D-Bus not built with -rdynamic so unable to print a backtrace
Aborted

If instead of that for loop I call dbus_pending_call_block() and then steal the reply \
it works fine. According \
tohttps://dbus.freedesktop.org/doc/api/html/group__DBusPendingCall.html#ga5a738928c2369fef093ce00658903d06 \
dbus_pending_call_steal_reply should return NULL if the reply isn't there yet, so I \
don't know, is this a bug with that function or was I doing something wrong?


[Attachment #3 (text/html)]

<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <pre>I was trying to receive a reply from a method call I made using \
dbus_pending_call_steal_reply but the thing is it tells me I'm trying to use an \
incorrect argument during runtime.</pre>  <pre>This is the code I was using:</pre>
    <pre>#include &lt;stdio.h&gt;
#include &lt;dbus/dbus.h&gt;                                                          \
 #include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;

int main(int argc, char *argv[]) {
        DBusError err;
        DBusConnection *con;
        DBusMessage *msg;
        DBusMessage *reply;
        DBusPendingCall *pending;

        dbus_error_init(&amp;err);

        con = dbus_bus_get(DBUS_BUS_SYSTEM, &amp;err);
        if (dbus_error_is_set(&amp;err)) {
                fprintf(stderr, "ERROR: %s\n", err.message);
                dbus_error_free(&amp;err);
                exit(EXIT_FAILURE);
        }

        msg = dbus_message_new_method_call("org.freedesktop.systemd1", \
"/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "GetUnit");  const \
char *msg_arg1 = "cron.service";  dbus_message_append_args(msg,
                                DBUS_TYPE_STRING, &amp;msg_arg1,
                                DBUS_TYPE_INVALID);

        dbus_connection_send_with_reply(con, msg, &amp;pending, \
DBUS_TIMEOUT_USE_DEFAULT);

        for (;;) {
                if ((reply = dbus_pending_call_steal_reply(pending)) == NULL)
                        continue;
                else
                        break;
        }

        return EXIT_SUCCESS;
}

And the error was:

dbus[6959]: arguments to dbus_pending_call_steal_reply() were incorrect, assertion \
"pending-&gt;completed" failed in file ../../../dbus/dbus-pending-call.c line 734. \
This is normally a bug in some application using the D-Bus library.

  D-Bus not built with -rdynamic so unable to print a backtrace
Aborted

If instead of that for loop I call dbus_pending_call_block() and then steal the reply \
it works fine. According to <a class="moz-txt-link-freetext" \
href="https://dbus.freedesktop.org/doc/api/html/group__DBusPendingCall.html#ga5a738928 \
c2369fef093ce00658903d06">https://dbus.freedesktop.org/doc/api/html/group__DBusPendingCall.html#ga5a738928c2369fef093ce00658903d06</a> \
dbus_pending_call_steal_reply should return NULL if the reply isn't there yet, so I \
don't know, is this a bug with that function or was I doing something wrong? </pre>
  </body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic