sd-varlink: change sd_varlink_error() to always return an error
authorLennart Poettering <lennart@poettering.net>
Wed, 30 Oct 2024 14:31:08 +0000 (15:31 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 31 Oct 2024 00:50:50 +0000 (09:50 +0900)
commitd2ebf5cc1d59e29139f06efaa3a9b2c184cdaa25
treec8c8486fb6bc86eaaf9862aacf3f8cea66e68f62
parent76a3af06308480600f354f8ea6dcd62587555a0c
sd-varlink: change sd_varlink_error() to always return an error

Let's make sure that sd_varlink_error() always returns an error code, so
that we can use it in a style "return sd_varlink_error(…);" everywhere,
which has two effects: return a good error reply to clients, and exit
the current stack frame with a failure code.

Interestingly sd_varlink_error_invalid_parameter() already worked like
this in some cases, but sd_varlink_error() itself didn't.

This is an alternative to the error handling tweak proposed in #34882,
but I think is a lot more generically useful, since it establishes a
pattern.

I checked our codebase, and this change should generally be OK without
breaking callsites, since the current callers (with exception of the
machined case from #34882) called sd_varlink_error() in the outermost
varlink method call dispatch stack frame, where this behaviour change
does not alter anything.

This is similar btw, how sd_bus_error_setf() and friends always return
error codes too, synthesized from its parameters.
src/libsystemd/sd-varlink/sd-varlink.c
src/test/test-varlink.c