From b7d7f327a3a7c5adf9628851b1d7eb31e612d018 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 7 Nov 2024 11:49:33 +0100 Subject: [PATCH] sd-varlink: expose api to get input/output fd separately --- src/libsystemd/libsystemd.sym | 4 +++- src/libsystemd/sd-varlink/sd-varlink.c | 24 ++++++++++++++++++++++++ src/systemd/sd-varlink.h | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 6fbe621c3dd..73ad9f8d26c 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -1062,8 +1062,10 @@ global: LIBSYSTEMD_258 { global: + sd_device_enumerator_add_all_parents; sd_json_variant_type_from_string; sd_json_variant_type_to_string; + sd_varlink_get_input_fd; + sd_varlink_get_output_fd; sd_varlink_reset_fds; - sd_device_enumerator_add_all_parents; } LIBSYSTEMD_257; diff --git a/src/libsystemd/sd-varlink/sd-varlink.c b/src/libsystemd/sd-varlink/sd-varlink.c index 5568388c372..3aa39b048db 100644 --- a/src/libsystemd/sd-varlink/sd-varlink.c +++ b/src/libsystemd/sd-varlink/sd-varlink.c @@ -1673,6 +1673,30 @@ _public_ int sd_varlink_get_fd(sd_varlink *v) { return v->input_fd; } +_public_ int sd_varlink_get_input_fd(sd_varlink *v) { + + assert_return(v, -EINVAL); + + if (v->state == VARLINK_DISCONNECTED) + return varlink_log_errno(v, SYNTHETIC_ERRNO(ENOTCONN), "Not connected."); + if (v->input_fd < 0) + return varlink_log_errno(v, SYNTHETIC_ERRNO(EBADF), "No valid input fd."); + + return v->input_fd; +} + +_public_ int sd_varlink_get_output_fd(sd_varlink *v) { + + assert_return(v, -EINVAL); + + if (v->state == VARLINK_DISCONNECTED) + return varlink_log_errno(v, SYNTHETIC_ERRNO(ENOTCONN), "Not connected."); + if (v->output_fd < 0) + return varlink_log_errno(v, SYNTHETIC_ERRNO(EBADF), "No valid output fd."); + + return v->output_fd; +} + _public_ int sd_varlink_get_events(sd_varlink *v) { int ret = 0; diff --git a/src/systemd/sd-varlink.h b/src/systemd/sd-varlink.h index 816b9b0ebfe..1fad8677be0 100644 --- a/src/systemd/sd-varlink.h +++ b/src/systemd/sd-varlink.h @@ -96,6 +96,8 @@ sd_varlink* sd_varlink_ref(sd_varlink *link); sd_varlink* sd_varlink_unref(sd_varlink *v); int sd_varlink_get_fd(sd_varlink *v); +int sd_varlink_get_input_fd(sd_varlink *v); +int sd_varlink_get_output_fd(sd_varlink *v); int sd_varlink_get_events(sd_varlink *v); int sd_varlink_get_timeout(sd_varlink *v, uint64_t *ret);