* [FFmpeg-devel] [PATCH v2 2/3] avformat/file: dup file descriptor for pipe protocol
[not found] <20221211151729.120662-1-quinkblack@foxmail.com>
@ 2022-12-11 15:17 ` Zhao Zhili
2022-12-11 15:17 ` [FFmpeg-devel] [PATCH v2 3/3] fftools/ffmpeg_demux: fix stdin interaction condition Zhao Zhili
1 sibling, 0 replies; 2+ messages in thread
From: Zhao Zhili @ 2022-12-11 15:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
This can fix read/write error when user close the file descriptor
earlier. Now user can close the file descriptor earlier to avoid
file descriptor leak. So it's safer in both way.
---
libavformat/file.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/libavformat/file.c b/libavformat/file.c
index b8725c1f48..f7ebd52433 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -401,7 +401,9 @@ static int pipe_open(URLContext *h, const char *filename, int flags)
#if HAVE_SETMODE
setmode(fd, O_BINARY);
#endif
- c->fd = fd;
+ c->fd = dup(fd);
+ if (c->fd < 0)
+ return AVERROR(errno);
h->is_streamed = 1;
return 0;
}
@@ -411,6 +413,7 @@ const URLProtocol ff_pipe_protocol = {
.url_open = pipe_open,
.url_read = file_read,
.url_write = file_write,
+ .url_close = file_close,
.url_get_file_handle = file_get_handle,
.url_check = file_check,
.priv_data_size = sizeof(FileContext),
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH v2 3/3] fftools/ffmpeg_demux: fix stdin interaction condition
[not found] <20221211151729.120662-1-quinkblack@foxmail.com>
2022-12-11 15:17 ` [FFmpeg-devel] [PATCH v2 2/3] avformat/file: dup file descriptor for pipe protocol Zhao Zhili
@ 2022-12-11 15:17 ` Zhao Zhili
1 sibling, 0 replies; 2+ messages in thread
From: Zhao Zhili @ 2022-12-11 15:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhao Zhili
From: Zhao Zhili <zhilizhao@tencent.com>
Disable stdin interaction for pipe and fd protocols only if the
file descriptor is explicitly or implicitly setting to zero.
---
fftools/ffmpeg_demux.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index e845e6784d..57695c25a3 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -885,7 +885,10 @@ int ifile_open(const OptionsContext *o, const char *filename)
if (!strcmp(filename, "-"))
filename = "pipe:";
- stdin_interaction &= strncmp(filename, "pipe:", 5) &&
+ stdin_interaction &= strcmp(filename, "pipe:") &&
+ strcmp(filename, "pipe:0") &&
+ strcmp(filename, "fd:") &&
+ strcmp(filename, "fd:0") &&
strcmp(filename, "/dev/stdin");
/* get default parameters from command line */
--
2.25.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread