[web] Make the temporary file name actually unique to handle concurrent requests

This commit is contained in:
Sidi Liang 2024-11-04 20:46:31 +08:00
parent 40976bf0c1
commit 8dc06c085c
No known key found for this signature in database
GPG Key ID: 9785F5EECFFA5311
1 changed files with 2 additions and 1 deletions

View File

@ -84,7 +84,8 @@ const char* nasal_eval(void* context, const char* code, int show_time) {
nasal::codegen gen;
// Create a unique temporary file
char temp_filename[] = "/tmp/nasal_eval_XXXXXX.nasal";
char temp_filename[256];
snprintf(temp_filename, sizeof(temp_filename), "/tmp/nasal_eval_%d.nasal", getpid());
int fd = mkstemp(temp_filename);
if (fd == -1) {
throw std::runtime_error("Failed to create temporary file");