summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mixer
diff options
context:
space:
mode:
authorariff <ariff@FreeBSD.org>2006-01-01 20:19:49 +0000
committerariff <ariff@FreeBSD.org>2006-01-01 20:19:49 +0000
commita5d25bd12d20e6415d8317448070802bbd3fe126 (patch)
tree037f674c9a45c540d255e9166a977d2804df22e9 /usr.sbin/mixer
parenta50f13bf117d51d0c002bdba876b95539fae7ab9 (diff)
downloadFreeBSD-src-a5d25bd12d20e6415d8317448070802bbd3fe126.zip
FreeBSD-src-a5d25bd12d20e6415d8317448070802bbd3fe126.tar.gz
- Fix possible memory leak due to repetetive strdup(3) without matching
free(3). - print_recsrc() should honor shortflag and give appropriate output for later consumption by /etc/rc.d/mixer. This will ensure that recording device selections survived across reboot. Output everything to stdout instead if stderr. MFC after: 3 days
Diffstat (limited to 'usr.sbin/mixer')
-rw-r--r--usr.sbin/mixer/mixer.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/usr.sbin/mixer/mixer.c b/usr.sbin/mixer/mixer.c
index 35772c5..36cbddf 100644
--- a/usr.sbin/mixer/mixer.c
+++ b/usr.sbin/mixer/mixer.c
@@ -26,7 +26,7 @@ const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
void usage(int devmask, int recmask);
int res_name(const char *name, int mask);
-void print_recsrc(int recsrc);
+void print_recsrc(int recsrc, int shortflag);
void
usage(int devmask, int recmask)
@@ -69,19 +69,27 @@ res_name(const char *name, int mask)
}
void
-print_recsrc(int recsrc)
+print_recsrc(int recsrc, int shortflag)
{
int i, n = 0;
- fprintf(stderr, "Recording source: ");
+
+ if (!shortflag)
+ printf("Recording source: ");
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
if ((1 << i) & recsrc) {
- if (n)
- fprintf(stderr, ", ");
- fprintf(stderr, "%s", names[i]);
+ if (shortflag) {
+ if (n)
+ printf(" +rec ");
+ else
+ printf("=rec ");
+ } else if (n)
+ printf(", ");
+ printf("%s", names[i]);
n = 1;
}
- fprintf(stderr, "\n");
+ if (!shortflag)
+ printf("\n");
}
int
@@ -97,17 +105,17 @@ main(int argc, char *argv[])
char *name;
- name = strdup("/dev/mixer");
+ name = "/dev/mixer";
if (!strcmp(argv[0], "mixer2"))
- name = strdup("/dev/mixer1");
+ name = "/dev/mixer1";
else if (!strcmp(argv[0], "mixer3"))
- name = strdup("/dev/mixer2");
+ name = "/dev/mixer2";
while ((ch = getopt(argc, argv, "f:sS")) != -1)
switch (ch) {
case 'f':
- name = strdup(optarg);
+ name = optarg;
break;
case 's':
shortflag = 1;
@@ -123,7 +131,6 @@ main(int argc, char *argv[])
if ((baz = open(name, O_RDWR)) < 0)
err(1, "%s", name);
- free(name);
if (ioctl(baz, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
err(1, "SOUND_MIXER_READ_DEVMASK");
if (ioctl(baz, SOUND_MIXER_READ_RECMASK, &recmask) == -1)
@@ -152,7 +159,7 @@ main(int argc, char *argv[])
}
if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1)
err(1, "SOUND_MIXER_READ_RECSRC");
- print_recsrc(recsrc);
+ print_recsrc(recsrc, shortflag || Shortflag);
return(0);
}
@@ -288,7 +295,7 @@ main(int argc, char *argv[])
if (drecsrc) {
if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1)
err(1, "SOUND_MIXER_READ_RECSRC");
- print_recsrc(recsrc);
+ print_recsrc(recsrc, shortflag || Shortflag);
}
close(baz);
OpenPOWER on IntegriCloud