aboutsummaryrefslogtreecommitdiffstats
path: root/tools/killev.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2003-04-08 00:06:50 +0800
committerDan Winship <danw@src.gnome.org>2003-04-08 00:06:50 +0800
commit49eb4eb0e49f99762537e5d4337f06f90db084a2 (patch)
treeb09437b83a0e3a1dd7e4918c482974b17bc359ed /tools/killev.c
parent091e937669ab19e779ff3e2ef143722c93e41b79 (diff)
downloadgsoc2013-evolution-49eb4eb0e49f99762537e5d4337f06f90db084a2.tar
gsoc2013-evolution-49eb4eb0e49f99762537e5d4337f06f90db084a2.tar.gz
gsoc2013-evolution-49eb4eb0e49f99762537e5d4337f06f90db084a2.tar.bz2
gsoc2013-evolution-49eb4eb0e49f99762537e5d4337f06f90db084a2.tar.lz
gsoc2013-evolution-49eb4eb0e49f99762537e5d4337f06f90db084a2.tar.xz
gsoc2013-evolution-49eb4eb0e49f99762537e5d4337f06f90db084a2.tar.zst
gsoc2013-evolution-49eb4eb0e49f99762537e5d4337f06f90db084a2.zip
Install these in privlibexecdir, not privdatadir. Move killev from SCRIPTS
* tools/Makefile.am (privlibexec_SCRIPTS, privlibexec_PROGRAMS): Install these in privlibexecdir, not privdatadir. Move killev from SCRIPTS to PROGRAMS. (killev_SOURCES, killev_LDADD): Add * tools/killev.c: New C port of killev, since "bonobo-activation-query" does not return as much information as "oaf-client" did. Also has prettier output. (Still shells out to killall/pkill to do the actual killing.) * tools/killev: Gone * tools/evolution-move-tasks: Removed since the evolution-calendar code that called it is also gone now. svn path=/trunk/; revision=20700
Diffstat (limited to 'tools/killev.c')
-rw-r--r--tools/killev.c217
1 files changed, 217 insertions, 0 deletions
diff --git a/tools/killev.c b/tools/killev.c
new file mode 100644
index 0000000000..6904b02243
--- /dev/null
+++ b/tools/killev.c
@@ -0,0 +1,217 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* killev.c
+ *
+ * Copyright (C) 2003 Ximian, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+
+#include <bonobo/bonobo-exception.h>
+#include <bonobo-activation/bonobo-activation.h>
+#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-util.h>
+
+#include "e-util/e-lang-utils.h"
+
+typedef struct {
+ char *location;
+ GPtrArray *names;
+} KillevComponent;
+
+GSList *languages;
+GHashTable *components;
+
+static gboolean
+kill_process (const char *proc_name, KillevComponent *comp)
+{
+ int status, i;
+ char *command;
+ GString *desc;
+
+ command = g_strdup_printf (KILL_PROCESS_CMD " -0 %s 2> /dev/null",
+ proc_name);
+ status = system (command);
+ g_free (command);
+
+ if (status == -1 || !WIFEXITED (status)) {
+ /* This most likely means that KILL_PROCESS_CMD wasn't
+ * found, so just bail completely.
+ */
+ fprintf (stderr, _("Could not execute '%s': %s\n"),
+ KILL_PROCESS_CMD, strerror (errno));
+ exit (1);
+ }
+
+ if (WEXITSTATUS (status) != 0)
+ return FALSE;
+
+ desc = g_string_new (NULL);
+ for (i = 0; i < comp->names->len; i++) {
+ if (i > 0)
+ g_string_append (desc, " / ");
+ g_string_append (desc, comp->names->pdata[i]);
+ }
+
+ printf (_("Shutting down %s (%s)\n"), proc_name, desc->str);
+ g_string_free (desc, TRUE);
+ command = g_strdup_printf (KILL_PROCESS_CMD " -9 %s 2> /dev/null",
+ proc_name);
+ system (command);
+ g_free (command);
+ return TRUE;
+};
+
+static gboolean
+kill_component (gpointer key, gpointer value, gpointer data)
+{
+ KillevComponent *comp = value;
+ char *exe_name;
+
+ if (kill_process (comp->location, comp))
+ return TRUE;
+
+ exe_name = g_strdup_printf ("lt-%s", comp->location);
+ if (kill_process (exe_name, comp)) {
+ g_free (exe_name);
+ return TRUE;
+ }
+
+ if (strlen (exe_name) > 16) {
+ exe_name[16] = '\0';
+ if (kill_process (exe_name, comp)) {
+ g_free (exe_name);
+ return TRUE;
+ }
+ }
+ g_free (exe_name);
+
+ if (strlen (comp->location) > 16) {
+ exe_name = g_strndup (comp->location, 16);
+ kill_process (exe_name, comp);
+ g_free (exe_name);
+ }
+
+ return TRUE;
+}
+
+static void
+add_matching_query (const char *query)
+{
+ Bonobo_ServerInfoList *info_list;
+ Bonobo_ServerInfo *info;
+ CORBA_Environment ev;
+ const char *location, *name;
+ KillevComponent *comp;
+ int i;
+
+ CORBA_exception_init (&ev);
+
+ info_list = bonobo_activation_query (query, NULL, &ev);
+ if (ev._major != CORBA_NO_EXCEPTION) {
+ printf ("Bonobo activation failure: %s\n",
+ bonobo_exception_get_text (&ev));
+ CORBA_exception_free (&ev);
+ return;
+ }
+
+ for (i = 0; i < info_list->_length; i++) {
+ info = &info_list->_buffer[i];
+
+ if (strcmp (info->server_type, "exe") != 0)
+ continue;
+
+ location = info->location_info;
+ if (strchr (location, '/'))
+ location = strrchr (location, '/') + 1;
+
+ comp = g_hash_table_lookup (components, location);
+ if (!comp) {
+ comp = g_new (KillevComponent, 1);
+ comp->location = g_strdup (location);
+ comp->names = g_ptr_array_new ();
+ g_hash_table_insert (components, comp->location, comp);
+ }
+
+ name = bonobo_server_info_prop_lookup (info, "name", languages);
+ if (name)
+ g_ptr_array_add (comp->names, g_strdup (name));
+ }
+
+ CORBA_free (info_list);
+ CORBA_exception_free (&ev);
+}
+
+static void
+add_matching_repo_id (const char *repo_id)
+{
+ char *query;
+
+ query = g_strdup_printf ("repo_ids.has ('%s')", repo_id);
+ add_matching_query (query);
+ g_free (query);
+}
+
+static void
+add_matching_iid (const char *iid)
+{
+ char *query;
+
+ query = g_strdup_printf ("iid == '%s'", iid);
+ add_matching_query (query);
+ g_free (query);
+}
+
+int
+main (int argc, char **argv)
+{
+ bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ gnome_program_init (PACKAGE, VERSION, LIBGNOME_MODULE, argc, argv,
+ GNOME_PROGRAM_STANDARD_PROPERTIES,
+ NULL);
+
+ languages = e_get_language_list ();
+ components = g_hash_table_new (g_str_hash, g_str_equal);
+
+ add_matching_repo_id ("IDL:GNOME/Evolution/Shell:1.0");
+ g_hash_table_foreach_remove (components, kill_component, NULL);
+
+ add_matching_repo_id ("IDL:GNOME/Evolution/ShellComponent:1.0");
+ add_matching_repo_id ("IDL:GNOME/Evolution/Calendar/CalFactory:1.0");
+ add_matching_repo_id ("IDL:GNOME/Evolution/BookFactory:1.0");
+ add_matching_repo_id ("IDL:GNOME/Evolution/Importer:1.0");
+ add_matching_repo_id ("IDL:GNOME/Evolution/IntelligentImporter:1.0");
+ add_matching_repo_id ("IDL:GNOME/Spell/Checker:0.1");
+
+ add_matching_iid ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory");
+ add_matching_iid ("OAFIID:GNOME_GtkHTML_Editor_Factory:3.0");
+
+ g_hash_table_foreach_remove (components, kill_component, NULL);
+
+ return 0;
+}