From: David Zeuthen Date: Fri, 27 Aug 2010 14:50:03 +0000 (-0400) Subject: Bug 628084 – gdbus-peer fails with assertion X-Git-Tag: 2.25.15~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1e7243ad7b48d833ef6eec8fa305f25487f640b0;p=platform%2Fupstream%2Fglib.git Bug 628084 – gdbus-peer fails with assertion Make it work on systems where /etc/hosts is bigger than 1024 bytes. https://bugzilla.gnome.org/show_bug.cgi?id=628084 Signed-off-by: David Zeuthen --- diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c index 5aa9754..9fb709d 100644 --- a/gio/tests/gdbus-peer.c +++ b/gio/tests/gdbus-peer.c @@ -28,6 +28,7 @@ #include #include #include +#include /* for g_unlink() */ #include @@ -39,6 +40,7 @@ /* used in test_overflow */ #ifdef G_OS_UNIX #include +#include #endif #include "gdbus-tests.h" @@ -511,6 +513,55 @@ on_do_disconnect_in_idle (gpointer data) } #endif +#ifdef G_OS_UNIX +static gchar * +read_all_from_fd (gint fd, gsize *out_len, GError **error) +{ + GString *str; + gchar buf[64]; + gssize num_read; + + str = g_string_new (NULL); + + do + { + num_read = read (fd, buf, sizeof (buf)); + if (num_read == -1) + { + if (errno == EAGAIN || errno == EWOULDBLOCK) + continue; + g_set_error (error, + G_IO_ERROR, + g_io_error_from_errno (errno), + "Failed reading %d bytes into offset %d: %s", + (gint) sizeof (buf), + (gint) str->len, + strerror (errno)); + goto error; + } + else if (num_read > 0) + { + g_string_append_len (str, buf, num_read); + } + else if (num_read == 0) + { + break; + } + } + while (TRUE); + + if (out_len != NULL) + *out_len = str->len; + return g_string_free (str, FALSE); + + error: + if (out_len != NULL) + out_len = 0; + g_string_free (str, TRUE); + return NULL; +} +#endif + static void test_peer (void) { @@ -654,8 +705,8 @@ test_peer (void) GDBusMessage *method_reply_message; GUnixFDList *fd_list; gint fd; - gchar buf[1024]; - gssize len; + gchar *buf; + gsize len; gchar *buf2; gsize len2; @@ -683,8 +734,10 @@ test_peer (void) g_object_unref (method_call_message); g_object_unref (method_reply_message); - memset (buf, '\0', sizeof (buf)); - len = read (fd, buf, sizeof (buf) - 1); + error = NULL; + buf = read_all_from_fd (fd, &len, &error); + g_assert_no_error (error); + g_assert (buf != NULL); close (fd); error = NULL; @@ -693,10 +746,10 @@ test_peer (void) &len2, &error); g_assert_no_error (error); - if (len2 > sizeof (buf)) - buf2[sizeof (buf)] = '\0'; - g_assert_cmpstr (buf, ==, buf2); + g_assert_cmpint (len, ==, len2); + g_assert (memcmp (buf, buf2, len) == 0); g_free (buf2); + g_free (buf); } #else error = NULL;