Skip to content

Commit

Permalink
Merge pull request #24 from miko/errno
Browse files Browse the repository at this point in the history
Added support for errno to better diagnose errors
  • Loading branch information
wchu-citrusleaf committed Mar 16, 2016
2 parents 7d1014f + 2400ccc commit c87e172
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions act.c
Expand Up @@ -34,6 +34,7 @@

#include <dirent.h>
#include <execinfo.h> // for debugging
#include <errno.h> // for detailed error reporting
#include <fcntl.h>
#include <inttypes.h>
#include <pthread.h>
Expand Down Expand Up @@ -277,7 +278,7 @@ int main(int argc, char* argv[]) {

if (pthread_create(&p_device->large_block_write_thread, NULL,
run_large_block_writes, (void*)p_device)) {
fprintf(stdout, "ERROR: create large op write thread %d\n", n);
fprintf(stdout, "ERROR: create large op write thread %d errno=%d err_msg=\"%s\\n", n, errno, strerror(errno));
exit(-1);
}
}
Expand All @@ -287,7 +288,7 @@ int main(int argc, char* argv[]) {

if (pthread_create(&p_device->large_block_read_thread, NULL,
run_large_block_reads, (void*)p_device)) {
fprintf(stdout, "ERROR: create large op read thread %d\n", n);
fprintf(stdout, "ERROR: create large op read thread %d errno=%d err_msg=\"%s\\n", n, errno, strerror(errno));
exit(-1);
}
}
Expand Down Expand Up @@ -877,7 +878,7 @@ static int fd_get(device* p_device) {
fd = open(p_device->name, O_DIRECT | O_RDWR, S_IRUSR | S_IWUSR);

if (fd == -1) {
fprintf(stdout, "ERROR: open device %s\n", p_device->name);
fprintf(stdout, "ERROR: open device %s errno=%d err_msg=\"%s\"\n", p_device->name, errno, strerror(errno));
}
}

Expand Down Expand Up @@ -967,7 +968,7 @@ static uint64_t read_from_device(device* p_device, uint64_t offset,
if (lseek(fd, offset, SEEK_SET) != offset ||
read(fd, p_buffer, size) != (ssize_t)size) {
close(fd);
fprintf(stdout, "ERROR: seek & read\n");
fprintf(stdout, "ERROR: seek & read errno=%d err_msg=\"%s\"\n", errno, strerror(errno));
return -1;
}

Expand Down Expand Up @@ -1011,8 +1012,8 @@ static void set_schedulers() {
}

if (fwrite(mode, mode_length, 1, scheduler_file) != 1) {
fprintf(stdout, "ERROR: writing %s to %s\n", mode,
scheduler_file_name);
fprintf(stdout, "ERROR: writing %s to %s errno=%d err_msg=\"%s\"\n", mode,
scheduler_file_name, errno, strerror(errno));
}

fclose(scheduler_file);
Expand Down Expand Up @@ -1052,7 +1053,7 @@ static uint64_t write_to_device(device* p_device, uint64_t offset,
if (lseek(fd, offset, SEEK_SET) != offset ||
write(fd, p_buffer, size) != (ssize_t)size) {
close(fd);
fprintf(stdout, "ERROR: seek & write\n");
fprintf(stdout, "ERROR: seek & write errno=%d err_msg=\"%s\"\n", errno, strerror(errno));
return -1;
}

Expand Down

0 comments on commit c87e172

Please sign in to comment.