* How to get the return value using the command busctl set-property?
@ 2021-04-16 4:46 Bruce Lee (李昀峻)
2021-04-16 14:58 ` Patrick Williams
0 siblings, 1 reply; 3+ messages in thread
From: Bruce Lee (李昀峻) @ 2021-04-16 4:46 UTC (permalink / raw)
To: openbmc; +Cc: edtanous, Nan Zhou
Does busctl set-property can get its return value?
I use the below command, and I found it has no return value.
Dose set-property does not provide a return message like the get-property function?
If can get its return value from set-property, how to do it?
i.e.
busctl set-property xyz.openbmc_project.Hwmon-3687764522.Hwmon1 /xyz/openbmc_project/sensors/voltage/vbat xyz.openbmc_project.Sensor.Value Value d 22
or
in bmcweb the code as below:
i.e.
crow::connections::systemBus->async_method_call(
[sensorAsyncResp](const boost::system::error_code ec) {
if (ec)
{
BMCWEB_LOG_DEBUG
<< "setOverrideValueStatus DBUS error: "<< ec;
messages::internalError(sensorAsyncResp->res);
return;
}
},
item.second, item.first,
"org.freedesktop.DBus.Properties", "Set",
"xyz.openbmc_project.Sensor.Value", "Value",
std::variant<double>(iterator->second.first));
in dbus-monitor --system I also not found its return value when I use set-property
dbus-monitor message as below:
method call time=1618547183.313540 sender=:1.87 -> destination=xyz.openbmc_project.Hwmon-3687764522.Hwmon1 serial=2 path=/xyz/openbmc_project/sensors/voltage/vbat; interfa
string "xyz.openbmc_project.Sensor.Value"
string "Value"
variant double 22
method call time=1618547183.317152 sender=:1.45 -> destination=org.freedesktop.DBus serial=35 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetConnect
string ":1.87"
method return time=1618547183.317937 sender=org.freedesktop.DBus -> destination=:1.45 serial=4294967295 reply_serial=35
uint32 0
method return time=1618547183.330441 sender=:1.45 -> destination=:1.87 serial=36 reply_serial=2
The set-property code as below:
int setSensorValue(const double& newValue, double& oldValue)
{
if (!internalSet)
{
oldValue = newValue;
overriddenState = true;
// check thresholds for external set
value = newValue;
checkThresholds();
}
else if (!overriddenState)
{
oldValue = newValue;
}
return 1;
}
sensorInterface->register_property(
"Value", value, [&](const double& newValue, double& oldValue) {
return setSensorValue(newValue, oldValue);
});
Thanks,
Bruce.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to get the return value using the command busctl set-property?
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
2021-04-19 11:15 ` Bruce Lee (李昀峻)
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Williams @ 2021-04-16 14:58 UTC (permalink / raw)
To: Bruce Lee (李昀峻); +Cc: openbmc, edtanous, Nan Zhou
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: How to get the return value using the command busctl set-property?
2021-04-16 14:58 ` Patrick Williams
@ 2021-04-19 11:15 ` Bruce Lee (李昀峻)
0 siblings, 0 replies; 3+ messages in thread
From: Bruce Lee (李昀峻) @ 2021-04-19 11:15 UTC (permalink / raw)
To: Patrick Williams; +Cc: openbmc, edtanous, Nan Zhou
> -----Original Message-----
> From: Patrick Williams <patrick@stwcx.xyz>
> Sent: Friday, April 16, 2021 10:58 PM
> To: Bruce Lee (李昀峻) <Bruce_Lee@quantatw.com>
> Cc: openbmc@lists.ozlabs.org; edtanous@google.com; Nan Zhou
> <nanzhou@google.com>
> Subject: Re: How to get the return value using the command busctl set-property?
>
> 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.
>
Thanks for your reply, it's very useful to me.
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-19 11:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2021-04-19 11:15 ` Bruce Lee (李昀峻)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).