From 01c65655488bf9ceb5e997c2b1a6205ef0ff9e8d Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 6 Oct 2025 22:07:19 +0200 Subject: [PATCH] mute-console: don't unmute twice when not running as varlink service This also avoids the spurious "not restoring" logs if we fail to dispatch varlink call. --- src/mute-console/mute-console.c | 34 +++++++++------------------------ 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/src/mute-console/mute-console.c b/src/mute-console/mute-console.c index 680e15296e8..40c0839367b 100644 --- a/src/mute-console/mute-console.c +++ b/src/mute-console/mute-console.c @@ -248,28 +248,6 @@ static int unmute_kernel(Context *c) { return 0; } -static void context_done(Context *c) { - assert(c); - - (void) unmute_pid1(c); - (void) unmute_kernel(c); - - if (c->link) { - (void) sd_varlink_set_userdata(c->link, NULL); - c->link = sd_varlink_flush_close_unref(c->link); - } -} - -static Context* context_free(Context *c) { - if (!c) - return NULL; - - context_done(c); - return mfree(c); -} - -DEFINE_TRIVIAL_CLEANUP_FUNC(Context*, context_free); - static void vl_on_disconnect(sd_varlink_server *server, sd_varlink *link, void *userdata) { assert(link); @@ -277,7 +255,13 @@ static void vl_on_disconnect(sd_varlink_server *server, sd_varlink *link, void * if (!c) return; - context_free(c); + (void) unmute_pid1(c); + (void) unmute_kernel(c); + + (void) sd_varlink_set_userdata(c->link, NULL); + sd_varlink_flush_close_unref(c->link); + + free(c); } static int vl_method_mute( @@ -290,7 +274,7 @@ static int vl_method_mute( assert(link); - _cleanup_(context_freep) Context *nc = new(Context, 1); + _cleanup_free_ Context *nc = new(Context, 1); if (!nc) return -ENOMEM; @@ -384,7 +368,7 @@ static int run(int argc, char* argv[]) { if (!arg_mute_pid1 && !arg_mute_kernel) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Not asked to mute anything, refusing."); - _cleanup_(context_done) Context c = { + Context c = { .mute_pid1 = arg_mute_pid1, .mute_kernel = arg_mute_kernel, .saved_kernel = -1, -- 2.47.3