跳转到主要内容

sd_varlink_call_and_upgrade

systemd

3

#include <systemd/sd-varlink.h>

int

const char *

method

sd_json_variant *

parameters

sd_json_variant **

ret_parameters

const char **

ret_error_id

int *

ret_input_fd

int *

ret_output_fd

int

const char *

method

sd_json_variant **

ret_parameters

const char **

ret_error_id

int *

ret_input_fd

int *

ret_output_fd

…

int

const char *

method

sd_json_variant **

ret_parameters

const char **

ret_error_id

int *

ret_input_fd

int *

ret_output_fd

…

int

const char *

method

sd_json_variant *

parameters

int

const char *

method

…

int

const char *

method

…

Description

These functions implement the client side of a Varlink protocol upgrade. They are the counterpart of the server-side sd_varlink_reply_and_upgrade(3) family. If a method call is issued this way, the connection may switch, after the reply, from the Varlink protocol to an arbitrary, non-Varlink ("raw") protocol spoken over the underlying socket or pipe file descriptors, in a manner similar to the Upgrade: mechanism of HTTP.

If the server replies with a regular reply (rather than a Varlink error) the connection is upgraded: it is disconnected from the Varlink protocol, and ownership of the underlying file descriptors is transferred to the caller via ret_input_fd and ret_output_fd, which is responsible for eventually closing them with close(2). If the server replies with a Varlink error instead, the connection is not upgraded and no file descriptors are returned; the error identifier is reported in ret_error_id (if non-NULL), otherwise a negative errno-style error derived from it is returned.

The returned file descriptors are switched to blocking mode. For bidirectional sockets a single underlying file descriptor carries both directions; in this case ret_input_fd and ret_output_fd are returned as two independent (duplicated) descriptors referring to the same socket, so they may be closed separately. For transports backed by a pair of pipes the two descriptors differ and refer to the distinct read and write ends. At least one of ret_input_fd or ret_output_fd must be non-NULL.

Return Value

On success, sd_varlink_call_and_upgrade() and its variants return a positive integer if the connection was upgraded. If the server returns a Varlink error and ret_error_id was provided by the caller, it is set to the error identifier and zero is returned. Otherwise, the Varlink error is treated as a failure. sd_varlink_invoke_and_upgrade() and its variants return zero once the request has been enqueued. On failure, all functions return a negative errno-style error code.

Errors

Returned errors may indicate the following problems:

-EINVAL
An argument is invalid.

-ENOTCONN
The Varlink connection object is not connected.

-EBUSY
Another method call is pending on the connection. Note that while a request enqueued with sd_varlink_invoke_and_upgrade() is pending, this error is also returned by any other function that enqueues a method call on the connection, such as sd_varlink_call(3) or sd_varlink_invoke().

-EPROTO
A protocol error occurred, for example the server sent unexpected raw protocol data before the upgrade completed.

-ENOMEM
Memory allocation failed.

History

See Also

systemd(1), sd-varlink(3), sd_varlink_call(3), sd_varlink_reply_and_upgrade(3), sd_json_build(3)