Received: by 10.223.176.5 with SMTP id f5csp1562917wra; Wed, 7 Feb 2018 23:06:36 -0800 (PST) X-Google-Smtp-Source: AH8x226VmNSMHWm2BTmPkBf1jCzrRXdaSkcm3cOvZz3JJeLdgQT9UWbtGZIG3IZLpEfN1bQu+NSZ X-Received: by 2002:a17:902:570f:: with SMTP id k15-v6mr8475853pli.321.1518073596851; Wed, 07 Feb 2018 23:06:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518073596; cv=none; d=google.com; s=arc-20160816; b=vYEIysyrhbiviUBsoGRFlNOhBiXrioiZtlwX2IMmuR3TD1Yo77nfwWnGen5gYLdnnM shknqxifD3T55USZoKLMtG0s3MQuyJb6C5S8NuNXK3sL+3v3kXN9UncwHnCV91JfkO+L Ugco1hgJd42FPtAH6eAQyIZcCjRVfS9oV1y6utrQ2ySHe7ZmddWlHF19bxLMhmipS5+D US0znZ3Z9fmGMH8rVCKRN8/I09yLeaHcPBvGXW4IaI88CSpoQ9nUheRjGpxcQE4tsLw2 dZXYP2+V3CjbVrXDk6e4HiyzKq1BNJ44+VxllDRSFGFw+cpJjVDXJZg2QG1HxDWan/iE vQgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=6D8RN1E5VDqjoDZUS10UWoAnB/IJ7eBTa05iMT6VgdQ=; b=d6NrSINX787KTl6zTLnttTEWkIYngbIzyb6t1BGZZMTmhnc/swpW7T3LXHtcY7QCue lXWtao7rBoW2rCBepyN6jRuXMHIG/KDbr9YGiG4CeM65TrXnLaTfqA9B7EvCIrL1YOAH qPcjPcJN/oLJ/SwU/olx6C1Kn7p2maINYBSGdRkktOVfbnzx2IN3nB2h5/TCYNEee13J rv9ZNHYGJcLXC5IyY8lU00Y4ln75nWhc9K/lPsL7DEmp6HzPe/1VbrYarICOd8f6D/zX xqyTlOl+L0xZiOXKKq5VfICt1TOjoGIed2scgLN/JE8Nx+Aih3l1nQUSwC3/SjwkEQLh UwvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q/ZCVY36; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2-v6si2433159pll.483.2018.02.07.23.06.23; Wed, 07 Feb 2018 23:06:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q/ZCVY36; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751068AbeBHHFm (ORCPT + 99 others); Thu, 8 Feb 2018 02:05:42 -0500 Received: from mail-ua0-f194.google.com ([209.85.217.194]:45771 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750766AbeBHHFk (ORCPT ); Thu, 8 Feb 2018 02:05:40 -0500 Received: by mail-ua0-f194.google.com with SMTP id z3so2241077uae.12; Wed, 07 Feb 2018 23:05:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=6D8RN1E5VDqjoDZUS10UWoAnB/IJ7eBTa05iMT6VgdQ=; b=q/ZCVY36Z0zTefNS0koe+tq2c+PH7Q1vi2SLWxe3DlnREf+dATELIJZKbANz4qrEJC ujvBM03ha0i2uj1IhfAWqMDT8/Co9UCCAoiwuAi7PYbfP/MqAF1jAjHIv6yejZTjBQ3X 0G4vDd5508TcaTeSvtukQndEXY1yZ7KlqIl2JGeLIK1gLN2Kf967rXuf3nQzHaB13ruL HPIDwT36/iWycq1IO8hPi+l8GRc1QUTln82BSAQ5Chjno5SnWzsOiUDQPYLBI+kN8MSI 5+ASMYIqCcS5NFTbMP9+XOj9myWP+3+eerS2K72PQGSp1NgEHJADInbM/yQwPEsV2f4m I7XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=6D8RN1E5VDqjoDZUS10UWoAnB/IJ7eBTa05iMT6VgdQ=; b=bXSKLld1EIBq3butLRvYMwRd62+uwLq3i3/ZB1VLAvQIU2qn8U7oFjDCqQXjE2kuyY Aw4s314gm/Wo4AZsVzVxymnsPmy1Ol+n+vBF57vLouC1VjgKI7tdKel2H7NICPWjI6MB AEEvWFsmOQDn6aPVlEe0MUWbJMHD9Fc9oDcWwDx81lTpouugX7IePg+NPcsVBxg8tZX9 cnLqRNSIUhK+4+JdGCEOuqPaJ07XddtDH7NIvfxZpmiqn5qbGqGqER/Ax3RsVsiU/a6P 2vprULgZehQm9JqGPpuBsI5vQOOFZo03Cb3HGug+ZhRIByoMqrOgxUHpPrZSVnTFER/f pzWQ== X-Gm-Message-State: APf1xPA8JwPLoVWq4yCqVaSMsBNZV0VxqKuPNkxLkeQIGKEFwo4Wm2Fn lUjqdBbYkunZhee+OzWggRPgqoxqczI0x/Mi1kg= X-Received: by 10.159.41.33 with SMTP id t30mr7488756uat.16.1518073539989; Wed, 07 Feb 2018 23:05:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.70.21 with HTTP; Wed, 7 Feb 2018 23:05:39 -0800 (PST) In-Reply-To: References: <1518069400-7037-1-git-send-email-yamada.masahiro@socionext.com> <1518069400-7037-2-git-send-email-yamada.masahiro@socionext.com> From: Ulf Magnusson Date: Thu, 8 Feb 2018 08:05:39 +0100 Message-ID: Subject: Re: [PATCH 2/2] kconfig: echo stdin to stdout if either is redirected To: Masahiro Yamada Cc: Linux Kbuild mailing list , Sam Ravnborg , Michal Marek , Randy Dunlap , "Luis R . Rodriguez" , Linux Kernel Mailing List , Marc Herbert Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 8, 2018 at 7:51 AM, Ulf Magnusson wrote: > On Thu, Feb 8, 2018 at 7:35 AM, Ulf Magnusson wrote: >> On Thu, Feb 8, 2018 at 6:56 AM, Masahiro Yamada >> wrote: >>> If stdio is not tty, conf_askvalue() puts additional new line to >>> prevent prompts are all concatenated into a single line. This care >>> is missing in conf_choice(), so a 'choice' prompt and the next prompt >>> are shown in the same line. >>> >>> Move the code into xfgets() to take care of all cases. To improve >>> this more, echo stdin to stdout. This clarifies what keys were input >>> from stdio and the stdout looks like as if it were from tty. >>> >>> I removed the isatty(2) check since stderr is unrelated here. >>> >>> Signed-off-by: Masahiro Yamada >>> --- >>> >>> scripts/kconfig/conf.c | 7 ++++--- >>> 1 file changed, 4 insertions(+), 3 deletions(-) >>> >>> diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c >>> index 358e2e4..c5318d3 100644 >>> --- a/scripts/kconfig/conf.c >>> +++ b/scripts/kconfig/conf.c >>> @@ -76,6 +76,9 @@ static void xfgets(char *str, int size, FILE *in) >>> { >>> if (!fgets(str, size, in)) >>> fprintf(stderr, "\nError in reading or end of file.\n"); >>> + >>> + if (!tty_stdio) >>> + printf("%s", str); >>> } >>> >>> static int conf_askvalue(struct symbol *sym, const char *def) >>> @@ -106,8 +109,6 @@ static int conf_askvalue(struct symbol *sym, const char *def) >>> case oldaskconfig: >>> fflush(stdout); >>> xfgets(line, sizeof(line), stdin); >>> - if (!tty_stdio) >>> - printf("\n"); >>> return 1; >>> default: >>> break; >>> @@ -495,7 +496,7 @@ int main(int ac, char **av) >>> bindtextdomain(PACKAGE, LOCALEDIR); >>> textdomain(PACKAGE); >>> >>> - tty_stdio = isatty(0) && isatty(1) && isatty(2); >>> + tty_stdio = isatty(0) && isatty(1); >>> >>> while ((opt = getopt_long(ac, av, "s", long_opts, NULL)) != -1) { >>> if (opt == 's') { >>> -- >>> 2.7.4 >>> >> >> Reviewed-by: Ulf Magnusson >> >> Might be some case I'm not thinking of, but wouldn't it make sense to >> just check isatty(1) as well? If stdout is a regular file, it seems >> it'd be nice to have the input appear there, regardless of where stdin >> is from. >> >> Maybe the tty_stdio variable could be removed then as well, replaced >> with just 'if (!isatty(1))'. >> >> Cheers, >> Ulf > > Hmm... if stdout is a tty and stdin isn't, this would prevent the > input from showing up on the terminal though, so I guess it makes > sense. That case seems more important than the weird > stdin=tty/stdout=file case. > > Tricky stuff. :) > > Cheers, > Ulf Oh... and that one's already taken care of too, reading closer. stdin | stdout | wants stdin written to stdout ------+--------+------------------------------------- tty | tty | no (already echoed by tty) tty | file | yes (echoed by tty, written to file) file | tty | yes (not echoed by tty) file | file | yes So !(tty(0) && tty(1)) makes sense. Excuse the rambling... Cheers, Ulf