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.
Unified · Split
| @@ -3733,7 +3733,7 @@ static void opt_output_file(const char *filename) · 3732 unmodified lines | ||
| 3733 | 3733 | (strchr(filename, ':') == NULL || |
| 3734 | 3734 | filename[1] == ':' || |
| 3735 | 3735 | av_strstart(filename, "file:", NULL))) { |
| 3736 | − if (url_exist(filename)) { | |
| 3736 | + if (avio_check(filename, 0) == 0) { | |
| 3737 | 3737 | if (!using_stdin) { |
| 3738 | 3738 | fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); |
| 3739 | 3739 | fflush(stderr); |
| @@ -3679,7 +3679,7 @@ static void build_feed_streams(void) · 3678 unmodified lines | ||
| 3679 | 3679 | for(feed = first_feed; feed != NULL; feed = feed->next_feed) { |
| 3680 | 3680 | int fd; |
| 3681 | 3681 | |
| 3682 | − if (url_exist(feed->feed_filename)) { | |
| 3682 | + if (avio_check(feed->feed_filename, AVIO_FLAG_READ) > 0) { | |
| 3683 | 3683 | /* See if it matches */ |
| 3684 | 3684 | AVFormatContext *s; |
| 3685 | 3685 | int matches = 0; |
| @@ -3752,7 +3752,7 @@ static void build_feed_streams(void) · 66 unmodified lines | ||
| 3752 | 3752 | unlink(feed->feed_filename); |
| 3753 | 3753 | } |
| 3754 | 3754 | } |
| 3755 | − if (!url_exist(feed->feed_filename)) { | |
| 3755 | + if (avio_check(feed->feed_filename, AVIO_FLAG_WRITE) <= 0) { | |
| 3756 | 3756 | AVFormatContext s1 = {0}, *s = &s1; |
| 3757 | 3757 | |
| 3758 | 3758 | if (feed->readonly) { |
| @@ -131,11 +131,11 @@ static int find_image_range(int *pfirst_index, int *plast_index, · 130 unmodified lines | ||
| 131 | 131 | if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){ |
| 132 | 132 | *pfirst_index = |
| 133 | 133 | *plast_index = 1; |
| 134 | − if(url_exist(buf)) | |
| 134 | + if (avio_check(buf, AVIO_FLAG_READ) > 0) | |
| 135 | 135 | return 0; |
| 136 | 136 | return -1; |
| 137 | 137 | } |
| 138 | − if (url_exist(buf)) | |
| 138 | + if (avio_check(buf, AVIO_FLAG_READ) > 0) | |
| 139 | 139 | break; |
| 140 | 140 | } |
| 141 | 141 | if (first_index == 5) |
| @@ -153,7 +153,7 @@ static int find_image_range(int *pfirst_index, int *plast_index, · 11 unmodified lines | ||
| 153 | 153 | if (av_get_frame_filename(buf, sizeof(buf), path, |
| 154 | 154 | last_index + range1) < 0) |
| 155 | 155 | goto fail; |
| 156 | − if (!url_exist(buf)) | |
| 156 | + if (avio_check(buf, AVIO_FLAG_READ) <= 0) | |
| 157 | 157 | break; |
| 158 | 158 | range = range1; |
| 159 | 159 | /* just in case... */ |