Skip to content

Commit

Permalink
ensure ordered writes to trace file
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandwalker authored and jonas committed Aug 1, 2017
1 parent 6af5102 commit c3d183b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/tig/tig.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <sys/select.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/file.h>
#include <time.h>
#include <fcntl.h>

Expand Down
3 changes: 3 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,19 @@ open_trace(int devnull, const char *argv[])
int fd = open(trace_file, O_RDWR | O_CREAT | O_APPEND, 0666);
int i;

flock(fd, LOCK_EX);
for (i = 0; argv[i]; i++) {
if (write(fd, argv[i], strlen(argv[i])) == -1
|| write(fd, " ", 1) == -1)
break;
}
if (argv[i] || write(fd, "\n", 1) == -1) {
flock(fd, LOCK_UN);
close(fd);
return devnull;
}

flock(fd, LOCK_UN);
return fd;
}

Expand Down

0 comments on commit c3d183b

Please sign in to comment.