From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Merge OpenBSD rev.
Date: Tue, 17 Sep 2013 19:07:22 -0400 (EDT) [thread overview]
Message-ID: <201309172307.r8HN7M3D016777@krisdoz.my.domain> (raw)
Log Message:
-----------
Merge OpenBSD rev. 1.34.
Do not truncate the production database when starting to build a new one.
Suggested by deraadt@.
Tags:
----
VERSION_1_12
Modified Files:
--------------
mdocml:
mandocdb.c
Revision Data
-------------
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.49.2.2
retrieving revision 1.49.2.3
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.49.2.2 -r1.49.2.3
--- mandocdb.c
+++ mandocdb.c
@@ -495,19 +495,38 @@ main(int argc, char *argv[])
exit((int)MANDOCLEVEL_SYSERR);
}
- strlcpy(mdb.dbn, MANDOC_DB, PATH_MAX);
- strlcpy(mdb.idxn, MANDOC_IDX, PATH_MAX);
+ /* Create a new database in two temporary files. */
- flags = O_CREAT | O_TRUNC | O_RDWR;
- mdb.db = dbopen(mdb.dbn, flags, 0644, DB_BTREE, &info);
- mdb.idx = dbopen(mdb.idxn, flags, 0644, DB_RECNO, NULL);
-
- if (NULL == mdb.db) {
- perror(mdb.dbn);
- exit((int)MANDOCLEVEL_SYSERR);
- } else if (NULL == mdb.idx) {
- perror(mdb.idxn);
- exit((int)MANDOCLEVEL_SYSERR);
+ flags = O_CREAT | O_EXCL | O_RDWR;
+ while (NULL == mdb.db) {
+ strlcpy(mdb.dbn, MANDOC_DB, PATH_MAX);
+ strlcat(mdb.dbn, ".XXXXXXXXXX", PATH_MAX);
+ if (NULL == mktemp(mdb.dbn)) {
+ perror(mdb.dbn);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+ mdb.db = dbopen(mdb.dbn, flags, 0644,
+ DB_BTREE, &info);
+ if (NULL == mdb.db && EEXIST != errno) {
+ perror(mdb.dbn);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+ }
+ while (NULL == mdb.idx) {
+ strlcpy(mdb.idxn, MANDOC_IDX, PATH_MAX);
+ strlcat(mdb.idxn, ".XXXXXXXXXX", PATH_MAX);
+ if (NULL == mktemp(mdb.idxn)) {
+ perror(mdb.idxn);
+ unlink(mdb.dbn);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+ mdb.idx = dbopen(mdb.idxn, flags, 0644,
+ DB_RECNO, NULL);
+ if (NULL == mdb.idx && EEXIST != errno) {
+ perror(mdb.idxn);
+ unlink(mdb.dbn);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
}
/*
@@ -527,6 +546,26 @@ main(int argc, char *argv[])
(*mdb.idx->close)(mdb.idx);
mdb.db = NULL;
mdb.idx = NULL;
+
+ /*
+ * Replace the old database with the new one.
+ * This is not perfectly atomic,
+ * but i cannot think of a better way.
+ */
+
+ if (-1 == rename(mdb.dbn, MANDOC_DB)) {
+ perror(MANDOC_DB);
+ unlink(mdb.dbn);
+ unlink(mdb.idxn);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
+ if (-1 == rename(mdb.idxn, MANDOC_IDX)) {
+ perror(MANDOC_IDX);
+ unlink(MANDOC_DB);
+ unlink(MANDOC_IDX);
+ unlink(mdb.idxn);
+ exit((int)MANDOCLEVEL_SYSERR);
+ }
}
out:
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
next reply other threads:[~2013-09-17 23:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-17 23:07 schwarze [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-07-11 22:27 mdocml: merge " schwarze
2014-07-11 22:25 schwarze
2014-06-18 19:34 mdocml: Merge " schwarze
2014-04-04 15:51 mdocml: merge " schwarze
2013-09-17 23:12 mdocml: Merge " schwarze
2013-09-17 22:48 mdocml: merge " schwarze
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201309172307.r8HN7M3D016777@krisdoz.my.domain \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).