Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>

#include "lock.h"
Expand All @@ -27,7 +28,17 @@ bool get_lockfile_path(char path[MAX_PATH_SIZE]) {
return false;
}

if (snprintf(path, MAX_PATH_SIZE, "%s/slurp-%s.lock", runtime_dir, display) >= MAX_PATH_SIZE) {
// Replace '/' with '-' in display to avoid creating subdirectories
char sanitized_display[256];
strncpy(sanitized_display, display, sizeof(sanitized_display) - 1);
sanitized_display[sizeof(sanitized_display) - 1] = '\0';
for (char *p = sanitized_display; *p; p++) {
if (*p == '/') {
*p = '-';
}
}

if (snprintf(path, MAX_PATH_SIZE, "%s/slurp-%s.lock", runtime_dir, sanitized_display) >= MAX_PATH_SIZE) {
fprintf(stderr, "lockfile path was too long\n");
return false;
}
Expand All @@ -51,6 +62,4 @@ bool acquire_lock() {
return false;
}
return true;
}


}