~ubuntu-branches/ubuntu/maverick/dbus/maverick-proposed

« back to all changes in this revision

Viewing changes to dbus/dbus-spawn.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-27 13:06:32 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20100927130632-bqs145trvchd2lmf
Tags: 1.4.0-0ubuntu1
* New upstream release
 - Fixes https://bugs.freedesktop.org/show_bug.cgi?id=17754 Race condition in protected_change_timeout
 - Requested by various upstream KDE developers http://lists.kde.org/?t=128514970000004&r=1&w=2

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
22
 *
23
23
 */
 
24
 
 
25
#include <config.h>
 
26
 
24
27
#include "dbus-spawn.h"
25
28
#include "dbus-sysdeps-unix.h"
26
29
#include "dbus-internals.h"
805
808
make_pipe (int         p[2],
806
809
           DBusError  *error)
807
810
{
 
811
  int retval;
 
812
 
 
813
#ifdef HAVE_PIPE2
 
814
  dbus_bool_t cloexec_done;
 
815
 
 
816
  retval = pipe2 (p, O_CLOEXEC);
 
817
  cloexec_done = retval >= 0;
 
818
 
 
819
  /* Check if kernel seems to be too old to know pipe2(). We assume
 
820
     that if pipe2 is available, O_CLOEXEC is too.  */
 
821
  if (retval < 0 && errno == ENOSYS)
 
822
#endif
 
823
    {
 
824
      retval = pipe(p);
 
825
    }
 
826
 
808
827
  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
809
 
  
810
 
  if (pipe (p) < 0)
 
828
 
 
829
  if (retval < 0)
811
830
    {
812
831
      dbus_set_error (error,
813
832
                      DBUS_ERROR_SPAWN_FAILED,
816
835
      return FALSE;
817
836
    }
818
837
 
 
838
#ifdef HAVE_PIPE2
 
839
  if (!cloexec_done)
 
840
#endif
 
841
    {
 
842
      _dbus_fd_set_close_on_exec (p[0]);
 
843
      _dbus_fd_set_close_on_exec (p[1]);
 
844
    }
 
845
 
819
846
  return TRUE;
820
847
}
821
848
 
1052
1079
      else if (pfds[1].revents & _DBUS_POLLIN)
1053
1080
        {
1054
1081
          char b;
1055
 
          read (sigchld_pipe[READ_END], &b, 1);
 
1082
          if (read (sigchld_pipe[READ_END], &b, 1) == -1)
 
1083
            /* ignore */;
1056
1084
          /* do waitpid check */
1057
1085
          check_babysit_events (grandchild_pid, parent_pipe, 0);
1058
1086
        }
1117
1145
  if (!make_pipe (child_err_report_pipe, error))
1118
1146
    goto cleanup_and_fail;
1119
1147
 
1120
 
  _dbus_fd_set_close_on_exec (child_err_report_pipe[READ_END]);
1121
 
  _dbus_fd_set_close_on_exec (child_err_report_pipe[WRITE_END]);
1122
 
 
1123
1148
  if (!_dbus_full_duplex_pipe (&babysitter_pipe[0], &babysitter_pipe[1], TRUE, error))
1124
1149
    goto cleanup_and_fail;
1125
1150
 
1126
 
  _dbus_fd_set_close_on_exec (babysitter_pipe[0]);
1127
 
  _dbus_fd_set_close_on_exec (babysitter_pipe[1]);
1128
 
 
1129
1151
  /* Setting up the babysitter is only useful in the parent,
1130
1152
   * but we don't want to run out of memory and fail
1131
1153
   * after we've already forked, since then we'd leak