commit:     dbacb3edd62cf3e30a3635c92c5582a7d754bf35
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Wed Sep 10 19:52:48 2014 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Sep 10 19:52:48 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/releng.git;a=commit;h=dbacb3ed

catalyst-auto: construct tempdir with mktemp rather than pid

This way we can sanely use pid namespaces without tempdirs clashing.

---
 tools/catalyst-auto | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/tools/catalyst-auto b/tools/catalyst-auto
index 3aa98b2..ebdb7c7 100755
--- a/tools/catalyst-auto
+++ b/tools/catalyst-auto
@@ -1,4 +1,6 @@
 #!/bin/bash
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
 
 # First let's get our own mount namespace to avoid leaking crap.
 if [[ -z ${UNSHARE} ]] ; then
@@ -8,8 +10,6 @@ if [[ -z ${UNSHARE} ]] ; then
 fi
 unset UNSHARE
 
-PID=$$
-
 config_file=
 verbose=0
 keep_tmpdir=0
@@ -118,7 +118,7 @@ fi
 
 source ${config_file}
 
-TMPDIR=${TMP_PATH:-/tmp}/catalyst-auto.${PID}
+TMPDIR=$(mktemp -d --tmpdir="${TMP_PATH:-/tmp}" catalyst-auto.XXXXXX)
 DATESTAMP=$(date +%Y%m%d)
 
 if [ ${verbose} = 1 ]; then
@@ -126,21 +126,11 @@ if [ ${verbose} = 1 ]; then
   echo "DATESTAMP = ${DATESTAMP}"
 fi
 
-# Check if tmp directory exists and remove it
-if [ -d "${TMPDIR}" ]; then
-  if ! rm -rf "${TMPDIR}"; then
-    echo "Couldn't remove stale tmpdir ${TMPDIR}!"
-    exit 1
-  fi
+if ! mkdir -p "${TMPDIR}"/{specs,kconfig,log}; then
+  echo "Couldn't create tempdirs!"
+  exit 1
 fi
 
-for i in ${TMPDIR} ${TMPDIR}/specs ${TMPDIR}/kconfig ${TMPDIR}/log; do
-  if ! mkdir -p "${i}"; then
-    echo "Couldn't create dir ${i}!"
-    exit 1
-  fi
-done
-
 if ! run_cmd "pre_build" "${TMPDIR}/log/pre_build.log"; then
   send_email "Catalyst build error - pre_build" "Your pre_build function 
sucks" "${TMPDIR}/log/pre_build.log"
   exit 1

Reply via email to