From 0eae2a4026dbfc2320b6a2ccc6f075deaad84f5c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 11 Jun 2008 18:02:49 -0400 Subject: [PATCH] Fixes and cleanups for autolaunch and launchd code paths * dbus/dbus-sysdeps-unix.c: Rename "address" to "result" to make clear _read_subprocess_line_argv isn't just for addresses exactly. Also fix parameter ordering and add casts to make GCC const warnings happy. --- dbus/dbus-sysdeps-unix.c | 51 ++++++++++++++++++++++----------------------- 1 files changed, 25 insertions(+), 26 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index a9d774c..bccee06 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -2803,17 +2803,17 @@ _dbus_get_tmpdir(void) * @param progname initial path to exec * @param fallback_with_path if exec fails, use this program name on PATH * @param argv NULL-terminated list of arguments - * @param address a DBusString where the output can be stored + * @param result a DBusString where the output can be stored * @param error a DBusError to store the error in case of failure * @returns #TRUE on success, #FALSE if an error happened */ static dbus_bool_t _read_subprocess_line_argv (const char *progpath, const char * const *argv, - DBusString *address, + DBusString *result, DBusError *error) { - int address_pipe[2] = { -1, -1 }; + int result_pipe[2] = { -1, -1 }; int errors_pipe[2] = { -1, -1 }; pid_t pid; int ret; @@ -2822,7 +2822,6 @@ _read_subprocess_line_argv (const char *progpath, int i; DBusString uuid; dbus_bool_t retval; - const char *progname; _DBUS_ASSERT_ERROR_IS_CLEAR (error); retval = FALSE; @@ -2833,11 +2832,11 @@ _read_subprocess_line_argv (const char *progpath, return FALSE; } - orig_len = _dbus_string_get_length (address); + orig_len = _dbus_string_get_length (result); #define READ_END 0 #define WRITE_END 1 - if (pipe (address_pipe) < 0) + if (pipe (result_pipe) < 0) { dbus_set_error (error, _dbus_error_from_errno (errno), "Failed to create a pipe: %s", @@ -2881,7 +2880,7 @@ _read_subprocess_line_argv (const char *progpath, _dbus_verbose ("/dev/null fd %d opened\n", fd); /* set-up stdXXX */ - close (address_pipe[READ_END]); + close (result_pipe[READ_END]); close (errors_pipe[READ_END]); close (0); /* close stdin */ close (1); /* close stdout */ @@ -2889,7 +2888,7 @@ _read_subprocess_line_argv (const char *progpath, if (dup2 (fd, 0) == -1) _exit (1); - if (dup2 (address_pipe[WRITE_END], 1) == -1) + if (dup2 (result_pipe[WRITE_END], 1) == -1) _exit (1); if (dup2 (errors_pipe[WRITE_END], 2) == -1) _exit (1); @@ -2909,31 +2908,31 @@ _read_subprocess_line_argv (const char *progpath, { const char *progname; - execv (progpath, argv); + execv (progpath, (char **) argv); /* If we failed with a direct exec, try extracting the binary name and search the PATH for it */ progname = strrchr (progpath, '/'); if (progname != NULL) - execvp (progname+1, argv); + execvp (progname+1, (char **) argv); } else - execvp (progpath, argv); + execvp (progpath, (char **) argv); /* still nothing, we failed */ _exit (1); } /* parent process */ - close (address_pipe[WRITE_END]); + close (result_pipe[WRITE_END]); close (errors_pipe[WRITE_END]); - address_pipe[WRITE_END] = -1; + result_pipe[WRITE_END] = -1; errors_pipe[WRITE_END] = -1; ret = 0; do { - ret = _dbus_read (address_pipe[READ_END], address, 1024); + ret = _dbus_read (result_pipe[READ_END], result, 1024); } while (ret > 0); @@ -2947,7 +2946,7 @@ _read_subprocess_line_argv (const char *progpath, /* We succeeded if the process exited with status 0 and anything was read */ if (!WIFEXITED (status) || WEXITSTATUS (status) != 0 || - _dbus_string_get_length (address) == orig_len) + _dbus_string_get_length (result) == orig_len) { /* The process ended with error */ DBusString error_message; @@ -2959,7 +2958,7 @@ _read_subprocess_line_argv (const char *progpath, } while (ret > 0); - _dbus_string_set_length (address, orig_len); + _dbus_string_set_length (result, orig_len); if (_dbus_string_get_length (&error_message) > 0) dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED, "dbus-launch failed to autolaunch D-Bus session: %s", @@ -2978,10 +2977,10 @@ _read_subprocess_line_argv (const char *progpath, else _DBUS_ASSERT_ERROR_IS_SET (error); - if (address_pipe[0] != -1) - close (address_pipe[0]); - if (address_pipe[1] != -1) - close (address_pipe[1]); + if (result_pipe[0] != -1) + close (result_pipe[0]); + if (result_pipe[1] != -1) + close (result_pipe[1]); if (errors_pipe[0] != -1) close (errors_pipe[0]); if (errors_pipe[1] != -1) @@ -3041,9 +3040,10 @@ _dbus_get_autolaunch_address (DBusString *address, _dbus_assert (i == _DBUS_N_ELEMENTS (argv)); - retval = _read_subprocess_line_argv (address, error, - DBUS_BINDIR "/dbus-launch", - argv); + retval = _read_subprocess_line_argv (DBUS_BINDIR "/dbus-launch", + (const char * const*) argv, + address, error); + out: _dbus_string_free (&uuid); return retval; @@ -3073,9 +3073,8 @@ _dbus_lookup_session_address_macos (DBusString *address, _dbus_assert (i == _DBUS_N_ELEMENTS (argv)); - return _read_subprocess_line_argv (address, error, - "launchd", - argv); + return _read_subprocess_line_argv ("launchd", (const char * const*) argv, + address, error); } #endif -- 1.5.5.1