diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-11-06 11:58:56 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2025-01-02 16:37:52 +0100 |
commit | 1a2e4b614e2f286db4fd8e440059c97ac049d836 (patch) | |
tree | 110fca2b2b79c758a21f32a924169600c9adee1d | |
parent | sd-varlink: expose api to get input/output fd separately (diff) | |
download | systemd-1a2e4b614e2f286db4fd8e440059c97ac049d836.tar.xz systemd-1a2e4b614e2f286db4fd8e440059c97ac049d836.zip |
pcrextend: split out varlink server setup into its own function
-rw-r--r-- | src/pcrextend/pcrextend.c | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/pcrextend/pcrextend.c b/src/pcrextend/pcrextend.c index ef4d1a1f17..54c31c3a82 100644 --- a/src/pcrextend/pcrextend.c +++ b/src/pcrextend/pcrextend.c @@ -297,6 +297,29 @@ static int vl_method_extend(sd_varlink *link, sd_json_variant *parameters, sd_va return sd_varlink_reply(link, NULL); } +static int vl_server(void) { + _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL; + int r; + + r = varlink_server_new(&varlink_server, SD_VARLINK_SERVER_ROOT_ONLY, /* userdata= */ NULL); + if (r < 0) + return log_error_errno(r, "Failed to allocate Varlink server: %m"); + + r = sd_varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_PCRExtend); + if (r < 0) + return log_error_errno(r, "Failed to add Varlink interface: %m"); + + r = sd_varlink_server_bind_method(varlink_server, "io.systemd.PCRExtend.Extend", vl_method_extend); + if (r < 0) + return log_error_errno(r, "Failed to bind Varlink method: %m"); + + r = sd_varlink_server_loop_auto(varlink_server); + if (r < 0) + return log_error_errno(r, "Failed to run Varlink event loop: %m"); + + return 0; +} + static int run(int argc, char *argv[]) { _cleanup_free_ char *word = NULL; Tpm2UserspaceEventType event; @@ -308,29 +331,8 @@ static int run(int argc, char *argv[]) { if (r <= 0) return r; - if (arg_varlink) { - _cleanup_(sd_varlink_server_unrefp) sd_varlink_server *varlink_server = NULL; - - /* Invocation as Varlink service */ - - r = varlink_server_new(&varlink_server, SD_VARLINK_SERVER_ROOT_ONLY, NULL); - if (r < 0) - return log_error_errno(r, "Failed to allocate Varlink server: %m"); - - r = sd_varlink_server_add_interface(varlink_server, &vl_interface_io_systemd_PCRExtend); - if (r < 0) - return log_error_errno(r, "Failed to add Varlink interface: %m"); - - r = sd_varlink_server_bind_method(varlink_server, "io.systemd.PCRExtend.Extend", vl_method_extend); - if (r < 0) - return log_error_errno(r, "Failed to bind Varlink method: %m"); - - r = sd_varlink_server_loop_auto(varlink_server); - if (r < 0) - return log_error_errno(r, "Failed to run Varlink event loop: %m"); - - return EXIT_SUCCESS; - } + if (arg_varlink) + return vl_server(); /* Invocation as Varlink service */ if (arg_file_system) { if (optind != argc) |