add a job_count file to keep track of job ids. This should fix many hard to fix oddites when restarting the daemon at odd times
This commit is contained in:
parent
164174a9b5
commit
819bfb84e0
@ -1,6 +1,7 @@
|
||||
SUBDIRS = \
|
||||
policy \
|
||||
man \
|
||||
data \
|
||||
libselftest \
|
||||
libgbus \
|
||||
libpackagekit \
|
||||
|
@ -313,6 +313,7 @@ AC_OUTPUT([
|
||||
packagekit.pc
|
||||
Makefile
|
||||
man/Makefile
|
||||
data/Makefile
|
||||
libselftest/Makefile
|
||||
libgbus/Makefile
|
||||
libpackagekit/Makefile
|
||||
|
2
data/.gitignore
vendored
Normal file
2
data/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
org.freedesktop.PackageKit.service
|
||||
|
33
data/Makefile.am
Normal file
33
data/Makefile.am
Normal file
@ -0,0 +1,33 @@
|
||||
## We require new-style dependency handling.
|
||||
AUTOMAKE_OPTIONS = 1.7
|
||||
|
||||
NULL =
|
||||
|
||||
servicedir = $(DBUS_SERVICES_DIR)
|
||||
service_in_files = org.freedesktop.PackageKit.service.in
|
||||
service_DATA = $(service_in_files:.service.in=.service)
|
||||
|
||||
$(service_DATA): $(service_in_files) Makefile
|
||||
@sed -e "s|\@servicedir\@|$(sbindir)|" $< > $@
|
||||
|
||||
localcachedir = $(localstatedir)/run/PackageKit
|
||||
localcache_DATA = \
|
||||
job_count.dat \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(service_in_files) \
|
||||
$(localcache_DATA) \
|
||||
$(NULL)
|
||||
|
||||
clean-local:
|
||||
rm -f *~
|
||||
|
||||
DISTCLEANFILES = \
|
||||
org.freedesktop.PackageKit.service
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
*~ \
|
||||
Makefile.in \
|
||||
$(NULL)
|
||||
|
1
data/job_count.dat
Normal file
1
data/job_count.dat
Normal file
@ -0,0 +1 @@
|
||||
0
|
1
src/.gitignore
vendored
1
src/.gitignore
vendored
@ -7,5 +7,4 @@ pk-interface.h
|
||||
packagekitd
|
||||
pk-self-test
|
||||
debug.log
|
||||
org.freedesktop.PackageKit.service
|
||||
|
||||
|
@ -3,13 +3,6 @@ AUTOMAKE_OPTIONS = 1.7
|
||||
|
||||
NULL =
|
||||
|
||||
servicedir = $(DBUS_SERVICES_DIR)
|
||||
service_in_files = org.freedesktop.PackageKit.service.in
|
||||
service_DATA = $(service_in_files:.service.in=.service)
|
||||
|
||||
$(service_DATA): $(service_in_files) Makefile
|
||||
@sed -e "s|\@servicedir\@|$(sbindir)|" $< > $@
|
||||
|
||||
PK_LIBS = \
|
||||
$(top_builddir)/libpackagekit/libpackagekit.la \
|
||||
$(NULL)
|
||||
@ -18,13 +11,6 @@ SELFTEST_LIBS = \
|
||||
$(top_builddir)/libselftest/libselftest.la \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = \
|
||||
pk-marshal.list \
|
||||
pk-interface.xml \
|
||||
pk-spawn-test.sh \
|
||||
$(service_in_files) \
|
||||
$(NULL)
|
||||
|
||||
INCLUDES = \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(DBUS_CFLAGS) \
|
||||
@ -37,6 +23,7 @@ INCLUDES = \
|
||||
-DLIBDIR=\""$(libdir)"\" \
|
||||
-DVERSION="\"$(VERSION)\"" \
|
||||
-DPK_DATA=\"$(pkgdatadir)\" \
|
||||
-DLOCALSTATEDIR=\""$(localstatedir)"\" \
|
||||
-I$(top_srcdir)/libpackagekit \
|
||||
-I$(top_srcdir)/libselftest \
|
||||
$(NULL)
|
||||
@ -148,13 +135,16 @@ pk_self_test_LDADD = \
|
||||
pk_self_test_CPPFLAGS= \
|
||||
-DPK_BUILD_TESTS
|
||||
|
||||
EXTRA_DIST = \
|
||||
pk-marshal.list \
|
||||
pk-interface.xml \
|
||||
pk-spawn-test.sh \
|
||||
$(NULL)
|
||||
|
||||
clean-local:
|
||||
rm -f *~
|
||||
rm -f pk-marshal.c pk-marshal.h
|
||||
|
||||
DISTCLEANFILES = \
|
||||
org.freedesktop.PackageKit.service
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
TESTS = pk-self-test
|
||||
|
@ -52,11 +52,13 @@ static void pk_engine_init (PkEngine *engine);
|
||||
static void pk_engine_finalize (GObject *object);
|
||||
|
||||
#define PK_ENGINE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_ENGINE, PkEnginePrivate))
|
||||
#define PK_ENGINE_JOB_LAST_COUNT_FILE LOCALSTATEDIR "/run/PackageKit/job_count.dat"
|
||||
|
||||
struct PkEnginePrivate
|
||||
{
|
||||
GPtrArray *array;
|
||||
GTimer *timer;
|
||||
guint job_count;
|
||||
PolKitContext *pk_context;
|
||||
DBusConnection *connection;
|
||||
};
|
||||
@ -399,6 +401,44 @@ pk_engine_allow_interrupt_cb (PkTask *task, gboolean allow_kill, PkEngine *engin
|
||||
g_signal_emit (engine, signals [PK_ENGINE_ALLOW_INTERRUPT], 0, job, allow_kill);
|
||||
}
|
||||
|
||||
/**
|
||||
* pk_engine_load_job_count:
|
||||
**/
|
||||
static gboolean
|
||||
pk_engine_load_job_count (PkEngine *engine)
|
||||
{
|
||||
gboolean ret;
|
||||
gchar *contents;
|
||||
ret = g_file_get_contents (PK_ENGINE_JOB_LAST_COUNT_FILE, &contents, NULL, NULL);
|
||||
if (ret == FALSE) {
|
||||
pk_warning ("failed to get last job");
|
||||
return FALSE;
|
||||
}
|
||||
engine->priv->job_count = atoi (contents);
|
||||
pk_debug ("job=%i", engine->priv->job_count);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* pk_engine_save_job_count:
|
||||
**/
|
||||
static gboolean
|
||||
pk_engine_save_job_count (PkEngine *engine)
|
||||
{
|
||||
gboolean ret;
|
||||
gchar *contents;
|
||||
|
||||
pk_debug ("saving %i", engine->priv->job_count);
|
||||
contents = g_strdup_printf ("%i", engine->priv->job_count);
|
||||
ret = g_file_set_contents (PK_ENGINE_JOB_LAST_COUNT_FILE, contents, -1, NULL);
|
||||
g_free (contents);
|
||||
if (ret == FALSE) {
|
||||
pk_warning ("failed to set last job");
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* pk_engine_new_task:
|
||||
**/
|
||||
@ -406,10 +446,9 @@ static PkTask *
|
||||
pk_engine_new_task (PkEngine *engine)
|
||||
{
|
||||
PkTask *task;
|
||||
static guint job = 0;
|
||||
|
||||
/* increment the job number - we never repeat an id */
|
||||
job++;
|
||||
engine->priv->job_count++;
|
||||
|
||||
/* allocate a new task */
|
||||
task = pk_task_new ();
|
||||
@ -441,9 +480,12 @@ pk_engine_new_task (PkEngine *engine)
|
||||
pk_task_common_init (task);
|
||||
|
||||
/* set the job ID */
|
||||
pk_task_set_job (task, job);
|
||||
pk_task_set_job (task, engine->priv->job_count);
|
||||
pk_engine_reset_timer (engine);
|
||||
|
||||
/* in an ideal workd we don't need this, but do it in case the daemon is ctrl-c;d */
|
||||
pk_engine_save_job_count (engine);
|
||||
|
||||
/* we don't add to the array or do the job-list-changed yet
|
||||
* as this job might fail */
|
||||
return task;
|
||||
@ -1271,6 +1313,8 @@ pk_engine_init (PkEngine *engine)
|
||||
engine->priv->array = g_ptr_array_new ();
|
||||
engine->priv->timer = g_timer_new ();
|
||||
|
||||
engine->priv->job_count = pk_engine_load_job_count (engine);
|
||||
|
||||
/* get a connection to the bus */
|
||||
dbus_error_init (&dbus_error);
|
||||
engine->priv->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
|
||||
@ -1304,6 +1348,9 @@ pk_engine_finalize (GObject *object)
|
||||
|
||||
g_return_if_fail (engine->priv != NULL);
|
||||
|
||||
/* save last job id so we don't ever repeat */
|
||||
pk_engine_save_job_count (engine);
|
||||
|
||||
/* compulsory gobjects */
|
||||
g_ptr_array_free (engine->priv->array, TRUE);
|
||||
g_timer_destroy (engine->priv->timer);
|
||||
|
Loading…
Reference in New Issue
Block a user