diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 28 | ||||
-rwxr-xr-x | tools/evolution-move-tasks | 135 | ||||
-rwxr-xr-x | tools/killev | 142 | ||||
-rw-r--r-- | tools/killev.c | 217 |
4 files changed, 233 insertions, 289 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index 5687cc174b..eb8ba15f25 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,15 +1,13 @@ -toolsdir = $(privdatadir)/tools - -tools_SCRIPTS = \ +privlibexec_SCRIPTS = \ csv2vcard \ - evolution-move-tasks \ - evolution-addressbook-clean \ - killev + evolution-addressbook-clean -tools_PROGRAMS = \ +privlibexec_PROGRAMS = \ evolution-addressbook-import \ evolution-addressbook-export \ - evolution-launch-composer + evolution-launch-composer \ + killev + noinst_PROGRAMS = evolution-addressbook-abuse @@ -56,8 +54,8 @@ evolution_addressbook_export_LDADD = \ evolution_addressbook_abuse_LDADD = \ $(evolution_addressbook_import_LDADD) -evolution_launch_composer_SOURCES = \ - $(CORBA_SOURCE) \ +evolution_launch_composer_SOURCES = \ + $(CORBA_SOURCE) \ evolution-launch-composer.c evolution_launch_composer_LDADD = \ @@ -65,11 +63,17 @@ evolution_launch_composer_LDADD = \ $(top_builddir)/addressbook/backend/ebook/libebook.la \ $(top_builddir)/widgets/menus/libmenus.la -CLEANFILES = evolution-addressbook-clean $(BUILD_SOURCES) +killev_SOURCES = \ + killev.c + +killev_LDADD = \ + $(top_builddir)/e-util/libeutil.la + +CLEANFILES = evolution-addressbook-clean $(BUILT_SOURCES) evolution-addressbook-clean: evolution-addressbook-clean.in Makefile ## Use sed and then mv to avoid problems if the user interrupts. - sed -e 's?\@EVOLUTION_TOOLSDIR\@?$(toolsdir)?g' \ + sed -e 's?\@EVOLUTION_TOOLSDIR\@?$(privlibexecdir)?g' \ < $(srcdir)/evolution-addressbook-clean.in > evolution-addressbook-clean.tmp \ && mv evolution-addressbook-clean.tmp evolution-addressbook-clean diff --git a/tools/evolution-move-tasks b/tools/evolution-move-tasks deleted file mode 100755 index 05c27cbce2..0000000000 --- a/tools/evolution-move-tasks +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env perl -# The above is a portable way to invoke Perl, according to the GNU Autotools -# book. It is useful since we don't know where perl is installed. -# -# evolution-move-tasks: a Perl script to move tasks from the Calendar folder -# to the new Tasks folder. -# - -use diagnostics; - -# You may have to change this if your Evolution files are somewhere else. -$EVOLUTION_DIR = "$ENV{'HOME'}/evolution"; - -$CALENDAR_DIR = "$EVOLUTION_DIR/local/Calendar"; -$TASKS_DIR = "$EVOLUTION_DIR/local/Tasks"; - -# Create the Tasks folder if needed. -&EnsureTasksFolderExists ($TASKS_DIR); - -# Get any tasks from the calendar .ics file. -$tasks = &LoadTasks ("$CALENDAR_DIR/calendar.ics"); - -# Get any tasks already in the tasks .ics file. -$tasks .= &LoadTasks ("$TASKS_DIR/tasks.ics"); - -# Create a new Tasks .ics file containing all the tasks. -&OutputTasks ("$TASKS_DIR/tasks.new", $tasks); - -# Move the existing tasks file to a backup. -if (-e "$TASKS_DIR/tasks.ics") { - rename "$TASKS_DIR/tasks.ics", "$TASKS_DIR/tasks.bak" - || die "Can't rename $TASKS_DIR/tasks.ics to $TASKS_DIR/tasks.bak"; -} - -# Move the new file into position. -rename "$TASKS_DIR/tasks.new", "$TASKS_DIR/tasks.ics" - || die "Can't rename $TASKS_DIR/tasks.new to $TASKS_DIR/tasks.ics"; - -# Move the new Calendar file (without the Tasks) into position. -rename "$CALENDAR_DIR/calendar.ics.new", "$CALENDAR_DIR/calendar.ics" - || die "Can't rename $TASKS_DIR/tasks.new to $TASKS_DIR/tasks.ics"; - -0; - - -# If the evolution/local/Tasks folder does not exist, this creates it and -# creates the metadata XML file. -sub EnsureTasksFolderExists { - my ($tasks_dir) = @_; - - return if (-e $tasks_dir); - - print "Creating Tasks folder in: $tasks_dir\n"; - - mkdir ($tasks_dir, 0777) - || die "Can't create Tasks folder directory: $tasks_dir"; - - $metadata = "$tasks_dir/folder-metadata.xml"; - open (METADATA, ">$metadata") - || die "Can't create metadata file: $metadata"; - - print METADATA <<EOF; -<?xml version="1.0"?> -<efolder> - <type>tasks</type> - <description>Tasks</description> -</efolder> -EOF - - close (METADATA); -} - - -sub LoadTasks { - my ($icalendar_file) = @_; - - return "" if (! -e $icalendar_file); - - open (ICSFILE, $icalendar_file) - || die "Can't open iCalendar file: $icalendar_file"; - - open (NEWICSFILE, ">$icalendar_file.new") - || die "Can't open iCalendar file: $icalendar_file.new"; - - $tasks = ""; - $in_task = 0; - while (<ICSFILE>) { - if ($in_task) { - $tasks .= $_; - - if (m/^END:VTODO/) { - $in_task = 0; - } - - } else { - if (m/^BEGIN:VTODO/) { - print "Found task\n"; - - $tasks .= $_; - $in_task = 1; - } else { - print NEWICSFILE $_; - } - } - } - - close (NEWICSFILE); - close (ICSFILE); - - return $tasks; -} - - -sub OutputTasks { - my ($icalendar_file, $tasks) = @_; - - open (ICSFILE, ">$icalendar_file") - || die "Can't create iCalendar file: $icalendar_file"; - - print ICSFILE <<EOF; -BEGIN:VCALENDAR -CALSCALE - :GREGORIAN -PRODID - :-//Helix Code//NONSGML Evolution Calendar//EN -VERSION - :2.0 -$tasks -END:VCALENDAR -EOF - - close (ICSFILE); -} - - diff --git a/tools/killev b/tools/killev deleted file mode 100755 index dc8920c271..0000000000 --- a/tools/killev +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/perl - -# set to 1 if you want some extra spew -$debug=0; - -# Interfaces of CORBA servers that need to die. -@idls = ("IDL:GNOME/Evolution/ShellComponent:1.0", - "IDL:GNOME/Evolution/CalFactory:1.0", - "IDL:GNOME/Evolution/BookFactory:1.0", - "IDL:GNOME/Evolution/Importer:1.0", - "IDL:GNOME/Evolution/IntelligentImporter:1.0", - "IDL:GNOME/Evolution/Shell:1.0", - "IDL:GNOME/Spell/Checker:0.1"); - - -# IIDs of specific CORBA servers that need to die that don't implement -# useful interfaces (for querying, anyway) -@iids = ("OAFIID:GNOME_Evolution_Calendar_AlarmNotify_Factory", - "OAFIID:GNOME_GtkHTML_Editor_Factory:1.1", - "OAFIID:Bonobo_Moniker_xmldb_Factory"); - -## -## You shouldn't have to change anything below this point -## - -$sysname=`uname -s`; -chop $sysname; - -if ($sysname eq "SunOS") { - $killcmd="pkill"; -} -else { - $killcmd="killall"; -} - -sub kill_exe { - my ($exe_name) = @_; - my $lt_name = "lt-$exe_name"; - my $sub_exe_name = substr ($exe_name, 0, 16); - my $sub_lt_name = substr ($lt_name, 0, 16); - - printf ("killing $exe_name\n"); - - $redirect = "2> /dev/null"; - - print "$killcmd -9 $exe_name\n" if ($debug); - `$killcmd -9 $exe_name $redirect`; - - print "$killcmd -9 $lt_name\n" if ($debug); - `$killcmd -9 $lt_name $redirect`; - - print "$killcmd -9 $sub_exe_name\n" if ($debug); - `$killcmd -9 $sub_exe_name $redirect`; - - print "$killcmd -9 $sub_lt_name\n" if ($debug); - `$killcmd -9 $sub_lt_name $redirect`; -} - -sub kill_exes { - while (($key, $value) = each %things_to_kill) { - &kill_exe($key); - } -} - -sub add_exe { - my ($exe_name) = @_; - $things_to_kill{$exe_name} = $exe_name; -} - -sub add_factory { - my ($factory_iid) = @_; - - open (FACTORY_QUERY, "oaf-client -q -s \"iid == '$factory_iid'\"|"); - while (<FACTORY_QUERY>) { - if (/type exe, location (.*)$/) { - &add_exe ($1); - } - } - close (FACTORY_QUERY); -} - -# we need to do separate queries for iids because cvs OAF loses when -# you do more than one 'iid ==' separated by OR's. It returns a list -# of all CORBA servers. Cool, eh? - -sub run_iid_query { - my $iid_query; - - for ($i = 0; $i < @iids; $i++) { - $iid_query = "iid == '$iids[$i]'"; - - #printf ("$iid_query\n"); - - open (QUERY, "oaf-client -q -s \"$iid_query\"|"); - while (<QUERY>) { - if (/type exe, location (.*)$/) { - &add_exe ($1); - } - elsif (/type factory, location (.*)$/) { - &add_factory ($1); - } - } - close (QUERY); - } -} - -sub run_query { - my ($idl_query, $iid_query, $oaf_query); - - $idl_query = ""; - for ($i = 0; $i < @idls; $i++) { - $idl_query .= "repo_ids.has('$idls[$i]')"; - $idl_query .= " OR " if ($i < @idls - 1); - } - - #$iid_query = ""; - #for ($i = 0; $i < @iids; $i++) { - # $iid_query .= "iid == '$iids[$i]'"; - # $iid_query .= " OR " if ($i < @iids - 1); - #} - - $oaf_query = $idl_query; - #$oaf_query .= " OR $iid_query" if (@iids > 0); - - #printf ("$oaf_query\n"); - - open (QUERY, "oaf-client -q -s \"$oaf_query\"|"); - - while (<QUERY>) { - if (/type exe, location (.*)$/) { - &add_exe ($1); - } - elsif (/type factory, location (.*)$/) { - &add_factory ($1); - } - } - close (QUERY); -} - -&run_query (); -&run_iid_query (); -&kill_exes(); 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; +} |