Commit 3c319c71 authored by Lennart Poettering's avatar Lennart Poettering

cloexec: make use of pipe2(O_CLOEXEC) when available

This should fix another CLOEXEC race.
parent 18b08180
...@@ -816,6 +816,8 @@ fi ...@@ -816,6 +816,8 @@ fi
AC_CHECK_FUNCS(getpeerucred getpeereid) AC_CHECK_FUNCS(getpeerucred getpeereid)
AC_CHECK_FUNCS(pipe2)
#### Abstract sockets #### Abstract sockets
if test x$enable_abstract_sockets = xauto; then if test x$enable_abstract_sockets = xauto; then
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
*/ */
#include <config.h>
#include "dbus-spawn.h" #include "dbus-spawn.h"
#include "dbus-sysdeps-unix.h" #include "dbus-sysdeps-unix.h"
#include "dbus-internals.h" #include "dbus-internals.h"
...@@ -805,9 +808,25 @@ static dbus_bool_t ...@@ -805,9 +808,25 @@ static dbus_bool_t
make_pipe (int p[2], make_pipe (int p[2],
DBusError *error) 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); _DBUS_ASSERT_ERROR_IS_CLEAR (error);
if (pipe (p) < 0) if (retval < 0)
{ {
dbus_set_error (error, dbus_set_error (error,
DBUS_ERROR_SPAWN_FAILED, DBUS_ERROR_SPAWN_FAILED,
...@@ -816,6 +835,14 @@ make_pipe (int p[2], ...@@ -816,6 +835,14 @@ make_pipe (int p[2],
return FALSE; 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; return TRUE;
} }
...@@ -1117,9 +1144,6 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p, ...@@ -1117,9 +1144,6 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
if (!make_pipe (child_err_report_pipe, error)) if (!make_pipe (child_err_report_pipe, error))
goto cleanup_and_fail; goto cleanup_and_fail;
_dbus_fd_set_close_on_exec (child_err_report_pipe[READ_END]);
_dbus_fd_set_close_on_exec (child_err_report_pipe[WRITE_END]);
if (!_dbus_full_duplex_pipe (&babysitter_pipe[0], &babysitter_pipe[1], TRUE, error)) if (!_dbus_full_duplex_pipe (&babysitter_pipe[0], &babysitter_pipe[1], TRUE, error))
goto cleanup_and_fail; goto cleanup_and_fail;
......
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