From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6126 invoked by alias); 14 Feb 2008 21:41:57 -0000 Received: (qmail 6015 invoked by uid 367); 14 Feb 2008 21:41:55 -0000 Date: Thu, 14 Feb 2008 21:41:00 -0000 Message-ID: <20080214214155.5999.qmail@sourceware.org> From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Event-loop on main thread; consistent with other command-line utilities. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 536bdb48547f55541dca484b61a1ba930363e407 X-Git-Newrev: ea824c83ac5c61c806ad4fff8bd7fc304aab8b3a Mailing-List: contact frysk-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-cvs-owner@sourceware.org Reply-To: frysk@sourceware.org X-SW-Source: 2008-q1/txt/msg00214.txt.bz2 The branch, master has been updated via ea824c83ac5c61c806ad4fff8bd7fc304aab8b3a (commit) from 536bdb48547f55541dca484b61a1ba930363e407 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit ea824c83ac5c61c806ad4fff8bd7fc304aab8b3a Author: Andrew Cagney Date: Thu Feb 14 16:41:13 2008 -0500 Event-loop on main thread; consistent with other command-line utilities. frysk-core/frysk/bindir/ChangeLog 2008-02-14 Andrew Cagney * fhpd.java: Run the CLI in a sub-thread and the event-loop on the main thread. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/bindir/ChangeLog | 5 ++ frysk-core/frysk/bindir/fhpd.java | 134 +++++++++++++++++++++--------------- 2 files changed, 83 insertions(+), 56 deletions(-) First 500 lines of diff: diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog index 4167d36..1f83ca9 100644 --- a/frysk-core/frysk/bindir/ChangeLog +++ b/frysk-core/frysk/bindir/ChangeLog @@ -1,3 +1,8 @@ +2008-02-14 Andrew Cagney + + * fhpd.java: Run the CLI in a sub-thread and the event-loop on the + main thread. + 2008-02-13 Andrew Cagney * fexe.java: Update to match Exe. diff --git a/frysk-core/frysk/bindir/fhpd.java b/frysk-core/frysk/bindir/fhpd.java index 11d9d72..b32bfbb 100644 --- a/frysk-core/frysk/bindir/fhpd.java +++ b/frysk-core/frysk/bindir/fhpd.java @@ -39,6 +39,7 @@ package frysk.bindir; +import frysk.event.Event; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -51,19 +52,19 @@ import frysk.util.CoreExePair; import frysk.proc.Manager; import frysk.proc.ProcId; import frysk.util.CommandlineParser; -//import frysk.util.PtyTerminal; import frysk.util.ObservingTerminal; import gnu.classpath.tools.getopt.Option; import gnu.classpath.tools.getopt.OptionException; import frysk.sys.FileDescriptor; public class fhpd { - static int pid; - static File execFile; - static File core; - static File exeFile; - static boolean noExe = false; - static String sysroot; + private static int pid; + private static File execFile; + private static File core; + private static File exeFile; + private static boolean noExe = false; + private static String sysroot; + private static int exitStatus; final static class FhpdCompletor implements Completor { CLI cli; @@ -75,10 +76,74 @@ public class fhpd { } } + // Start the command line in its own thread; but from within + // the event-loop. This ensures that the event-loop is up and + // running before the CLI. + static class CommandLine extends Thread implements Event { + private String line = ""; + private CLI cli; + private ConsoleReader reader; + CommandLine() { + // Construct a command to pass in as initialization + try { + if (pid > 0) + line = "attach " + pid; + else if (execFile != null) + line = "load " + execFile.getCanonicalPath(); + else if (core != null) { + line = "core " + core.getCanonicalPath(); + if (exeFile != null) + line += " " + exeFile.getCanonicalPath(); + else if (noExe) + line +=" -noexe"; + } + if (sysroot != null) + line = line + " -sysroot " + sysroot; + } catch (IOException e) { + System.err.println("Error: " + e); + System.exit(1); + return; + } + // Construct the HPD. + cli = new CLI("(fhpd) ", System.out); + try { + reader = new ConsoleReader + (new FileInputStream(java.io.FileDescriptor.in), + new PrintWriter(System.out), + null, + new ObservingTerminal(FileDescriptor.in)); + } catch (IOException ioe) { + System.out.println("ERROR: Could not create a command line"); + System.out.print(ioe.getMessage()); + System.exit(1); + return; + } + Completor fhpdCompletor = new FhpdCompletor(cli); + reader.addCompletor(fhpdCompletor); + } + public void execute() { + start(); + } + public void run() { + try { + cli.execCommand(line); + while (line != null && ! (line.equals("quit") + || line.equals("q") + || line.equals("exit"))) { + line = reader.readLine(cli.getPrompt()); + cli.execCommand(line); + } + } catch (IOException ioe) { + System.out.println("ERROR: Could not read from command line"); + System.out.print(ioe.getMessage()); + exitStatus = 1; + } + Manager.eventLoop.requestStop(); + } + } + public static void main (String[] args) { - CLI cli; CommandlineParser parser = new CommandlineParser ("fhpd") { - //@Override public void parseCommand (String[] command) { execFile = new File (command[0]); @@ -88,7 +153,6 @@ public class fhpd { + command[0]); } } - //@Override public void parsePids (ProcId[] pids) { pid = pids[0].id; @@ -126,53 +190,11 @@ public class fhpd { parser.setHeader("Usage: fhpd || fhpd || fhpd []"); parser.parse(args); - Manager.eventLoop.start(); - String line = ""; - - try { - if (pid > 0) - line = "attach " + pid; - else if (execFile != null) - line = "load " + execFile.getCanonicalPath(); - else if (core != null) { - line = "core " + core.getCanonicalPath(); - if (exeFile != null) - line += " " + exeFile.getCanonicalPath(); - else if (noExe) - line +=" -noexe"; - } - if (sysroot != null) - line = line + " -sysroot " + sysroot; - } - catch (IOException ignore) {} - - cli = new CLI("(fhpd) ", System.out); - ConsoleReader reader = null; // the jline reader - try { - reader = new ConsoleReader(new FileInputStream(java.io.FileDescriptor.in), - new PrintWriter(System.out), - null, - new ObservingTerminal(FileDescriptor.in)); - } - catch (IOException ioe) { - System.out.println("ERROR: Could not create a command line"); - System.out.print(ioe.getMessage()); - } + Manager.eventLoop.add(new CommandLine()); - Completor fhpdCompletor = new FhpdCompletor(cli); - reader.addCompletor(fhpdCompletor); - try { - cli.execCommand(line); - while (line != null && ! (line.equals("quit") || line.equals("q") - || line.equals("exit"))) { - line = reader.readLine(cli.getPrompt()); - cli.execCommand(line); - } - } - catch (IOException ioe) { - System.out.println("ERROR: Could not read from command line"); - System.out.print(ioe.getMessage()); - } + // Run the event loop then exit when it exits (or crashes). + Manager.eventLoop.run(); + System.exit(exitStatus); } } hooks/post-receive -- frysk system monitor/debugger