]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python/tests/gpo: this should fix a Popen deadlock
authorStefan Metzmacher <metze@samba.org>
Mon, 7 Sep 2020 08:31:36 +0000 (10:31 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 7 Sep 2020 12:02:15 +0000 (12:02 +0000)
It is inspired by commit 5dc773a5b00834c7a53130a73a48f49048bd55e8
   Author: Joe Guo <joeg@catalyst.net.nz>
   Date:   Fri Sep 15 16:13:26 2017 +1200

      python: use communicate to fix Popen deadlock

      `Popen.wait()` will deadlock when using stdout=PIPE and/or stderr=PIPE and the
      child process generates large output to a pipe such that it blocks waiting for
      the OS pipe buffer to accept more data. Use communicate() to avoid that.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
      Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
      Autobuild-Date(master): Thu Oct 19 09:27:16 CEST 2017 on sn-devel-144

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Noel Power <noel.power@suse.com>
python/samba/tests/gpo.py

index 43a4aacfc14896fff3992d8e956c64fa72de4201..c8440929b11435c91c00277850c4595b02889d5b 100644 (file)
@@ -54,23 +54,22 @@ def days2rel_nttime(val):
     sam_add = 10000000
     return -(val * seconds * minutes * hours * sam_add)
 
-def gpupdate_force(lp):
+def gpupdate(lp, arg):
     gpupdate = lp.get('gpo update command')
-    gpupdate.append('--force')
+    gpupdate.append(arg)
 
-    return Popen(gpupdate, stdout=PIPE, stderr=PIPE).wait()
+    p = Popen(gpupdate, stdout=PIPE, stderr=PIPE)
+    stdoutdata, stderrdata = p.communicate()
+    return p.returncode
 
-def gpupdate_unapply(lp):
-    gpupdate = lp.get('gpo update command')
-    gpupdate.append('--unapply')
+def gpupdate_force(lp):
+    return gpupdate(lp, '--force')
 
-    return Popen(gpupdate, stdout=PIPE, stderr=PIPE).wait()
+def gpupdate_unapply(lp):
+    return gpupdate(lp, '--unapply')
 
 def rsop(lp):
-    gpupdate = lp.get('gpo update command')
-    gpupdate.append('--rsop')
-
-    return Popen(gpupdate, stdout=PIPE).wait()
+    return gpupdate(lp, '--rsop')
 
 def stage_file(path, data):
     dirname = os.path.dirname(path)