zsh-users
 help / color / mirror / code / Atom feed
* signal handling via ssh
@ 2011-04-01  9:27 Sebastian Stark
  2011-04-01 14:14 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Stark @ 2011-04-01  9:27 UTC (permalink / raw)
  To: zsh-users


Dear list,

I have a question that is maybe off-topic, so please forgive me if it turns out that this is not at all zsh or even shell-related.

If I do the following:

  ssh -t $server "less /var/log/syslog; exec \$SHELL -l"

end then press 'q' I end up on $server in a login shell. That's what I want.

However, If I do this:

  ssh -t $server "less +F /var/log/syslog; exec \$SHELL -l"

and press '^C' I'm logged off from $server. The '^C' does not seem to go through to only the less process.

How can I achieve something like the above but such that ^C does not end the ssh connection?

Thanks for any help.


Sebastian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: signal handling via ssh
  2011-04-01  9:27 signal handling via ssh Sebastian Stark
@ 2011-04-01 14:14 ` Bart Schaefer
  2011-04-04  9:25   ` Sebastian Stark
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2011-04-01 14:14 UTC (permalink / raw)
  To: zsh-users

On Apr 1, 11:27am, Sebastian Stark wrote:
}
}   ssh -t $server "less +F /var/log/syslog; exec \$SHELL -l"
} 
} and press '^C' I'm logged off from $server. The '^C' does not seem to
} go through to only the less process.
}
} How can I achieve something like the above but such that ^C does not
} end the ssh connection?

The ^C is a tty-driver interrupt, which means it's sent to the "process
group leader" which controls the pseudo-tty allocated by ssh -t.  In
this example the group leader is the entire shell process that has been
invoked to run those two commands in sequence.

So what you need to do is stop the group leader from reacting to the
signal while allowing "less" to do so.  You can do the first with the
trap command, but that ignores the signal in all sub-processes as well,
so you have to restore the signal handling in a new process created
explicitly for that purpose.  It all comes out like this:

ssh -t $server "trap '' INT; \
                (trap - INT && exec less +F /var/log/syslog); \
	        exec \$SHELL -l"

-- 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: signal handling via ssh
  2011-04-01 14:14 ` Bart Schaefer
@ 2011-04-04  9:25   ` Sebastian Stark
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Stark @ 2011-04-04  9:25 UTC (permalink / raw)
  To: zsh-users


Am 01.04.2011 um 16:14 schrieb Bart Schaefer:

> On Apr 1, 11:27am, Sebastian Stark wrote:
> }
> }   ssh -t $server "less +F /var/log/syslog; exec \$SHELL -l"
> } 
> } and press '^C' I'm logged off from $server. The '^C' does not seem to
> } go through to only the less process.
> }
> } How can I achieve something like the above but such that ^C does not
> } end the ssh connection?
> 
> The ^C is a tty-driver interrupt, which means it's sent to the "process
> group leader" which controls the pseudo-tty allocated by ssh -t.  In
> this example the group leader is the entire shell process that has been
> invoked to run those two commands in sequence.
> 
> So what you need to do is stop the group leader from reacting to the
> signal while allowing "less" to do so.  You can do the first with the
> trap command, but that ignores the signal in all sub-processes as well,
> so you have to restore the signal handling in a new process created
> explicitly for that purpose.  It all comes out like this:
> 
> ssh -t $server "trap '' INT; \
>                (trap - INT && exec less +F /var/log/syslog); \
> 	        exec \$SHELL -l"

Works for me, thank you very much for both, code and explanation!


Sebastian


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-04-04  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-01  9:27 signal handling via ssh Sebastian Stark
2011-04-01 14:14 ` Bart Schaefer
2011-04-04  9:25   ` Sebastian Stark

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).