From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28680 invoked by alias); 27 Feb 2008 17:40:02 -0000 Received: (qmail 28589 invoked by uid 9708); 27 Feb 2008 17:40:00 -0000 Date: Wed, 27 Feb 2008 17:40:00 -0000 Message-ID: <20080227174000.28574.qmail@sourceware.org> From: tthomas@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Add shell command to hpd. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: eea07e127e177d7620874e979e4476f3f3f62cf6 X-Git-Newrev: b7b5cd5297f20f4946c1913a45bfddcb837cbf00 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/msg00265.txt.bz2 The branch, master has been updated via b7b5cd5297f20f4946c1913a45bfddcb837cbf00 (commit) via 0e9e76764cb8d9eb120428282a1e91c221dde6a4 (commit) via 16e5c9150876994e9f028bff29778e0048161bb2 (commit) from eea07e127e177d7620874e979e4476f3f3f62cf6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit b7b5cd5297f20f4946c1913a45bfddcb837cbf00 Author: Teresa Date: Wed Feb 27 12:23:13 2008 -0500 Add shell command to hpd. frysk-core/frysk/hpd/ChangeLog: 2008-02-27 Teresa Thomas * ShellCommand.java: New file. * TestShellCommand.java: New file. * TopLevelCommand.java (TopLevelCommand): Add shell command. commit 0e9e76764cb8d9eb120428282a1e91c221dde6a4 Author: Teresa Date: Wed Feb 27 12:19:42 2008 -0500 Add class to handle commands that should not interpret options. frysk-core/frysk/hpd/ChangeLog: 2008-02-27 Teresa Thomas * NoOptsCommand.java: New file. commit 16e5c9150876994e9f028bff29778e0048161bb2 Author: Teresa Date: Wed Feb 27 12:15:54 2008 -0500 Add functions to set and reset terminal settings. frysk-core/frysk/util/ChangeLog: 2008-02-27 Teresa Thomas * PtyTerminal.java (setToInitConsole): New. (setToCharBufferedConsole): New. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/hpd/ChangeLog | 8 ++ .../frysk/hpd/NoOptsCommand.java | 63 +++++----- frysk-core/frysk/hpd/ShellCommand.java | 129 ++++++++++++++++++++ .../funit-libcall.c => hpd/TestShellCommand.java} | 31 ++--- frysk-core/frysk/hpd/TopLevelCommand.java | 1 + frysk-core/frysk/util/ChangeLog | 5 + frysk-core/frysk/util/PtyTerminal.java | 36 +++++- 7 files changed, 217 insertions(+), 56 deletions(-) copy frysk-sys/frysk/sys/Pipe.java => frysk-core/frysk/hpd/NoOptsCommand.java (73%) create mode 100644 frysk-core/frysk/hpd/ShellCommand.java copy frysk-core/frysk/{pkglibdir/funit-libcall.c => hpd/TestShellCommand.java} (84%) First 500 lines of diff: diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog index 1199c61..01b7a46 100644 --- a/frysk-core/frysk/hpd/ChangeLog +++ b/frysk-core/frysk/hpd/ChangeLog @@ -1,3 +1,11 @@ +2008-02-27 Teresa Thomas + + * ShellCommand.java: New file. + * TestShellCommand.java: New file. + * TopLevelCommand.java (TopLevelCommand): Add shell command. + + * NoOptsCommand.java: New file. + 2008-02-26 Andrew Cagney * LoadCommand.java (load(Proc,CLI,String)): New. diff --git a/frysk-sys/frysk/sys/Pipe.java b/frysk-core/frysk/hpd/NoOptsCommand.java similarity index 73% copy from frysk-sys/frysk/sys/Pipe.java copy to frysk-core/frysk/hpd/NoOptsCommand.java index bd88db4..7edc566 100644 --- a/frysk-sys/frysk/sys/Pipe.java +++ b/frysk-core/frysk/hpd/NoOptsCommand.java @@ -37,46 +37,43 @@ // version and license this file solely under the GPL without // exception. -package frysk.sys; +package frysk.hpd; /** - * Open a Pipe. + * Handle commands that should not interpret options. */ -public class Pipe -{ - /** - * Use this end for reading. - */ - public final FileDescriptor in; - /** - * Use this end for writing. - */ - public final FileDescriptor out; - +public abstract class NoOptsCommand extends Command { + + private final String syntax; + private final String full; + + public NoOptsCommand(String description, String syntax, String full) { + super (description, syntax, full); + this.syntax = syntax; + this.full = full; + } + /** - * Create a bi-directional pipe. + * Treat option help as special case. */ - public Pipe () - { - FileDescriptor[] filedes = pipe(); - in = filedes[0]; - out = filedes[1]; - } - - public String toString () - { - return "[" + out.getFd () + "|" + in.getFd () + "]"; - } - - public void close () - { - in.close (); - out.close (); + void interpret(CLI cli, Input input) { + + if (input.parameter(0).equals("-help")) { + help (cli, input); + return; + } + interpretCommand(cli, input); } /** - * Really create the pipe. + * Interpret commands. */ - private native FileDescriptor[] pipe (); -} + abstract void interpretCommand(CLI cli, Input input); + + void help(CLI cli, Input input) { + cli.outWriter.print(syntax); + cli.outWriter.println(); + cli.outWriter.println(full); + } +} \ No newline at end of file diff --git a/frysk-core/frysk/hpd/ShellCommand.java b/frysk-core/frysk/hpd/ShellCommand.java new file mode 100644 index 0000000..14345e3 --- /dev/null +++ b/frysk-core/frysk/hpd/ShellCommand.java @@ -0,0 +1,129 @@ +// This file is part of the program FRYSK. +// +// Copyright 2008 Red Hat Inc. +// +// FRYSK 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; version 2 of the License. +// +// FRYSK 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 FRYSK; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// In addition, as a special exception, Red Hat, Inc. gives You the +// additional right to link the code of FRYSK with code not covered +// under the GNU General Public License ("Non-GPL Code") and to +// distribute linked combinations including the two, subject to the +// limitations in this paragraph. Non-GPL Code permitted under this +// exception must only link to the code of FRYSK through those well +// defined interfaces identified in the file named EXCEPTION found in +// the source code files (the "Approved Interfaces"). The files of +// Non-GPL Code may instantiate templates or use macros or inline +// functions from the Approved Interfaces without causing the +// resulting work to be covered by the GNU General Public +// License. Only Red Hat, Inc. may make changes or additions to the +// list of Approved Interfaces. You must obey the GNU General Public +// License in all respects for all of the FRYSK code and other code +// used in conjunction with FRYSK except the Non-GPL Code covered by +// this exception. If you modify this file, you may extend this +// exception to your version of the file, but you are not obligated to +// do so. If you do not wish to provide this exception without +// modification, you must delete this exception statement from your +// version and license this file solely under the GPL without +// exception. + +package frysk.hpd; + +import java.util.List; + +import frysk.proc.Action; +import frysk.proc.Manager; +import frysk.proc.Task; +import frysk.proc.TaskObserver; +import frysk.sys.FileDescriptor; +import frysk.util.CountDownLatch; +import frysk.util.PtyTerminal; +import frysk.isa.signals.Signal; + +class ShellCommand extends NoOptsCommand { + + ShellCommand() { + super( "Execute a shell command.", "shell ", + "The shell command invokes a bash shell and executes the " + + "command string."); + } + + int complete(CLI cli, Input buffer, int cursor, List candidates) { + return -1; + } + + void interpretCommand(CLI cli, Input cmd) { + + if (cmd.size() == 0) { + throw new InvalidCommandException ("Missing command string"); + } + // Use latch to keep fhpd waiting until + // shell command terminates. + final CountDownLatch latch = new CountDownLatch(1); + + String[] command = new String [3]; + command [0] = "/bin/bash"; + command[1] = "-c"; + command[2] = cmd.toString().substring(cmd.toString().indexOf(" ")); + + // Set terminal to initial setting. + PtyTerminal.setToInitConsole(FileDescriptor.in); + + // Request an attached proc to execute command. + Manager.host.requestCreateAttachedProc(null, null, null, command, + new TaskObserver.Attached() + { + public Action updateAttached (Task task) + { + // On termination of command, resume fhpd. + task.requestAddTerminatedObserver(new TaskObserver.Terminated () + { + public Action updateTerminated(Task task, Signal signal, int value) { + // Count down the latch so fhpd can continue + latch.countDown(); + return Action.CONTINUE; + } + public void addFailed (Object observable, Throwable w) { + } + public void addedTo(Object observable) { + } + public void deletedFrom(Object observable) { + } + + }); + return Action.CONTINUE; + } + + public void addFailed (Object observable, Throwable w) { + throw new RuntimeException("addFailed: " + observable + " cause: " + w); + } + public void addedTo(Object observable) { + } + public void deletedFrom(Object observable) { + } + }); + + // Make fhpd wait till shell command is complete. + while (true) { + try { + latch.await(); + break; + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage()); + } + } + + // Set terminal back to fhpd settings, i.e. character buffered. + PtyTerminal.setToCharBufferedConsole(FileDescriptor.in); + } +} diff --git a/frysk-core/frysk/pkglibdir/funit-libcall.c b/frysk-core/frysk/hpd/TestShellCommand.java similarity index 84% copy from frysk-core/frysk/pkglibdir/funit-libcall.c copy to frysk-core/frysk/hpd/TestShellCommand.java index 578b0a2..2bb44e0 100644 --- a/frysk-core/frysk/pkglibdir/funit-libcall.c +++ b/frysk-core/frysk/hpd/TestShellCommand.java @@ -37,22 +37,19 @@ // version and license this file solely under the GPL without // exception. -#include -#include +package frysk.hpd; -static volatile long tmp = 0; +/** + * This class tests the "shell" command. + */ -void -foo () -{ - struct timeval t; - gettimeofday (&t, NULL); // _testIStepThrough_ - tmp += t.tv_usec; -} - -int -main (int argc, char **argv) -{ - foo (); - exit (0); -} +public class TestShellCommand extends TestLib { + + public void testShellCommand() { + e = new HpdTestbed(); + e.sendCommandExpectPrompt("shell echo $$", ".*[0-9]+.*"); + e.sendCommandExpectPrompt("shell blahBLAHblah", ".*command not found.*"); + e.sendCommandExpectPrompt("shell -help", ".*shell .*"); + e.close(); + } +} \ No newline at end of file diff --git a/frysk-core/frysk/hpd/TopLevelCommand.java b/frysk-core/frysk/hpd/TopLevelCommand.java index b2013e2..d6d14bc 100644 --- a/frysk-core/frysk/hpd/TopLevelCommand.java +++ b/frysk-core/frysk/hpd/TopLevelCommand.java @@ -104,6 +104,7 @@ public class TopLevelCommand extends MultiLevelCommand { add(quit, "quit"); add(new RegsCommand(), "regs"); add(new RunCommand(), "r|un"); + add(new ShellCommand(), "shell"); add(new StackCommands.Down(), "d|own"); add(new StackCommands.Frame(), "frame"); add(new StackCommands.Up(), "u|p"); diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog index df737d5..8031682 100644 --- a/frysk-core/frysk/util/ChangeLog +++ b/frysk-core/frysk/util/ChangeLog @@ -1,3 +1,8 @@ +2008-02-27 Teresa Thomas + + * PtyTerminal.java (setToInitConsole): New. + (setToCharBufferedConsole): New. + 2008-02-27 Andrew Cagney * Util.java (getProcFromCoreFile(File)): Delete. diff --git a/frysk-core/frysk/util/PtyTerminal.java b/frysk-core/frysk/util/PtyTerminal.java index 43d60c7..2d6f0d9 100644 --- a/frysk-core/frysk/util/PtyTerminal.java +++ b/frysk-core/frysk/util/PtyTerminal.java @@ -101,12 +101,9 @@ public class PtyTerminal throws IOException, InterruptedException { final Termios initialTermios = new Termios(fd); - final Termios termios = new Termios(fd); - // set the console to be character-buffered instead of line-buffered - termios.set(Local.CANONICAL, false); - termios.set(Local.ECHO_INPUT, false); - termios.set(Special.NON_CANONICAL_READ_MINIMUM, (char)1); - termios.set(fd); + // set the console to be character-buffered instead of line-buffered + setToCharBufferedConsole(fd); + // at exit, restore the original tty configuration try { @@ -123,6 +120,33 @@ public class PtyTerminal System.out.println(ame); } } + + /** + * Set console to initial terminal settings. + */ + public static void setToInitConsole (FileDescriptor fd) + { + final Termios termios = new Termios(fd); + // set the console to be line-buffered + termios.set(Local.CANONICAL, true); + termios.set(Local.ECHO_INPUT, true); + termios.set(Special.NON_CANONICAL_READ_MINIMUM, ' '); + termios.set(fd); + } + + /** + * Set console to character buffered settings. Used + * for fhpd. + */ + public static void setToCharBufferedConsole (FileDescriptor fd) + { + final Termios termios = new Termios(fd); + // set the console to be character-buffered + termios.set(Local.CANONICAL, false); + termios.set(Local.ECHO_INPUT, false); + termios.set(Special.NON_CANONICAL_READ_MINIMUM, (char)1); + termios.set(fd); + } public int readVirtualKey (InputStream in) throws IOException hooks/post-receive -- frysk system monitor/debugger