[orca] Fix for bgo#598917 - Orca Multiple Instances



commit e7d3b242d803c3495cfd5d9904a3e4acc3b507c6
Author: Willie Walker <william walker sun com>
Date:   Fri Nov 13 19:54:30 2009 -0500

    Fix for bgo#598917 -  Orca Multiple Instances
    
    This adds/honors a new --replace option.  Orca will now only kill
    existing Orca processes if the --replace option is used.

 docs/man/orca.1  |   21 ++++++++++++++++-----
 src/orca/orca.in |   49 +++++++++++++++++++++++++++++--------------------
 src/orca/orca.py |   20 ++++++++------------
 3 files changed, 53 insertions(+), 37 deletions(-)
---
diff --git a/docs/man/orca.1 b/docs/man/orca.1
index d8cdd0c..5fd4cbf 100644
--- a/docs/man/orca.1
+++ b/docs/man/orca.1
@@ -113,12 +113,23 @@ displays
 .B orca
 help and exits.
 .TP
-.B \-q, --quit
-Quit
-.BR orca .
+.B \--replace
+Replace a currently running
+.BR orca
+process.  By default, if
+.BR orca
+detects an existing
+.BR orca
+process for the same session, it will not start a new
+.BR orca
+process.  This option will kill and cleanup after any existing
+.BR orca
+process and then start a new
+.BR orca
+in its place.
 .TP
-.B \-z
-Do not automatically kill other orca processes.
+.B \-q, --quit
+Kill and cleanup after any existing Orca process.
 
 .SH KEYBOARD SETTINGS
 Orca provides two keyboard modes, Desktop and Laptop keyboard layout. The
diff --git a/src/orca/orca.in b/src/orca/orca.in
index f9c623a..72a8b39 100644
--- a/src/orca/orca.in
+++ b/src/orca/orca.in
@@ -144,6 +144,12 @@ if [ `echo $ARGS | grep -c "\-q"` -gt 0 ] ; then
     #
     cleanup
 else
+    # Allow a --replace to kill other orca processes.
+    #
+    if [ `echo $ARGS | grep -c "\-\-replace"` -gt 0 ] ; then
+	cleanup
+    fi
+
     # If the user passed in a flag that results in orca only
     # outputting data to the console, don't kill any other orca
     # process.  We do this by looking for flags that *should* result
@@ -153,30 +159,33 @@ else
     # text is emitted and the other orca is not killed.
     #
     if [ "x$ARGS" = "x" ] ; then
-        CLEANUP=1
+        WONT_EXIT=1
     else
-        CLEANUP=`echo $ARGS | egrep -c "\-s|\-t|\-n|\-u|\-e|\-d"`
+	WONT_EXIT=`echo $ARGS | egrep -c "\-s|\-t|\-n|\-u|\-e|\-d"`
     fi
 
-    # Allow a -z override to avoid cleanup.
+    # Do not run if another Orca is already running.
     #
-    if [ `echo $ARGS | grep -c "\-z"` -gt 0 ] ; then
-	CLEANUP=0
+    if [ "x$DBUS_SESSION_BUS_ADDRESS" != "x" ] && [ $WONT_EXIT -gt 0 ] ; then
+	IFS=:
+	DBUSSENDCMD=
+	for dir in $PATH:/usr/sfw/bin:/usr/local/bin; do
+	    test -x "$dir/dbus-send" && {
+		DBUSSENDCMD="$dir/dbus-send"
+		break
+	    }
+	done
+	if [ "x$DBUSSENDCMD" != "x" ] ; then
+	    $DBUSSENDCMD --reply-timeout=5000 --print-reply \
+		--dest=org.gnome.Orca / org.freedesktop.DBus.Peer.Ping \
+		> /dev/null 2>&1
+	    if [ "$?" -eq 0 ] ; then
+		echo "Another Orca process is already running for this session."
+		echo "Run \"orca --replace\" if you want to replace the current"
+		echo "process with a new one."
+		exit
+	    fi
+	fi
     fi
-
-    # Clean up before running orca to get anything that might
-    # be laying around.
-    #
-    if [ $CLEANUP -gt 0 ] ; then
-	cleanup
-    fi
-
     runOrca
-
-    # Clean up after running orca in case things were not 
-    # shutdown cleanly (e.g., speech).
-    #
-    if [ $CLEANUP -gt 0 ] ; then
-	cleanup
-    fi
 fi
diff --git a/src/orca/orca.py b/src/orca/orca.py
index 905abd8..f13556e 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -88,9 +88,6 @@ from input_event import KeyboardEvent
 from input_event import MouseButtonEvent
 from input_event import keyEventToString
 
-if settings.useDBus:
-    import dbusserver
-
 from orca_i18n import _           # for gettext support
 
 if settings.debugMemoryUsage:
@@ -1542,18 +1539,16 @@ def usage():
     print "-q, --quit                   " + \
           _("Quits Orca (if shell script used)")
 
-    # Translators: this is the Orca command line option that will enable to
-    # to launch multiple instances of orca on multi-head computers. If this
-    # command line option is specified, the script will not kill any other
-    # instances of Orca that are already running.
+    # Translators: this is the Orca command line option to tell Orca to
+    # replace any existing Orca process(es) that might be running.
     #
-    print "-z                           " +\
-          _("Orca does not kill other running orca processes")
-    print
+    print "--replace                    " +\
+          _("Replace a currently running Orca")
 
     # Translators: this is text being sent to a terminal and we want to
     # keep the text lines within terminal boundaries.
     #
+    print
     print _("If Orca has not been previously set up by the user, Orca\n" \
             "will automatically launch the preferences set up unless\n" \
             "the -n or --no-setup option is used.")
@@ -1635,7 +1630,7 @@ def main():
         #
         opts, args = getopt.getopt(
             arglist,
-            "?zstnvld:e:u:",
+            "?stnvld:e:u:",
             ["help",
              "user-prefs-dir=",
              "enable=",
@@ -1647,7 +1642,8 @@ def main():
              "list-apps",
              "debug",
              "debug-file=",
-             "version"])
+             "version",
+             "replace"])
         for opt, val in opts:
             if opt in ("-u", "--user-prefs-dir"):
                 userPrefsDir = val.strip()



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