* view.c (do_view_init): Use non-blocking open() followed by
fstat() to avoid race conditions. Unset O_NONBLOCK flag after the open().
Этот коммит содержится в:
родитель
382930fbf6
Коммит
6743211748
@ -1,5 +1,9 @@
|
||||
2002-12-15 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* view.c (do_view_init): Use non-blocking open() followed by
|
||||
fstat() to avoid race conditions. Unset O_NONBLOCK flag after
|
||||
the open().
|
||||
|
||||
* cmd.c (mkdir_cmd): Don't try to create a directory with empty
|
||||
name.
|
||||
|
||||
|
25
src/view.c
25
src/view.c
@ -644,8 +644,19 @@ do_view_init (WView *view, char *_command, const char *_file,
|
||||
if (_command && (view->viewer_magic_flag || _file[0] == '\0')) {
|
||||
error = init_growing_view (view, _command, view->filename);
|
||||
} else if (_file[0]) {
|
||||
int cntlflags;
|
||||
|
||||
/* Open the file */
|
||||
if ((fd = mc_open (_file, O_RDONLY | O_NONBLOCK)) == -1) {
|
||||
g_snprintf (tmp, sizeof (tmp), _(" Cannot open \"%s\"\n %s "),
|
||||
_file, unix_error_string (errno));
|
||||
error = set_view_init_error (view, tmp);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
/* Make sure we are working with a regular file */
|
||||
if (mc_stat (view->filename, &view->s) == -1) {
|
||||
if (mc_fstat (fd, &view->s) == -1) {
|
||||
mc_close (fd);
|
||||
g_snprintf (tmp, sizeof (tmp), _(" Cannot stat \"%s\"\n %s "),
|
||||
_file, unix_error_string (errno));
|
||||
error = set_view_init_error (view, tmp);
|
||||
@ -653,18 +664,18 @@ do_view_init (WView *view, char *_command, const char *_file,
|
||||
}
|
||||
|
||||
if (!S_ISREG (view->s.st_mode)) {
|
||||
mc_close (fd);
|
||||
g_snprintf (tmp, sizeof (tmp),
|
||||
_(" Cannot view: not a regular file "));
|
||||
error = set_view_init_error (view, tmp);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
/* Actually open the file */
|
||||
if ((fd = mc_open (_file, O_RDONLY)) == -1) {
|
||||
g_snprintf (tmp, sizeof (tmp), _(" Cannot open \"%s\"\n %s "),
|
||||
_file, unix_error_string (errno));
|
||||
error = set_view_init_error (view, tmp);
|
||||
goto finish;
|
||||
/* We don't need O_NONBLOCK after opening the file, unset it */
|
||||
cntlflags = fcntl (fd, F_GETFL, 0);
|
||||
if (cntlflags != -1) {
|
||||
cntlflags &= ~O_NONBLOCK;
|
||||
fcntl (fd, F_SETFL, cntlflags);
|
||||
}
|
||||
|
||||
type = get_compression_type (fd);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user