All of
 help / color / mirror / Atom feed
From: Alexander Volkov <>
Subject: [PATCH - alsa-utils 1/1] arecord: Remove only regular files
Date: Mon, 21 Sep 2015 16:05:57 +0300	[thread overview]
Message-ID: <> (raw)

arecord removes a file before writing into it. It's not
appropriate in some cases. For example, if you a pass
a symlink to a file, then the symlink will be removed
while the user expects to record into the symlink's target.
Another case is recording into the device file. Some
modems provide a tty device file as a voice device.
And it's not possible to write into it under root with
arecord, because it removes the device file.

So check the type of a file before writing into it and
remove only regular files.

Signed-off-by: Alexander Volkov <>

diff --git a/aplay/aplay.c b/aplay/aplay.c
index 459f7dd..1b2cdfc 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -2929,6 +2929,7 @@ static void capture(char *orig_name)
 	char *name = orig_name;	/* current filename */
 	char namebuf[PATH_MAX+1];
 	off64_t count, rest;		/* number of bytes to capture */
+	struct stat statbuf;
 	/* get number of bytes to capture */
 	count = calc_count();
@@ -2973,7 +2974,10 @@ static void capture(char *orig_name)
 			/* open a new file */
-			remove(name);
+			if (!lstat(name, &statbuf)) {
+				if (S_ISREG(statbuf.st_mode))
+					remove(name);
+			}
 			fd = safe_open(name);
 			if (fd < 0) {

             reply	other threads:[~2015-09-21 13:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-21 13:05 Alexander Volkov [this message]
2015-09-22 13:24 ` [PATCH - alsa-utils 1/1] arecord: Remove only regular files Arun Raghavan
2015-09-22 14:07   ` Александр Волков
2015-09-23 13:28     ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.