Skip to content

Commit 7c66fe3

Browse files
committed
Create transaction lock file after rebuilddb
Since 79b26f1 reading the keys is also protected by a transaction lock. A missing lock file will trip up users without write permissing to the rpmdb directory. RPM will try to create the file but fails. Normally the lock file is created during system installation. So rebuilding the rpmdb must also create the file to keep the rpmdb fully functional. Move the creation and freeing of the lock and it's path into separate functions. Related: rpm-software-management#3886
1 parent 0632d91 commit 7c66fe3

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

lib/rpmts.cc

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ int rpmtsSetDBMode(rpmts ts, int dbmode)
129129
return rc;
130130
}
131131

132+
static
133+
void rpmtsLockFree(rpmts ts);
132134

133135
int rpmtsRebuildDB(rpmts ts)
134136
{
@@ -151,6 +153,12 @@ int rpmtsRebuildDB(rpmts ts)
151153
rc = rpmdbRebuild(ts->rootDir, NULL, NULL, rebuildflags);
152154
rpmtxnEnd(txn);
153155
}
156+
/* Re-create lock file */
157+
rpmtsLockFree(ts);
158+
txn = rpmtxnBegin(ts, RPMTXN_WRITE);
159+
if (txn)
160+
rpmtxnEnd(txn);
161+
154162
return rc;
155163
}
156164

@@ -584,8 +592,7 @@ rpmts rpmtsFree(rpmts ts)
584592
ts->scriptFd = NULL;
585593
}
586594
ts->rootDir = _free(ts->rootDir);
587-
ts->lockPath = _free(ts->lockPath);
588-
ts->lock = rpmlockFree(ts->lock);
595+
rpmtsLockFree(ts);
589596

590597
ts->keyring = rpmKeyringFree(ts->keyring);
591598
ts->netsharedPaths = argvFree(ts->netsharedPaths);
@@ -1063,15 +1070,11 @@ rpmte rpmtsiNext(rpmtsi tsi, rpmElementTypes types)
10631070
}
10641071

10651072
#define RPMLOCK_PATH LOCALSTATEDIR "/rpm/.rpm.lock"
1066-
rpmtxn rpmtxnBegin(rpmts ts, rpmtxnFlags flags)
1073+
static
1074+
void rpmtsLockInit(rpmts ts)
10671075
{
10681076
static const char * const rpmlock_path_default = "%{?_rpmlock_path}";
1069-
rpmtxn txn = NULL;
1070-
1071-
if (ts == NULL)
1072-
return NULL;
1073-
1074-
if (ts->lockPath == NULL) {
1077+
if (ts && ts->lockPath == NULL) {
10751078
const char *rootDir = rpmtsRootDir(ts);
10761079
char *t;
10771080

@@ -1087,6 +1090,25 @@ rpmtxn rpmtxnBegin(rpmts ts, rpmtxnFlags flags)
10871090
(void) rpmioMkpath(dirname(t), 0755, getuid(), getgid());
10881091
free(t);
10891092
}
1093+
}
1094+
1095+
static
1096+
void rpmtsLockFree(rpmts ts)
1097+
{
1098+
if (ts) {
1099+
ts->lockPath = _free(ts->lockPath);
1100+
ts->lock = rpmlockFree(ts->lock);
1101+
}
1102+
}
1103+
1104+
rpmtxn rpmtxnBegin(rpmts ts, rpmtxnFlags flags)
1105+
{
1106+
rpmtxn txn = NULL;
1107+
1108+
if (ts == NULL)
1109+
return NULL;
1110+
1111+
rpmtsLockInit(ts);
10901112

10911113
if (ts->lock == NULL)
10921114
ts->lock = rpmlockNew(ts->lockPath, _("transaction"));

tests/rpmdb.at

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,16 @@ runroot rpm -U --noscripts --nodeps --ignorearch --nosignature \
567567
/data/RPMS/hello-2.0-1.i686.rpm
568568
runroot rpm -qa --qf "%{nevra} %{dbinstance}\n"
569569
runroot rpmdb --rebuilddb
570+
runroot ls `rpm -E "%{_dbpath}/.rpm.lock"`
570571
runroot rpm -qa --qf "%{nevra} %{dbinstance}\n"
572+
runroot ls `rpm -E "%{_dbpath}/.rpm.lock"`
571573
],
572574
[],
573575
[hello-1.0-1.i386 1
574576
hello-2.0-1.i686 2
577+
/var/lib/rpm-testsuite/.rpm.lock
575578
hello-2.0-1.i686 1
579+
/var/lib/rpm-testsuite/.rpm.lock
576580
],
577581
[])
578582
RPMTEST_CLEANUP
@@ -584,10 +588,14 @@ AT_KEYWORDS([rpmdb])
584588
RPMTEST_CHECK([
585589
RPMDB_RESET
586590
runroot rpmdb --rebuilddb
591+
runroot ls `rpm -E "%{_dbpath}/.rpm.lock"`
587592
runroot rpmdb --verifydb
593+
runroot ls `rpm -E "%{_dbpath}/.rpm.lock"`
588594
],
589595
[0],
590-
[],
596+
[/var/lib/rpm-testsuite/.rpm.lock
597+
/var/lib/rpm-testsuite/.rpm.lock
598+
],
591599
[])
592600
RPMTEST_CLEANUP
593601

0 commit comments

Comments
 (0)