47 lines
1.3 KiB
Diff
47 lines
1.3 KiB
Diff
Link: /os/embedded-buildsystem/busybox
|
|
Date: Mon Dec 2 13:41:39 2019 +0300
|
|
Subject: [PATCH] Check tcgetattr() return value.
|
|
Tags: common commit ee46bd2170fabdd03514c82e792afde85b539137
|
|
|
|
diff --git a/init/init.c b/init/init.c
|
|
index 08cfa2f..9fe8cd9 100644
|
|
--- a/init/init.c
|
|
+++ b/init/init.c
|
|
@@ -336,12 +336,15 @@ static void console_init(void)
|
|
}
|
|
|
|
/* Set terminal settings to reasonable defaults.
|
|
+ * Returns 0 on success, -1 on failure.
|
|
* NB: careful, we can be called after vfork! */
|
|
-static void set_sane_term(void)
|
|
+static int set_sane_term(void)
|
|
{
|
|
struct termios tty;
|
|
|
|
- tcgetattr(STDIN_FILENO, &tty);
|
|
+ /* tcgetattr() returns 0 on success, -1 on failure */
|
|
+ if (tcgetattr(STDIN_FILENO, &tty) == -1)
|
|
+ return 0;
|
|
|
|
/* set control chars */
|
|
tty.c_cc[VINTR] = 3; /* C-c */
|
|
@@ -375,7 +378,7 @@ static void set_sane_term(void)
|
|
/* local modes */
|
|
tty.c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
|
|
|
|
- tcsetattr_stdin_TCSANOW(&tty);
|
|
+ return !tcsetattr_stdin_TCSANOW(&tty);
|
|
}
|
|
|
|
/* Open the new terminal device.
|
|
@@ -397,8 +400,7 @@ static int open_stdio_to_tty(const char* tty_name)
|
|
dup2(STDIN_FILENO, STDOUT_FILENO);
|
|
dup2(STDIN_FILENO, STDERR_FILENO);
|
|
}
|
|
- set_sane_term();
|
|
- return 1; /* success */
|
|
+ return set_sane_term();
|
|
}
|
|
|
|
static void reset_sighandlers_and_unblock_sigs(void)
|