All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Williams <patrick@stwcx.xyz>
To: "Bruce Lee (李昀峻)" <Bruce_Lee@quantatw.com>
Cc: "openbmc@lists.ozlabs.org" <openbmc@lists.ozlabs.org>,
	"edtanous@google.com" <edtanous@google.com>,
	Nan Zhou <nanzhou@google.com>
Subject: Re: How to get the return value using the command busctl set-property?
Date: Fri, 16 Apr 2021 09:58:03 -0500	[thread overview]
Message-ID: <YHml+7IYIVEXYo6M@heinlein> (raw)
In-Reply-To: <PSAPR04MB42315F65948C859527E5D8E2F84C9@PSAPR04MB4231.apcprd04.prod.outlook.com>

[-- Attachment #1: Type: text/plain, Size: 2405 bytes --]

On Fri, Apr 16, 2021 at 04:46:00AM +0000, Bruce Lee (李昀峻) wrote:
> Does busctl set-property can get its return value?
...
> If can get its return value from set-property, how to do it?

There isn't really a return value from a set-property call; there is
only a possiblity of error.

If you look at 'man SD_BUS_PROPERTY' you'll see the function type
for a property set is:

       typedef int (*sd_bus_property_set_t)(sd_bus *bus, const char *path,
                                            const char *interface,
                                            const char *property,
                                            sd_bus_message *value,
                                            void *userdata,
                                            sd_bus_error *ret_error);

This is where the 'int' return you're seeing from these set-property
handlers coming from.  The way systemd handles the return code is that
any negative number becomes a negative errno style value that systemd
turns into an appropriate error message back across the dbus.  There is
a paragraph in the manpage with more details:

       If a callback was invoked to handle a request that expects a reply and
       the callback returns a negative value, the value is interpreted as a
       negative errno-style error code and sent back to the caller as a D-Bus
       error as if sd_bus_reply_method_errno(3) was called. Additionally, all
       callbacks take a sd_bus_error output parameter that can be used to
       provide more detailed error information. If ret_error is set when the
       callback finishes, the corresponding D-Bus error is sent back to the
       caller as if sd_bus_reply_method_error(3) was called. Any error stored
       in ret_error takes priority over any negative values returned by the
       same callback when determining which error to send back to the caller.

The *best* way for a set-property handler to return an error is to use
the sd_bus_reply_method_error or fill out the ret_error with
sd_bus_error_set.  Both the ASIO object_server.hpp and the
sdbus++-generated server bindings catch excpetions thrown out of the
set-property handlers and turn them into sd_bus_error_set calls.

Other than the negative value indicating a errno, the positive value has
no meaning and does not do anything at a dbus level.

-- 
Patrick Williams

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2021-04-16 14:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16  4:46 How to get the return value using the command busctl set-property? Bruce Lee (李昀峻)
2021-04-16 14:58 ` Patrick Williams [this message]
2021-04-19 11:15   ` Bruce Lee (李昀峻)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YHml+7IYIVEXYo6M@heinlein \
    --to=patrick@stwcx.xyz \
    --cc=Bruce_Lee@quantatw.com \
    --cc=edtanous@google.com \
    --cc=nanzhou@google.com \
    --cc=openbmc@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.