setup: joinpasswd.c Check much more return values, fsync file, close descri...
arekm
arekm at pld-linux.org
Thu Dec 8 10:32:02 CET 2011
Author: arekm Date: Thu Dec 8 09:32:02 2011 GMT
Module: setup Tag: HEAD
---- Log message:
Check much more return values, fsync file, close descriptor.
---- Files affected:
setup:
joinpasswd.c (1.11 -> 1.12)
---- Diffs:
================================================================
Index: setup/joinpasswd.c
diff -u setup/joinpasswd.c:1.11 setup/joinpasswd.c:1.12
--- setup/joinpasswd.c:1.11 Thu Dec 8 10:14:22 2011
+++ setup/joinpasswd.c Thu Dec 8 10:31:56 2011
@@ -60,6 +60,7 @@
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -274,9 +275,13 @@
fd = open(backup_name, O_WRONLY|O_CREAT|O_TRUNC, 0600);
if (fd < 0)
- fatal("cannot make backup");
- write(fd, old, old_sz);
- close(fd);
+ fatal("cannot create backup file");
+ if (write(fd, old, old_sz) < 0)
+ fatal("writting to backup file failed");
+ if (fsync(fd) < 0)
+ fatal("syncing backup file failed");
+ if (close(fd) < 0)
+ fatal("closing backup file failed");
#ifndef SILENT
eputs("merging content of `");
@@ -311,10 +316,13 @@
write(2, id, id_len);
eputs("'\n");
#endif /* SILENT */
- write(fd, id, line_len);
+ if (write(fd, id, line_len) < 0)
+ fatal("writting line failed, most likely you will need backup to restore backup file");
}
} else if (i < new_sz)
i++;
+ fsync(fd);
+ close(fd);
}
#if 0
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/setup/joinpasswd.c?r1=1.11&r2=1.12&f=u
More information about the pld-cvs-commit
mailing list