From: Stefano Sabatini <stefano.sabatini-l...@poste.it>

The problem with url_exist() is that it tries to open a resource in
RDONLY mode. If the file is a FIFO and there is already a reading
client, the open() call will hang.

By using avio_check() with access mode of 0, the second reading
process will check if the file exists without attempting to open it,
thus avoiding the lock.

Fix issue #1663.

Signed-off-by: Anton Khirnov <an...@khirnov.net>
---
 ffmpeg.c           |    2 +-
 ffserver.c         |    4 ++--
 libavformat/img2.c |    6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 80d2cca..bd02adb 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3735,7 +3735,7 @@ static void opt_output_file(const char *filename)
             (strchr(filename, ':') == NULL ||
              filename[1] == ':' ||
              av_strstart(filename, "file:", NULL))) {
-            if (url_exist(filename)) {
+            if (avio_check(filename, 0) == 0) {
                 if (!using_stdin) {
                     fprintf(stderr,"File '%s' already exists. Overwrite ? 
[y/N] ", filename);
                     fflush(stderr);
diff --git a/ffserver.c b/ffserver.c
index 36cd9ce..dcb9d14 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -3685,7 +3685,7 @@ static void build_feed_streams(void)
     for(feed = first_feed; feed != NULL; feed = feed->next_feed) {
         int fd;
 
-        if (url_exist(feed->feed_filename)) {
+        if (avio_check(feed->feed_filename, 0) == 0) {
             /* See if it matches */
             AVFormatContext *s;
             int matches = 0;
@@ -3758,7 +3758,7 @@ static void build_feed_streams(void)
                 unlink(feed->feed_filename);
             }
         }
-        if (!url_exist(feed->feed_filename)) {
+        if (avio_check(feed->feed_filename, 0) < 0) {
             AVFormatContext s1 = {0}, *s = &s1;
 
             if (feed->readonly) {
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 2b5d63b..ef7d359 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -131,11 +131,11 @@ static int find_image_range(int *pfirst_index, int 
*plast_index,
         if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){
             *pfirst_index =
             *plast_index = 1;
-            if(url_exist(buf))
+            if (avio_check(buf, AVIO_RDONLY|AVIO_RDWR) > 0)
                 return 0;
             return -1;
         }
-        if (url_exist(buf))
+        if (avio_check(buf, AVIO_RDONLY|AVIO_RDWR) > 0)
             break;
     }
     if (first_index == 5)
@@ -153,7 +153,7 @@ static int find_image_range(int *pfirst_index, int 
*plast_index,
             if (av_get_frame_filename(buf, sizeof(buf), path,
                                       last_index + range1) < 0)
                 goto fail;
-            if (!url_exist(buf))
+            if (avio_check(buf, AVIO_RDONLY|AVIO_RDWR) <= 0)
                 break;
             range = range1;
             /* just in case... */
-- 
1.7.4.1

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to