Save errno before calling other funcs that potentially alter it. Bug

* gio/gdesktopappinfo.c: (ensure_dir):
	* gio/glocalfile.c: (g_local_file_query_filesystem_info),
	(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
	(g_local_file_move):
	* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
	(_g_local_file_info_get_from_fd), (set_unix_mode),
	(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
	* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
	(g_local_file_input_stream_skip),
	(g_local_file_input_stream_close),
	(g_local_file_input_stream_seek):
	* gio/glocalfileoutputstream.c:
	(g_local_file_output_stream_write),
	(g_local_file_output_stream_close),
	(g_local_file_output_stream_seek),
	(g_local_file_output_stream_truncate), (copy_file_data),
	(handle_overwrite_open):
	* gio/gunixinputstream.c: (g_unix_input_stream_read),
	(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
	* gio/gunixoutputstream.c: (g_unix_output_stream_write),
	(g_unix_output_stream_close), (write_async_cb), (close_async_cb):
	Save
	errno before calling other funcs that potentially alter it. Bug
	#514766.

svn path=/trunk/; revision=6466
This commit is contained in:
Christian Persch 2008-02-06 15:10:08 +00:00
parent d87c1c0af4
commit 37ac644bd1
8 changed files with 232 additions and 112 deletions

View File

@ -1,3 +1,28 @@
2008-02-06 Christian Persch <chpe@gnome.org>
* gio/gdesktopappinfo.c: (ensure_dir):
* gio/glocalfile.c: (g_local_file_query_filesystem_info),
(g_local_file_read), (g_local_file_delete), (g_local_file_trash),
(g_local_file_move):
* gio/glocalfileinfo.c: (set_xattr), (_g_local_file_info_get),
(_g_local_file_info_get_from_fd), (set_unix_mode),
(set_unix_uid_gid), (set_symlink), (set_mtime_atime):
* gio/glocalfileinputstream.c: (g_local_file_input_stream_read),
(g_local_file_input_stream_skip),
(g_local_file_input_stream_close),
(g_local_file_input_stream_seek):
* gio/glocalfileoutputstream.c: (g_local_file_output_stream_write),
(g_local_file_output_stream_close),
(g_local_file_output_stream_seek),
(g_local_file_output_stream_truncate), (copy_file_data),
(handle_overwrite_open):
* gio/gunixinputstream.c: (g_unix_input_stream_read),
(g_unix_input_stream_close), (read_async_cb), (close_async_cb):
* gio/gunixoutputstream.c: (g_unix_output_stream_write),
(g_unix_output_stream_close), (write_async_cb), (close_async_cb): Save
errno before calling other funcs that potentially alter it. Bug
#514766.
2008-02-05 18:42:42 Tim Janik <timj@imendio.com>
* configure.in: generate gobject/tests/Makefile.

View File

@ -1096,7 +1096,7 @@ ensure_dir (DirType type,
GError **error)
{
char *path, *display_name;
int err;
int errsv;
if (type == APP_DIR)
path = g_build_filename (g_get_user_data_dir (), "applications", NULL);
@ -1107,16 +1107,16 @@ ensure_dir (DirType type,
if (g_mkdir_with_parents (path, 0700) == 0)
return path;
err = errno;
errsv = errno;
display_name = g_filename_display_name (path);
if (type == APP_DIR)
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (err),
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
_("Can't create user application configuration folder %s: %s"),
display_name, g_strerror (err));
display_name, g_strerror (errsv));
else
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (err),
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
_("Can't create user MIME configuration folder %s: %s"),
display_name, g_strerror (err));
display_name, g_strerror (errsv));
g_free (display_name);
g_free (path);

View File

@ -840,10 +840,12 @@ g_local_file_query_filesystem_info (GFile *file,
if (statfs_result == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error getting filesystem info: %s"),
g_strerror (errno));
g_strerror (errsv));
return NULL;
}
@ -1110,10 +1112,12 @@ g_local_file_read (GFile *file,
fd = g_open (local->filename, O_RDONLY, 0);
if (fd == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error opening file: %s"),
g_strerror (errno));
g_strerror (errsv));
return NULL;
}
@ -1172,10 +1176,12 @@ g_local_file_delete (GFile *file,
if (g_remove (local->filename) == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error removing file: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
@ -1464,10 +1470,12 @@ g_local_file_trash (GFile *file,
if (g_lstat (local->filename, &file_stat) != 0)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error trashing file: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
@ -1484,14 +1492,13 @@ g_local_file_trash (GFile *file,
if (g_mkdir_with_parents (trashdir, 0700) < 0)
{
char *display_name;
int err;
int errsv = errno;
err = errno;
display_name = g_filename_display_name (trashdir);
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (err),
g_io_error_from_errno (errsv),
_("Unable to create trash dir %s: %s"),
display_name, g_strerror (err));
display_name, g_strerror (errsv));
g_free (display_name);
g_free (trashdir);
return FALSE;
@ -1639,15 +1646,17 @@ g_local_file_trash (GFile *file,
if (fd == -1)
{
int errsv = errno;
g_free (filesdir);
g_free (topdir);
g_free (trashname);
g_free (infofile);
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Unable to create trashing info file: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
@ -1662,15 +1671,17 @@ g_local_file_trash (GFile *file,
if (g_rename (local->filename, trashfile) == -1)
{
int errsv = errno;
g_free (topdir);
g_free (trashname);
g_free (infofile);
g_free (trashfile);
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Unable to trash file: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
@ -1822,10 +1833,12 @@ g_local_file_move (GFile *source,
res = g_lstat (local_source->filename, &statbuf);
if (res == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error moving file: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
else
@ -1884,10 +1897,12 @@ g_local_file_move (GFile *source,
res = unlink (local_destination->filename);
if (res == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error removing target file: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
}

View File

@ -759,7 +759,7 @@ set_xattr (char *filename,
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errsv),
_("Error setting extended attribute '%s': %s"),
escaped_attribute, g_strerror (errno));
escaped_attribute, g_strerror (errsv));
return FALSE;
}
@ -1388,11 +1388,13 @@ _g_local_file_info_get (const char *basename,
res = g_lstat (path, &statbuf);
if (res == -1)
{
int errsv = errno;
g_object_unref (info);
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error stating file '%s': %s"),
path, g_strerror (errno));
path, g_strerror (errsv));
return NULL;
}
@ -1619,10 +1621,12 @@ _g_local_file_info_get_from_fd (int fd,
if (fstat (fd, &stat_buf) == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error stating file descriptor: %s"),
g_strerror (errno));
g_strerror (errsv));
return NULL;
}
@ -1723,10 +1727,12 @@ set_unix_mode (char *filename,
if (g_chmod (filename, val) == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error setting permissions: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
return TRUE;
@ -1772,10 +1778,12 @@ set_unix_uid_gid (char *filename,
if (res == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error setting owner: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
return TRUE;
@ -1803,10 +1811,12 @@ set_symlink (char *filename,
if (g_lstat (filename, &statbuf))
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error setting symlink: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
@ -1820,19 +1830,23 @@ set_symlink (char *filename,
if (g_unlink (filename))
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error setting symlink: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
if (symlink (filename, val) != 0)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error setting symlink: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
@ -1932,10 +1946,12 @@ set_mtime_atime (char *filename,
res = utimes (filename, times);
if (res == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error setting owner: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
return TRUE;

View File

@ -150,13 +150,15 @@ g_local_file_input_stream_read (GInputStream *stream,
res = read (file->priv->fd, buffer, count);
if (res == -1)
{
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error reading from file: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
@ -182,20 +184,24 @@ g_local_file_input_stream_skip (GInputStream *stream,
start = lseek (file->priv->fd, 0, SEEK_CUR);
if (start == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
g_strerror (errno));
g_strerror (errsv));
return -1;
}
res = lseek (file->priv->fd, count, SEEK_CUR);
if (res == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
g_strerror (errno));
g_strerror (errsv));
return -1;
}
@ -219,10 +225,14 @@ g_local_file_input_stream_close (GInputStream *stream,
{
res = close (file->priv->fd);
if (res == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error closing file: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
}
@ -295,10 +305,12 @@ g_local_file_input_stream_seek (GFileInputStream *stream,
if (pos == (off_t)-1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}

View File

@ -158,13 +158,15 @@ g_local_file_output_stream_write (GOutputStream *stream,
res = write (file->priv->fd, buffer, count);
if (res == -1)
{
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error writing to file: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
@ -200,10 +202,12 @@ g_local_file_output_stream_close (GOutputStream *stream,
if (unlink (file->priv->backup_filename) != 0 &&
errno != ENOENT)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
G_IO_ERROR_CANT_CREATE_BACKUP,
_("Error removing old backup link: %s"),
g_strerror (errno));
g_strerror (errsv));
goto err_out;
}
@ -212,10 +216,12 @@ g_local_file_output_stream_close (GOutputStream *stream,
/* link failed or is not supported, try rename */
if (rename (file->priv->original_filename, file->priv->backup_filename) != 0)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
G_IO_ERROR_CANT_CREATE_BACKUP,
_("Error creating backup copy: %s"),
g_strerror (errno));
g_strerror (errsv));
goto err_out;
}
}
@ -223,10 +229,12 @@ g_local_file_output_stream_close (GOutputStream *stream,
/* If link not supported, just rename... */
if (rename (file->priv->original_filename, file->priv->backup_filename) != 0)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
G_IO_ERROR_CANT_CREATE_BACKUP,
_("Error creating backup copy: %s"),
g_strerror (errno));
g_strerror (errsv));
goto err_out;
}
#endif
@ -239,10 +247,12 @@ g_local_file_output_stream_close (GOutputStream *stream,
/* tmp -> original */
if (rename (file->priv->tmp_filename, file->priv->original_filename) != 0)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
_("Error renaming temporary file: %s"),
g_strerror (errno));
g_strerror (errsv));
goto err_out;
}
}
@ -258,10 +268,12 @@ g_local_file_output_stream_close (GOutputStream *stream,
res = close (file->priv->fd);
if (res == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error closing file: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
}
@ -349,10 +361,12 @@ g_local_file_output_stream_seek (GFileOutputStream *stream,
if (pos == (off_t)-1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
@ -386,7 +400,9 @@ g_local_file_output_stream_truncate (GFileOutputStream *stream,
if (res == -1)
{
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
{
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
@ -394,9 +410,9 @@ g_local_file_output_stream_truncate (GFileOutputStream *stream,
}
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error truncating file: %s"),
g_strerror (errno));
g_strerror (errsv));
return FALSE;
}
@ -532,13 +548,15 @@ copy_file_data (gint sfd,
bytes_read = read (sfd, buffer, BUFSIZE);
if (bytes_read == -1)
{
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error reading from file: %s"),
g_strerror (errno));
g_strerror (errsv));
ret = FALSE;
break;
}
@ -551,13 +569,15 @@ copy_file_data (gint sfd,
bytes_written = write (dfd, write_buffer, bytes_to_write);
if (bytes_written == -1)
{
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error writing to file: %s"),
g_strerror (errno));
g_strerror (errsv));
ret = FALSE;
break;
}
@ -615,19 +635,23 @@ handle_overwrite_open (const char *filename,
if (fd == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error opening file '%s': %s"),
filename, g_strerror (errno));
filename, g_strerror (errsv));
return -1;
}
if (fstat (fd, &original_stat) != 0)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error stating file '%s': %s"),
filename, g_strerror (errno));
filename, g_strerror (errsv));
goto err_out;
}
@ -809,10 +833,12 @@ handle_overwrite_open (const char *filename,
/* Seek back to the start of the file after the backup copy */
if (lseek (fd, 0, SEEK_SET) == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error seeking in file: %s"),
g_strerror (errno));
g_strerror (errsv));
goto err_out;
}
}
@ -824,10 +850,12 @@ handle_overwrite_open (const char *filename,
if (ftruncate (fd, 0) == -1)
#endif
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error truncating file: %s"),
g_strerror (errno));
g_strerror (errsv));
goto err_out;
}

