Skip to content

Commit

Permalink
fixup! add an option to skip draining on tty close
Browse files Browse the repository at this point in the history
  • Loading branch information
mstory21 committed Dec 20, 2024
1 parent 1a71df5 commit 1567573
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ int main(int argc, char *argv[], char *envp[])
{
opts.tty = 1;
opts.ttyopts.ptmx = tty_default_ptmx;
opts.ttyopts.drain = true;

/* 128 is enough to support everything */
struct kvlist kvlist[128];
Expand Down
3 changes: 3 additions & 0 deletions man/bst.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ spacetime process.
- *ptmx*=<path>: use the specified ptmx device (relative to the target root)
to allocated the pty.

- *drain*: whether to drain the tty on stdin closure. The default is true,
so prepend a _'-'_ to this option to prevent draining.

By default bst inherits the parent's terminal device (or lack thereof). Use
the --tty option to allocate a new pty for the child process.

Expand Down
7 changes: 2 additions & 5 deletions tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ void tty_parent_setup(struct tty_opts *opts, int epollfd, int socket)

struct termios tios;

if (opts->drain != NULL) {
info.drain = *opts->drain;
}
info.drain = opts->drain;

info.stdinIsatty = tcgetattr(STDIN_FILENO, &tios) == 0;
if (!info.stdinIsatty && errno != ENOTTY) {
Expand Down Expand Up @@ -669,8 +667,7 @@ static void parse_drain(struct tty_opts *opts, const char *key, const char *val,
if (val != NULL) {
errx(2, "tty option '%s' must have no value", key);
}
opts->drain = malloc(sizeof(bool));
*opts->drain = (key[0] != '-');
opts->drain = (key[0] != '-');
}

static int cmp_flag(const void *key, const void *elem)
Expand Down
2 changes: 1 addition & 1 deletion tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct tty_opts {
const char *ptmx;
struct termios termios;
struct termios neg_termios;
bool *drain;
bool drain;
};

extern const char *tty_default_ptmx;
Expand Down

0 comments on commit 1567573

Please sign in to comment.