]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mute-console: don't unmute twice when not running as varlink service 39229/head
authorMike Yuan <me@yhndnzj.com>
Mon, 6 Oct 2025 20:07:19 +0000 (22:07 +0200)
committerMike Yuan <me@yhndnzj.com>
Tue, 7 Oct 2025 11:38:21 +0000 (13:38 +0200)
This also avoids the spurious "not restoring" logs if we fail
to dispatch varlink call.

src/mute-console/mute-console.c

index 680e15296e825f18ac9a7227a100a97ce41681cb..40c0839367b97740161e28ea9af7babd19468027 100644 (file)
@@ -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,