Sujet : Re: Initiate command in another shell session?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shellDate : 13. Mar 2025, 17:49:48
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250313093734.372@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-03-13, Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
The question occurred to me whether it would be possible to remotely
execute a command as if started from another shell session *in* that
shell session.
The target shell session has to run some service loop listening for
these requests, on a pipe or something.
On top of that you can build remote procedure calls.
Running any command specified by the caller is equivalent to having
"eval" available as a remote procedure call.
Or something lesser: running any simple command (command name
with arguments). When the function unpacks the arguments,
it can subject them to some validation, checking for allowed
commands or command/argument combinations.
About the service loop, we don't have threads in the popular
shells like Bash.
If it's all one the same machine, you could set a trap for a
signal in the target shell. Then when the caller deposits a
message in the message box (however that is implemented)
it kills that shell with the signal. The trap handler will
then dispatch the RPC.
If the target shell is interactive, you might want it so that
the commands are not immediately dispatched while that shell
is executing code, only when it's ide. (And by the way, when the shell
is suspended waiting for an external command, like an editor to exit, it
won't be able to take RPCs).
The trap handler can check a global flag indicating whether the
shell is idle (OK to dispatch command now) or busy (queue
the command, to be run when it goes out of the busy state).
As you can guess, my thinking here is influenced by having
worked on the Basta extension, which updates the status line
in response to timer signals.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca