* [PATCH - alsa-utils 1/1] arecord: Remove only regular files
@ 2015-09-21 13:05 Alexander Volkov
2015-09-22 13:24 ` Arun Raghavan
0 siblings, 1 reply; 4+ messages in thread
From: Alexander Volkov @ 2015-09-21 13:05 UTC (permalink / raw)
To: patch; +Cc: alsa-devel
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 <a.volkov@rusbitech.ru>
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) {
perror(name);
--
2.4.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH - alsa-utils 1/1] arecord: Remove only regular files
2015-09-21 13:05 [PATCH - alsa-utils 1/1] arecord: Remove only regular files Alexander Volkov
@ 2015-09-22 13:24 ` Arun Raghavan
2015-09-22 14:07 ` Александр Волков
0 siblings, 1 reply; 4+ messages in thread
From: Arun Raghavan @ 2015-09-22 13:24 UTC (permalink / raw)
To: Alexander Volkov; +Cc: alsa-devel, patch
On 21 September 2015 at 18:35, Alexander Volkov <a.volkov@rusbitech.ru> wrote:
> 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 <a.volkov@rusbitech.ru>
>
> 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) {
> perror(name);
Would it work to just open with O_TRUNC?
-- Arun
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH - alsa-utils 1/1] arecord: Remove only regular files
2015-09-22 13:24 ` Arun Raghavan
@ 2015-09-22 14:07 ` Александр Волков
2015-09-23 13:28 ` Takashi Iwai
0 siblings, 1 reply; 4+ messages in thread
From: Александр Волков @ 2015-09-22 14:07 UTC (permalink / raw)
To: Arun Raghavan; +Cc: alsa-devel, patch
22.09.2015 16:24, Arun Raghavan пишет:
> On 21 September 2015 at 18:35, Alexander Volkov <a.volkov@rusbitech.ru> wrote:
>> 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 <a.volkov@rusbitech.ru>
>>
>> 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) {
>> perror(name);
> Would it work to just open with O_TRUNC?
>
> -- Arun
I guess that "remove" is used here to exclude mutual access to the file.
We can record to the created file while some program may read the
removed file.
Using O_TRUNC will break this use case.
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH - alsa-utils 1/1] arecord: Remove only regular files
2015-09-22 14:07 ` Александр Волков
@ 2015-09-23 13:28 ` Takashi Iwai
0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2015-09-23 13:28 UTC (permalink / raw)
To: Александр
Волков
Cc: alsa-devel, Arun Raghavan
On Tue, 22 Sep 2015 16:07:21 +0200,
Александр Волков wrote:
>
> 22.09.2015 16:24, Arun Raghavan пишет:
> > On 21 September 2015 at 18:35, Alexander Volkov <a.volkov@rusbitech.ru> wrote:
> >> 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 <a.volkov@rusbitech.ru>
> >>
> >> 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) {
> >> perror(name);
> > Would it work to just open with O_TRUNC?
> >
> > -- Arun
> I guess that "remove" is used here to exclude mutual access to the file.
> We can record to the created file while some program may read the
> removed file.
> Using O_TRUNC will break this use case.
Yeah, it's a good argument. I applied your patch as is now.
thanks,
Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-23 13:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-21 13:05 [PATCH - alsa-utils 1/1] arecord: Remove only regular files Alexander Volkov
2015-09-22 13:24 ` Arun Raghavan
2015-09-22 14:07 ` Александр Волков
2015-09-23 13:28 ` Takashi Iwai
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.