tracker r3114 - in trunk: . src/tracker-indexer src/tracker-utils



Author: mr
Date: Fri Mar 20 18:48:57 2009
New Revision: 3114
URL: http://svn.gnome.org/viewvc/tracker?rev=3114&view=rev

Log:
	* src/tracker-indexer/tracker-module-metadata-utils.c: Used code
	from tracker-processes utility to find tracker-extract when we get
	a dbus timed out (and other type) messages and kill it with
	SIGKILL. This should fix the problems we were seeing with the
	extractor locking up for long periods of time on the device.

	* src/tracker-utils/Makefile.am:
	* src/tracker-utils/tracker-processes.c: Added utility to get all
	tracker processes running on the system.


Added:
   trunk/src/tracker-utils/tracker-processes.c
Modified:
   trunk/ChangeLog
   trunk/src/tracker-indexer/tracker-module-metadata-utils.c
   trunk/src/tracker-utils/Makefile.am

Modified: trunk/src/tracker-indexer/tracker-module-metadata-utils.c
==============================================================================
--- trunk/src/tracker-indexer/tracker-module-metadata-utils.c	(original)
+++ trunk/src/tracker-indexer/tracker-module-metadata-utils.c	Fri Mar 20 18:48:57 2009
@@ -22,9 +22,16 @@
 #include "config.h"
 
 #include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <errno.h>
 
 #include <gio/gio.h>
 
+#define DBUS_API_SUBJECT_TO_CHANGE
+#include <dbus/dbus-glib-lowlevel.h>
+
 #include <libtracker-common/tracker-file-utils.h>
 #include <libtracker-common/tracker-type-utils.h>
 #include <libtracker-common/tracker-os-dependant.h>
@@ -86,9 +93,9 @@
 					   "org.freedesktop.Tracker.Extract",
 					   "/org/freedesktop/Tracker/Extract",
 					   "org.freedesktop.Tracker.Extract");
-	
+
 	if (!proxy) {
-		g_critical ("Couldn't create a DBusGProxy to the extract service");
+		g_critical ("Could not create a DBusGProxy to the extract service");
 	}
 
 	return proxy;
@@ -188,6 +195,42 @@
 	return context;
 }
 
+static GSList *
+get_pids (void)
+{
+	GError *error = NULL;
+	GDir *dir;
+	GSList *pids = NULL;
+	const gchar *name;
+
+	dir = g_dir_open ("/proc", 0, &error);
+	if (error) {
+		g_warning ("Could not open /proc, %s\n",
+			   error ? error->message : "no error given");
+		g_clear_error (&error);
+		return NULL;
+	}
+
+	while ((name = g_dir_read_name (dir)) != NULL) { 
+		gchar c;
+		gboolean is_pid = TRUE;
+
+		for (c = *name; c && c != ':' && is_pid; c++) {		
+			is_pid &= g_ascii_isdigit (c);
+		}
+
+		if (!is_pid) {
+			continue;
+		}
+
+		pids = g_slist_prepend (pids, g_strdup (name));
+	}
+
+	g_dir_close (dir);
+
+	return g_slist_reverse (pids);
+}
+
 static void
 metadata_utils_add_embedded_data (TrackerModuleMetadata *metadata,
 				  TrackerField          *field,
@@ -285,11 +328,104 @@
 							   mime_type, 
 							   &values, 
 							   &error)) {
+		GSList *pids, *l;
+		gboolean should_kill = TRUE;
+		gboolean was_killed;
+
+		if (G_LIKELY (error)) {
+			switch (error->code) {
+			case DBUS_GERROR_FAILED:
+			case DBUS_GERROR_NO_MEMORY:
+			case DBUS_GERROR_NO_REPLY:
+			case DBUS_GERROR_IO_ERROR:
+			case DBUS_GERROR_LIMITS_EXCEEDED:
+			case DBUS_GERROR_TIMEOUT:
+			case DBUS_GERROR_DISCONNECTED:
+			case DBUS_GERROR_TIMED_OUT:
+			case DBUS_GERROR_REMOTE_EXCEPTION:
+				break;
+
+			default:
+				should_kill = FALSE;
+				break;
+			}
+		}
+
 		g_message ("Couldn't extract metadata for path:'%s' and mime:'%s', %s",
 			   path,
 			   mime_type,
 			   error ? error->message : "no error given");
+
 		g_clear_error (&error);
+
+		if (!should_kill) {
+			return;
+		}
+
+		was_killed = FALSE;
+
+		/* Kill extractor, most likely it got stuck */
+		g_message ("Attempting to kill tracker-extract with SIGKILL");
+		
+		pids = get_pids ();
+		g_message ("  Found %d pids...", g_slist_length (pids));
+
+		for (l = pids; l; l = l->next) {
+			gchar *filename;
+			gchar *contents = NULL;
+			gchar **strv;
+
+			filename = g_build_filename ("/proc", l->data, "cmdline", NULL);
+			g_file_get_contents (filename, &contents, NULL, &error);
+			
+			if (error) {
+				g_warning ("Could not open '%s', %s",
+					   filename,
+					   error ? error->message : "no error given");
+				g_clear_error (&error);
+				g_free (contents);
+				g_free (filename);
+				
+				continue;
+			}
+			
+			strv = g_strsplit (contents, "^@", 2);
+			if (strv && strv[0]) {
+				gchar *basename;
+				
+				basename = g_path_get_basename (strv[0]);
+				if (g_strcmp0 (basename, "tracker-extract") == 0) {
+					pid_t p;
+
+					p = atoi (l->data);
+					g_message ("  Found process ID:%d", p);
+
+					if (kill (p, SIGKILL) == -1) {
+						const gchar *str = g_strerror (errno);
+						
+						g_message ("Couldn't kill process %d, %s",
+							   p,
+							   str ? str : "no error given");
+					} else {
+						was_killed = TRUE;
+					}
+				}
+				
+				g_free (basename);
+			}
+			
+			g_strfreev (strv);
+			g_free (contents);
+			g_free (filename);
+		}
+
+		if (!was_killed) {
+			g_message ("  No process was found to kill");
+		}
+		
+		g_slist_foreach (pids, (GFunc) g_free, NULL);
+		g_slist_free (pids);
+
 		return;
 	}
 

