History

prefer avio_check() over url_exist()

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.

Stefano Sabatini committed 15 years ago

Commit 55815ed1 parent 59d96943 files · +6 −6Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t