Commit 03b9ca6d authored by Havoc Pennington's avatar Havoc Pennington

2003-04-04 Havoc Pennington <hp@redhat.com>

	* dbus/dbus-spawn.c, dbus/dbus-spawn.h: Change dbus_spawn to
	return a "babysitter" object that is used to monitor the status of
	the spawned process and reap it when required.

	* test/test-segfault.c, test/test-exit.c,
	test/test-sleep-forever.c: binaries that do various lame things,
	used in the test suite.

	* dbus/dbus-sysdeps.c: kill _dbus_errno_to_string()
parent 45d1479f
2003-04-04 Havoc Pennington <hp@redhat.com>
* dbus/dbus-spawn.c, dbus/dbus-spawn.h: Change dbus_spawn to
return a "babysitter" object that is used to monitor the status of
the spawned process and reap it when required.
* test/test-segfault.c, test/test-exit.c,
test/test-sleep-forever.c: binaries that do various lame things,
used in the test suite.
* dbus/dbus-sysdeps.c: kill _dbus_errno_to_string()
2003-04-03 Havoc Pennington <hp@pobox.com>
* dbus/dbus-spawn.c: Move dbus-spawn into a separate file
......
......@@ -619,9 +619,9 @@ bus_activation_activate_service (BusActivation *activation,
argv[0] = entry->exec;
argv[1] = NULL;
if (!_dbus_spawn_async (argv,
child_setup, activation,
error))
if (!_dbus_spawn_async_with_babysitter (NULL, argv,
child_setup, activation,
error))
{
_dbus_hash_table_remove_string (activation->pending_activations,
pending_activation->service_name);
......
......@@ -406,11 +406,18 @@ AM_CONDITIONAL(DBUS_INIT_SCRIPTS_RED_HAT, test x$with_init_scripts = xredhat)
#### Tell tests where to find certain stuff in builddir
ABSOLUTE_TOP_BUILDDIR=`cd ${ac_top_builddir}. && pwd`
TEST_SERVICE_BINARY=${ABSOLUTE_TOP_BUILDDIR}/test/test-service
AC_SUBST(TEST_SERVICE_BINARY)
AC_DEFUN(TEST_PATH, [
TEST_$1=${ABSOLUTE_TOP_BUILDDIR}/test/$2
AC_DEFINE_UNQUOTED(TEST_$1, "$TEST_$1",
[Full path to test file test/$2 in builddir])
AC_SUBST(TEST_$1)
])
TEST_SERVICE_DIR=${ABSOLUTE_TOP_BUILDDIR}/test/data/valid-service-files
AC_SUBST(TEST_SERVICE_DIR)
TEST_PATH(SERVICE_DIR, data/valid-service-files)
TEST_PATH(SERVICE_BINARY, test-service)
TEST_PATH(EXIT_BINARY, test-exit)
TEST_PATH(SEGFAULT_BINARY, test-segfault)
TEST_PATH(SLEEP_FOREVER_BINARY, test-sleep-forever)
AC_OUTPUT([
Doxyfile
......
......@@ -51,7 +51,10 @@ struct DBusError
#define DBUS_ERROR_FAILED "org.freedesktop.DBus.Error.Failed"
#define DBUS_ERROR_ACTIVATE_SERVICE_NOT_FOUND "org.freedesktop.DBus.Activate.ServiceNotFound"
#define DBUS_ERROR_SPAWN_EXEC_FAILED "org.freedesktop.DBus.Error.Spawn.ExecFailed"
#define DBUS_ERROR_SPAWN_FORK_FAILED "org.freedesktop.DBus.Error.Spawn.ForkFailed"
#define DBUS_ERROR_SPAWN_CHILD_EXITED "org.freedesktop.DBus.Error.Spawn.ChildExited"
#define DBUS_ERROR_SPAWN_CHILD_SIGNALED "org.freedesktop.DBus.Error.Spawn.ChildSignaled"
#define DBUS_ERROR_SPAWN_FAILED "org.freedesktop.DBus.Error.Spawn.Failed"
#define DBUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory"
#define DBUS_ERROR_SERVICE_DOES_NOT_EXIST "org.freedesktop.DBus.Error.ServiceDoesNotExist"
......
......@@ -244,7 +244,7 @@ _dbus_transport_debug_pipe_new (const char *server_name,
return NULL;
}
if (!_dbus_full_duplex_pipe (&client_fd, &server_fd,
if (!_dbus_full_duplex_pipe (&client_fd, &server_fd, FALSE,
NULL))
{
_dbus_verbose ("failed to create full duplex pipe\n");
......
This diff is collapsed.
......@@ -27,9 +27,37 @@
#include <dbus/dbus-string.h>
#include <dbus/dbus-errors.h>
#include <dbus/dbus-watch.h>
DBUS_BEGIN_DECLS;
typedef void (* DBusSpawnChildSetupFunc) (void *user_data);
typedef struct DBusBabysitter DBusBabysitter;
dbus_bool_t _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
char **argv,
DBusSpawnChildSetupFunc child_setup,
void *user_data,
DBusError *error);
void _dbus_babysitter_ref (DBusBabysitter *sitter);
void _dbus_babysitter_unref (DBusBabysitter *sitter);
void _dbus_babysitter_kill_child (DBusBabysitter *sitter);
dbus_bool_t _dbus_babysitter_get_child_exited (DBusBabysitter *sitter);
void _dbus_babysitter_set_child_exit_error (DBusBabysitter *sitter,
DBusError *error);
dbus_bool_t _dbus_babysitter_set_watch_functions (DBusBabysitter *sitter,
DBusAddWatchFunction add_function,
DBusRemoveWatchFunction remove_function,
DBusWatchToggledFunction toggled_function,
void *data,
DBusFreeFunction free_data_function);
dbus_bool_t _dbus_babysitter_handle_watch (DBusBabysitter *sitter,
DBusWatch *watch,
unsigned int condition);
DBUS_END_DECLS;
#endif /* DBUS_SPAWN_H */
......@@ -2197,7 +2197,7 @@ _dbus_create_file_exclusively (const DBusString *filename,
DBUS_ERROR_FAILED,
"Could not create file %s: %s\n",
filename_c,
_dbus_errno_to_string (errno));
_dbus_strerror (errno));
return FALSE;
}
......@@ -2207,7 +2207,7 @@ _dbus_create_file_exclusively (const DBusString *filename,
DBUS_ERROR_FAILED,
"Could not close file %s: %s\n",
filename_c,
_dbus_errno_to_string (errno));
_dbus_strerror (errno));
return FALSE;
}
......@@ -2556,27 +2556,6 @@ _dbus_generate_random_bytes (DBusString *str,
return FALSE;
}
/**
* A wrapper around strerror()
*
* @todo get rid of this function, it's the same as
* _dbus_strerror().
*
* @param errnum the errno
* @returns an error message (never #NULL)
*/
const char *
_dbus_errno_to_string (int errnum)
{
const char *msg;
msg = strerror (errnum);
if (msg == NULL)
msg = "unknown";
return msg;
}
/**
* A wrapper around strerror() because some platforms
* may be lame and not have strerror().
......@@ -2781,13 +2760,15 @@ _dbus_stat (const DBusString *filename,
*
* @param fd1 return location for one end
* @param fd2 return location for the other end
* @param blocking #TRUE if pipe should be blocking
* @param error error return
* @returns #FALSE on failure (if error is set)
*/
dbus_bool_t
_dbus_full_duplex_pipe (int *fd1,
int *fd2,
DBusError *error)
_dbus_full_duplex_pipe (int *fd1,
int *fd2,
dbus_bool_t blocking,
DBusError *error)
{
#ifdef HAVE_SOCKETPAIR
int fds[2];
......@@ -2801,7 +2782,8 @@ _dbus_full_duplex_pipe (int *fd1,
return FALSE;
}
if (!_dbus_set_fd_nonblocking (fds[0], NULL) ||
if (!blocking &&
!_dbus_set_fd_nonblocking (fds[0], NULL) ||
!_dbus_set_fd_nonblocking (fds[1], NULL))
{
dbus_set_error (error, _dbus_error_from_errno (errno),
......
......@@ -184,14 +184,6 @@ dbus_bool_t _dbus_generate_random_bytes (DBusString *str,
const char *_dbus_errno_to_string (int errnum);
const char* _dbus_error_from_errno (int error_number);
typedef void (* DBusSpawnChildSetupFunc) (void *user_data);
dbus_bool_t _dbus_spawn_async (char **argv,
DBusSpawnChildSetupFunc child_setup,
void *user_data,
DBusError *error);
void _dbus_disable_sigpipe (void);
void _dbus_fd_set_close_on_exec (int fd);
......@@ -215,6 +207,7 @@ dbus_bool_t _dbus_stat (const DBusString *filename,
DBusError *error);
dbus_bool_t _dbus_full_duplex_pipe (int *fd1,
int *fd2,
dbus_bool_t blocking,
DBusError *error);
dbus_bool_t _dbus_close (int fd,
DBusError *error);
......
......@@ -84,6 +84,12 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
die ("sysdeps");
check_memleaks ();
printf ("%s: running spawn tests\n", "dbus-test");
if (!_dbus_spawn_test (test_data_dir))
die ("spawn");
check_memleaks ();
printf ("%s: running data slot tests\n", "dbus-test");
if (!_dbus_data_slot_test ())
......
......@@ -49,6 +49,7 @@ dbus_bool_t _dbus_sha_test (const char *test_data_dir);
dbus_bool_t _dbus_keyring_test (void);
dbus_bool_t _dbus_data_slot_test (void);
dbus_bool_t _dbus_sysdeps_test (void);
dbus_bool_t _dbus_spawn_test (const char *test_data_dir);
void dbus_internal_do_not_use_run_tests (const char *test_data_dir);
dbus_bool_t dbus_internal_do_not_use_try_message_file (const DBusString *filename,
......
......@@ -201,7 +201,6 @@ _dbus_watch_list_free (DBusWatchList *watch_list)
/* free watch_data and removes watches as a side effect */
_dbus_watch_list_set_functions (watch_list,
NULL, NULL, NULL, NULL, NULL);
_dbus_list_foreach (&watch_list->watches,
(DBusForeachFunction) _dbus_watch_unref,
NULL);
......
......@@ -65,3 +65,13 @@
- there are various bits of code to manage ref/unref of data slots, that should
be merged into a generic facility
- add _dbus_return_if_fail, _dbus_return_val_if_fail() and use on public entry
points in place of _dbus_assert(). Add --disable-checks to control whether these
do anything.
- assorted _-prefixed symbols in libdbus aren't actually used by
libdbus, only by the message bus. These bloat up the library
size. Not sure how to fix, really.
- dbus_error_has_name(), dbus_message_name_is()
......@@ -2,7 +2,7 @@
INCLUDES=-I$(top_srcdir) $(DBUS_TEST_CFLAGS)
if DBUS_BUILD_TESTS
TEST_BINARIES=test-service echo-client echo-server unbase64 break-loader spawn-test
TEST_BINARIES=test-service echo-client echo-server unbase64 break-loader spawn-test test-segfault test-exit test-sleep-forever
else
TEST_BINARIES=
endif
......@@ -40,6 +40,15 @@ break_loader_SOURCES= \
spawn_test_SOURCES= \
spawn-test.c
test_exit_SOURCES = \
test-exit.c
test_segfault_SOURCES = \
test-segfault.c
test_sleep_forever_SOURCES = \
test-sleep-forever.c
TEST_LIBS=$(DBUS_TEST_LIBS) $(top_builddir)/dbus/libdbus-convenience.la
echo_client_LDADD=$(TEST_LIBS)
......
......@@ -2,6 +2,7 @@
#define DBUS_COMPILATION /* cheat and use dbus-sysdeps */
#include <dbus/dbus-sysdeps.h>
#include <dbus/dbus-spawn.h>
#undef DBUS_COMPILATION
#include <stdio.h>
......@@ -30,7 +31,7 @@ main (int argc, char **argv)
argv_copy [i] = argv[i + 1];
argv_copy[argc - 1] = NULL;
if (!_dbus_spawn_async (argv_copy, setup_func, NULL, &error))
if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy, setup_func, NULL, &error))
{
fprintf (stderr, "Could not launch application: \"%s\"\n",
error.message);
......
/* This is a process that just exits with a failure code */
int
main (int argc, char **argv)
{
return 1;
}
/* This is simply a process that segfaults */
#include <signal.h>
int
main (int argc, char **argv)
{
char *p = 0;
raise (SIGSEGV);
*p = 'a';
return 0;
}
/* This is a process that just sleeps infinitely. */
#include <unistd.h>
int
main (int argc, char **argv)
{
while (1)
sleep (10000000);
return 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment