From da897250cca792d8b4a73ae6c37a8ea59e4a5abd Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 13 Dec 2016 11:45:16 +0100 Subject: [PATCH] Avoid interactive prompts when redirected, assume no --- common/flatpak-utils.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index e5659e47e..f03ffa953 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -4270,6 +4270,13 @@ flatpak_yes_no_prompt (const char *prompt, ...) while (TRUE) { g_print ("%s %s: ", s, "[y/n]"); + + if (!isatty (STDIN_FILENO) || !isatty (STDOUT_FILENO)) + { + g_print ("n\n"); + return FALSE; + } + if (fgets (buf, sizeof (buf), stdin) == NULL) return FALSE; @@ -4311,8 +4318,15 @@ flatpak_number_prompt (int min, int max, const char *prompt, ...) while (TRUE) { g_print ("%s [%d-%d]: ", s, min, max); + + if (!isatty (STDIN_FILENO) || !isatty (STDOUT_FILENO)) + { + g_print ("0\n"); + return 0; + } + if (fgets (buf, sizeof (buf), stdin) == NULL) - return FALSE; + return 0; g_strstrip (buf);