Commit de27bbd7 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Unlink the state file if writing failed.

parent 2b50102e
...@@ -523,12 +523,15 @@ main(int argc, char **argv) ...@@ -523,12 +523,15 @@ main(int argc, char **argv)
fd = open(state_file, O_WRONLY | O_TRUNC | O_CREAT, 0644); fd = open(state_file, O_WRONLY | O_TRUNC | O_CREAT, 0644);
if(fd < 0) { if(fd < 0) {
perror("creat(babel-state)"); perror("creat(babel-state)");
unlink(state_file);
} else { } else {
char buf[100]; char buf[100];
rc = snprintf(buf, 100, "%d %d\n", seqno, (int)now.tv_sec); rc = snprintf(buf, 100, "%d %d\n", seqno, (int)now.tv_sec);
rc = write(fd, buf, rc); rc = write(fd, buf, rc);
if(rc < 0) if(rc < 0) {
perror("write(babel-state)"); perror("write(babel-state)");
unlink(state_file);
}
close(fd); close(fd);
} }
debugf("Done."); debugf("Done.");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment