28 #include "dbus-spawn.h" 29 #include "dbus-sysdeps.h" 30 #include "dbus-test.h" 33 get_test_exec (
const char *exe,
36 const char *dbus_test_exec;
40 if (dbus_test_exec ==
NULL)
47 dbus_test_exec, exe, DBUS_EXEEXT))
53 return _dbus_string_get_data (scratch_space);
57 check_spawn_nonexistent (
void *data)
59 static const char arg_does_not_exist[] =
"/this/does/not/exist/32542sdgafgafdg";
67 argv[0] = arg_does_not_exist;
69 (
char *
const *) argv,
70 NULL, DBUS_SPAWN_NONE, NULL, NULL,
77 _dbus_babysitter_block_for_child_exit (sitter);
86 _dbus_warn (
"Did not get an error launching nonexistent executable");
93 _dbus_warn (
"Not expecting error when launching nonexistent executable: %s: %s",
94 error.name, error.message);
105 check_spawn_segfault (
void *data)
114 argv[0] = get_test_exec (
"test-segfault", &argv0);
123 NULL, DBUS_SPAWN_NONE, NULL, NULL,
130 _dbus_babysitter_block_for_child_exit (sitter);
141 _dbus_warn (
"Did not get an error launching segfaulting binary");
152 _dbus_warn (
"Not expecting error when launching segfaulting executable: %s: %s",
153 error.name, error.message);
164 check_spawn_exit (
void *data)
173 argv[0] = get_test_exec (
"test-exit", &argv0);
182 NULL, DBUS_SPAWN_NONE, NULL, NULL,
189 _dbus_babysitter_block_for_child_exit (sitter);
200 _dbus_warn (
"Did not get an error launching binary that exited with failure code");
207 _dbus_warn (
"Not expecting error when launching exiting executable: %s: %s",
208 error.name, error.message);
219 check_spawn_and_kill (
void *data)
228 argv[0] = get_test_exec (
"test-sleep-forever", &argv0);
237 NULL, DBUS_SPAWN_NONE, NULL, NULL,
246 _dbus_babysitter_block_for_child_exit (sitter);
258 _dbus_warn (
"Did not get an error after killing spawned binary");
269 _dbus_warn (
"Not expecting error when killing executable: %s: %s",
270 error.name, error.message);
281 _dbus_spawn_test (
const char *test_data_dir)
283 if (!_dbus_test_oom_handling (
"spawn_nonexistent",
284 check_spawn_nonexistent,
288 if (!_dbus_test_oom_handling (
"spawn_segfault",
289 check_spawn_segfault,
293 if (!_dbus_test_oom_handling (
"spawn_exit",
298 if (!_dbus_test_oom_handling (
"spawn_and_kill",
299 check_spawn_and_kill,
dbus_bool_t dbus_error_has_name(const DBusError *error, const char *name)
Checks whether the error is set and has the given name.
#define NULL
A null pointer, defined appropriately for C or C++.
#define DBUS_ERROR_SPAWN_EXEC_FAILED
While starting a new process, the exec() call failed.
#define DBUS_ERROR_SPAWN_CHILD_EXITED
While starting a new process, the child exited with a status code.
#define DBUS_ERROR_INIT
Expands to a suitable initializer for a DBusError on the stack.
void dbus_error_free(DBusError *error)
Frees an error that's been set (or just initialized), then reinitializes the error as in dbus_error_i...
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
#define DBUS_ERROR_SPAWN_CHILD_SIGNALED
While starting a new process, the child exited on a signal.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
void _dbus_babysitter_kill_child(DBusBabysitter *sitter)
Blocks until the babysitter process gives us the PID of the spawned grandchild, then kills the spawne...
Babysitter implementation details.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
dbus_bool_t _dbus_spawn_async_with_babysitter(DBusBabysitter **sitter_p, const char *log_name, char *const *argv, char **env, DBusSpawnFlags flags, DBusSpawnChildSetupFunc child_setup, void *user_data, DBusError *error)
Spawns a new process.
dbus_bool_t _dbus_string_append_printf(DBusString *str, const char *format,...)
Appends a printf-style formatted string to the DBusString.
Object representing an exception.
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
#define TRUE
Expands to "1".
void _dbus_babysitter_unref(DBusBabysitter *sitter)
Decrement the reference count on the babysitter object.
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation.
#define FALSE
Expands to "0".
void _dbus_babysitter_set_child_exit_error(DBusBabysitter *sitter, DBusError *error)
Sets the DBusError with an explanation of why the spawned child process exited (on a signal...
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
dbus_bool_t dbus_error_is_set(const DBusError *error)
Checks whether an error occurred (the error is set).