Skip to content

Commit 91c47a3

Browse files
committed
Use subprocess umask support where available
This simplifies pre-exec function handling on newer Python versions
1 parent 597fd89 commit 91c47a3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/buildstream/utils.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import hashlib
3232
import math
3333
import os
34+
import sys
3435
import re
3536
import shutil
3637
import signal
@@ -1330,14 +1331,18 @@ def _call(*popenargs, terminate=False, **kwargs):
13301331

13311332
process = None
13321333

1333-
old_preexec_fn = kwargs.get("preexec_fn")
1334-
if "preexec_fn" in kwargs:
1335-
del kwargs["preexec_fn"]
1334+
if (sys.version_info.major, sys.version_info.minor) < (3, 9):
1335+
# Old Python versions are missing umask support and need this workaround
1336+
old_preexec_fn = kwargs.pop("preexec_fn", None)
13361337

1337-
def preexec_fn():
1338-
os.umask(stat.S_IWGRP | stat.S_IWOTH)
1339-
if old_preexec_fn is not None:
1340-
old_preexec_fn()
1338+
def preexec_fn():
1339+
os.umask(stat.S_IWGRP | stat.S_IWOTH)
1340+
if old_preexec_fn is not None:
1341+
old_preexec_fn()
1342+
1343+
else:
1344+
kwargs["umask"] = stat.S_IWGRP | stat.S_IWOTH
1345+
preexec_fn = kwargs.pop("preexec_fn", None)
13411346

13421347
# Handle termination, suspend and resume
13431348
def kill_proc():

0 commit comments

Comments
 (0)