aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author7heo <7heo@mail.com>2016-09-17 15:24:46 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2017-01-10 13:50:25 +0100
commitee68c18cd617d58a3ec4bbfb0c821855e279a09b (patch)
treedbe11c141d052a09f2d22e6888322e32bb67fa9e
parent1c9d07cfd6dddc487a4b695295c65470ee8792a8 (diff)
downloadmkinitfs-ee68c18cd617d58a3ec4bbfb0c821855e279a09b.tar.bz2
mkinitfs-ee68c18cd617d58a3ec4bbfb0c821855e279a09b.tar.xz
nlplug-findfs: verify that stdin is TTY
-rw-r--r--nlplug-findfs.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/nlplug-findfs.c b/nlplug-findfs.c
index 7104d40..3f6680d 100644
--- a/nlplug-findfs.c
+++ b/nlplug-findfs.c
@@ -516,11 +516,15 @@ static int read_pass(char *pass, size_t pass_size)
new_flags.c_lflag &= ~ECHO;
new_flags.c_lflag |= ECHONL;
- r = tcsetattr(STDIN_FILENO, TCSANOW, &new_flags);
- if (r < 0) {
- warn("tcsetattr");
- return r;
- }
+ if (isatty(STDIN_FILENO)) {
+ r = tcsetattr(STDIN_FILENO, TCSANOW, &new_flags);
+ if (r < 0) {
+ warn("tcsetattr");
+ return r;
+ }
+ }// else {
+ // fprintf(stderr, "The program isn't executed in a TTY, the echo-disabling has been skipped.\n");
+ //}
if (fgets(pass, pass_size, stdin) == NULL) {
warn("fgets");
@@ -528,10 +532,14 @@ static int read_pass(char *pass, size_t pass_size)
}
pass[strlen(pass) - 1] = '\0';
- if (tcsetattr(STDIN_FILENO, TCSANOW, &old_flags) < 0) {
- warn("tcsetattr");
- return r;
- }
+ if (isatty(STDIN_FILENO)) {
+ if (tcsetattr(STDIN_FILENO, TCSANOW, &old_flags) < 0) {
+ warn("tcsetattr");
+ return r;
+ }
+ }// else {
+ // fprintf(stderr, "The program isn't executed in a TTY, the echo-reenabling has been skipped.\n");
+ //}
return 0;
}