Title: [271764] trunk/Tools
Revision
271764
Author
[email protected]
Date
2021-01-22 15:59:48 -0800 (Fri, 22 Jan 2021)

Log Message

[webkitpy][GTK] Xvfb driver fails to start with python3
https://bugs.webkit.org/show_bug.cgi?id=220870

Reviewed by Jonathan Bedard.

Python2 and Python3 differ in how they handle file descriptor inheritance
and Popen's close_fds default value.

In Python2, os.pipe creates the fds with the inheritable flag set, and
Popen's close_fds defaults to True.

In Python3, os.pipe creates the fds non-inheritable, requiring a call
to os.set_inheritable to enable it. Also, Popen's close_fds defaults
to False, closing all file descriptors except stdin, stdout and stderr.

With this commit, Python3 is able to launch the Xvfb driver for
run-webdriver-tests, but is still failing later with some pytest issue
to be tracked in another bug.

* Scripts/webkitpy/port/xvfbdriver.py:
(XvfbDriver._xvfb_pipe): Make the write_fd inheritable if in py3.
(XvfbDriver._xvfb_read_display_id): Encode for py3 bytes compatibility.
(XvfbDriver._xvfb_run): Tell popen to keep the file descriptors open.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (271763 => 271764)


--- trunk/Tools/ChangeLog	2021-01-22 23:56:02 UTC (rev 271763)
+++ trunk/Tools/ChangeLog	2021-01-22 23:59:48 UTC (rev 271764)
@@ -1,3 +1,29 @@
+2021-01-22  Lauro Moura  <[email protected]>
+
+        [webkitpy][GTK] Xvfb driver fails to start with python3
+        https://bugs.webkit.org/show_bug.cgi?id=220870
+
+        Reviewed by Jonathan Bedard.
+
+        Python2 and Python3 differ in how they handle file descriptor inheritance
+        and Popen's close_fds default value.
+
+        In Python2, os.pipe creates the fds with the inheritable flag set, and
+        Popen's close_fds defaults to True.
+
+        In Python3, os.pipe creates the fds non-inheritable, requiring a call
+        to os.set_inheritable to enable it. Also, Popen's close_fds defaults
+        to False, closing all file descriptors except stdin, stdout and stderr.
+
+        With this commit, Python3 is able to launch the Xvfb driver for
+        run-webdriver-tests, but is still failing later with some pytest issue
+        to be tracked in another bug.
+
+        * Scripts/webkitpy/port/xvfbdriver.py:
+        (XvfbDriver._xvfb_pipe): Make the write_fd inheritable if in py3.
+        (XvfbDriver._xvfb_read_display_id): Encode for py3 bytes compatibility.
+        (XvfbDriver._xvfb_run): Tell popen to keep the file descriptors open.
+
 2021-01-21  Wenson Hsieh  <[email protected]>
 
         DisplayList::Replayer should stop replay and inform clients after encountering an invalid item

Modified: trunk/Tools/Scripts/webkitpy/port/xvfbdriver.py (271763 => 271764)


--- trunk/Tools/Scripts/webkitpy/port/xvfbdriver.py	2021-01-22 23:56:02 UTC (rev 271763)
+++ trunk/Tools/Scripts/webkitpy/port/xvfbdriver.py	2021-01-22 23:59:48 UTC (rev 271764)
@@ -29,9 +29,11 @@
 
 import logging
 import os
+import sys
 import re
 import time
 
+from webkitcorepy import string_utils
 from webkitpy.port.server_process import ServerProcess
 from webkitpy.port.driver import Driver
 
@@ -50,8 +52,14 @@
         return xvfb_found
 
     def _xvfb_pipe(self):
-        return os.pipe()
+        read_fd, write_fd = os.pipe()
 
+        # By default, python3 creates file descriptors as non-inheritable
+        if sys.version_info.major == 3:
+            os.set_inheritable(write_fd, True)
+
+        return (read_fd, write_fd)
+
     def _xvfb_read_display_id(self, read_fd):
         import errno
         import select
@@ -67,7 +75,7 @@
 
             if read_fd in fd_list:
                 # We only expect a number, so first read should be enough.
-                display_id = os.read(read_fd, 256).strip('\n')
+                display_id = os.read(read_fd, 256).strip(string_utils.encode('\n'))
                 fd_set = []
 
         return int(display_id)
@@ -82,7 +90,8 @@
         if self._port._should_use_jhbuild():
             run_xvfb = self._port._jhbuild_wrapper + run_xvfb
         with open(os.devnull, 'w') as devnull:
-            self._xvfb_process = self._port.host.executive.popen(run_xvfb, stderr=devnull, env=environment)
+            # python3 will try to close the file descriptors by default
+            self._xvfb_process = self._port.host.executive.popen(run_xvfb, stderr=devnull, env=environment, close_fds=False)
             display_id = self._xvfb_read_display_id(read_fd)
 
         self._xvfb_close_pipe((read_fd, write_fd))
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to