-
-
Notifications
You must be signed in to change notification settings - Fork 951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix pty close behavior, signals at exit #2387
Changes from all commits
d8b3df7
ebaba89
edc6016
fc43939
6e5cdaf
7cc11f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,16 +110,7 @@ void tty_release(struct tty *tty) { | |
cond_destroy(&tty->produced); | ||
free(tty); | ||
} else { | ||
// bit of a hack | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bravo for cleaning this up |
||
struct tty *master = NULL; | ||
if (tty->driver == &pty_slave && tty->refcount == 1) | ||
master = tty->pty.other; | ||
unlock(&tty->lock); | ||
if (master != NULL) { | ||
lock(&master->lock); | ||
tty_poll_wakeup(master, POLL_READ | POLL_HUP); | ||
unlock(&master->lock); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -207,11 +198,14 @@ static int tty_device_open(int major, int minor, struct fd *fd) { | |
|
||
static int tty_close(struct fd *fd) { | ||
if (fd->tty != NULL) { | ||
lock(&fd->tty->fds_lock); | ||
struct tty *tty = fd->tty; | ||
lock(&tty->fds_lock); | ||
list_remove_safe(&fd->tty_other_fds); | ||
unlock(&fd->tty->fds_lock); | ||
unlock(&tty->fds_lock); | ||
lock(&ttys_lock); | ||
tty_release(fd->tty); | ||
if (tty->driver->ops->close) | ||
tty->driver->ops->close(tty); | ||
tty_release(tty); | ||
unlock(&ttys_lock); | ||
} | ||
return 0; | ||
|
@@ -414,7 +408,7 @@ static bool pty_is_half_closed_master(struct tty *tty) { | |
struct tty *slave = tty->pty.other; | ||
// only time one tty lock is nested in another | ||
lock(&slave->lock); | ||
bool half_closed = slave->ever_opened && slave->refcount == 1; | ||
bool half_closed = slave->ever_opened && (slave->refcount == 1 || slave->hung_up); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if the refcount check is still necessary? Would the new pty_slave_close do that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed when |
||
unlock(&slave->lock); | ||
return half_closed; | ||
} | ||
|
@@ -450,7 +444,7 @@ static ssize_t tty_read(struct fd *fd, void *buf, size_t bufsize) { | |
struct tty *tty = fd->tty; | ||
lock(&pids_lock); | ||
lock(&tty->lock); | ||
if (tty->hung_up) { | ||
if (tty->hung_up || pty_is_half_closed_master(tty)) { | ||
unlock(&pids_lock); | ||
goto error; | ||
} | ||
|
@@ -546,7 +540,7 @@ static ssize_t tty_read(struct fd *fd, void *buf, size_t bufsize) { | |
static ssize_t tty_write(struct fd *fd, const void *buf, size_t bufsize) { | ||
struct tty *tty = fd->tty; | ||
lock(&tty->lock); | ||
if (tty->hung_up) { | ||
if (tty->hung_up || pty_is_half_closed_master(tty)) { | ||
unlock(&tty->lock); | ||
return _EIO; | ||
} | ||
|
@@ -672,7 +666,7 @@ static int tiocgpgrp(struct tty *tty, pid_t_ *fg_group) { | |
lock(&slave->lock); | ||
} | ||
|
||
if (tty == slave && !tty_is_current(slave) || slave->fg_group == 0) { | ||
if (tty == slave && (!tty_is_current(slave) || slave->fg_group == 0)) { | ||
err = _ENOTTY; | ||
goto error_no_ctrl_tty; | ||
} | ||
|
@@ -800,7 +794,7 @@ void tty_set_winsize(struct tty *tty, struct winsize_ winsize) { | |
|
||
void tty_hangup(struct tty *tty) { | ||
tty->hung_up = true; | ||
tty_poll_wakeup(tty, POLL_READ | POLL_WRITE | POLL_ERR | POLL_HUP); | ||
tty_input_wakeup(tty); | ||
} | ||
|
||
struct dev_ops tty_dev = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
process handle -n 0 -p 1 -s 0 SIGUSR1 SIGTTIN SIGPIPE |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,10 @@ static void log_line(const char *line) { | |
static void log_line(const char *line) { | ||
os_log_fault(OS_LOG_DEFAULT, "%s", line); | ||
} | ||
#elif LOG_HANDLER_STDERR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unclear on the utility of this since the program in ish may also be writing to stderr, but if you found it useful it doesn't hurt to have. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If iSH is running interactively (stdin and stdout are on a tty), then emulated programs are running with both stdout and stderr on the iSH tty driver. (This will be true for iSH.app as well, but writing to stderr might be less useful there.) I hadn't even thought of CLI iSH supporting non-interactive use but yes, it does support that, and logging to stderr would be inappropriate then. |
||
static void log_line(const char *line) { | ||
fprintf(stderr, "%s\n", line); | ||
} | ||
#endif | ||
|
||
static void default_die_handler(const char *msg) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a really tricky bit. Could you add a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.