Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F140671286
D2982.id6668.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D2982.id6668.diff
View Options
Index: usr.bin/cap_mkdb/cap_mkdb.c
===================================================================
--- usr.bin/cap_mkdb/cap_mkdb.c
+++ usr.bin/cap_mkdb/cap_mkdb.c
@@ -119,7 +119,7 @@
(void)snprintf(buf, sizeof(buf), "%s.db", capname ? capname : *argv);
if ((capname = strdup(buf)) == NULL)
errx(1, "strdup failed");
- if ((capdbp = dbopen(capname, O_CREAT | O_TRUNC | O_RDWR,
+ if ((capdbp = dbopen(capname, O_CREAT | O_TRUNC | O_RDWR | O_SYNC,
DEFFILEMODE, DB_HASH, &openinfo)) == NULL)
err(1, "%s", buf);
Index: usr.sbin/services_mkdb/services_mkdb.c
===================================================================
--- usr.sbin/services_mkdb/services_mkdb.c
+++ usr.sbin/services_mkdb/services_mkdb.c
@@ -44,6 +44,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <libgen.h>
#include <libutil.h>
#include <ctype.h>
#include <errno.h>
@@ -91,6 +92,8 @@
size_t cnt = 0;
StringList *sl, ***svc;
size_t port, proto;
+ char *dbname_dir;
+ int dbname_dir_fd = -1;
setprogname(argv[0]);
@@ -138,7 +141,7 @@
err(1, "Cannot install exit handler");
(void)snprintf(tname, sizeof(tname), "%s.tmp", dbname);
- db = dbopen(tname, O_RDWR | O_CREAT | O_EXCL,
+ db = dbopen(tname, O_RDWR | O_CREAT | O_EXCL | O_SYNC,
(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), DB_HASH, &hinfo);
if (!db)
err(1, "Error opening temporary database `%s'", tname);
@@ -164,9 +167,22 @@
if ((db->close)(db))
err(1, "Error closing temporary database `%s'", tname);
- if (rename(tname, dbname) == -1)
+ /*
+ * Make sure file is safe on disk. To improve performance we will call
+ * fsync() to the directory where file lies
+ */
+ if (rename(tname, dbname) == -1 ||
+ (dbname_dir = dirname(dbname)) == NULL ||
+ (dbname_dir_fd = open(dbname_dir, O_RDONLY|O_DIRECTORY)) == -1 ||
+ fsync(dbname_dir_fd) != 0) {
+ if (dbname_dir_fd != -1)
+ close(dbname_dir_fd);
err(1, "Cannot rename `%s' to `%s'", tname, dbname);
+ }
+ if (dbname_dir_fd != -1)
+ close(dbname_dir_fd);
+
return 0;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 27, 4:57 PM (1 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27308975
Default Alt Text
D2982.id6668.diff (2 KB)
Attached To
Mode
D2982: Make cap_mkdb and services_mkdb file operations sync
Attached
Detach File
Event Timeline
Log In to Comment