Modified: trunk/src/tracker-utils/Makefile.am
==============================================================================
--- trunk/src/tracker-utils/Makefile.am	(original)
+++ trunk/src/tracker-utils/Makefile.am	Fri Mar 20 18:48:57 2009
@@ -28,6 +28,7 @@
 	tracker-status							\
 	tracker-unique							\
 	tracker-info							\
+	tracker-processes						\
 	tracker-services
 
 tracker_search_SOURCES = tracker-search.c
@@ -57,5 +58,8 @@
 tracker_info_SOURCES = tracker-info.c
 tracker_info_LDADD = $(libs)
 
+tracker_processes_SOURCES = tracker-processes.c
+tracker_processes_LDADD = $(libs)
+
 tracker_services_SOURCES = tracker-services.c
 tracker_services_LDADD = $(libs)

Added: trunk/src/tracker-utils/tracker-processes.c
==============================================================================
--- (empty file)
+++ trunk/src/tracker-utils/tracker-processes.c	Fri Mar 20 18:48:57 2009
@@ -0,0 +1,133 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library 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 <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <locale.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+static GSList *
+get_pids (void)
+{
+	GError *error = NULL;
+	GDir *dir;
+	GSList *pids = NULL;
+	const gchar *name;
+
+	dir = g_dir_open ("/proc", 0, &error);
+	if (error) {
+		g_printerr ("Could not open /proc, %s\n",
+			    error ? error->message : "no error given");
+		g_clear_error (&error);
+		return NULL;
+	}
+
+	while ((name = g_dir_read_name (dir)) != NULL) { 
+		gchar c;
+		gboolean is_pid = TRUE;
+
+		for (c = *name; c && c != ':' && is_pid; c++) {		
+			is_pid &= g_ascii_isdigit (c);
+		}
+
+		if (!is_pid) {
+			continue;
+		}
+
+		pids = g_slist_prepend (pids, g_strdup (name));
+	}
+
+	g_dir_close (dir);
+
+	return g_slist_reverse (pids);
+}
+
+int
+main (int argc, char **argv)
+{
+	GOptionContext *context;
+	GError	       *error = NULL;
+	GSList         *pids;
+	GSList         *l;
+
+	setlocale (LC_ALL, "");
+
+	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	/* Translators: this messagge will apper immediately after the	*/
+	/* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>	*/
+	context = g_option_context_new (_(" - Show the processes the tracker project is using"));
+	g_option_context_parse (context, &argc, &argv, NULL);
+	g_option_context_free (context);
+
+	pids = get_pids ();
+	g_print ("Found %d pids...\n", g_slist_length (pids));
+
+	for (l = pids; l; l = l->next) {
+		gchar *filename;
+		gchar *contents = NULL;
+		gchar **strv;
+
+		filename = g_build_filename ("/proc", l->data, "cmdline", NULL);
+		g_file_get_contents (filename, &contents, NULL, &error);
+
+		if (error) {
+			g_printerr ("Could not open '%s', %s\n",
+				    filename,
+				    error ? error->message : "no error given");
+			g_clear_error (&error);
+			g_free (contents);
+			g_free (filename);
+
+			continue;
+		}
+		
+		strv = g_strsplit (contents, "^@", 2);
+		if (strv && strv[0]) {
+			gchar *basename;
+
+			basename = g_path_get_basename (strv[0]);
+			if (g_str_has_prefix (basename, "tracker")) {
+				g_print ("Found process ID:%s for '%s'\n",
+					 (gchar*) l->data,
+					 strv[0]);
+			}
+
+			g_free (basename);
+		}
+
+		g_strfreev (strv);
+		g_free (contents);
+		g_free (filename);
+	}
+
+	g_slist_foreach (pids, (GFunc) g_free, NULL);
+	g_slist_free (pids);
+
+	return EXIT_SUCCESS;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]