err-file-writing steps fail, there's no reason we can't be a little
more careful in doing it. Do so (including using fflush, fsync,
and close).
memcpy(newfn, "err", 3);
mkdir("err", 0700);
fd = open(newfn, O_WRONLY | O_EXCL | O_CREAT, 0644);
- errfile = fdopen(fd, "w");
- if (errfile) {
- fprintf(errfile, "%s:%d\n", fail, olderrno);
+ if (fd >= 0) {
+ errfile = fdopen(fd, "w");
+ if (errfile) {
+ fprintf(errfile, "%s:%d\n", fail, olderrno);
+ fflush(errfile);
+ }
+ fsync(fd);
+ close(fd);
}
}