[tracker] tracker-miner-fs: Watch after tracker-extract process
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tracker-miner-fs: Watch after tracker-extract process
- Date: Thu, 8 Dec 2016 14:47:20 +0000 (UTC)
commit 32104d5cd83dc4a8de0c566de5a8aefa9fcaeba0
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Dec 8 15:33:29 2016 +0100
tracker-miner-fs: Watch after tracker-extract process
Ensure it's restarted after going away (eg. due to unintended
crashes), the extractor will eventually skip over the file and
keep going.
src/miners/fs/Makefile.am | 2 +
src/miners/fs/tracker-extract-watchdog.c | 157 ++++++++++++++++++++++++++++++
src/miners/fs/tracker-extract-watchdog.h | 38 +++++++
src/miners/fs/tracker-miner-files.c | 6 +
4 files changed, 203 insertions(+), 0 deletions(-)
---
diff --git a/src/miners/fs/Makefile.am b/src/miners/fs/Makefile.am
index 75060f1..c1dc2da 100644
--- a/src/miners/fs/Makefile.am
+++ b/src/miners/fs/Makefile.am
@@ -29,6 +29,8 @@ tracker_miner_fs_SOURCES = \
$(power_headers) \
tracker-config.c \
tracker-config.h \
+ tracker-extract-watchdog.c \
+ tracker-extract-watchdog.h \
tracker-main.c \
tracker-miner-files.c \
tracker-miner-files.h \
diff --git a/src/miners/fs/tracker-extract-watchdog.c b/src/miners/fs/tracker-extract-watchdog.c
new file mode 100644
index 0000000..fd0b88f
--- /dev/null
+++ b/src/miners/fs/tracker-extract-watchdog.c
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2016, Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "tracker-extract-watchdog.h"
+
+#include <libtracker-common/tracker-common.h>
+#include <libtracker-miner/tracker-miner.h>
+
+struct _TrackerExtractWatchdog {
+ GObject parent_class;
+ guint extractor_watchdog_id;
+ guint timeout_id;
+ gboolean initializing;
+};
+
+static void extract_watchdog_start (TrackerExtractWatchdog *watchdog,
+ gboolean autostart);
+
+G_DEFINE_TYPE (TrackerExtractWatchdog, tracker_extract_watchdog, G_TYPE_OBJECT)
+
+static void
+extract_watchdog_stop (TrackerExtractWatchdog *watchdog)
+{
+ if (watchdog->extractor_watchdog_id) {
+ g_bus_unwatch_name (watchdog->extractor_watchdog_id);
+ watchdog->extractor_watchdog_id = 0;
+ }
+}
+
+static gboolean
+extract_watchdog_name_vanished_timeout (gpointer user_data)
+{
+ TrackerExtractWatchdog *watchdog = user_data;
+
+ watchdog->timeout_id = 0;
+ extract_watchdog_start (watchdog, TRUE);
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+extract_watchdog_name_appeared (GDBusConnection *conn,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
+{
+ TrackerExtractWatchdog *watchdog = user_data;
+
+ if (watchdog->initializing)
+ watchdog->initializing = FALSE;
+}
+
+static void
+extract_watchdog_name_vanished (GDBusConnection *conn,
+ const gchar *name,
+ gpointer user_data)
+{
+ TrackerExtractWatchdog *watchdog = user_data;
+
+ /* If connection is lost, there's not much we can startup */
+ if (conn == NULL)
+ return;
+
+ /* We will ignore the first call after initialization, as we
+ * don't want to autostart tracker-extract in this case (useful
+ * for debugging purposes).
+ */
+ if (watchdog->initializing) {
+ watchdog->initializing = FALSE;
+ return;
+ }
+
+ g_debug ("tracker-extract vanished, restarting after grace period.");
+
+ /* Close the name watch, so we'll create another one that will
+ * autostart the service if it not already running.
+ */
+ extract_watchdog_stop (watchdog);
+
+ /* Give a period of grace before restarting, so we allow replacing
+ * from eg. a terminal.
+ */
+ watchdog->timeout_id =
+ g_timeout_add_seconds (1, extract_watchdog_name_vanished_timeout,
+ watchdog);
+}
+
+static void
+extract_watchdog_start (TrackerExtractWatchdog *watchdog,
+ gboolean autostart)
+{
+ g_debug ("Setting up watch on tracker-extract (autostart: %s)",
+ autostart ? "yes" : "no");
+
+ watchdog->extractor_watchdog_id =
+ g_bus_watch_name (TRACKER_IPC_BUS,
+ TRACKER_MINER_DBUS_NAME_PREFIX "Extract",
+ (autostart ?
+ G_BUS_NAME_WATCHER_FLAGS_AUTO_START :
+ G_BUS_NAME_WATCHER_FLAGS_NONE),
+ NULL, extract_watchdog_name_vanished,
+ watchdog, NULL);
+}
+
+static void
+tracker_extract_watchdog_finalize (GObject *object)
+{
+ TrackerExtractWatchdog *watchdog = TRACKER_EXTRACT_WATCHDOG (object);
+
+ extract_watchdog_stop (watchdog);
+
+ if (watchdog->timeout_id) {
+ g_source_remove (watchdog->timeout_id);
+ }
+
+ G_OBJECT_CLASS (tracker_extract_watchdog_parent_class)->finalize (object);
+}
+
+static void
+tracker_extract_watchdog_class_init (TrackerExtractWatchdogClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = tracker_extract_watchdog_finalize;
+}
+
+static void
+tracker_extract_watchdog_init (TrackerExtractWatchdog *watchdog)
+{
+ watchdog->initializing = TRUE;
+ extract_watchdog_start (watchdog, FALSE);
+}
+
+TrackerExtractWatchdog *
+tracker_extract_watchdog_new (void)
+{
+ return g_object_new (TRACKER_TYPE_EXTRACT_WATCHDOG,
+ NULL);
+}
diff --git a/src/miners/fs/tracker-extract-watchdog.h b/src/miners/fs/tracker-extract-watchdog.h
new file mode 100644
index 0000000..1dab018
--- /dev/null
+++ b/src/miners/fs/tracker-extract-watchdog.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2016, Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TRACKER_EXTRACT_WATCHDOG_H__
+#define __TRACKER_EXTRACT_WATCHDOG_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_EXTRACT_WATCHDOG (tracker_extract_watchdog_get_type ())
+
+G_DECLARE_FINAL_TYPE (TrackerExtractWatchdog,
+ tracker_extract_watchdog,
+ TRACKER, EXTRACT_WATCHDOG,
+ GObject)
+
+TrackerExtractWatchdog * tracker_extract_watchdog_new (void);
+
+G_END_DECLS
+
+#endif /* __TRACKER_EXTRACT_WATCHDOG_H__ */
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index e0cd48d..e2db5a7 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -44,6 +44,7 @@
#include "tracker-miner-files.h"
#include "tracker-config.h"
#include "tracker-storage.h"
+#include "tracker-extract-watchdog.h"
#define DISK_SPACE_CHECK_FREQUENCY 10
#define SECONDS_PER_DAY 86400
@@ -65,6 +66,7 @@ struct ProcessFileData {
struct TrackerMinerFilesPrivate {
TrackerConfig *config;
TrackerStorage *storage;
+ TrackerExtractWatchdog *extract_watchdog;
GVolumeMonitor *volume_monitor;
@@ -552,6 +554,8 @@ miner_files_initable_init (GInitable *initable,
disk_space_check_start (mf);
+ mf->private->extract_watchdog = tracker_extract_watchdog_new ();
+
return TRUE;
}
@@ -604,6 +608,8 @@ miner_files_finalize (GObject *object)
mf = TRACKER_MINER_FILES (object);
priv = mf->private;
+ g_clear_object (&priv->extract_watchdog);
+
if (priv->config) {
g_signal_handlers_disconnect_by_func (priv->config,
low_disk_space_limit_cb,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]