RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Ralf S. Engelschall
Root: /v/rpm/cvs Email: rse@rpm5.org
Module: rpm Date: 30-Jun-2007 17:55:06
Branch: HEAD Handle: 2007063016550600
Modified files:
rpm CHANGES macros.in
rpm/rpmdb db_emu.h dbconfig.c sqlite.c
Log:
Add support to the SQLite RPM DB backend for the following RPM database
configuration parameters (set via macros "_dbi_config_[<tag>]"):
- "tmpdir=<path>"
Implemented via SQL "PRAGMA temp_store_directory = '<path>';"
directly after the database was opened.
- "excl"
Implemented via SQL "PRAGMA locking_mode = EXCLUSIVE;"
directly after the database was opened.
- "cachesize=<bytes>"
Implemented via SQL "PRAGMA cache_size = <bytes>;"
directly after the database was opened.
- "pagesize=<bytes>"
Implemented via SQL "PRAGMA page_size = <bytes>;"
directly after the database was opened.
- "temporary"
Implememted via SQL "CREATE TEMPORARY TABLE" instead of "CREATE
TABLE". This way the created table is (excerpt from SQLite
documentation) "only visible within that same database connection and
is automatically deleted when the database connection is closed. Any
indices created on a temporary table are also temporary. Temporary
tables and indices are stored in a separate file distinct from the
main database file.
- "private"
Implemented by opening the special SQLite database file ":memory:"
instead of the actually requested file. This creates an in-core
temporary database which is automatically destroyed on database
connection close.
- "perms=<bitmask>"
Implemented by wrapping the sqlite3_open() call (which internally
unfortunately uses hard-coded permissions 0644 and provides no API for
specifying the permissions explicitly) via umask(2) for pre-security
and chmod(2) for post-semantic purposes.
- "nofsync"
This was already implemented. No changes were made. Just for the
record: it is implemented via SQL "PRAGMA synchronous = OFF;" directly
after the database was opened.
- "root", "home", "file", "subfile"
These were already implemented. No changes were made. Just for the
record: they are just RPM internal parameters for determining the
database filename.
Use this now in "macros" to configure RPM DB for SQLite with at least
the parameters "perms", "tmpdir", "nofsync", "private" and "temporary"
by default.
Summary:
Revision Changes Path
1.1419 +1 -0 rpm/CHANGES
1.169 +5 -5 rpm/macros.in
1.3 +2 -0 rpm/rpmdb/db_emu.h
1.40 +10 -4 rpm/rpmdb/dbconfig.c
1.7 +51 -3 rpm/rpmdb/sqlite.c
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: rpm/CHANGES
============================================================================
$ cvs diff -u -r1.1418 -r1.1419 CHANGES
--- rpm/CHANGES 29 Jun 2007 20:23:06 -0000 1.1418
+++ rpm/CHANGES 30 Jun 2007 15:55:06 -0000 1.1419
@@ -1,4 +1,5 @@
4.5 -> 5.0:
+ - rse: add SQLite RPM DB support for "tmpdir=<path> excl cachesize=<bytes> pagesize=<bytes> temporary private perms=<bitmask>"
- mgh: allow rpm to be built w/o neon
- rse: remove unused rpmio/sexp/ sub-library
- rse: add "errno" information to be more informative in error message when lstat(2) on verification fails.
@@ .
patch -p0 <<'@@ .'
Index: rpm/macros.in
============================================================================
$ cvs diff -u -r1.168 -r1.169 macros.in
--- rpm/macros.in 29 Jun 2007 11:59:14 -0000 1.168
+++ rpm/macros.in 30 Jun 2007 15:55:06 -0000 1.169
@@ -1,7 +1,7 @@
#/*! \page config_macros Default configuration: @USRLIBRPM@/macros
# \verbatim
#
-# $Id: macros.in,v 1.168 2007/06/29 11:59:14 rse Exp $
+# $Id: macros.in,v 1.169 2007/06/30 15:55:06 rse Exp $
#
# This is a global RPM configuration file. All changes made here will
# be lost when the rpm package is upgraded. Any per-system configuration
@@ -638,8 +638,8 @@
%{nil}
# database configuration: SQLite
-%__dbi_sqlconfig_current %{nil}
-%__dbi_sqlconfig_rebuild nofsync
+%__dbi_sqlconfig_current perms=0644 %{?_tmppath:tmpdir=%{_tmppath}}
+%__dbi_sqlconfig_rebuild %{__dbi_sqlconfig_current} nofsync
%_dbi_sqlconfig \
%{?_rpmdb_rebuild:%{__dbi_sqlconfig_rebuild}}\
%{!?_rpmdb_rebuild:%{__dbi_sqlconfig_current}}\
@@ -648,7 +648,7 @@
# database tag configuration
%_dbi_tags %{expand:%%{_dbi_tags_%{_dbapi_used}}}
%_dbi_tags_3 Packages:Name:Basenames:Group:Requirename:Providename:Conflictname:Triggername:Dirnames:Requireversion:Provideversion:Installtid:Sigmd5:Sha1header:Filemd5s:Pubkeys:Packagecolor:Depends
-%_dbi_tags_4 Packages:Name:Basenames:Group:Requirename:Providename:Conflictname:Triggername:Dirnames:Requireversion:Provideversion:Installtid:Sigmd5:Sha1header:Filemd5s:Pubkeys:Packagecolor
+%_dbi_tags_4 Packages:Name:Basenames:Group:Requirename:Providename:Conflictname:Triggername:Dirnames:Requireversion:Provideversion:Installtid:Sigmd5:Sha1header:Filemd5s:Pubkeys:Packagecolor:Depends
# database configuration: Berkeley-DB [dbapi 3 hooks]
%_dbi_config_3 %{_dbi_btconfig}
@@ -692,7 +692,7 @@
%_dbi_config_4_Sigmd5 %{_dbi_sqlconfig}
%_dbi_config_4_Triggername %{_dbi_sqlconfig}
%_dbi_config_4_Packages %{_dbi_sqlconfig}
-%_dbi_config_4_Depends %{_dbi_sqlconfig}
+%_dbi_config_4_Depends %{_dbi_sqlconfig} temporary private
# database configuration [code entry hooks]
%_dbi_config %{expand:%%{_dbi_config_%{_dbapi_used}}}
@@ .
patch -p0 <<'@@ .'
Index: rpm/rpmdb/db_emu.h
============================================================================
$ cvs diff -u -r1.2 -r1.3 db_emu.h
--- rpm/rpmdb/db_emu.h 28 Jun 2007 15:52:05 -0000 1.2
+++ rpm/rpmdb/db_emu.h 30 Jun 2007 15:55:06 -0000 1.3
@@ -48,6 +48,8 @@
#define DB_SET 32
#define DB_WRITECURSOR 39
#define DB_NOTFOUND (-30990)
+#define DB_PRIVATE 0x0200000
+#define DB_EXCL 0x0004000
#define DB_VERSION_MAJOR 3
#define DB_VERSION_MINOR 0
@@ .
patch -p0 <<'@@ .'
Index: rpm/rpmdb/dbconfig.c
============================================================================
$ cvs diff -u -r1.39 -r1.40 dbconfig.c
--- rpm/rpmdb/dbconfig.c 28 Jun 2007 15:52:05 -0000 1.39
+++ rpm/rpmdb/dbconfig.c 30 Jun 2007 15:55:06 -0000 1.40
@@ -112,7 +112,7 @@
{ "lockdown", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_LOCKDOWN,
NULL, NULL },
#endif
-#if defined(WITH_DB) && defined(DB_PRIVATE)
+#if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_PRIVATE)
{ "private", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_PRIVATE,
NULL, NULL },
#endif
@@ -196,7 +196,7 @@
#endif
/* DB->open */
-#if defined(WITH_DB) && defined(DB_EXCL)
+#if (defined(WITH_DB) || defined(WITH_SQLITE)) && defined(DB_EXCL)
{ "excl", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_EXCL,
NULL, NULL },
#endif
@@ -252,13 +252,15 @@
#if defined(WITH_DB)
{ "mode", 0,POPT_ARG_INT, &db3dbi.dbi_mode, 0,
NULL, NULL },
+#endif
{ "perms", 0,POPT_ARG_INT, &db3dbi.dbi_perms, 0,
NULL, NULL },
+#if defined(WITH_DB)
{ "shmkey", 0,POPT_ARG_LONG, &db3dbi.dbi_shmkey, 0,
NULL, NULL },
+#endif
{ "tmpdir", 0,POPT_ARG_STRING, &db3dbi.dbi_tmpdir, 0,
NULL, NULL },
-#endif
#if defined(WITH_DB)
{ "host", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
@@ -288,16 +290,18 @@
NULL, NULL },
{ "lockdbfd", 0,POPT_ARG_NONE, &db3dbi.dbi_lockdbfd, 0,
NULL, NULL },
+#endif
{ "temporary", 0,POPT_ARG_NONE, &db3dbi.dbi_temporary, 0,
NULL, NULL },
+#if defined(WITH_DB)
{ "debug", 0,POPT_ARG_NONE, &db3dbi.dbi_debug, 0,
NULL, NULL },
#endif
/* XXX set_alloc */
-#if defined(WITH_DB)
{ "cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
NULL, NULL },
+#if defined(WITH_DB)
/* XXX set_dup_compare */
/* XXX set_encrypt */
{ "errpfx", 0,POPT_ARG_STRING, &db3dbi.dbi_errpfx, 0,
@@ -305,9 +309,11 @@
/* XXX set_feedback */
{ "lorder", 0,POPT_ARG_INT, &db3dbi.dbi_lorder, 0,
NULL, NULL },
+#endif
{ "pagesize", 0,POPT_ARG_INT, &db3dbi.dbi_pagesize, 0,
NULL, NULL },
+#if defined(WITH_DB)
{ "region_init", 0,POPT_ARG_VAL, &db3dbi.dbi_region_init, 1,
NULL, NULL },
@@ .
patch -p0 <<'@@ .'
Index: rpm/rpmdb/sqlite.c
============================================================================
$ cvs diff -u -r1.6 -r1.7 sqlite.c
--- rpm/rpmdb/sqlite.c 19 Jun 2007 09:34:45 -0000 1.6
+++ rpm/rpmdb/sqlite.c 30 Jun 2007 15:55:06 -0000 1.7
@@ -686,6 +686,38 @@
char cmd[BUFSIZ];
int rc = 0;
+ if (dbi->dbi_tmpdir) {
+ const char *root;
+ const char *tmpdir;
+ root = (dbi->dbi_root ? dbi->dbi_root : dbi->dbi_rpmdb->db_root);
+ /*@-boundsread@*/
+ if ((root[0] == '/' && root[1] == '\0') || dbi->dbi_rpmdb->db_chrootDone)
+ root = NULL;
+ /*@=boundsread@*/
+ /*@-mods@*/
+ tmpdir = rpmGenPath(root, dbi->dbi_tmpdir, NULL);
+ /*@=mods@*/
+ int xx;
+ sprintf(cmd, "PRAGMA temp_store_directory = '%s';", tmpdir);
+ xx = sqlite3_exec(sqldb->db, cmd, NULL, NULL, (char **)&scp->pzErrmsg);
+ tmpdir = _free(tmpdir);
+ }
+ if (dbi->dbi_eflags & DB_EXCL) {
+ int xx;
+ sprintf(cmd, "PRAGMA locking_mode = EXCLUSIVE;");
+ xx = sqlite3_exec(sqldb->db, cmd, NULL, NULL, (char **)&scp->pzErrmsg);
+ }
+ if (dbi->dbi_pagesize > 0) {
+ int xx;
+ sprintf(cmd, "PRAGMA cache_size = %d;", dbi->dbi_cachesize);
+ xx = sqlite3_exec(sqldb->db, cmd, NULL, NULL, (char **)&scp->pzErrmsg);
+ }
+ if (dbi->dbi_cachesize > 0) {
+ int xx;
+ sprintf(cmd, "PRAGMA page_size = %d;", dbi->dbi_pagesize);
+ xx = sqlite3_exec(sqldb->db, cmd, NULL, NULL, (char **)&scp->pzErrmsg);
+ }
+
/* Check if the table exists... */
sprintf(cmd,
"SELECT name FROM 'sqlite_master' WHERE type='table' and name='%s';",
@@ -729,13 +761,15 @@
}
if (_debug)
fprintf(stderr, "\t%s(%d) type(%d) keytype %s\n", tagName(dbi->dbi_rpmtag), dbi->dbi_rpmtag, (tagType(dbi->dbi_rpmtag) & RPM_MASK_TYPE), keytype);
- sprintf(cmd, "CREATE TABLE '%s' (key %s, value %s)",
+ sprintf(cmd, "CREATE %sTABLE '%s' (key %s, value %s)",
+ dbi->dbi_temporary ? "TEMPORARY " : "",
dbi->dbi_subfile, keytype, valtype);
rc = sqlite3_exec(sqldb->db, cmd, NULL, NULL, (char **)&scp->pzErrmsg);
if (rc)
goto exit;
- sprintf(cmd, "CREATE TABLE 'db_info' (endian TEXT)");
+ sprintf(cmd, "CREATE %sTABLE 'db_info' (endian TEXT)",
+ dbi->dbi_temporary ? "TEMPORARY " : "");
rc = sqlite3_exec(sqldb->db, cmd, NULL, NULL, (char **)&scp->pzErrmsg);
if (rc)
goto exit;
@@ -859,6 +893,7 @@
const char * dbfile;
const char * dbfname;
const char * sql_errcode;
+ mode_t umask_safed;
dbiIndex dbi;
SQL_DB * sqldb;
size_t len;
@@ -922,7 +957,10 @@
*/
(void) rpmioMkpath(dbhome, 0755, getuid(), getgid());
- dbfname = rpmGenPath(dbhome, dbi->dbi_file, NULL);
+ if (dbi->dbi_eflags & DB_PRIVATE)
+ dbfname = strdup(":memory:");
+ else
+ dbfname = rpmGenPath(dbhome, dbi->dbi_file, NULL);
rpmMessage(RPMMESS_DEBUG, _("opening sql db %s (%s) mode=0x%x\n"),
dbfname, dbi->dbi_subfile, dbi->dbi_mode);
@@ -931,7 +969,17 @@
sqldb = xcalloc(1, sizeof(*sqldb));
sql_errcode = NULL;
+ if (dbi->dbi_perms)
+ /* mask-out permission bits which are not requested (security) */
+ umask_safed = umask(~((mode_t)(dbi->dbi_perms)));
xx = sqlite3_open(dbfname, &sqldb->db);
+ if (dbi->dbi_perms) {
+ if ((0644 /* = SQLite hard-coded default */ & dbi->dbi_perms) != dbi->dbi_perms) {
+ /* add requested permission bits which are still missing (semantic) */
+ chmod(dbfname, dbi->dbi_perms);
+ }
+ umask(umask_safed);
+ }
if (xx != SQLITE_OK)
sql_errcode = sqlite3_errmsg(sqldb->db);
@@ .
Received on Sat Jun 30 17:55:06 2007