From: Andrew Cagney <cagney@redhat.com>
To: Stan Cox <scox@redhat.com>
Cc: Frysk List <frysk@sourceware.org>
Subject: Re: fhpd <program>
Date: Tue, 06 Mar 2007 16:31:00 -0000 [thread overview]
Message-ID: <45ED9747.9000003@redhat.com> (raw)
In-Reply-To: <1172765357.27599.17.camel@multics.rdu.redhat.com>
Hi Stan,
I'm not sure what you mean by never regains I/O control.
One key issue though is wiring the child process up to a
frysk.sys.PseudoTerminal - otherwise the process and fhpd will be
fighting over control of the terminal. Don't forget that there are two
cases to handle:
- fhpd command line where it clearly should create the PTY
- UI where the pty will be part of a Terminal panel and the code should
bind the created process to that
The alternative approach I've seen implemented in the past is to use
job-control like mechanisms where fhpd and the child alternate over who
is the terminal's controlling process; similar to bash and fg/bg et.al.
Since being able to direct the child's I/O to a graphical terminal is a
requirement, and this alternative has no such mechanism, the approach is
considered flawed.
Andrew
Stan Cox wrote:
> This is my rather quick attempt at getting 'fhpd <program>' to work.
> <program> starts as a child of fhpd but fhpd never regains I/O control.
>
> AttachHandler
> -parse <program>
> -requestCreateAttachedProc for <program>
>
> ProcObserver
> -new
>
>
>
> ------------------------------------------------------------------------
>
> /home/scox/frysk/src /home/scox/frysk ~
> Index: frysk-core/frysk/cli/hpd/CLI.java
> ===================================================================
> RCS file: /cvs/frysk/frysk-core/frysk/cli/hpd/CLI.java,v
> retrieving revision 1.45
> diff -u -p -r1.45 CLI.java
> --- frysk-core/frysk/cli/hpd/CLI.java 27 Feb 2007 17:16:43 -0000 1.45
> +++ frysk-core/frysk/cli/hpd/CLI.java 1 Mar 2007 15:59:20 -0000
> @@ -62,13 +62,19 @@ import javax.naming.NameNotFoundExceptio
>
> import frysk.value.InvalidOperatorException;
> import frysk.value.Variable;
> +// import frysk.proc.Action;
> +import frysk.proc.Action;
> import frysk.proc.Host;
> import frysk.proc.Manager;
> import frysk.proc.Proc;
> import frysk.proc.ProcId;
> import frysk.proc.Task;
> +import frysk.proc.TaskObserver;
> import frysk.rt.RunState;
> import frysk.rt.StackFrame;
> +//import frysk.sys.Pid;
> +import frysk.sys.Signal;
> +import frysk.sys.Sig;
> import frysk.rt.LineBreakpoint;
>
>
> @@ -86,6 +92,7 @@ public class CLI
> int stackLevel = 0;
> static Object monitor = new Object();
> static boolean attached;
> + static boolean child_created;
> RunState runState;
> private RunStateObserver runStateObserver;
> private ActionpointTable apTable = new ActionpointTable();
> @@ -356,11 +363,13 @@ public class CLI
> }
> }
> }
> -
> - class AttachHandler implements CommandHandler
> +
> + class AttachHandler implements CommandHandler
> {
> public void handle(Command cmd) throws ParseException
> {
> + String[] args = new String[1];
> +
> refreshSymtab(); // XXX ?
> ArrayList params = cmd.getParameters();
> boolean cli = true;
> @@ -391,27 +400,38 @@ public class CLI
> }
> else if (((String)params.get(idx)).matches("[0-9]+"))
> pid = Integer.parseInt((String)params.get(idx));
> + else args[0] = (String)params.get(idx);
> }
>
> + final ProcObserver procObserver = new ProcObserver();
> if (cli)
> - {
> - Manager.host.requestFindProc(new ProcId(pid), new Host.FindProc() {
> -
> - public void procFound (ProcId procId)
> - {
> -
> - Manager.eventLoop.requestStop();
> - }
> -
> - public void procNotFound (ProcId procId, Exception e)
> - {
> - }});
> - Manager.eventLoop.run();
> - CLIEventLoop eventLoop = new CLIEventLoop();
> - eventLoop.start();
> - }
> + {
> + if (pid > 0)
> + {
> + Manager.host.requestFindProc(new ProcId(pid), new Host.FindProc()
> + {
> + public void procFound (ProcId procId)
> + {
> + Manager.eventLoop.requestStop();
> + }
> +
> + public void procNotFound (ProcId procId, Exception e)
> + {
> + }
> + });
> + }
> + else
> + {
> + Manager.host.requestCreateAttachedProc(args, procObserver);
> + child_created = true;
> + }
> + Manager.eventLoop.run();
> + Manager.eventLoop.start();
> + }
>
> - proc = Manager.host.getProc (new ProcId (pid));
> + proc = Manager.host.getProc(new ProcId(pid));
> + //Proc me = Manager.host.getProc(new ProcId(Pid.get()));
> + //me.getMainTask().requestAddSignaledObserver(procObserver);
> if (proc == null)
> {
> addMessage("The event manager is not running.", Message.TYPE_ERROR);
> @@ -962,6 +982,8 @@ public class CLI
> DetachHandler detachHandler = new DetachHandler();
> Command command = new Command ("detach");
> detachHandler.handle(command);
> + if (child_created)
> + Signal.tkill (pid, Sig.TERM);
> addMessage("Quitting...", Message.TYPE_NORMAL);
> }
> }
> @@ -1232,30 +1254,57 @@ public class CLI
> }
> return result;
> }
> -
> - private static class CLIEventLoop extends Thread
> +
> + private class ProcObserver
> + implements TaskObserver.Attached,
> + TaskObserver.Terminated,
> + TaskObserver.Signaled
> {
> - public void run()
> +
> + public void addedTo (Object o)
> + {
> + }
> +
> + public Action updateAttached (Task taskp)
> + {
> + proc = taskp.getProc();
> + taskp.requestAddTerminatedObserver(this);
> + return Action.CONTINUE;
> + }
> +
> + public void addFailed (Object observable, Throwable w)
> {
> - try
> - {
> - Manager.eventLoop.run();
> - }
> - finally
> - {
> - synchronized (monitor)
> - {
> - monitor.notifyAll();
> - }
> - }
> }
>
> - public void requestStop()
> + public void deletedFrom (Object o)
> + {
> + }
> +
> + public Action updateTerminated(Task task, boolean signal, int exit)
> {
> Manager.eventLoop.requestStop();
> + return Action.CONTINUE;
> }
> - }
>
> + public Action updateSignaled (Task task, int signal)
> + {
> + System.out.println("From PID: " + task.getProc().getPid() + " TID: " + task.getTid());
> + switch (signal)
> + {
> + case 2:
> + System.out.println("SIGINT detected");
> + break;
> + case 3:
> + System.out.println("SIGQUIT detected");
> + break;
> + case 15:
> + System.out.println("SIGTERM detected");
> + break;
> + }
> + return Action.CONTINUE;
> + }
> + }
> +
> private class RunStateObserver implements Observer
> {
> public void update(Observable observable, Object arg)
>
next prev parent reply other threads:[~2007-03-06 16:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-01 16:15 Stan Cox
2007-03-06 16:31 ` Andrew Cagney [this message]
2007-03-07 13:43 ` Tim Moore
2007-03-07 21:51 ` Andrew Cagney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45ED9747.9000003@redhat.com \
--to=cagney@redhat.com \
--cc=frysk@sourceware.org \
--cc=scox@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).