Patchwork patch.bbclass: unset TMPDIR after use

login
register
mail settings
Submitter Ross Burton
Date June 26, 2014, 2:16 p.m.
Message ID <1403792215-4306-1-git-send-email-ross.burton@intel.com>
Download mbox | patch
Permalink /patch/74413/
State Accepted
Commit 442efc3959a65fc9da73f79b3afda95d1cffadf3
Headers show

Comments

Ross Burton - June 26, 2014, 2:16 p.m.
GNU Patch < 2.6.1 has a race condition so we create a per-instance TMPDIR to
avoid this.  This was implemented by setting os.environ[TMPDIR] but at the end
of do_patch the temporary directory is deleted but TMPDIR is not unset.

In general this doesn't cause a problem but if do_patch is embedded in a larger
function then TMPDIR is set to a directory that doesn't exist.  Avoid this by
removing TMPDIR from os.environ when the directory is deleted.

Signed-off-by: Ross Burton <ross.burton@intel.com>
---
 meta/classes/patch.bbclass |    1 +
 1 file changed, 1 insertion(+)
Ross Burton - June 26, 2014, 2:20 p.m.
I forgot to say that Robert sent almost exactly this patch last year
but I nacked it because the TMPDIR assignment should happen when patch
is exec'd.  I'm not so sure now as that would cause an unnecessary
overhead to patching.

Ross

On 26 June 2014 15:16, Ross Burton <ross.burton@intel.com> wrote:
> GNU Patch < 2.6.1 has a race condition so we create a per-instance TMPDIR to
> avoid this.  This was implemented by setting os.environ[TMPDIR] but at the end
> of do_patch the temporary directory is deleted but TMPDIR is not unset.
>
> In general this doesn't cause a problem but if do_patch is embedded in a larger
> function then TMPDIR is set to a directory that doesn't exist.  Avoid this by
> removing TMPDIR from os.environ when the directory is deleted.
>
> Signed-off-by: Ross Burton <ross.burton@intel.com>
> ---
>  meta/classes/patch.bbclass |    1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
> index 86c65b3..1e2aab0 100644
> --- a/meta/classes/patch.bbclass
> +++ b/meta/classes/patch.bbclass
> @@ -177,6 +177,7 @@ python patch_do_patch() {
>              bb.fatal(str(e))
>
>      bb.utils.remove(process_tmpdir, True)
> +    del os.environ['TMPDIR']
>  }
>  patch_do_patch[vardepsexclude] = "PATCHRESOLVE"
>
> --
> 1.7.10.4
>

Patch

diff --git a/meta/classes/patch.bbclass b/meta/classes/patch.bbclass
index 86c65b3..1e2aab0 100644
--- a/meta/classes/patch.bbclass
+++ b/meta/classes/patch.bbclass
@@ -177,6 +177,7 @@  python patch_do_patch() {
             bb.fatal(str(e))
 
     bb.utils.remove(process_tmpdir, True)
+    del os.environ['TMPDIR']
 }
 patch_do_patch[vardepsexclude] = "PATCHRESOLVE"