|
1 |
| -/* $OpenBSD: channels.c,v 1.426 2023/01/06 02:47:18 djm Exp $ */ |
| 1 | +/* $OpenBSD: channels.c,v 1.427 2023/01/18 02:00:10 djm Exp $ */ |
2 | 2 | /*
|
3 | 3 | * Author: Tatu Ylonen <[email protected]>
|
4 | 4 | * Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
|
@@ -417,16 +417,19 @@ channel_register_fds(struct ssh *ssh, Channel *c, int rfd, int wfd, int efd,
|
417 | 417 | */
|
418 | 418 | if (rfd != -1 && !isatty(rfd) &&
|
419 | 419 | (val = fcntl(rfd, F_GETFL)) != -1 && !(val & O_NONBLOCK)) {
|
| 420 | + c->restore_flags[0] = val; |
420 | 421 | c->restore_block |= CHANNEL_RESTORE_RFD;
|
421 | 422 | set_nonblock(rfd);
|
422 | 423 | }
|
423 | 424 | if (wfd != -1 && !isatty(wfd) &&
|
424 | 425 | (val = fcntl(wfd, F_GETFL)) != -1 && !(val & O_NONBLOCK)) {
|
| 426 | + c->restore_flags[1] = val; |
425 | 427 | c->restore_block |= CHANNEL_RESTORE_WFD;
|
426 | 428 | set_nonblock(wfd);
|
427 | 429 | }
|
428 | 430 | if (efd != -1 && !isatty(efd) &&
|
429 | 431 | (val = fcntl(efd, F_GETFL)) != -1 && !(val & O_NONBLOCK)) {
|
| 432 | + c->restore_flags[2] = val; |
430 | 433 | c->restore_block |= CHANNEL_RESTORE_EFD;
|
431 | 434 | set_nonblock(efd);
|
432 | 435 | }
|
@@ -510,10 +513,16 @@ channel_close_fd(struct ssh *ssh, Channel *c, int *fdp)
|
510 | 513 | if (fd == -1)
|
511 | 514 | return 0;
|
512 | 515 |
|
513 |
| - if ((*fdp == c->rfd && (c->restore_block & CHANNEL_RESTORE_RFD) != 0) || |
514 |
| - (*fdp == c->wfd && (c->restore_block & CHANNEL_RESTORE_WFD) != 0) || |
515 |
| - (*fdp == c->efd && (c->restore_block & CHANNEL_RESTORE_EFD) != 0)) |
516 |
| - (void)fcntl(*fdp, F_SETFL, 0); /* restore blocking */ |
| 516 | + /* restore blocking */ |
| 517 | + if (*fdp == c->rfd && |
| 518 | + (c->restore_block & CHANNEL_RESTORE_RFD) != 0) |
| 519 | + (void)fcntl(*fdp, F_SETFL, c->restore_flags[0]); |
| 520 | + else if (*fdp == c->wfd && |
| 521 | + (c->restore_block & CHANNEL_RESTORE_WFD) != 0) |
| 522 | + (void)fcntl(*fdp, F_SETFL, c->restore_flags[1]); |
| 523 | + else if (*fdp == c->efd && |
| 524 | + (c->restore_block & CHANNEL_RESTORE_EFD) != 0) |
| 525 | + (void)fcntl(*fdp, F_SETFL, c->restore_flags[2]); |
517 | 526 |
|
518 | 527 | if (*fdp == c->rfd) {
|
519 | 528 | c->io_want &= ~SSH_CHAN_IO_RFD;
|
|
0 commit comments