summaryrefslogtreecommitdiffstats
path: root/src/basic/fileio.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-16 18:35:34 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-17 12:07:19 +0200
commitee41670ffbecb000db873f839a7381495bbe2bc6 (patch)
tree7c8a00b2ab65e254fbd28726fd510c31be7d9806 /src/basic/fileio.c
parentfirstboot: only list all options on demand (diff)
downloadsystemd-ee41670ffbecb000db873f839a7381495bbe2bc6.tar.xz
systemd-ee41670ffbecb000db873f839a7381495bbe2bc6.zip
firstboot: fix hang waiting for second Enter on input
The comment explains the reason: we'd wait for the second \n and then ungetc() it. Then the buffered \n would cause a problem when the next prompt was issued, so in effect it wasn't possible to answer the second question.
Diffstat (limited to '')
-rw-r--r--src/basic/fileio.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index bd4c964bec..623e43e4ca 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -776,7 +776,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(FILE*, funlockfile);
int read_line_full(FILE *f, size_t limit, ReadLineFlags flags, char **ret) {
size_t n = 0, allocated = 0, count = 0;
_cleanup_free_ char *buffer = NULL;
- int r;
+ int r, tty = -1;
assert(f);
@@ -851,6 +851,17 @@ int read_line_full(FILE *f, size_t limit, ReadLineFlags flags, char **ret) {
count++;
if (eol != EOL_NONE) {
+ /* If we are on a tty, we can't wait for more input. But we expect only
+ * \n as the single EOL marker, so there is no need to wait. We check
+ * this condition last to avoid isatty() check if not necessary. */
+
+ if (tty < 0)
+ tty = isatty(fileno(f));
+ if (tty > 0)
+ break;
+ }
+
+ if (eol != EOL_NONE) {
previous_eol |= eol;
continue;
}