View File

@ -195,10 +195,12 @@ g_unix_input_stream_read (GInputStream *stream,
if (poll_ret == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error reading from unix: %s"),
g_strerror (errno));
g_strerror (errsv));
return -1;
}
}
@ -210,13 +212,15 @@ g_unix_input_stream_read (GInputStream *stream,
res = read (unix_stream->priv->fd, buffer, count);
if (res == -1)
{
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error reading from unix: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
@ -243,10 +247,14 @@ g_unix_input_stream_close (GInputStream *stream,
/* This might block during the close. Doesn't seem to be a way to avoid it though. */
res = close (unix_stream->priv->fd);
if (res == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error closing unix: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
}
@ -282,13 +290,15 @@ read_async_cb (ReadAsyncData *data,
count_read = read (data->stream->priv->fd, data->buffer, data->count);
if (count_read == -1)
{
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
continue;
g_set_error (&error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error reading from unix: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
}
@ -419,10 +429,14 @@ close_async_cb (CloseAsyncData *data)
{
res = close (unix_stream->priv->fd);
if (res == -1)
{
int errsv = errno;
g_set_error (&error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error closing unix: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
}

View File

@ -183,10 +183,12 @@ g_unix_output_stream_write (GOutputStream *stream,
if (poll_ret == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error writing to unix: %s"),
g_strerror (errno));
g_strerror (errsv));
return -1;
}
}
@ -199,13 +201,15 @@ g_unix_output_stream_write (GOutputStream *stream,
res = write (unix_stream->priv->fd, buffer, count);
if (res == -1)
{
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
continue;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error writing to unix: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
@ -233,10 +237,12 @@ g_unix_output_stream_close (GOutputStream *stream,
res = close (unix_stream->priv->fd);
if (res == -1)
{
int errsv = errno;
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error closing unix: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
}
@ -273,13 +279,15 @@ write_async_cb (WriteAsyncData *data,
count_written = write (data->stream->priv->fd, data->buffer, data->count);
if (count_written == -1)
{
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
continue;
g_set_error (&error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error reading from unix: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
}
@ -380,10 +388,12 @@ close_async_cb (CloseAsyncData *data)
res = close (unix_stream->priv->fd);
if (res == -1)
{
int errsv = errno;
g_set_error (&error, G_IO_ERROR,
g_io_error_from_errno (errno),
g_io_error_from_errno (errsv),
_("Error closing unix: %s"),
g_strerror (errno));
g_strerror (errsv));
}
break;
}