changeset 81:346c4a4ca40b

Fix possible deadlock in install. When using`stderr=subprocess.PIPE, stdout=subprocess.PIPE`, you can (will) deadlock if one pipe fills up (in this case, stdout) while the other is being written too. The subprocess documentation is littered with warnings about this but somehow this has survived here for nearly 10 years. :) commit e3bed6a7172a03c2f03bc1355634ad7e9994b260
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 14 Jun 2020 22:38:56 +0200
parents 2500587e4a5e
children 77ed99bd6c71
files uwsginl/files/patch-uwsgiconfig.py
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/uwsginl/files/patch-uwsgiconfig.py	Sun Jun 14 22:23:07 2020 +0200
+++ b/uwsginl/files/patch-uwsgiconfig.py	Sun Jun 14 22:38:56 2020 +0200
@@ -1,6 +1,22 @@
 --- uwsgiconfig.py.orig	2019-02-09 14:48:07 UTC
 +++ uwsgiconfig.py
-@@ -1457,7 +1457,8 @@ def build_plugin(path, uc, cflags, ldflags, libs, name
+@@ -203,11 +203,12 @@ int main()
+ 
+ def spcall3(cmd):
+     p = subprocess.Popen(cmd, shell=True, stdin=open('/dev/null'), stderr=subprocess.PIPE, stdout=subprocess.PIPE)
++    (out, err) = p.communicate()
+ 
+-    if p.wait() == 0:
++    if p.returncode == 0:
+         if sys.version_info[0] > 2:
+-            return p.stderr.read().rstrip().decode()
+-        return p.stderr.read().rstrip()
++            return err.rstrip().decode()
++        return err.rstrip()
+     else:
+         return None
+ 
+@@ -1457,7 +1458,8 @@ def build_plugin(path, uc, cflags, ldflags, libs, name
              gcc_list.append(path + '/' + cfile)
      for bfile in up.get('BINARY_LIST', []):
          try:
@@ -10,7 +26,7 @@
              print(binary_link_cmd)
              if os.system(binary_link_cmd) != 0:
                  raise Exception('unable to link binary file')
-@@ -1550,6 +1551,17 @@ def build_plugin(path, uc, cflags, ldflags, libs, name
+@@ -1550,6 +1552,17 @@ def build_plugin(path, uc, cflags, ldflags, libs, name
  
      print("build time: %d seconds" % (time.time() - plugin_started_at))
      print("*** %s plugin built and available in %s ***" % (name, plugin_dest + '.so'))