diff --git a/dbus/dbus-spawn-unix.c b/dbus/dbus-spawn-unix.c index 0bf476bd..1966a41d 100644 --- a/dbus/dbus-spawn-unix.c +++ b/dbus/dbus-spawn-unix.c @@ -922,48 +922,6 @@ close_and_invalidate (int *fd) return ret; } -static dbus_bool_t -make_pipe (int p[2], - DBusError *error) -{ - int retval; - -#ifdef HAVE_PIPE2 - dbus_bool_t cloexec_done; - - retval = pipe2 (p, O_CLOEXEC); - cloexec_done = retval >= 0; - - /* Check if kernel seems to be too old to know pipe2(). We assume - that if pipe2 is available, O_CLOEXEC is too. */ - if (retval < 0 && errno == ENOSYS) -#endif - { - retval = pipe(p); - } - - _DBUS_ASSERT_ERROR_IS_CLEAR (error); - - if (retval < 0) - { - dbus_set_error (error, - DBUS_ERROR_SPAWN_FAILED, - "Failed to create pipe for communicating with child process (%s)", - _dbus_strerror (errno)); - return FALSE; - } - -#ifdef HAVE_PIPE2 - if (!cloexec_done) -#endif - { - _dbus_fd_set_close_on_exec (p[0]); - _dbus_fd_set_close_on_exec (p[1]); - } - - return TRUE; -} - static void do_write (int fd, const void *buf, size_t count) { @@ -1317,7 +1275,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, goto cleanup_and_fail; } - if (!make_pipe (child_err_report_pipe, error)) + if (!_dbus_unix_make_pipe (child_err_report_pipe, error)) goto cleanup_and_fail; if (!_dbus_socketpair (&babysitter_pipe[0], &babysitter_pipe[1], TRUE, error)) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 59d4afcf..af346a4b 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -5273,4 +5273,46 @@ _dbus_get_low_level_socket_errno (void) return errno; } +dbus_bool_t +_dbus_unix_make_pipe (int p[2], + DBusError *error) +{ + int retval; + +#ifdef HAVE_PIPE2 + dbus_bool_t cloexec_done; + + retval = pipe2 (p, O_CLOEXEC); + cloexec_done = retval >= 0; + + /* Check if kernel seems to be too old to know pipe2(). We assume + that if pipe2 is available, O_CLOEXEC is too. */ + if (retval < 0 && errno == ENOSYS) +#endif + { + retval = pipe(p); + } + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (retval < 0) + { + dbus_set_error (error, + _dbus_error_from_errno (errno), + "Failed to create pipe (%s)", + _dbus_strerror (errno)); + return FALSE; + } + +#ifdef HAVE_PIPE2 + if (!cloexec_done) +#endif + { + _dbus_fd_set_close_on_exec (p[0]); + _dbus_fd_set_close_on_exec (p[1]); + } + + return TRUE; +} + /* tests in dbus-sysdeps-util.c */ diff --git a/dbus/dbus-sysdeps-unix.h b/dbus/dbus-sysdeps-unix.h index b400cf86..8c4addcc 100644 --- a/dbus/dbus-sysdeps-unix.h +++ b/dbus/dbus-sysdeps-unix.h @@ -162,6 +162,10 @@ void _dbus_set_signal_handler (int sig, dbus_bool_t _dbus_reset_oom_score_adj (const char **error_str_p); +DBUS_PRIVATE_EXPORT +dbus_bool_t _dbus_unix_make_pipe (int p[2], + DBusError *error); + /** @} */ DBUS_END_DECLS