Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add 2 function to open/retrive the file descriptor of the cachedir and the dbdir to simplify capsicumization
Baptiste Daroussin committed 9 years ago
commit c8191ab18f283022a0f87f18f5a208c9800ce4d5
parent 479a396
4 files changed +50 -0
modified libpkg/libpkg.ver
@@ -45,6 +45,8 @@ global:
	pkg_free;
	pkg_from_old;
	pkg_get2;
+
	pkg_get_cachedirfd;
+
	pkg_get_dbdirfd;
	pkg_get_dir;
	pkg_get_file;
	pkg_get_myarch;
modified libpkg/pkg.h.in
@@ -1708,6 +1708,9 @@ char *pkg_absolutepath(const char *src, char *dest, size_t dest_len, bool fromro

void pkg_cache_full_clean(void);

+
int pkg_get_cachedirfd(void);
+
int pkg_get_dbdirfd(void);
+

#ifdef __cplusplus
}
#endif
modified libpkg/pkg_config.c
@@ -67,6 +67,8 @@ int64_t debug_level = 0;
bool developer_mode = false;
const char *pkg_rootdir = NULL;
int rootfd = -1;
+
int cachedirfd = -1;
+
int pkg_dbdirfd = -1;

struct config_entry {
	uint8_t type;
@@ -1282,6 +1284,13 @@ pkg_shutdown(void)
	ucl_object_unref(config);
	HASH_FREE(repos, pkg_repo_free);

+
	if (rootfd != -1)
+
		close(rootfd);
+
	if (cachedirfd != -1)
+
		close(rootfd);
+
	if (pkg_dbdirfd != -1)
+
		close(pkg_dbdirfd);
+

	parsed = false;

	return;
@@ -1408,3 +1417,37 @@ pkg_set_rootdir(const char *rootdir) {

	return (EPKG_OK);
}
+

+
int
+
pkg_get_cachedirfd(void)
+
{
+
	const char *cachedir;
+

+
	if (cachedirfd == -1) {
+
		cachedir = pkg_object_string(pkg_config_get("PKG_CACHEDIR"));
+
		/*
+
		 * do not check the value as if we cannot open it means
+
		 * it has not been created yet
+
		 */
+
		cachedirfd = open(cachedir, O_DIRECTORY);
+
	}
+

+
	return (cachedirfd);
+
}
+

+
int
+
pkg_get_dbdirfd(void)
+
{
+
	const char *dbdir;
+

+
	if (pkg_dbdirfd == -1) {
+
		dbdir = pkg_object_string(pkg_config_get("PKG_DBDIR"));
+
		/*
+
		 * do not check the value as if we cannot open it means
+
		 * it has not been created yet
+
		 */
+
		pkg_dbdirfd = open(dbdir, O_DIRECTORY);
+
	}
+

+
	return (pkg_dbdirfd);
+
}
modified libpkg/private/pkg.h
@@ -222,6 +222,8 @@ extern int64_t debug_level;
extern bool developer_mode;
extern const char *pkg_rootdir;
extern int rootfd;
+
extern int cachedirfd;
+
extern int pkg_dbdirfd;

struct pkg_repo_it;
struct pkg_repo;