summaryrefslogtreecommitdiffstats
path: root/src/CLI
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2010-05-05 14:57:00 +0200
committerKarel Klic <kklic@redhat.com>2010-05-05 14:57:00 +0200
commite7933c1157a0dcf38ba2cd40018eac038d2870f7 (patch)
tree446dae8e6828cb165f5d8938b79764f2ba22c569 /src/CLI
parent40ab6c1093012099afe89fbe5944bbcf9184d3a5 (diff)
downloadabrt-e7933c1157a0dcf38ba2cd40018eac038d2870f7.tar.gz
abrt-e7933c1157a0dcf38ba2cd40018eac038d2870f7.tar.xz
abrt-e7933c1157a0dcf38ba2cd40018eac038d2870f7.zip
Improved echo switching as suggested by Denys
Diffstat (limited to 'src/CLI')
-rw-r--r--src/CLI/report.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/CLI/report.cpp b/src/CLI/report.cpp
index 3946e6bb..cb88c3ca 100644
--- a/src/CLI/report.cpp
+++ b/src/CLI/report.cpp
@@ -530,18 +530,23 @@ static bool ask_yesno(const char *question)
return ((answer[0] | 0x20) == 'y');
}
-static void set_echo(bool enabled)
+/* Returns true if echo has been changed from another state. */
+static bool set_echo(bool enabled)
{
if (isatty(STDIN_FILENO) == 0)
{
/* Clean errno, which is set by isatty. */
errno = 0;
- return;
+ return false;
}
struct termios t;
if (tcgetattr(STDIN_FILENO, &t) < 0)
- perror_msg_and_die("tcgetattr failed");
+ return false;
+
+ /* No change needed. */
+ if ((bool)(t.c_lflag & ECHO) == enabled)
+ return false;
if (enabled)
t.c_lflag |= ECHO;
@@ -550,6 +555,8 @@ static void set_echo(bool enabled)
if (tcsetattr(STDIN_FILENO, TCSANOW, &t) < 0)
perror_msg_and_die("tcsetattr failed");
+
+ return true;
}
/**
@@ -627,9 +634,11 @@ static void get_reporter_plugin_settings(const vector_string_t& reporters,
}
if (passwordMissing)
{
- set_echo(false);
+ bool changed = set_echo(false);
read_from_stdin(_("Enter your password: "), result, 64);
- set_echo(true);
+ if (changed)
+ set_echo(true);
+
// Newline was not added by pressing Enter because ECHO was disabled, so add it now.
puts("");
single_plugin_settings["Password"] = std::string(result);