diff options
| author | Paul Fox <pgf@brightstareng.com> | 2008-04-23 15:31:29 +0000 |
|---|---|---|
| committer | Paul Fox <pgf@brightstareng.com> | 2008-04-23 15:31:29 +0000 |
| commit | a50a9b0fdf3d752fc88182bccd47a1eaac79cb4b (patch) | |
| tree | 753926c07ace7bc20ab9621bfed7bdcf0e2a94e0 /miscutils | |
| parent | 765c1c3c31493787b9cb53cc80574734e42a8844 (diff) | |
| download | busybox-w32-a50a9b0fdf3d752fc88182bccd47a1eaac79cb4b.tar.gz busybox-w32-a50a9b0fdf3d752fc88182bccd47a1eaac79cb4b.tar.bz2 busybox-w32-a50a9b0fdf3d752fc88182bccd47a1eaac79cb4b.zip | |
delay reconfig of input tty until target device has been both opened
and configured correctly.
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/microcom.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/miscutils/microcom.c b/miscutils/microcom.c index 5ce430a03..1608960e9 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c | |||
| @@ -96,14 +96,6 @@ int microcom_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 96 | // error exit code if we fail to open the device | 96 | // error exit code if we fail to open the device |
| 97 | signalled = 1; | 97 | signalled = 1; |
| 98 | 98 | ||
| 99 | // put stdin to "raw mode" (if stdin is a TTY), | ||
| 100 | // handle one character at a time | ||
| 101 | if (isatty(STDIN_FILENO)) { | ||
| 102 | xget1(STDIN_FILENO, &tio, &tio0); | ||
| 103 | if (xset1(STDIN_FILENO, &tio, "stdin")) | ||
| 104 | goto done; | ||
| 105 | } | ||
| 106 | |||
| 107 | // open device | 99 | // open device |
| 108 | sfd = open_or_warn(argv[0], O_RDWR | O_NOCTTY | O_NONBLOCK); | 100 | sfd = open_or_warn(argv[0], O_RDWR | O_NOCTTY | O_NONBLOCK); |
| 109 | if (sfd < 0) | 101 | if (sfd < 0) |
| @@ -112,11 +104,18 @@ int microcom_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 112 | 104 | ||
| 113 | // put device to "raw mode" | 105 | // put device to "raw mode" |
| 114 | xget1(sfd, &tio, &tiosfd); | 106 | xget1(sfd, &tio, &tiosfd); |
| 115 | // tio.c_cflag |= (CREAD|HUPCL); // we just bail out on any device error | ||
| 116 | // set device speed | 107 | // set device speed |
| 117 | cfsetspeed(&tio, tty_value_to_baud(speed)); | 108 | cfsetspeed(&tio, tty_value_to_baud(speed)); |
| 118 | if (xset1(sfd, &tio, argv[0])) | 109 | if (xset1(sfd, &tio, argv[0])) |
| 119 | goto restore0_and_done; | 110 | goto done; |
| 111 | |||
| 112 | // put stdin to "raw mode" (if stdin is a TTY), | ||
| 113 | // handle one character at a time | ||
| 114 | if (isatty(STDIN_FILENO)) { | ||
| 115 | xget1(STDIN_FILENO, &tio, &tio0); | ||
| 116 | if (xset1(STDIN_FILENO, &tio, "stdin")) | ||
| 117 | goto done; | ||
| 118 | } | ||
| 120 | 119 | ||
| 121 | // main loop: check with poll(), then read/write bytes across | 120 | // main loop: check with poll(), then read/write bytes across |
| 122 | pfd[0].fd = sfd; | 121 | pfd[0].fd = sfd; |
| @@ -169,7 +168,6 @@ skip_write: ; | |||
| 169 | // restore device mode | 168 | // restore device mode |
| 170 | tcsetattr(sfd, TCSAFLUSH, &tiosfd); | 169 | tcsetattr(sfd, TCSAFLUSH, &tiosfd); |
| 171 | 170 | ||
| 172 | restore0_and_done: | ||
| 173 | if (isatty(STDIN_FILENO)) | 171 | if (isatty(STDIN_FILENO)) |
| 174 | tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio0); | 172 | tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio0); |
| 175 | 173 | ||
