Skip to content

Conversation

ilya-kupchenko
Copy link
Contributor

@ilya-kupchenko ilya-kupchenko commented Aug 22, 2025

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.

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.

Address maintainer feedback to use mktemp instead of custom naming.
This provides better atomicity and security while maintaining
shorter paths for embedded system compatibility.

- Replace custom temp dir naming with mktemp -d

Addresses feedback in tensorflow#3042
Copy link
Member

@ddavis-2015 ddavis-2015 left a comment

Choose a reason for hiding this comment

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

Looks good to me. On to @veblush

@mergify mergify bot merged commit 302a90d into tensorflow:main Sep 3, 2025
98 of 99 checks passed
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
4 participants