Skip to content

Commit 302a90d

Browse files
Fix non-unique /tmp filenames in external library download scripts (#3182)
Description: bug=fixes #3042 ## Problem Multiple users or processes compiling tflite-micro simultaneously encounter permission conflicts due to fixed temporary filenames in `/tmp`. ## Solution - Create unique temporary directories using username, PID, and timestamp - Implement automatic cleanup on all exit conditions ## Files Modified - tensorflow/lite/micro/tools/make/ext_libs/cmsis_download.sh - tensorflow/lite/micro/tools/make/ext_libs/cmsis_nn_download.sh - tensorflow/lite/micro/tools/make/ext_libs/eyalroz_printf_download.sh ## Testing Tested with multiple concurrent users - no more /tmp conflicts.
1 parent 3b20912 commit 302a90d

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

tensorflow/lite/micro/tools/make/ext_libs/cmsis_download.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,34 @@ if [ -d ${DOWNLOADED_CMSIS_PATH} ]; then
4848
echo >&2 "${DOWNLOADED_CMSIS_PATH} already exists, skipping the download."
4949
else
5050

51+
# Create a temporary directory with the unique name for better isolation
52+
TEMP_DIR=$(mktemp -d /tmp/$(basename $0 .sh).XXXXXX)
53+
54+
# Set up cleanup trap for all exit conditions
55+
trap 'rm -rf "${TEMP_DIR}"' EXIT INT TERM
56+
5157
ZIP_PREFIX="5782d6f8057906d360f4b95ec08a2354afe5c9b9"
5258
CMSIS_URL="http://github.com/ARM-software/CMSIS_6/archive/${ZIP_PREFIX}.zip"
5359
CMSIS_MD5="563e7c6465f63bdc034359e9b536b366"
5460

5561
# wget is much faster than git clone of the entire repo. So we wget a specific
5662
# version and can then apply a patch, as needed.
57-
wget ${CMSIS_URL} -O /tmp/${ZIP_PREFIX}.zip >&2
58-
check_md5 /tmp/${ZIP_PREFIX}.zip ${CMSIS_MD5}
63+
wget ${CMSIS_URL} -O ${TEMP_DIR}/${ZIP_PREFIX}.zip >&2
64+
check_md5 ${TEMP_DIR}/${ZIP_PREFIX}.zip ${CMSIS_MD5}
5965

60-
unzip -qo /tmp/${ZIP_PREFIX}.zip -d /tmp >&2
61-
mv /tmp/CMSIS_6-${ZIP_PREFIX} ${DOWNLOADED_CMSIS_PATH}
66+
unzip -qo ${TEMP_DIR}/${ZIP_PREFIX}.zip -d ${TEMP_DIR} >&2
67+
mv ${TEMP_DIR}/CMSIS_6-${ZIP_PREFIX} ${DOWNLOADED_CMSIS_PATH}
6268

6369
# Also pull the related CMSIS Cortex_DFP component for generic Arm Cortex-M device support
6470
ZIP_PREFIX="c2c70a97a20fb355815e2ead3d4a40e35a4a3cdf"
6571
CMSIS_DFP_URL="http://github.com/ARM-software/Cortex_DFP/archive/${ZIP_PREFIX}.zip"
6672
CMSIS_DFP_MD5="3cbb6955b6d093a2fe078ef2341f6b89"
6773

68-
wget ${CMSIS_DFP_URL} -O /tmp/${ZIP_PREFIX}.zip >&2
69-
check_md5 /tmp/${ZIP_PREFIX}.zip ${CMSIS_DFP_MD5}
74+
wget ${CMSIS_DFP_URL} -O ${TEMP_DIR}/${ZIP_PREFIX}.zip >&2
75+
check_md5 ${TEMP_DIR}/${ZIP_PREFIX}.zip ${CMSIS_DFP_MD5}
7076

71-
unzip -qo /tmp/${ZIP_PREFIX}.zip -d /tmp >&2
72-
mv /tmp/Cortex_DFP-${ZIP_PREFIX} ${DOWNLOADED_CORTEX_DFP_PATH}
77+
unzip -qo ${TEMP_DIR}/${ZIP_PREFIX}.zip -d ${TEMP_DIR} >&2
78+
mv ${TEMP_DIR}/Cortex_DFP-${ZIP_PREFIX} ${DOWNLOADED_CORTEX_DFP_PATH}
7379

7480
fi
7581

tensorflow/lite/micro/tools/make/ext_libs/cmsis_nn_download.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,20 @@ elif [ ! -d ${DOWNLOADS_DIR} ]; then
5252
elif [ -d ${DOWNLOADED_CMSIS_NN_PATH} ]; then
5353
echo >&2 "${DOWNLOADED_CMSIS_NN_PATH} already exists, skipping the download."
5454
else
55+
56+
# Create a temporary directory with the unique name for better isolation
57+
TEMP_DIR=$(mktemp -d /tmp/$(basename $0 .sh).XXXXXX)
58+
59+
# Set up cleanup trap for all exit conditions
60+
trap 'rm -rf "${TEMP_DIR}"' EXIT INT TERM
61+
5562
# wget is much faster than git clone of the entire repo. So we wget a specific
5663
# version and can then apply a patch, as needed.
57-
wget ${CMSIS_NN_URL} -O /tmp/${ZIP_PREFIX_NN}.zip >&2
58-
check_md5 /tmp/${ZIP_PREFIX_NN}.zip ${CMSIS_NN_MD5}
64+
wget ${CMSIS_NN_URL} -O ${TEMP_DIR}/${ZIP_PREFIX_NN}.zip >&2
65+
check_md5 ${TEMP_DIR}/${ZIP_PREFIX_NN}.zip ${CMSIS_NN_MD5}
5966

60-
unzip -qo /tmp/${ZIP_PREFIX_NN}.zip -d /tmp >&2
61-
mv /tmp/CMSIS-NN-${ZIP_PREFIX_NN} ${DOWNLOADED_CMSIS_NN_PATH}
67+
unzip -qo ${TEMP_DIR}/${ZIP_PREFIX_NN}.zip -d ${TEMP_DIR} >&2
68+
mv ${TEMP_DIR}/CMSIS-NN-${ZIP_PREFIX_NN} ${DOWNLOADED_CMSIS_NN_PATH}
6269
fi
6370

6471
echo "SUCCESS"

tensorflow/lite/micro/tools/make/ext_libs/eyalroz_printf_download.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,23 @@ if [ -d ${DOWNLOADED_PRINTF_PATH} ]; then
4747
echo >&2 "${DOWNLOADED_PRINTF_PATH} already exists, skipping the download."
4848
else
4949

50+
# Create a temporary directory with the unique name for better isolation
51+
TEMP_DIR=$(mktemp -d /tmp/$(basename $0 .sh).XXXXXX)
52+
53+
# Set up cleanup trap for all exit conditions
54+
trap 'rm -rf "${TEMP_DIR}"' EXIT INT TERM
55+
5056
ZIP_PREFIX="f8ed5a9bd9fa8384430973465e94aa14c925872d"
5157
PRINTF_URL="https://github.com/eyalroz/printf/archive/${ZIP_PREFIX}.zip"
5258
PRINTF_MD5="5772534c1d6f718301bca1fefaba28f3"
5359

5460
# wget is much faster than git clone of the entire repo. So we wget a specific
5561
# version and can then apply a patch, as needed.
56-
wget ${PRINTF_URL} -O /tmp/${ZIP_PREFIX}.zip >&2
57-
check_md5 /tmp/${ZIP_PREFIX}.zip ${PRINTF_MD5}
62+
wget ${PRINTF_URL} -O ${TEMP_DIR}/${ZIP_PREFIX}.zip >&2
63+
check_md5 ${TEMP_DIR}/${ZIP_PREFIX}.zip ${PRINTF_MD5}
5864

59-
unzip -qo /tmp/${ZIP_PREFIX}.zip -d /tmp >&2
60-
mv /tmp/printf-${ZIP_PREFIX} ${DOWNLOADED_PRINTF_PATH}
65+
unzip -qo ${TEMP_DIR}/${ZIP_PREFIX}.zip -d ${TEMP_DIR} >&2
66+
mv ${TEMP_DIR}/printf-${ZIP_PREFIX} ${DOWNLOADED_PRINTF_PATH}
6167
fi
6268

63-
echo "SUCCESS"
69+
echo "SUCCESS"

0 commit comments

Comments
 (0)