]> git.alsa-project.org Git - alsa-utils.git/commitdiff
aplay: fix the multiple open file descriptors for the raw capture
authorJaroslav Kysela <perex@perex.cz>
Tue, 12 Mar 2019 15:14:50 +0000 (16:14 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 12 Mar 2019 16:36:11 +0000 (17:36 +0100)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
aplay/aplay.c

index efc1eb4cae3a1bf7a5aa5077cc9c2d18ffd5dac4..8bdf45b40d2ffd6a48ad48bcf072e220cafedd0e 100644 (file)
@@ -2690,8 +2690,6 @@ static void end_voc(int fd)
        bt.datalen_h = (u_char) ((cnt & 0xFF0000) >> 16);
        if (lseek64(fd, length_seek, SEEK_SET) == length_seek)
                xwrite(fd, &bt, sizeof(VocBlockType));
-       if (fd != 1)
-               close(fd);
 }
 
 static void end_wave(int fd)
@@ -2712,8 +2710,6 @@ static void end_wave(int fd)
                xwrite(fd, &rifflen, 4);
        if (lseek64(fd, length_seek, SEEK_SET) == length_seek)
                xwrite(fd, &cd, sizeof(WaveChunkHeader));
-       if (fd != 1)
-               close(fd);
 }
 
 static void end_au(int fd)
@@ -2725,8 +2721,6 @@ static void end_au(int fd)
        ah.data_size = fdcount > 0xffffffff ? 0xffffffff : BE_INT(fdcount);
        if (lseek64(fd, length_seek, SEEK_SET) == length_seek)
                xwrite(fd, &ah.data_size, sizeof(ah.data_size));
-       if (fd != 1)
-               close(fd);
 }
 
 static void header(int rtype, char *name)
@@ -2938,7 +2932,7 @@ static void playback(char *name)
                break;
         }
 
-       if (fd != 0)
+       if (fd != fileno(stdin))
                close(fd);
 }
 
@@ -3151,7 +3145,7 @@ static void capture(char *orig_name)
        if (!name || !strcmp(name, "-")) {
                fd = fileno(stdout);
                name = "stdout";
-               tostdout=1;
+               tostdout = 1;
                if (count > fmt_rec_table[file_type].max_filesize)
                        count = fmt_rec_table[file_type].max_filesize;
        }
@@ -3159,7 +3153,7 @@ static void capture(char *orig_name)
 
        do {
                /* open a file to write */
-               if(!tostdout) {
+               if (!tostdout) {
                        /* upon the second file we start the numbering scheme */
                        if (filecount || use_strftime) {
                                filecount = new_capture_file(orig_name, namebuf,
@@ -3218,8 +3212,10 @@ static void capture(char *orig_name)
                }
 
                /* finish sample container */
-               if (fmt_rec_table[file_type].end && !tostdout) {
-                       fmt_rec_table[file_type].end(fd);
+               if (!tostdout) {
+                       if (fmt_rec_table[file_type].end)
+                               fmt_rec_table[file_type].end(fd);
+                       close(fd);
                        fd = -1;
                }