Skip to content

Commit

Permalink
Make SIGTSTP work as expected if received during iopen.
Browse files Browse the repository at this point in the history
In ca59eda iopen was created
which handles SIGINT received during a blocked open(). But as
noted in the commit message, SIGTSTP was handled the same as SIGINT.
This commit fixes SIGTSTP to stop the process rather than kill it.
This required changing psignals() to send SIGSTOP rather than SIGTSTP
to the current process to stop it. SIGTSTP doesn't stop the process
even though the handler is set to SIG_DFL. I don't know why, but
it seems harmless enough to use SIGSTOP rather than SIGTSTP.
  • Loading branch information
gwsw committed Jan 18, 2025
1 parent 59452b6 commit 2de3c52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion os.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,14 @@ public ssize_t iread(int fd, unsigned char *buf, size_t len)
public int iopen(constant char *filename, int flags)
{
int r;
if (!opening && SET_JUMP(open_label))
while (!opening && SET_JUMP(open_label))
{
opening = FALSE;
if (sigs & S_STOP)
{
psignals(); /* Stop the process */
continue;
}
sigs = 0;
#if HAVE_SETTABLE_ERRNO
#ifdef EINTR
Expand Down
9 changes: 9 additions & 0 deletions signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,16 @@ public void psignals(void)
LSIGNAL(SIGTTOU, SIG_DFL);
#endif
LSIGNAL(SIGTSTP, SIG_DFL);
/*
* {{ For reasons I don't understand, sending SIGTSTP does not stop
* the process if called from iopen, even though we set SIGTSTP
* to SIG_DFL above. So we use SIGSTOP if possible. }}
*/
#ifdef SIGSTOP
kill(getpid(), SIGSTOP);
#else
kill(getpid(), SIGTSTP);
#endif
/*
* ... Bye bye. ...
* Hopefully we'll be back later and resume here...
Expand Down

0 comments on commit 2de3c52

Please sign in to comment.