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
This commit is contained in:
Christos Margiolis 2024-02-12 12:59:28 +02:00
parent cc7479d7dc
commit 5daa7cf42f

View file

@ -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);