Switch all open() calls to use g_open()

Because it now handles EINTR.  And we should do so.  While most people
use Linux, which tries very hard to avoid propagating EINTR back up
into userspace, it can still happen.

https://bugzilla.gnome.org/show_bug.cgi?id=682833
This commit is contained in:
Colin Walters 2012-08-27 18:30:06 -04:00
parent 2542b6f604
commit 6e64ba58b9
9 changed files with 17 additions and 16 deletions

View File

@ -2017,7 +2017,7 @@ g_local_file_trash (GFile *file,
infofile = g_build_filename (infodir, infoname, NULL);
g_free (infoname);
fd = open (infofile, O_CREAT | O_EXCL, 0666);
fd = g_open (infofile, O_CREAT | O_EXCL, 0666);
} while (fd == -1 && errno == EEXIST);
g_free (basename);

View File

@ -1247,10 +1247,10 @@ get_content_type (const char *basename,
sniff_length = 4096;
#ifdef O_NOATIME
fd = open (path, O_RDONLY | O_NOATIME);
fd = g_open (path, O_RDONLY | O_NOATIME, 0);
if (fd < 0 && errno == EPERM)
#endif
fd = open (path, O_RDONLY);
fd = g_open (path, O_RDONLY, 0);
if (fd != -1)
{

View File

@ -37,6 +37,7 @@
#endif
#include <gio/gio.h>
#include <glib/gstdio.h>
#include <gi18n.h>
/* GResource functions {{{1 */
@ -142,7 +143,7 @@ get_elf (const gchar *file,
if (elf_version (EV_CURRENT) == EV_NONE )
return NULL;
*fd = open (file, O_RDONLY);
*fd = g_open (file, O_RDONLY, 0);
if (*fd < 0)
return NULL;

View File

@ -178,7 +178,7 @@ test_interface_method_call (GDBusConnection *connection,
error = NULL;
fd = open (path, O_RDONLY);
fd = g_open (path, O_RDONLY, 0);
g_unix_fd_list_append (fd_list, fd, &error);
g_assert_no_error (error);
close (fd);

View File

@ -19,6 +19,7 @@
*/
#include <gio/gio.h>
#include <glib/gstdio.h>
#ifdef G_OS_UNIX
#include <fcntl.h>
@ -154,7 +155,7 @@ test_pollable_unix (void)
g_object_unref (out);
/* Non-pipe/socket unix streams are not pollable */
fd = open ("/dev/null", O_RDWR);
fd = g_open ("/dev/null", O_RDWR, 0);
g_assert_cmpint (fd, !=, -1);
in = G_POLLABLE_INPUT_STREAM (g_unix_input_stream_new (fd, FALSE));
out = g_unix_output_stream_new (fd, FALSE);

View File

@ -42,6 +42,7 @@
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <glib/gstdio.h>
#include "giochannel.h"
@ -525,12 +526,7 @@ g_io_channel_new_file (const gchar *filename,
create_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
do
{
fid = open (filename, flags, create_mode);
}
while (fid == -1 && errno == EINTR);
fid = g_open (filename, flags, create_mode);
if (fid == -1)
{
int err = errno;

View File

@ -28,6 +28,7 @@
#include <sys/wait.h>
#include <sys/time.h>
#include <fcntl.h>
#include <glib/gstdio.h>
#endif
#include <string.h>
#include <stdlib.h>
@ -2177,7 +2178,7 @@ g_test_trap_fork (guint64 usec_timeout,
close (stderr_pipe[0]);
close (stdtst_pipe[0]);
if (!(test_trap_flags & G_TEST_TRAP_INHERIT_STDIN))
fd0 = open ("/dev/null", O_RDONLY);
fd0 = g_open ("/dev/null", O_RDONLY, 0);
if (sane_dup2 (stdout_pipe[1], 1) < 0 || sane_dup2 (stderr_pipe[1], 2) < 0 || (fd0 >= 0 && sane_dup2 (fd0, 0) < 0))
g_error ("failed to dup2() in forked test program: %s", g_strerror (errno));
if (fd0 >= 3)

View File

@ -6,6 +6,7 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <glib/gstdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
@ -120,7 +121,7 @@ test_writable_fd (void)
}
error = NULL;
fd = open (SRCDIR "/4096-random-bytes", O_RDWR, 0);
fd = g_open (SRCDIR "/4096-random-bytes", O_RDWR, 0);
g_assert (fd != -1);
file = g_mapped_file_new_from_fd (fd, TRUE, &error);
g_assert_no_error (error);
@ -135,7 +136,7 @@ test_writable_fd (void)
close (fd);
error = NULL;
fd = open (SRCDIR "/4096-random-bytes", O_RDWR, 0);
fd = g_open (SRCDIR "/4096-random-bytes", O_RDWR, 0);
g_assert (fd != -1);
file = g_mapped_file_new_from_fd (fd, TRUE, &error);
g_assert_no_error (error);

View File

@ -28,6 +28,7 @@
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <glib/gstdio.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "GLib-Genmarshal"
@ -848,7 +849,7 @@ main (int argc,
/* Mostly for Win32. This is equivalent to opening /dev/stdin */
fd = dup (0);
else
fd = open (file, O_RDONLY);
fd = g_open (file, O_RDONLY, 0);
if (fd < 0)
{