zsh-users
 help / color / mirror / code / Atom feed
From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-users@zsh.org
Subject: Re: How to propagate SIGTERM to the foreground job, if any?
Date: Tue, 23 Apr 2024 17:17:17 +0200	[thread overview]
Message-ID: <20240423151717.GA82287@qaa.vinc17.org> (raw)
In-Reply-To: <CAH+w=7aWJ0BZ1tTdjih8H5SzP1RRBfBdgFcb4Y2JDvwt75GoWA@mail.gmail.com>

I think that I should start to test with something simpler, with
a command like

  unison -sshcmd ~/scripts/ssh ~/testdir ssh://remote_host/testdir

For ~/scripts/ssh, the following works with I type Ctrl-C
when ssh-add asks for the passphrase:

------------------------------------------------------------
#!/usr/bin/env zsh                                                              

unset DISPLAY

setopt TRAPS_ASYNC
trap 'echo term >&2; kill %1; exit' TERM INT

ssh-add file1 file2 file3

echo end... >&2
exit
------------------------------------------------------------

But %1 might not be the right job in more complex cases.
BTW, I'm wondering why %1 works, but not %%.

Moreover "term" is output twice. Why?

The following, based on what you proposed, also works:

------------------------------------------------------------
#!/usr/bin/env zsh

unset DISPLAY

setopt TRAPS_ASYNC
trap 'echo term >&2; kill $e; exit' TERM INT

ssh-add file1 file2 file3 &
e=$!
wait $e

echo end... >&2
exit
------------------------------------------------------------

This time, "term" is output 1, 2 or 3 times.

But these solutions do not work when ssh-add is in a zsh function,
even in a simple case like:

f()
{
  ssh-add file1 file2 file3
}

and use "f" instead of "ssh-add file1 file2 file3".

Is this a bug or is there any reason?

On 2024-04-21 17:41:38 -0700, Bart Schaefer wrote:
> Try this:
>   trap 'setopt MONITOR HUP NOCHECKJOBS; exit' TERM

This doesn't work at all with the above test.

> >   ssh-add file1 file2 file3 &
> >
> > ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
> > ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
> > ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
> 
> That's ... interesting.  The error makes it look like ssh-askpass is
> what's not being found, but it's probably choking trying to open a
> terminal.  I can think of some possible ways to fake it but perhaps
> with the above MONITOR tweak it isn't necessary.

I don't remember what I did exactly. These errors occur if DISPLAY
is set (with my usual wrapper, I unset DISPLAY, so that there may
be another cause).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


  reply	other threads:[~2024-04-23 15:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 17:17 Vincent Lefevre
2024-04-19 18:30 ` Bart Schaefer
2024-04-19 19:00   ` Vincent Lefevre
2024-04-19 20:06     ` Bart Schaefer
2024-04-19 21:32       ` Vincent Lefevre
2024-04-21  4:09         ` Bart Schaefer
2024-04-21 17:29           ` Vincent Lefevre
2024-04-21 17:43             ` Vincent Lefevre
2024-04-21 21:25               ` Bart Schaefer
2024-04-21 23:59                 ` Vincent Lefevre
2024-04-22  0:41                   ` Bart Schaefer
2024-04-23 15:17                     ` Vincent Lefevre [this message]
2024-04-23 17:32                       ` Bart Schaefer

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=20240423151717.GA82287@qaa.vinc17.org \
    --to=vincent@vinc17.net \
    --cc=zsh-users@zsh.org \
    /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.
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).