Drop rpmdb shutdown on exit()

This is continuation to the previous commit, this was necessary for
clean Berkeley DB shutdown but current backends do not need it. And
as we no longer route signals through a polled machinery to get an
exit() from eg ctrl-c, this is for all practical purposes dead code,
callers are expected to free their iterators as needed anyway.

As a bonus, eliminating these static structures improves thread-safety
without complicated locking.
This commit is contained in:
Panu Matilainen 2022-03-03 11:41:44 +02:00
parent f9290999e9
commit 35b93119a3
3 changed files with 0 additions and 75 deletions

View File

@ -62,8 +62,6 @@ RPM_GNUC_INTERNAL
void rpmRelocationBuild(Header h, rpmRelocation *rawrelocs,
int *rnrelocs, rpmRelocation **rrelocs, uint8_t **rbadrelocs);
RPM_GNUC_INTERNAL
void rpmAtExit(void);
#ifdef __cplusplus
}
#endif

View File

@ -302,26 +302,6 @@ struct rpmdbIndexIterator_s {
int ii_skipdata;
};
static rpmdb rpmdbRock;
static rpmdbMatchIterator rpmmiRock;
static rpmdbIndexIterator rpmiiRock;
void rpmAtExit(void)
{
rpmdb db;
rpmdbMatchIterator mi;
rpmdbIndexIterator ii;
while ((mi = rpmmiRock) != NULL)
rpmdbFreeIterator(mi);
while ((ii = rpmiiRock) != NULL)
rpmdbIndexIteratorFree(ii);
while ((db = rpmdbRock) != NULL)
(void) rpmdbClose(db);
}
rpmop rpmdbOp(rpmdb rpmdb, rpmdbOpX opx)
{
rpmop op = NULL;
@ -385,18 +365,11 @@ static int dbiForeach(dbiIndex *dbis, int ndbi,
int rpmdbClose(rpmdb db)
{
rpmdb * prev, next;
int rc = 0;
if (db == NULL)
goto exit;
prev = &rpmdbRock;
while ((next = *prev) != NULL && next != db)
prev = &next->db_next;
if (!next)
goto exit;
(void) rpmdbUnlink(db);
if (db->nrefs > 0)
@ -416,11 +389,6 @@ int rpmdbClose(rpmdb db)
db->db_checked = dbChkFree(db->db_checked);
db->db_indexes = _free(db->db_indexes);
if (next) {
*prev = next->db_next;
next->db_next = NULL;
}
db = _free(db);
exit:
@ -495,9 +463,6 @@ static int openDatabase(const char * prefix,
if (db == NULL)
return 1;
db->db_next = rpmdbRock;
rpmdbRock = db;
/* Try to ensure db home exists, error out if we can't even create */
rc = rpmioMkpath(rpmdbHome(db), 0755, getuid(), getgid());
if (rc == 0) {
@ -988,22 +953,12 @@ static int miFreeHeader(rpmdbMatchIterator mi, dbiIndex dbi)
rpmdbMatchIterator rpmdbFreeIterator(rpmdbMatchIterator mi)
{
rpmdbMatchIterator * prev, next;
dbiIndex dbi = NULL;
int i;
if (mi == NULL)
return NULL;
prev = &rpmmiRock;
while ((next = *prev) != NULL && next != mi)
prev = &next->mi_next;
if (next) {
*prev = next->mi_next;
next->mi_next = NULL;
} else
return NULL;
pkgdbOpen(mi->mi_db, 0, &dbi);
miFreeHeader(mi, dbi);
@ -1673,10 +1628,6 @@ rpmdbMatchIterator rpmdbNewIterator(rpmdb db, rpmDbiTagVal dbitag)
mi->mi_ts = NULL;
mi->mi_hdrchk = NULL;
/* Chain cursors for teardown on abnormal exit. */
mi->mi_next = rpmmiRock;
rpmmiRock = mi;
return mi;
};
@ -1867,11 +1818,7 @@ rpmdbIndexIterator rpmdbIndexIteratorInit(rpmdb db, rpmDbiTag rpmtag)
if (indexOpen(db, rpmtag, 0, &dbi))
return NULL;
/* Chain cursors for teardown on abnormal exit. */
ii = xcalloc(1, sizeof(*ii));
ii->ii_next = rpmiiRock;
rpmiiRock = ii;
ii->ii_db = rpmdbLink(db);
ii->ii_rpmtag = rpmtag;
ii->ii_dbi = dbi;
@ -1999,20 +1946,9 @@ unsigned int rpmdbIndexIteratorTagNum(rpmdbIndexIterator ii, unsigned int nr)
rpmdbIndexIterator rpmdbIndexIteratorFree(rpmdbIndexIterator ii)
{
rpmdbIndexIterator * prev, next;
if (ii == NULL)
return NULL;
prev = &rpmiiRock;
while ((next = *prev) != NULL && next != ii)
prev = &next->ii_next;
if (next) {
*prev = next->ii_next;
next->ii_next = NULL;
} else
return NULL;
ii->ii_dbc = dbiCursorFree(ii->ii_dbi, ii->ii_dbc);
ii->ii_dbi = NULL;
rpmdbClose(ii->ii_db);

View File

@ -1622,22 +1622,13 @@ exit:
return rc;
}
static void register_atexit(void)
{
if (atexit(rpmAtExit) != 0)
rpmlog(RPMLOG_WARNING, _("failed to register exit handler"));
}
/* External interfaces */
int rpmReadConfigFiles(const char * file, const char * target)
{
static pthread_once_t atexit_registered = PTHREAD_ONCE_INIT;
int rc = -1; /* assume failure */
rpmrcCtx ctx = rpmrcCtxAcquire(1);
pthread_once(&atexit_registered, register_atexit);
if (rpmInitCrypto())
goto exit;