Bug 15242 - packagekitd deadlocks if database does not exist
Summary: packagekitd deadlocks if database does not exist
Alias: None
Product: PackageKit
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Richard Hughes
QA Contact:
Depends on:
Reported: 2008-03-28 09:10 UTC by Klaus Kämpf
Modified: 2008-04-04 03:09 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Description Klaus Kämpf 2008-03-28 09:10:57 UTC
Running packagekitd without a previous "make install" will result in a database open failure (because /var/lib/PackageKit does not exist) warning.
However, packagekitd continues to run and listens to client requests.

Any incoming client request (e.g. pkcon get repos) will leave packagekit in an unknown state. A second client request leads to a deadlock.

Proposed solution:
Either error out if the database does not exist or force creation of the database directory and retry.
Comment 1 Richard Hughes 2008-03-28 09:41:34 UTC
We have already:

static void
pk_transaction_db_init (PkTransactionDb *tdb)
	gboolean create_file;
	const gchar *statement;
	gint rc;

	g_return_if_fail (tdb != NULL);
	g_return_if_fail (PK_IS_TRANSACTION_DB (tdb));


	/* if the database file was not installed (or was nuked) recreate it */
	create_file = g_file_test (PK_TRANSACTION_DB_FILE, G_FILE_TEST_EXISTS);

	pk_debug ("trying to open database '%s'", PK_TRANSACTION_DB_FILE);
	rc = sqlite3_open (PK_TRANSACTION_DB_FILE, &tdb->priv->db);
	if (rc) {
		pk_warning ("Can't open database: %s\n", sqlite3_errmsg (tdb->priv->db));
		sqlite3_close (tdb->priv->db);
	} else {
		if (create_file == FALSE) {
			statement = "CREATE TABLE transactions ("
				    "transaction_id TEXT primary key,"
				    "timespec TEXT,"
				    "duration INTEGER,"
				    "succeeded INTEGER DEFAULT 0,"
				    "role TEXT,"
				    "data TEXT,"
				    "description TEXT);";
			sqlite3_exec (tdb->priv->db, statement, NULL, NULL, NULL);

	/* we might be running an old database, recreate */
	pk_transaction_db_create_table_last_action (tdb);

So I think all we need to do is error out on the pk_warning ("Can't open database... string? What do you think?
Comment 2 Klaus Kämpf 2008-03-28 09:46:02 UTC
Erroring out is probably the best solution.

It seems as if the rest of the code cannot handle a non-existing database. I get random crashes when ending packagekitd with Ctrl-C.
Comment 3 Richard Hughes 2008-03-28 09:49:22 UTC
Yup, I've added a load of checks in 02c8fd68a96cf5f5aece013afee94ecbb1e5752c

Does the daemon now do what you expect?
Comment 4 Klaus Kämpf 2008-04-04 03:09:02 UTC
Looks good now.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.