Summary: Fix amixer to reject invalid commands
The patch brings amixer to reject invalid commands, for example: "amixer set Master,0 nocap" makes no sense, if there is no capture switch at the Master Mixer Control. It also handles the invalid command, when more than 1 command is submited. For example: "amixer set Master,0 nocap 50%,50%" does nothing. Additional it rejects commands like "amixer -c 1 get Line,0 80%,40% unmute cap" where unnecessary options are submited. Signed-off-by: Torsten Büchner <[EMAIL PROTECTED]> Patch for alsa-utils-1.0.10: --- amixer.orig.c 2005-09-22 14:47:02.000000000 +0200 +++ amixer.c 2006-01-30 08:01:58.000000000 +0100 @@ -1188,6 +1188,10 @@ fprintf(stderr, "Specify what you want to set...\n"); return 1; } + if (roflag && !(argc < 2)) { + fprintf(stderr, "Unknown option: %s\n", argv[1]); + return 1; + } if ((err = snd_mixer_open(&handle, 0)) < 0) { error("Mixer %s open error: %s\n", card, snd_strerror(err)); return err; @@ -1218,6 +1222,28 @@ goto __skip_write; snd_mixer_selem_get_playback_volume_range(elem, &pmin, &pmax); snd_mixer_selem_get_capture_volume_range(elem, &cmin, &cmax); + for (idx = 1; idx < argc; idx++) { + char *ptr = argv[idx]; + channels = channels_mask(&ptr, channels); + if (*ptr == '\0') + continue; + dir = dir_mask(&ptr, dir); + if (*ptr == '\0') + continue; + for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++) { + if (!(channels & (1 << chn))) + continue; + if ((!strncmp(ptr, "mute", 4) || !strncmp(ptr, "off", 3) || !strncmp(ptr, "unmute", 6) || + !strncmp(ptr, "on", 2) || !strncmp(ptr, "toggle", 6)) && snd_mixer_selem_has_playback_switch(elem)) continue; + if ((isdigit(*ptr) || *ptr == '-' || *ptr == '+') && snd_mixer_selem_has_playback_volume(elem)) continue; + + if ((!strncmp(ptr, "cap", 3) || !strncmp(ptr, "rec", 3) || !strncmp(ptr, "nocap", 5) || + !strncmp(ptr, "norec", 5) || !strncmp(ptr, "toggle", 6)) && snd_mixer_selem_has_capture_switch(elem)) continue; + if ((isdigit(*ptr) || *ptr == '-' || *ptr == '+') && snd_mixer_selem_has_capture_volume(elem)) continue; + fprintf(stderr, "Setup not available: %s\n",ptr); + return 1; + } + } for (idx = 1; idx < argc; idx++) { char *ptr = argv[idx], *optr; int multi, firstchn = 1;