- 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
This commit is contained in:
parent
a50f13bf11
commit
a5d25bd12d
@ -26,7 +26,7 @@ const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
|
|||||||
|
|
||||||
void usage(int devmask, int recmask);
|
void usage(int devmask, int recmask);
|
||||||
int res_name(const char *name, int mask);
|
int res_name(const char *name, int mask);
|
||||||
void print_recsrc(int recsrc);
|
void print_recsrc(int recsrc, int shortflag);
|
||||||
|
|
||||||
void
|
void
|
||||||
usage(int devmask, int recmask)
|
usage(int devmask, int recmask)
|
||||||
@ -69,19 +69,27 @@ res_name(const char *name, int mask)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
print_recsrc(int recsrc)
|
print_recsrc(int recsrc, int shortflag)
|
||||||
{
|
{
|
||||||
int i, n = 0;
|
int i, n = 0;
|
||||||
fprintf(stderr, "Recording source: ");
|
|
||||||
|
if (!shortflag)
|
||||||
|
printf("Recording source: ");
|
||||||
|
|
||||||
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
|
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
|
||||||
if ((1 << i) & recsrc) {
|
if ((1 << i) & recsrc) {
|
||||||
if (n)
|
if (shortflag) {
|
||||||
fprintf(stderr, ", ");
|
if (n)
|
||||||
fprintf(stderr, "%s", names[i]);
|
printf(" +rec ");
|
||||||
|
else
|
||||||
|
printf("=rec ");
|
||||||
|
} else if (n)
|
||||||
|
printf(", ");
|
||||||
|
printf("%s", names[i]);
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
if (!shortflag)
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -97,17 +105,17 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
name = strdup("/dev/mixer");
|
name = "/dev/mixer";
|
||||||
|
|
||||||
if (!strcmp(argv[0], "mixer2"))
|
if (!strcmp(argv[0], "mixer2"))
|
||||||
name = strdup("/dev/mixer1");
|
name = "/dev/mixer1";
|
||||||
else if (!strcmp(argv[0], "mixer3"))
|
else if (!strcmp(argv[0], "mixer3"))
|
||||||
name = strdup("/dev/mixer2");
|
name = "/dev/mixer2";
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "f:sS")) != -1)
|
while ((ch = getopt(argc, argv, "f:sS")) != -1)
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'f':
|
case 'f':
|
||||||
name = strdup(optarg);
|
name = optarg;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
shortflag = 1;
|
shortflag = 1;
|
||||||
@ -123,7 +131,6 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
if ((baz = open(name, O_RDWR)) < 0)
|
if ((baz = open(name, O_RDWR)) < 0)
|
||||||
err(1, "%s", name);
|
err(1, "%s", name);
|
||||||
free(name);
|
|
||||||
if (ioctl(baz, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
|
if (ioctl(baz, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
|
||||||
err(1, "SOUND_MIXER_READ_DEVMASK");
|
err(1, "SOUND_MIXER_READ_DEVMASK");
|
||||||
if (ioctl(baz, SOUND_MIXER_READ_RECMASK, &recmask) == -1)
|
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)
|
if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1)
|
||||||
err(1, "SOUND_MIXER_READ_RECSRC");
|
err(1, "SOUND_MIXER_READ_RECSRC");
|
||||||
print_recsrc(recsrc);
|
print_recsrc(recsrc, shortflag || Shortflag);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +295,7 @@ main(int argc, char *argv[])
|
|||||||
if (drecsrc) {
|
if (drecsrc) {
|
||||||
if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1)
|
if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1)
|
||||||
err(1, "SOUND_MIXER_READ_RECSRC");
|
err(1, "SOUND_MIXER_READ_RECSRC");
|
||||||
print_recsrc(recsrc);
|
print_recsrc(recsrc, shortflag || Shortflag);
|
||||||
}
|
}
|
||||||
|
|
||||||
close(baz);
|
close(baz);
|
||||||
|
Loading…
Reference in New Issue
Block a user