Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
more informative create_file failure logs (#40)
Browse files Browse the repository at this point in the history
# Description

`create_file()` failures now log the filename argument so we can see
what failed to be created.
  • Loading branch information
nclack authored Nov 13, 2023
1 parent 9298169 commit 8bea9c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/acquire-core-platform/linux/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@ int
file_create(struct file* file, const char* filename, size_t bytesof_filename)
{
file->fid = open(filename, O_RDWR | O_CREAT | O_NONBLOCK, 0666);
if (file->fid < 0)
if (file->fid < 0) {
CHECK_POSIX(errno);
{
} else {
int ret = flock(file->fid, LOCK_EX | LOCK_NB);
if (ret < 0) {
LOGE("Failed to create existing file \"%s\"", filename);
int tmp = errno;
close(file->fid);
CHECK_POSIX(tmp);
}
}
return 1;
Error:
LOGE("Failed to create \"%s\"", filename);
return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion src/acquire-core-platform/osx/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ int
file_create(struct file* file, const char* filename, size_t bytesof_filename)
{
file->fid = open(filename, O_RDWR | O_CREAT | O_EXLOCK | O_NONBLOCK, 0666);
if (file->fid < 0)
if (file->fid < 0) {
CHECK_POSIX(errno);
}
return 1;
Error:
LOGE("Failed to create \"%s\"", filename);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/acquire-core-platform/win32/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ file_create(struct file* file, const char* filename, size_t bytes_of_filename)
0));
return 1;
Error:
LOGE("Could not create \"%s\"", filename);
return 0;
}

Expand Down Expand Up @@ -438,8 +439,7 @@ thread_join(struct thread* self)
if (thread != INVALID_HANDLE_VALUE) {
self->inner_ = INVALID_HANDLE_VALUE;
TRACE("WFSO %p", thread);
WaitForSingleObject(thread,
INFINITE);
WaitForSingleObject(thread, INFINITE);
CloseHandle(thread);
}
}
Expand Down

0 comments on commit 8bea9c8

Please sign in to comment.