[orca] More work on the orca shellscriptectomy



commit cee3a48e6757deb2705dc3a040b9d7defcd69383
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Fri May 11 09:54:08 2012 -0400

    More work on the orca shellscriptectomy

 src/orca/orca.in |   53 +----------------------------------------------------
 src/orca/orca.py |   30 +++++++++++++++++++++++-------
 2 files changed, 24 insertions(+), 59 deletions(-)
---
diff --git a/src/orca/orca.in b/src/orca/orca.in
index 49a1743..e8e5ceb 100644
--- a/src/orca/orca.in
+++ b/src/orca/orca.in
@@ -76,39 +76,6 @@ restoreXmodmap()
     fi
 }
 
-# Cleans up any orca-related processes that might be running,
-# restricting it to those processes owned by the user. These include
-# orca itself, any speech synthesis drivers, and festival processes
-# running in server mode.
-#
-cleanup()
-{
-
-    # Check if we should force orca to quit, or just ask it nicely.
-    # kill -15, will give orca time to shutdown gracefully
-    # kill -9 will terminate immediately
-    if [ "$1" = "-f" ];then
-        KILLARG="-KILL"
-    else
-        KILLARG="-TERM"
-    fi
-    USERID=$(id -u)
-    PATTERN="orca[.]orca|festival [-][-]server"
-
-    pkill $KILLARG -U $USERID -f "$PATTERN"
-}
-
-waitForCleanup()
-{
-    while $(cleanup) ; do
-        sleep 0.5
-    done
-}
-
-trap cleanup HUP QUIT TERM INT ABRT
-
-# Runs orca.
-#
 runOrca()
 {
     exec_prefix= prefix@
@@ -119,22 +86,4 @@ runOrca()
     restoreXmodmap
 }
 
-if [ `echo $ARGS | grep -c "\-q"` -gt 0 ] ; then
-    # If the user has done -q or --quit, that means to tell any
-    # existing orca process to quit.  So, we just do a cleanup.
-    #
-    cleanup
-elif [ `echo $ARGS | egrep -c " \-f|^\-f|\-\-forcequit"` -gt 0 ] ; then
-    # If the user has done -f or --forcequit, that means 
-    # that Orca has probably hung badly, and needs to be killed with force.
-    #
-    cleanup "-f"
-else
-    # Allow a --replace to kill other orca processes.
-    #
-    if [ `echo $ARGS | grep -c "\-\-replace"` -gt 0 ] ; then
-        waitForCleanup
-    fi
-
-    runOrca
-fi
+runOrca
diff --git a/src/orca/orca.py b/src/orca/orca.py
index 31dc309..0c22e8a 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -1373,9 +1373,8 @@ def examineProcesses():
         debug.println(
             debug.LEVEL_ALL, '%3i. %s (pid: %s) %s' % (i+1, name, pid, cmd))
 
-def multipleOrcas():
-    """Returns True if multiple instances of Orca are running
-    which are owned by the same user."""
+def otherOrcas():
+    """Returns the pid of any other instances of Orca owned by this user."""
 
     openFile = os.popen('pgrep -u %s orca' % os.getuid())
     pids = openFile.read()
@@ -1384,7 +1383,18 @@ def multipleOrcas():
 
     pid = os.getpid()
     ppid = os.getppid()
-    return len([p for p in orcas if p not in [pid, ppid]]) > 0
+    return [p for p in orcas if p not in [pid, ppid]]
+
+def multipleOrcas():
+    """Returns True if multiple instances of Orca are running which are
+    are owned by this user."""
+
+    return len(otherOrcas()) > 0
+
+def cleanup(sigval):
+    """Tries to clean up any other running Orca instances owned by this user."""
+
+    map(lambda x: os.kill(x, sigval), otherOrcas())
 
 def cleanupGarbage():
     """Cleans up garbage on the heap."""
@@ -1417,16 +1427,22 @@ def main():
     signal.signal(signal.SIGSEGV, abortOnSignal)
 
     if multipleOrcas():
-        if not options.replace:
+        if presentInvalidOptions(invalidOpts):
+            die(0)
+        elif options.replace or options.quit or options.forceQuit:
+            cleanup(signal.SIGKILL)
+        else:
             # Translators: This message is presented to the user when
             # he/she tries to launch Orca, but Orca is already running.
             print(_('Another Orca process is already running for this ' \
                     'session.\n Run "orca --replace" to replace that ' \
                     'process with a new one.'))
             return 1
-        if presentInvalidOptions(invalidOpts):
-            die(0)
 
+    if options.quit:
+        die(signal.SIGTERM)
+    elif options.forceQuit:
+        die(signal.SIGKILL)
 
     _commandLineSettings.update(options.convertToSettings())
     for profile in options.profiles:



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