[PATCH] dtrace: Use deterministic temp file creation for all temp files
Florian Weimer
fweimer@redhat.com
Mon Feb 27 15:49:06 GMT 2023
* Gioele Barabucci via Systemtap:
> +def mktemp_determ(sources, suffix):
> + # for reproducible-builds purposes, use a predictable tmpfile path
> + sha = hashlib.sha256()
> + for source in sources:
> + sha.update(source.encode('utf-8'))
> + fname = ".dtrace-temp." + sha.hexdigest()[:8] + suffix
> + tries = 0
> + while True:
> + tries += 1
> + if tries > 100: # if file exists due to previous crash or whatever
> + raise Exception("cannot create temporary file \""+fname+"\"")
> + try:
> + wxmode = 'x' if sys.version_info > (3,0) else 'wx'
> + fdesc = open(fname, mode=wxmode)
> + break
> + except FileExistsError:
> + time.sleep(0.1) # vague estimate of elapsed time for concurrent identical gcc job
> + pass # Try again
> +
> + return fdesc, fname
This looks like creating a file with a suitable name may block forward
progress indefinitely? Like from a previous crash of the tool?
It might be more robust to use a dedicated temporary directory and a
predictable file name under that directory.
Thanks,
Florian
More information about the Systemtap
mailing list