diff options
author | Colin Watson <cjwatson@debian.org> | 2022-01-30 00:01:51 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2022-01-30 00:01:51 +0000 |
commit | 106287fe531ee04ae3f6d0a793084b01659afa16 (patch) | |
tree | cabc4c3dc3d951e86887ef59eeab3e11d4b98541 /.gitignore | |
parent | bf6d84c6d828db3d94d8218b2266b771ab6e5fa3 (diff) |
mandb: Don't modify DB without changing its mtime
In d9ebedad15 (man-db 2.7.0), mandb started relying on the modification
times of database files themselves rather than using a special row, in
order to make databases reproducible between otherwise-identical
installations (subject to predictable behaviour from the underlying
database).
There was a difficulty with this change. Because purging deleted pages
from the database opened and closed the database in a separate phase
before the main phase of looking for updated manual pages, and because
the main phase relies on comparing against the mtime of the database to
find changed files, I had to arrange to restore the original mtime at
the end of the purge phase in order to avoid confusing the main phase
into being a no-op. However, in some cases (perhaps due to other bugs,
but nevertheless), it's possible for the purge phase to find work to do
without the main phase ever finding any modified directories, which
meant that the net effect of mandb would be to modify its database
without changing its mtime. This is bad form, and confused some backup
systems into believing that the filesystem had been corrupted, since
files having their contents changed without updating their mtime is
indeed a likely symptom of filesystem corruption.
To avoid this, restructure our database-handling code so that a given
mandb run opens any given database at most once. This means that we no
longer need to modify mtimes manually, so the usual filesystem rules
apply.
Fixes Debian bug #1004355 and Ubuntu bug #1411633.
* bootstrap.conf (gnulib_modules): Remove futimens.
* libdb/db_btree.c (man_btree_close): Rename to ...
(man_btree_free): ... this. Check whether wrap->file is set. Free
wrap->mtime.
(man_btree_new): New function.
(man_btree_open): Convert to running on the result of man_btree_new.
(man_btree_get_time): Cache return value in wrap->mtime.
(man_btree_set_time): Remove.
* libdb/db_gdbm.c (man_gdbm_new): New function.
(man_gdbm_open_wrapper): Convert to running on the result of
man_gdbm_new.
(man_gdbm_get_time): Cache return value in wrap->mtime.
(man_gdbm_set_time): Remove.
(raw_close): Check whether wrap->file is set.
(man_gdbm_close): Rename to ...
(man_gdbm_free): ... this.
* libdb/db_ndbm.c (raw_close): Check whether wrap->file is set.
(man_ndbm_close): Rename to ...
(man_ndbm_free): ... this.
(man_ndbm_new): New function.
(man_ndbm_open): Convert to running on the result of man_ndbm_new.
(man_ndbm_get_time): Cache return value in wrap->mtime.
(man_ndbm_set_time): Remove.
* libdb/db_xdbm.c (man_xdbm_close): Rename to ...
(man_xdbm_free): ... this. Update all callers. Free dbf->mtime.
* libdb/db_xdbm.h (man_xdbm_close): Rename to ...
(man_xdbm_free): ... this.
* libdb/mydbm.h (man_gdbm_wrapper, man_ndbm_wrapper, man_btree_wrapper):
Add mtime.
(man_gdbm_new, man_ndbm_new, man_btree_new): Add prototypes.
(man_gdbm_open_wrapper, man_ndbm_open, man_btree_open): Update
prototypes.
(man_gdbm_set_time, man_ndbm_set_time, man_btree_set_time): Remove
prototypes.
(man_gdbm_close, man_ndbm_close, man_btree_close): Rename to ...
(man_gdbm_free, man_ndbm_free, man_btree_free): ... these, respectively.
(MYDBM_NEW): New macro.
(MYDBM_CTRWOPEN, MYDBM_RWOPEN, MYDBM_RDOPEN): Rename file argument to
wrap.
(MYDBM_CLOSE): Rename to ...
(MYDBM_FREE): ... this.
(MYDBM_SET_TIME): Remove macro.
* src/catman.c (parse_for_sec): Take a MYDBM_FILE argument rather than a
database path.
* src/check_mandirs.c (gripe_rwopen_failed, testmandirs, create_db,
update_db, purge_missing): Likewise.
* src/mandb.c (update_one_file, update_db_wrapper): Likewise.
* src/straycats.c (straycats): Likewise.
* src/check_mandirs.h (create_db, update_db, purge_missing): Update
prototypes.
* src/straycats.h (straycats): Likewise.
* src/check_mandirs.c (ensure_db_open): New function.
(testmandirs): Only open the database if it wasn't already open, and
don't close it.
(update_db, purge_missing): Likewise.
* src/mandb.c (update_one_file): Likewise.
* src/straycats.c (straycats): Assert that the database is already open,
and don't close it.
* src/accessdb.c (main): Update database opening code.
* src/catman.c (post_fork): Update database closing code.
(parse_for_sec): Move database opening and closing code to ...
(main): ... here, and update it.
* src/man.c (dbdelete_wrapper): Update database opening and closing
code.
* src/whatis.c (search): Update database opening and closing code.
* src/check_mandirs.c (purge_missing): Don't reorganize the database.
* src/mandb.c (mandb): Create a MYDBM_FILE from the database path, and
close and free it before returning. Rearrange purging so that it runs
on the temporary database copy, which we close and remove if
purge_missing finds a consistency problem requiring us to rescan from
scratch. Unless purging requires a rescan, all of the purge, main, and
stray cats phases now run on the same open database file. Reorganize
the database before closing it if the purge phase did any work.
(process_manpath): Rename the temporary database into place if either of
the purge or stray cats phases did any work, even if the main phase
didn't.
* src/check_mandirs.c (update_db_time): Remove.
(create_db): Don't manually update the database mtime.
(update_db, purge_missing): Likewise.
* src/tests/Makefile.am (ALL_TESTS): Add mandb-purge-updates-timestamp.
(check_PROGRAMS): Add get-mtime.
(get_mtime_SOURCES, get_mtime_LDADD): Add.
* src/tests/get-mtime.c: New file: test helper to get a file's mtime
portably.
* src/tests/mandb-purge-updates-timestamp: New file.
* .gitignore: Add src/tests/get-mtime.
* NEWS: Document this.
Diffstat (limited to '.gitignore')
-rw-r--r-- | .gitignore | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -129,4 +129,5 @@ src/tests/.deps src/tests/*.log src/tests/*.trs src/tests/fspause +src/tests/get-mtime src/tests/tmp-* |