[1/2] kconfig: remove check_stdin()

Message ID 1518069400-7037-1-git-send-email-yamada.masahiro@socionext.com
State New
Headers show
Series
  • [1/2] kconfig: remove check_stdin()
Related show

Commit Message

Masahiro Yamada Feb. 8, 2018, 5:56 a.m.
Except silentoldconfig, valid_stdin is 1, so check_stdin() is no-op.

oldconfig and silentoldconfig work almost in the same way except that
the latter generates additional files.  Both ask users for input for
new symbols.

I do not know why only silentoldconfig requires stdio be tty.

  $ rm -f .config; touch .config
  $ yes "" | make oldconfig > stdout
  $ rm -f .config; touch .config
  $ yes "" | make silentoldconfig > stdout
  make[1]: *** [silentoldconfig] Error 1
  make: *** [silentoldconfig] Error 2
  $ tail -n 4 stdout
  Console input/output is redirected. Run 'make oldconfig' to update configuration.

  scripts/kconfig/Makefile:40: recipe for target 'silentoldconfig' failed
  Makefile:507: recipe for target 'silentoldconfig' failed

Redirection is useful, for example, for testing where we want to give
particular key inputs from a test file, then check the result.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

---

 scripts/kconfig/conf.c | 14 --------------
 1 file changed, 14 deletions(-)

-- 
2.7.4

Comments

Ulf Magnusson Feb. 8, 2018, 6:21 a.m. | #1
On Thu, Feb 8, 2018 at 6:56 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> Except silentoldconfig, valid_stdin is 1, so check_stdin() is no-op.

>

> oldconfig and silentoldconfig work almost in the same way except that

> the latter generates additional files.  Both ask users for input for

> new symbols.

>

> I do not know why only silentoldconfig requires stdio be tty.

>

>   $ rm -f .config; touch .config

>   $ yes "" | make oldconfig > stdout

>   $ rm -f .config; touch .config

>   $ yes "" | make silentoldconfig > stdout

>   make[1]: *** [silentoldconfig] Error 1

>   make: *** [silentoldconfig] Error 2

>   $ tail -n 4 stdout

>   Console input/output is redirected. Run 'make oldconfig' to update configuration.

>

>   scripts/kconfig/Makefile:40: recipe for target 'silentoldconfig' failed

>   Makefile:507: recipe for target 'silentoldconfig' failed

>

> Redirection is useful, for example, for testing where we want to give

> particular key inputs from a test file, then check the result.

>

> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

> ---

>

>  scripts/kconfig/conf.c | 14 --------------

>  1 file changed, 14 deletions(-)

>

> diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c

> index 307bc3f..358e2e4 100644

> --- a/scripts/kconfig/conf.c

> +++ b/scripts/kconfig/conf.c

> @@ -39,7 +39,6 @@ static enum input_mode input_mode = oldaskconfig;

>

>  static int indent = 1;

>  static int tty_stdio;

> -static int valid_stdin = 1;

>  static int sync_kconfig;

>  static int conf_cnt;

>  static char line[PATH_MAX];

> @@ -72,16 +71,6 @@ static void strip(char *str)

>                 *p-- = 0;

>  }

>

> -static void check_stdin(void)

> -{

> -       if (!valid_stdin) {

> -               printf(_("aborted!\n\n"));

> -               printf(_("Console input/output is redirected. "));

> -               printf(_("Run 'make oldconfig' to update configuration.\n\n"));

> -               exit(1);

> -       }

> -}

> -

>  /* Helper function to facilitate fgets() by Jean Sacren. */

>  static void xfgets(char *str, int size, FILE *in)

>  {

> @@ -113,7 +102,6 @@ static int conf_askvalue(struct symbol *sym, const char *def)

>                         printf("%s\n", def);

>                         return 0;

>                 }

> -               check_stdin();

>                 /* fall through */

>         case oldaskconfig:

>                 fflush(stdout);

> @@ -315,7 +303,6 @@ static int conf_choice(struct menu *menu)

>                                 printf("%d\n", cnt);

>                                 break;

>                         }

> -                       check_stdin();

>                         /* fall through */

>                 case oldaskconfig:

>                         fflush(stdout);

> @@ -650,7 +637,6 @@ int main(int ac, char **av)

>                                 return 1;

>                         }

>                 }

> -               valid_stdin = tty_stdio;

>         }

>

>         switch (input_mode) {

> --

> 2.7.4

>


Reviewed-by: Ulf Magnusson <ulfalizer@gmail.com>


Lots of weird stuff indeed...

Cheers,
Ulf
Sam Ravnborg Feb. 18, 2018, 7:44 p.m. | #2
On Thu, Feb 08, 2018 at 02:56:39PM +0900, Masahiro Yamada wrote:
> Except silentoldconfig, valid_stdin is 1, so check_stdin() is no-op.

> 

> oldconfig and silentoldconfig work almost in the same way except that

> the latter generates additional files.  Both ask users for input for

> new symbols.

> 

> I do not know why only silentoldconfig requires stdio be tty.


The general idea was to error out if stdout was not a tty and
kconfig wanted to prompt the user for anything.

So we avoided having a kconfig that would hang waiting for
user inputs when the user could not see that anything was prompted for.

The actual implementation may not follow this today as many seems not
to be aware of this little trick.

	Sam

Patch

diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 307bc3f..358e2e4 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -39,7 +39,6 @@  static enum input_mode input_mode = oldaskconfig;
 
 static int indent = 1;
 static int tty_stdio;
-static int valid_stdin = 1;
 static int sync_kconfig;
 static int conf_cnt;
 static char line[PATH_MAX];
@@ -72,16 +71,6 @@  static void strip(char *str)
 		*p-- = 0;
 }
 
-static void check_stdin(void)
-{
-	if (!valid_stdin) {
-		printf(_("aborted!\n\n"));
-		printf(_("Console input/output is redirected. "));
-		printf(_("Run 'make oldconfig' to update configuration.\n\n"));
-		exit(1);
-	}
-}
-
 /* Helper function to facilitate fgets() by Jean Sacren. */
 static void xfgets(char *str, int size, FILE *in)
 {
@@ -113,7 +102,6 @@  static int conf_askvalue(struct symbol *sym, const char *def)
 			printf("%s\n", def);
 			return 0;
 		}
-		check_stdin();
 		/* fall through */
 	case oldaskconfig:
 		fflush(stdout);
@@ -315,7 +303,6 @@  static int conf_choice(struct menu *menu)
 				printf("%d\n", cnt);
 				break;
 			}
-			check_stdin();
 			/* fall through */
 		case oldaskconfig:
 			fflush(stdout);
@@ -650,7 +637,6 @@  int main(int ac, char **av)
 				return 1;
 			}
 		}
-		valid_stdin = tty_stdio;
 	}
 
 	switch (input_mode) {