[pacman-dev] [PATCH] Fix broken output when asking question and stdin is piped (FS#27909)
When asking question and stdin is piped, the response does not get printed out, resulting in a missing \n and broken output (FS#27909); printing the response fixes it. Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> --- src/pacman/util.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index 2d88bac..876a15b 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1429,6 +1429,13 @@ static int question(short preset, char *fmt, va_list args) if(len == 0) { return preset; } + + /* if stdin is piped, response does not get printed out, and as a result + * a \n is missing, resulting in broken output (FS#27909) */ + struct stat sb; + if (fstat(STDIN_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode)) { + fprintf(stream, "%s\n", response); + } if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) { return 1; -- 1.7.8.3
On Thu, Jan 12, 2012 at 7:10 AM, Olivier Brunel <i.am.jack.mail@gmail.com> wrote:
When asking question and stdin is piped, the response does not get printed out, resulting in a missing \n and broken output (FS#27909); printing the response fixes it.
Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> --- src/pacman/util.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 2d88bac..876a15b 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1429,6 +1429,13 @@ static int question(short preset, char *fmt, va_list args) if(len == 0) { return preset; } + + /* if stdin is piped, response does not get printed out, and as a result + * a \n is missing, resulting in broken output (FS#27909) */ + struct stat sb; + if (fstat(STDIN_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode)) { + fprintf(stream, "%s\n", response); + } Noticing that our usual strategy is to use the isatty() function, e.g., if(isatty(fileno(stdin))) { xxx }
We probably want to stick with this convention if possible, especially since we are already using that convention in flush_term_input() which is called from question(). Otherwise this looks like the right approach. Thanks! (And minor note- please read HACKING for info on 'if(' vs 'if (' coding convention.)
if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) { return 1; -- 1.7.8.3
On 01/12/12 14:46, Dan McGee wrote:
On Thu, Jan 12, 2012 at 7:10 AM, Olivier Brunel <i.am.jack.mail@gmail.com> wrote:
When asking question and stdin is piped, the response does not get printed out, resulting in a missing \n and broken output (FS#27909); printing the response fixes it.
Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> --- src/pacman/util.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 2d88bac..876a15b 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1429,6 +1429,13 @@ static int question(short preset, char *fmt, va_list args) if(len == 0) { return preset; } + + /* if stdin is piped, response does not get printed out, and as a result + * a \n is missing, resulting in broken output (FS#27909) */ + struct stat sb; + if (fstat(STDIN_FILENO, &sb) == 0 && S_ISFIFO(sb.st_mode)) { + fprintf(stream, "%s\n", response); + } Noticing that our usual strategy is to use the isatty() function, e.g., if(isatty(fileno(stdin))) { xxx }
We probably want to stick with this convention if possible, especially since we are already using that convention in flush_term_input() which is called from question(). Otherwise this looks like the right approach.
Thanks! (And minor note- please read HACKING for info on 'if(' vs 'if (' coding convention.)
Oh right, sorry. I did read it actually, but I'm so used to putting a space I sometimes forget. And while reviewing the code before committing/sending it, I just failed to see it.
if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) { return 1; -- 1.7.8.3
When asking question and stdin is piped, the response does not get printed out, resulting in a missing \n and broken output (FS#27909); printing the response fixes it. Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> --- src/pacman/util.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index 2d88bac..0da86dd 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1429,6 +1429,12 @@ static int question(short preset, char *fmt, va_list args) if(len == 0) { return preset; } + + /* if stdin is piped, response does not get printed out, and as a result + * a \n is missing, resulting in broken output (FS#27909) */ + if(!isatty(fileno(stdin))) { + fprintf(stream, "%s\n", response); + } if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) { return 1; -- 1.7.8.3
On Thu, Jan 12, 2012 at 9:08 AM, Olivier Brunel <i.am.jack.mail@gmail.com> wrote:
When asking question and stdin is piped, the response does not get printed out, resulting in a missing \n and broken output (FS#27909); printing the response fixes it.
Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> Thanks! --- src/pacman/util.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 2d88bac..0da86dd 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1429,6 +1429,12 @@ static int question(short preset, char *fmt, va_list args) if(len == 0) { return preset; } + + /* if stdin is piped, response does not get printed out, and as a result + * a \n is missing, resulting in broken output (FS#27909) */ + if(!isatty(fileno(stdin))) { + fprintf(stream, "%s\n", response); + }
if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) { return 1; -- 1.7.8.3
On 13/01/12 01:08, Olivier Brunel wrote:
When asking question and stdin is piped, the response does not get printed out, resulting in a missing \n and broken output (FS#27909); printing the response fixes it.
Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> --- src/pacman/util.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 2d88bac..0da86dd 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1429,6 +1429,12 @@ static int question(short preset, char *fmt, va_list args) if(len == 0) { return preset; } + + /* if stdin is piped, response does not get printed out, and as a result + * a \n is missing, resulting in broken output (FS#27909) */ + if(!isatty(fileno(stdin))) {
Shouldn't we use STDIN_FILENO there to be nicely POSIX compliant?
+ fprintf(stream, "%s\n", response); + }
if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) { return 1;
On 13/01/12 07:35, Allan McRae wrote:
On 13/01/12 01:08, Olivier Brunel wrote:
When asking question and stdin is piped, the response does not get printed out, resulting in a missing \n and broken output (FS#27909); printing the response fixes it.
Signed-off-by: Olivier Brunel <i.am.jack.mail@gmail.com> --- src/pacman/util.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 2d88bac..0da86dd 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1429,6 +1429,12 @@ static int question(short preset, char *fmt, va_list args) if(len == 0) { return preset; } + + /* if stdin is piped, response does not get printed out, and as a result + * a \n is missing, resulting in broken output (FS#27909) */ + if(!isatty(fileno(stdin))) {
Shouldn't we use STDIN_FILENO there to be nicely POSIX compliant?
Crap... started reading email from the newest... You can ignore.
participants (4)
-
Allan McRae
-
Dan McGee
-
jjacky
-
Olivier Brunel