Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-9350

QProcess should provide a way to control whether sockets are inherited by the child process, or not

    XMLWordPrintable

Details

    • 068baa9bb6d526cccc0c8bc7cdbb84bbdf137f95

    Description

      Currently, QProcess::start() creates a child process that inherits all the sockets and file handles of the parent process. This is useful in some cases, but in other cases it opens the door for hard-to-find bugs to sneak in – for example, the TCP connections that the parent process had open when the child process was spawned are held open until the child process exits.

      When running under Mac or Unix/Linux, I can work around this problem by subclassing QProcess and overriding setupChildProcess(), like this:

      class MyQNetProcess : public QProcess
      {
      [...]

      #ifndef WIN32
      virtual void setupChildProcess()
      {
      QProcess::setupChildProcess();
      if (_inheritFileDescriptors == false)

      { int fdlimit = sysconf(_SC_OPEN_MAX); for (int i=STDERR_FILENO+1; i<fdlimit; i++) ::close(i); }

      }
      #endif

      However, that trick doesn't work under Windows. For Windows, I would need to pass FALSE as the bInheritFileHandles argument to CreateProcess(), but QProcessPrivate::startProcess() has it hard-coded as TRUE.

      In some cases I can avoid the problem by calling QProcess::startDetached() instead of QProcess::start(), but doing it that way precludes me from piping data to the child process's stdin, or reading data from the child process's stdout, and sometimes I need to be able to do that.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-9350
          # Subject Branch Project Status CR V

          Activity

            People

              jbornema Joerg Bornemann
              jfriesne Jeremy Friesner
              Votes:
              12 Vote for this issue
              Watchers:
              21 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes