2003-04-10 Havoc Pennington <hp@pobox.com>

* bus/dispatch.c (check_segfault_service_activation): add test
	for launching an executable that just crashes.

	* test/test-segfault.c (main): try setting coredumpsize to 0 so we
	don't leave a million cores. We'll see how portable this is.
This commit is contained in:
Havoc Pennington 2003-04-11 03:45:40 +00:00
parent eb63ba5039
commit 78e7902231
7 changed files with 141 additions and 18 deletions

View file

@ -1,7 +1,15 @@
2003-04-10 Havoc Pennington <hp@pobox.com>
* bus/dispatch.c (check_segfault_service_activation): add test
for launching an executable that just crashes.
* test/test-segfault.c (main): try setting coredumpsize to 0 so we
don't leave a million cores. We'll see how portable this is.
2003-04-10 Havoc Pennington <hp@pobox.com>
* dbus/dbus-spawn.c (_dbus_spawn_async_with_babysitter): move all
the possible parent failures before we fork, so that we don't
the possible parent failures before we fork, so that we don't q
fail to create a babysitter after creating the child.
* bus/activation.c (bus_activation_activate_service): kill child

View file

@ -1570,17 +1570,10 @@ check_existent_service_activation (BusContext *context,
{
; /* good, this is a valid response */
}
else if (dbus_message_name_is (message,
DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND))
{
; /* good, this is expected also */
}
else if (dbus_message_name_is (message,
DBUS_ERROR_SPAWN_CHILD_EXITED))
{
; /* good, this is expected also (child will exit if for example we don't
* have memory to register it)
*/
; /* good, this is expected also */
}
else
{
@ -1687,7 +1680,7 @@ check_existent_service_activation (BusContext *context,
goto out;
}
}
retval = TRUE;
out:
@ -1700,6 +1693,110 @@ check_existent_service_activation (BusContext *context,
return retval;
}
/* returns TRUE if the correct thing happens,
* but the correct thing may include OOM errors.
*/
static dbus_bool_t
check_segfault_service_activation (BusContext *context,
DBusConnection *connection)
{
DBusMessage *message;
dbus_int32_t serial;
dbus_bool_t retval;
DBusError error;
dbus_error_init (&error);
message = dbus_message_new (DBUS_SERVICE_DBUS,
DBUS_MESSAGE_ACTIVATE_SERVICE);
if (message == NULL)
return TRUE;
if (!dbus_message_append_args (message,
DBUS_TYPE_STRING,
"org.freedesktop.DBus.TestSuiteSegfaultService",
DBUS_TYPE_UINT32, 0,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
return TRUE;
}
if (!dbus_connection_send (connection, message, &serial))
{
dbus_message_unref (message);
return TRUE;
}
dbus_message_unref (message);
message = NULL;
bus_test_run_everything (context);
block_connection_until_message_from_bus (context, connection);
bus_test_run_everything (context);
if (!dbus_connection_get_is_connected (connection))
{
_dbus_verbose ("connection was disconnected\n");
return TRUE;
}
retval = FALSE;
message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
_dbus_warn ("Did not receive a reply to %s %d on %p\n",
DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
goto out;
}
_dbus_verbose ("Received %s on %p\n",
dbus_message_get_name (message), connection);
if (dbus_message_get_is_error (message))
{
if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
{
_dbus_warn ("Message has wrong sender %s\n",
dbus_message_get_sender (message) ?
dbus_message_get_sender (message) : "(none)");
goto out;
}
if (dbus_message_name_is (message,
DBUS_ERROR_NO_MEMORY))
{
; /* good, this is a valid response */
}
else if (dbus_message_name_is (message,
DBUS_ERROR_SPAWN_CHILD_SIGNALED))
{
; /* good, this is expected also */
}
else
{
_dbus_warn ("Did not expect error %s\n",
dbus_message_get_name (message));
goto out;
}
}
else
{
_dbus_warn ("Did not expect to successfully activate segfault service\n");
goto out;
}
retval = TRUE;
out:
if (message)
dbus_message_unref (message);
return retval;
}
typedef struct
{
Check1Func func;
@ -1825,16 +1922,17 @@ bus_dispatch_test (const DBusString *test_data_dir)
if (!check_hello_message (context, baz))
_dbus_assert_not_reached ("hello message failed");
#if 1
check2_try_iterations (context, foo, "existent_service_activation",
check_existent_service_activation);
#endif
check1_try_iterations (context, "create_and_hello",
check_hello_connection);
check2_try_iterations (context, foo, "nonexistent_service_activation",
check_nonexistent_service_activation);
check1_try_iterations (context, "create_and_hello",
check_hello_connection);
check2_try_iterations (context, foo, "segfault_service_activation",
check_segfault_service_activation);
check2_try_iterations (context, foo, "existent_service_activation",
check_existent_service_activation);
_dbus_verbose ("Disconnecting foo, bar, and baz\n");

View file

@ -530,6 +530,7 @@ dbus-1.0.pc
dbus-glib-1.0.pc
test/data/valid-config-files/debug-allow-all.conf
test/data/valid-service-files/debug-echo.service
test/data/valid-service-files/debug-segfault.service
])
dnl ==========================================================================

View file

@ -287,6 +287,9 @@ _dbus_babysitter_unref (DBusBabysitter *sitter)
}
else
{
_dbus_verbose ("Reaped %ld, waiting for babysitter %ld\n",
(long) ret, (long) sitter->sitter_pid);
if (WIFEXITED (sitter->status))
_dbus_verbose ("Babysitter exited with status %d\n",
WEXITSTATUS (sitter->status));

View file

@ -1,3 +1,3 @@
[D-BUS Service]
Name=org.freedesktop.DBus.TestSuiteEchoService
Exec=@TEST_SERVICE_BINARY@
Exec=@TEST_SERVICE_BINARY@

View file

@ -0,0 +1,4 @@
[D-BUS Service]
Name=org.freedesktop.DBus.TestSuiteSegfaultService
Exec=@TEST_SEGFAULT_BINARY@

View file

@ -1,13 +1,22 @@
/* This is simply a process that segfaults */
#include <signal.h>
#include <sys/resource.h>
int
main (int argc, char **argv)
{
char *p = 0;
char *p;
struct rlimit r = { 0, };
getrlimit (RLIMIT_CORE, &r);
r.rlim_cur = 0;
setrlimit (RLIMIT_CORE, &r);
raise (SIGSEGV);
p = 0;
*p = 'a';
return 0;