From 6ae4ed11c4d3f3c082e126eb9193ad535bf462ba Mon Sep 17 00:00:00 2001 From: Christos Margiolis Date: Mon, 12 Feb 2024 12:59:28 +0200 Subject: [PATCH] mixer(8): Use new mixer if we change the default unit If we use the -d option to change the default unit, close the current mixer and open the one we set as the default to avoid printing and applying changes (if any) to the old one. Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Reviewed by: dev_submerge.ch, markj Differential Revision: https://reviews.freebsd.org/D43809 (cherry picked from commit 5daa7cf42f4551cb2f4a452fd038807925320eac) --- usr.sbin/mixer/mixer.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c index 83e97df1911..47d8e6359b7 100644 --- a/usr.sbin/mixer/mixer.c +++ b/usr.sbin/mixer/mixer.c @@ -118,8 +118,21 @@ main(int argc, char *argv[]) initctls(m); - if (dflag && set_dunit(m, dunit) < 0) - goto parse; + if (dflag) { + if (set_dunit(m, dunit) < 0) + goto parse; + else { + /* + * Open current mixer since we changed the default + * unit, otherwise we'll print and apply changes to the + * old one. + */ + (void)mixer_close(m); + if ((m = mixer_open(NULL)) == NULL) + errx(1, "cannot open default mixer"); + initctls(m); + } + } if (sflag) { printrecsrc(m, oflag); (void)mixer_close(m);