Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Consider locking is always functional and tell the users if database if corrupted on nfs
Baptiste Daroussin committed 8 years ago
commit 655ddffae6ae4adc2820736a33736a99dea8dfc3
parent d4bb488
6 files changed +15 -19
modified docs/pkg.conf.5
@@ -15,7 +15,7 @@
.\"     @(#)pkg.1
.\" $FreeBSD$
.\"
-
.Dd February 02, 2017
+
.Dd October 06, 2017
.Dt PKG.CONF 5
.Os
.Sh NAME
@@ -186,8 +186,6 @@ When given as a hostname, will be converted to a list of IPv4 or IPv6
addresses by the default mechanisms configured on the system.
See
.Xr getaddrinfo 3 .
-
.It Cm NFS_WITH_PROPER_LOCKING: boolean
-
If set pkg will use its regular locking system instead of a directory lock.
.It Cm PERMISSIVE: boolean
Ignore conflicts while registering a package.
Note that the conflicting files will not be recorded as owned by the new
modified libpkg/pkg_config.c
@@ -414,12 +414,6 @@ static struct config_entry c[] = {
		NULL,
		"Write out the METALOG to the specified file",
	},
-
	{
-
		PKG_BOOL,
-
		"NFS_WITH_PROPER_LOCKING",
-
		"NO",
-
		"Set if running on NFS with properly setup locking system",
-
	},
};

static bool parsed = false;
modified libpkg/pkgdb.c
@@ -1035,11 +1035,11 @@ pkgdb_syscall_overload(void)
}

void
-
pkgdb_setup_lock(void)
+
pkgdb_nfs_corruption(sqlite3 *db)
{
	int dbdirfd = pkg_get_dbdirfd();

-
	if (pkg_object_bool(pkg_config_get("NFS_WITH_PROPER_LOCKING")))
+
	if (sqlite3_errcode(db) != SQLITE_CORRUPT)
		return;

	/*
@@ -1051,14 +1051,18 @@ pkgdb_setup_lock(void)

	if (fstatvfs(dbdirfd, &stfs) == 0) {
		if ((stfs.f_flag & ST_LOCAL) != ST_LOCAL)
-
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
			pkg_emit_error("You are running on a remote filesystem,"
+
			    " please make sure, the locking mechanism is "
+
			    " properly setup\n");
	}
#elif defined(HAVE_FSTATFS) && defined(MNT_LOCAL)
	struct statfs stfs;

	if (fstatfs(dbdirfd, &stfs) == 0) {
		if ((stfs.f_flags & MNT_LOCAL) != MNT_LOCAL)
-
			sqlite3_vfs_register(sqlite3_vfs_find("unix-dotfile"), 1);
+
			pkg_emit_error("You are running on a remote filesystem,"
+
			    " please make sure, the locking mechanism is "
+
			    " properly setup\n");
	}
#endif

@@ -1117,11 +1121,11 @@ retry:

		sqlite3_initialize();

-
		pkgdb_setup_lock();
		pkgdb_syscall_overload();

		if (sqlite3_open("/local.sqlite", &db->sqlite) != SQLITE_OK) {
			ERROR_SQLITE(db->sqlite, "sqlite open");
+
			pkgdb_nfs_corruption(db->sqlite);
			pkgdb_close(db);
			return (EPKG_FATAL);
		}
modified libpkg/private/pkgdb.h
@@ -186,6 +186,6 @@ void pkgdb_myarch(sqlite3_context *ctx, int argc, sqlite3_value **argv);
int pkgdb_sqlcmd_init(sqlite3 *db, const char **err, const void *noused);
int pkgdb_update_config_file_content(struct pkg *pkg, sqlite3 *s);
void pkgdb_syscall_overload(void);
-
void pkgdb_setup_lock(void);
+
void pkgdb_nfs_corruption(sqlite3 *s);

#endif
modified libpkg/repo/binary/init.c
@@ -306,7 +306,6 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)

	sqlite3_initialize();

-
	pkgdb_setup_lock();
	pkgdb_syscall_overload();

	dbdirfd = pkg_get_dbdirfd();
@@ -338,6 +337,7 @@ pkg_repo_binary_open(struct pkg_repo *repo, unsigned mode)

	flags = (mode & W_OK) != 0 ? SQLITE_OPEN_READWRITE : SQLITE_OPEN_READONLY;
	if (sqlite3_open_v2(filepath, &sqlite, flags, NULL) != SQLITE_OK) {
+
		pkgdb_nfs_corruption(sqlite);
		pkg_emit_error("Repository %s load error: "
				"cannot open sqlite3 db: %s", pkg_repo_name(repo),
				strerror(errno));
@@ -424,12 +424,13 @@ pkg_repo_binary_create(struct pkg_repo *repo)
	if (faccessat(dbdirfd, filepath, R_OK, 0) == 0)
		return (EPKG_CONFLICT);

-
	pkgdb_setup_lock();
	pkgdb_syscall_overload();

	/* Open for read/write/create */
-
	if (sqlite3_open(filepath, &sqlite) != SQLITE_OK)
+
	if (sqlite3_open(filepath, &sqlite) != SQLITE_OK) {
+
		pkgdb_nfs_corruption(sqlite);
		return (EPKG_FATAL);
+
	}

	retcode = sql_exec(sqlite, binary_repo_initsql, REPO_SCHEMA_VERSION);

modified scripts/completion/_pkg.in
@@ -128,7 +128,6 @@ _pkg_config_opts() {
		'LOCK_WAIT[wait time to regain a lock]:wait time (seconds):' \
		'METALOG[if set, write a METALOG of the extracted files]:string' \
		'NAMESERVER[hostname or IPv\[46\] address of a nameserver for DNS resolution]:name server:_hosts' \
-
		'NFS_WITH_PROPER_LOCKING[use regular locking system instead of a directory lock]:boolean:(yes no)' \
		'PERMISSIVE[ignore conflicts while registering a package]:boolean:(yes no)' \
		'PKG_CACHEDIR[specify cache directory for packages]:directory:_files -/' \
		'PKG_CREATE_VERBOSE[make pkg_create(8) use verbose mode]:boolean:(yes no)' \