return compose_string (envp, '\0');
}
+/**
+ * Creates a process with arguments and environment variables
+ *
+ * @param name name of the program
+ * @param argv list of char* pointers for the arguments
+ * @param envp list of char pointers for the environment
+ * @param inherit_handles specifies whether handles should be inherited by the child process
+ * @param error the error to set, if NULL no error will be set
+ * @return #NULL if an error occurred, the reason is returned in \p error
+ * @note The call to GetLastError() after this function may not return the expected value.
+ */
HANDLE
_dbus_spawn_program (const char *name,
char **argv,
char **envp,
- dbus_bool_t inherit_handles)
+ dbus_bool_t inherit_handles,
+ DBusError *error)
{
PROCESS_INFORMATION pi = { NULL, 0, 0, 0 };
STARTUPINFOA si;
arg_string = build_commandline (argv);
#endif
if (!arg_string)
- return NULL;
+ {
+ dbus_set_error (error, DBUS_ERROR_FAILED, "No arguments given to start '%s' or out of memory", name);
+ goto out;
+ }
env_string = build_env_string(envp);
free (env_string);
if (!result)
- return NULL;
+ {
+ _dbus_win_set_error_from_last_error (error, "Unable to start '%s' with arguments '%s'", name, arg_string);
+ goto out;
+ }
+
+out:
+ _DBUS_ASSERT_ERROR_XOR_BOOL (error, result);
CloseHandle (pi.hThread);
return pi.hProcess;
_dbus_verbose ("babysitter: spawn child '%s'\n", my_argv[0]);
PING();
- handle = _dbus_spawn_program (sitter->log_name, my_argv, (char **) envp, FALSE);
+ handle = _dbus_spawn_program (sitter->log_name, my_argv, (char **) envp, FALSE, NULL);
if (my_argv != NULL)
{
dbus_daemon_argv[3] = _dbus_string_get_data (&argv_strings[3]);
dbus_daemon_argv[4] = NULL;
- server_handle = _dbus_spawn_program (dbus_daemon, dbus_daemon_argv, NULL, TRUE);
+ server_handle = _dbus_spawn_program (dbus_daemon, dbus_daemon_argv, NULL, TRUE, &error);
if (server_handle == NULL)
- {
- _dbus_win_set_error_from_last_error (&error, "Could not start dbus daemon");
- goto out;
- }
+ goto out;
/* wait until dbus-daemon is ready for connections */
if (ready_event_handle != NULL)
if (!env)
goto out;
- app_handle = _dbus_spawn_program (argv[prog_arg], argv + prog_arg, env, FALSE);
+ app_handle = _dbus_spawn_program (argv[prog_arg], argv + prog_arg, env, FALSE, &error);
if (app_handle == NULL)
- {
- _dbus_win_set_error_from_last_error (&error, "Unable to start child process");
- goto out;
- }
+ goto out;
WaitForSingleObject (app_handle, INFINITE);
if (!GetExitCodeProcess (app_handle, &exit_code))