ref: ee68c18cd617d58a3ec4bbfb0c821855e279a09b
parent: 1c9d07cfd6dddc487a4b695295c65470ee8792a8
author: 7heo <7heo@mail.com>
date: Sat Sep 17 10:24:46 CDT 2016
nlplug-findfs: verify that stdin is TTY
--- a/nlplug-findfs.c
+++ b/nlplug-findfs.c
@@ -516,11 +516,15 @@
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 @@
}
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;
}