#include <glib.h>
+#include <stdlib.h>
#include <string.h>
#ifdef G_OS_UNIX
/* Arbitrary; included here to avoid relying on the default. */
#define MAX_INCOMING_UNIX_FDS (MAX_MESSAGE_UNIX_FDS * 4)
-/* Arbitrary, except that MAX_MESSAGE_UNIX_FDS * SOME_MESSAGES must be
+/* Arbitrary, except that MAX_MESSAGE_UNIX_FDS * SOME_MESSAGES should be
* less than the process's file descriptor limit. */
-#define SOME_MESSAGES 50
+#define SOME_MESSAGES 20
+/* To cover some situations on Linux we want this to be true. */
+_DBUS_STATIC_ASSERT (MAX_MESSAGE_UNIX_FDS * SOME_MESSAGES > 256);
/* Linux won't allow more than 253 fds per sendmsg(). */
#define TOO_MANY_FDS 255
int fd_before;
} Fixture;
-#if !GLIB_CHECK_VERSION (2, 38, 0)
-#define g_test_skip(s) my_test_skip (s)
-static inline void my_test_skip (const gchar *s)
-{
- g_message ("SKIP: %s", s);
-}
-#endif
-
#ifdef HAVE_UNIX_FD_PASSING
static void oom (const gchar *doing) G_GNUC_NORETURN;
oom (const gchar *doing)
{
g_error ("out of memory (%s)", doing);
+ abort ();
}
static void
while (f->left_server_conn == NULL)
{
- g_print (".");
+ test_progress ('.');
test_main_context_iterate (f->ctx, TRUE);
}
while (f->right_server_conn == NULL)
{
- g_print (".");
+ test_progress ('.');
test_main_context_iterate (f->ctx, TRUE);
}
!dbus_connection_get_is_authenticated (f->left_server_conn) ||
!dbus_connection_get_is_authenticated (f->right_server_conn))
{
- g_printerr ("*");
+ test_progress ('*');
test_main_context_iterate (f->ctx, TRUE);
}
while (g_queue_get_length (&f->messages) < 1)
{
- g_print (".");
+ test_progress ('.');
test_main_context_iterate (f->ctx, TRUE);
}
while (g_queue_get_length (&f->messages) < 1)
{
- g_print (".");
+ test_progress ('.');
test_main_context_iterate (f->ctx, TRUE);
}
{
#ifdef HAVE_UNIX_FD_PASSING
DBusMessage *outgoing;
- int i;
+ unsigned int i;
test_connect (f, data);
while (dbus_connection_get_is_connected (f->left_client_conn) ||
dbus_connection_get_is_connected (f->left_server_conn))
{
- g_print (".");
+ test_progress ('.');
test_main_context_iterate (f->ctx, TRUE);
}
#ifdef HAVE_UNIX_FD_PASSING
DBusMessage *outgoing;
int i;
- int left_client_socket;
+ DBusSocket left_client_socket;
char *payload;
int payload_len;
DBusString buffer;
/* This is blatant cheating, and the API documentation specifically
* tells you not use this function in this way. Never do this
* in application code. */
- if (!dbus_connection_get_socket (f->left_client_conn, &left_client_socket))
+ if (!dbus_connection_get_socket (f->left_client_conn,
+ &left_client_socket.fd))
g_error ("'unix:' DBusConnection should have had a socket");
/* Just to be sure that we're at a message boundary. */
while (dbus_connection_get_is_connected (f->left_client_conn) ||
dbus_connection_get_is_connected (f->left_server_conn))
{
- g_print (".");
+ test_progress ('.');
test_main_context_iterate (f->ctx, TRUE);
}
gconstpointer data)
{
#ifdef HAVE_UNIX_FD_PASSING
- int i, j;
+ unsigned int i, j;
DBusMessage *outgoing[SOME_MESSAGES];
dbus_uint32_t serial;
while (g_queue_get_length (&f->messages) < SOME_MESSAGES)
{
- g_print (".");
+ test_progress ('.');
test_main_context_iterate (f->ctx, TRUE);
}
while (dbus_connection_get_is_connected (f->left_client_conn) ||
dbus_connection_get_is_connected (f->left_server_conn))
{
- g_print (".");
+ test_progress ('.');
test_main_context_iterate (f->ctx, TRUE);
}
/* We're at or under the limit. The message gets through intact. */
while (g_queue_get_length (&f->messages) < 1)
{
- g_print (".");
+ test_progress ('.');
test_main_context_iterate (f->ctx, TRUE);
}
{
test_init (&argc, &argv);
+#ifdef HAVE_GETRLIMIT
+ {
+ struct rlimit lim;
+
+ if (getrlimit (RLIMIT_NOFILE, &lim) < 0)
+ g_error ("Failed to get RLIMIT_NOFILE limit: %s", g_strerror (errno));
+
+ if (lim.rlim_cur != RLIM_INFINITY &&
+ /* only run if we have a fairly generous margin of error
+ * for stdout, stderr, duplicates, the D-Bus connection, etc. */
+ lim.rlim_cur < 2 * MAX_MESSAGE_UNIX_FDS * SOME_MESSAGES)
+ {
+ g_message ("not enough RLIMIT_NOFILE to run this test");
+ /* Autotools exit code for "all skipped" */
+ return 77;
+ }
+ }
+#endif
+
g_test_add ("/relay", Fixture, NULL, setup,
test_relay, teardown);
g_test_add ("/limit", Fixture, NULL, setup,