Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/audiocfg return an error if testing fails, and dump ...



details:   https://anonhg.NetBSD.org/src/rev/5305b2918f2d
branches:  trunk
changeset: 757542:5305b2918f2d
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Sep 03 19:20:37 2010 +0000

description:
return an error if testing fails, and dump the device info before running tests

diffstat:

 usr.bin/audiocfg/audiodev.c |  13 ++++++++++---
 usr.bin/audiocfg/main.c     |  39 +++++++++++++++++++++++++--------------
 2 files changed, 35 insertions(+), 17 deletions(-)

diffs (116 lines):

diff -r 87704e4673d4 -r 5305b2918f2d usr.bin/audiocfg/audiodev.c
--- a/usr.bin/audiocfg/audiodev.c       Fri Sep 03 19:19:48 2010 +0000
+++ b/usr.bin/audiocfg/audiodev.c       Fri Sep 03 19:20:37 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.3 2010/09/02 02:17:35 jmcneill Exp $ */
+/* $NetBSD: audiodev.c,v 1.4 2010/09/03 19:20:37 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -245,6 +245,7 @@
        int16_t *buf;
        size_t buflen;
        off_t off;
+       int rv = 0;
 
        AUDIO_INITINFO(&info);
        info.play.sample_rate = AUDIODEV_SAMPLE_RATE;
@@ -271,7 +272,12 @@
                size_t wlen = info.play.buffer_size;
                if (wlen > buflen)
                        wlen = buflen;
-               write(adev->fd, (char *)buf + off, wlen);
+               wlen = write(adev->fd, (char *)buf + off, wlen);
+               if (wlen == -1) {
+                       perror("write");
+                       rv = -1;
+                       goto done;
+               }
                off += wlen;
                buflen -= wlen;
        }
@@ -279,7 +285,8 @@
        if (ioctl(adev->fd, AUDIO_DRAIN) == -1)
                perror("ioctl AUDIO_DRAIN");
 
+done:
        free(buf);
 
-       return 0;
+       return rv;
 }
diff -r 87704e4673d4 -r 5305b2918f2d usr.bin/audiocfg/main.c
--- a/usr.bin/audiocfg/main.c   Fri Sep 03 19:19:48 2010 +0000
+++ b/usr.bin/audiocfg/main.c   Fri Sep 03 19:20:37 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.5 2010/09/02 02:17:35 jmcneill Exp $ */
+/* $NetBSD: main.c,v 1.6 2010/09/03 19:20:37 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -26,6 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -45,6 +46,21 @@
        exit(EXIT_FAILURE);
 }
 
+static void
+print_audiodev(struct audiodev *adev, int i)
+{
+       assert(adev != NULL);
+
+       printf("%u: [%c] %s @ %s: ",
+           i, adev->defaultdev ? '*' : ' ',
+           adev->xname, adev->pxname);
+       printf("%s", adev->audio_device.name);
+       if (strlen(adev->audio_device.version) > 0)
+               printf(" %s", adev->audio_device.version);
+       printf(", %u playback channel%s\n",
+           adev->pchan, adev->pchan == 1 ? "" : "s");
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -60,17 +76,8 @@
 
        if (strcmp(argv[1], "list") == 0) {
                n = audiodev_count();
-               for (i = 0; i < n; i++) {
-                       adev = audiodev_get(i);
-                       printf("%u: [%c] %s @ %s: ",
-                           i, adev->defaultdev ? '*' : ' ',
-                           adev->xname, adev->pxname);
-                       printf("%s", adev->audio_device.name);
-                       if (strlen(adev->audio_device.version) > 0)
-                               printf(" %s", adev->audio_device.version);
-                       printf(", %u playback channel%s\n",
-                           adev->pchan, adev->pchan == 1 ? "" : "s");
-               }
+               for (i = 0; i < n; i++)
+                       print_audiodev(audiodev_get(i), i);
        } else if (strcmp(argv[1], "default") == 0 && argc == 3) {
                if (*argv[2] < '0' || *argv[2] > '9')
                        usage(argv[0]);
@@ -104,9 +111,13 @@
                        fprintf(stderr, "no such device\n");
                        return EXIT_FAILURE;
                }
+               print_audiodev(adev, i);
                for (i = 0; i < adev->pchan; i++) {
-                       printf("testing channel %d...\n", i);
-                       audiodev_test(adev, 1 << i);
+                       printf("  testing channel %d...", i);
+                       fflush(stdout);
+                       if (audiodev_test(adev, 1 << i) == -1)
+                               return EXIT_FAILURE;
+                       printf(" done\n");
                }
        } else
                usage(argv[0]);



Home | Main Index | Thread Index | Old Index