unix: don't clobber errno in uv_tty_reset_mode()
uv_tty_reset_mode() is designed to be async signal-safe and is therefore not allowed to clobber errno. PR-URL: https://github.com/libuv/libuv/pull/259 Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
parent
25d4abbabb
commit
1df46fe478
@ -237,8 +237,10 @@ uv_handle_type uv_guess_handle(uv_file file) {
|
|||||||
* critical section when the signal was raised.
|
* critical section when the signal was raised.
|
||||||
*/
|
*/
|
||||||
int uv_tty_reset_mode(void) {
|
int uv_tty_reset_mode(void) {
|
||||||
|
int saved_errno;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
saved_errno = errno;
|
||||||
if (!uv_spinlock_trylock(&termios_spinlock))
|
if (!uv_spinlock_trylock(&termios_spinlock))
|
||||||
return -EBUSY; /* In uv_tty_set_mode(). */
|
return -EBUSY; /* In uv_tty_set_mode(). */
|
||||||
|
|
||||||
@ -248,5 +250,7 @@ int uv_tty_reset_mode(void) {
|
|||||||
err = -errno;
|
err = -errno;
|
||||||
|
|
||||||
uv_spinlock_unlock(&termios_spinlock);
|
uv_spinlock_unlock(&termios_spinlock);
|
||||||
|
errno = saved_errno;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,6 +118,13 @@ TEST_IMPL(tty) {
|
|||||||
r = uv_tty_set_mode(&tty_in, UV_TTY_MODE_NORMAL);
|
r = uv_tty_set_mode(&tty_in, UV_TTY_MODE_NORMAL);
|
||||||
ASSERT(r == 0);
|
ASSERT(r == 0);
|
||||||
|
|
||||||
|
/* Calling uv_tty_reset_mode() repeatedly should not clobber errno. */
|
||||||
|
errno = 0;
|
||||||
|
ASSERT(0 == uv_tty_reset_mode());
|
||||||
|
ASSERT(0 == uv_tty_reset_mode());
|
||||||
|
ASSERT(0 == uv_tty_reset_mode());
|
||||||
|
ASSERT(0 == errno);
|
||||||
|
|
||||||
/* TODO check the actual mode! */
|
/* TODO check the actual mode! */
|
||||||
|
|
||||||
uv_close((uv_handle_t*) &tty_in, NULL);
|
uv_close((uv_handle_t*) &tty_in, NULL);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user