Skip to content

Fix non-unique /tmp filenames in external library download scripts #3182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ilya-kupchenko
Copy link

Description:
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.

Resolves issue where multiple users compiling tflite-micro simultaneously
would encounter permission conflicts due to fixed temporary filenames.

Changes:
- Create unique temporary directories using username, PID, and timestamp
- Implement automatic cleanup on all exit conditions

Scripts 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

Fixes tensorflow#3042
@ilya-kupchenko ilya-kupchenko requested a review from a team as a code owner August 22, 2025 06:19
@ddavis-2015 ddavis-2015 added the bug Something isn't working label Aug 22, 2025
@ddavis-2015 ddavis-2015 self-assigned this Aug 22, 2025
@ddavis-2015
Copy link
Member

Please add the following line to your PR description:
bug=fixes #3042

Comment on lines +51 to +57
# Create unique temporary directory name with username for better isolation
USERNAME=$(whoami 2>/dev/null || echo "unknown")
TEMP_DIR="/tmp/cmsis_dld_${USERNAME}_$(date +%s)_$$"
if ! mkdir -p "${TEMP_DIR}"; then
echo "ERROR: Failed to create temporary directory ${TEMP_DIR}" >&2
exit 1
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest something more akin to the following:

TEMP_DIR=$(mktemp -d /tmp/$(basename $0 .sh).XXXXXX)

Comment on lines +56 to +62
# Create unique temporary directory name with username for better isolation
USERNAME=$(whoami 2>/dev/null || echo "unknown")
TEMP_DIR="/tmp/cmsis_nn_dld_${USERNAME}_$(date +%s)_$$"
if ! mkdir -p "${TEMP_DIR}"; then
echo "ERROR: Failed to create temporary directory ${TEMP_DIR}" >&2
exit 1
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per previous comment.

Comment on lines +50 to +56
# Create unique temporary directory name with username for better isolation
USERNAME=$(whoami 2>/dev/null || echo "unknown")
TEMP_DIR="/tmp/eyalroz_dld_${USERNAME}_$(date +%s)_$$"
if ! mkdir -p "${TEMP_DIR}"; then
echo "ERROR: Failed to create temporary directory ${TEMP_DIR}" >&2
exit 1
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per previous comment.

@ddavis-2015
Copy link
Member

@ilya-kupchenko Thank you for your interest in TFLM. It is greatly appreciated that you have submitted a PR for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-Unique Filenames in /tmp Directory Affecting microlite Compilation
2 participants