From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lO4ao-000693-Jy for mharc-grub-devel@gnu.org; Sun, 21 Mar 2021 16:22:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lO4an-00068u-If for grub-devel@gnu.org; Sun, 21 Mar 2021 16:22:33 -0400 Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:42767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lO4al-0000xP-C3 for grub-devel@gnu.org; Sun, 21 Mar 2021 16:22:33 -0400 Received: by mail-qk1-x72a.google.com with SMTP id y5so7057437qkl.9 for ; Sun, 21 Mar 2021 13:22:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ETY+CGOqfLrotlOMsslLc2DbGjkDpu3DxfToyx1l9EM=; b=EDbL75X7VFunpvaZqLmZEfsCLVKyktUjTA5DLDjakhCFkJoLIG20j9h4plqCCg1Kii FbEncBuUFVkKqAr/ah0NWMGH2TcHZUZKx1qjw+RM5NoRpQGqvWV4CVi5VhPxoO+jEd56 4k9CzYfxQd+3BfSQdq3npaV8edvMOos1O+hcYeBBeixIwCscAka0XSdAt3ZqxYDOFsiT LhUXtQWTC5Z2xco0ROxuOtmNKaSQ5DX2RuqJp+nmUPtDFRlwphsaKeU/StnGtbdSTTST C3KPz37Sdj1bM5OsM4h6pKJeHwbQ6OsR9HSev+wI56Q7tQNkXoYvQxVzTkhzloAUl1Fx DZlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ETY+CGOqfLrotlOMsslLc2DbGjkDpu3DxfToyx1l9EM=; b=l5w9bMeLF7ZEXBuG1voF9T3KXFSbbTQp2haoB+IBLFqRNub/c5+iXg3jvGQmr2gISU QZYK5eQucvpYXWYO2x2arlHsxYTRjOyrssTbjvQYONQsng96sXGMbMrZ91g8wrrVLJ67 fNzSAO3cK7pma1tHBBJHakdIaeb1WAo9V1GsVg+Qly5R5zvgpzapWPjngOUEiDN5Gi4C ismJZ0e6GE4MQZy7SiMZxzRzudcB8nz1tOxp/IAzxF0TbyNvr88njC8nI0rNqDMed/hL JExBQkV7sQ13nPYvq/pIaz6hpnKvdNdI7l5spUhCfMe1Cw3dbiGxFy00G56TqTcqu2nO VaBw== X-Gm-Message-State: AOAM531M0c8315kTNQ7wA+NxP2H+h0ExiS5MnpDvejsW8Qdb7XvvEcm2 eKQHCiPYGCKtzLBVxJVFkgUTkmkA0lmyNA== X-Google-Smtp-Source: ABdhPJynCO3lJkGW+zhVuqHjGnWTEfssrBSb5Ap8RM9MA+bW1EjQSyVctZxkU21DC5iNn+H93eI6HQ== X-Received: by 2002:a37:a0ca:: with SMTP id j193mr8207350qke.242.1616358149739; Sun, 21 Mar 2021 13:22:29 -0700 (PDT) Received: from localhost.localdomain ([2605:a601:ab16:db00:23af:6780:efd4:8e25]) by smtp.gmail.com with ESMTPSA id j15sm7677577qtr.34.2021.03.21.13.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 13:22:29 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH] command: Add silent mode to read command to suppress input echo Date: Sun, 21 Mar 2021 15:22:19 -0500 Message-Id: <20210321202219.1947765-1-development@efficientek.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=development@efficientek.com; helo=mail-qk1-x72a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Mar 2021 20:22:33 -0000 This conforms to the behavior of the -s option of the bash read command. docs/grub: Document the -s option for the read command. Signed-off-by: Glenn Washburn --- docs/grub.texi | 5 +++-- grub-core/commands/read.c | 29 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index eeb3118eb..5f5b67e3b 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -4924,10 +4924,11 @@ and the system will reboot. @node read @subsection read -@deffn Command read [var] +@deffn Command read [-s] [var] Read a line of input from the user. If an environment variable @var{var} is given, set that environment variable to the line of input that was read, -with no terminating newline. +with no terminating newline. If the parameter @option{-s} is used, enable +silent mode where input is not printed to the terminal. @end deffn diff --git a/grub-core/commands/read.c b/grub-core/commands/read.c index fe3e88b15..0fba58996 100644 --- a/grub-core/commands/read.c +++ b/grub-core/commands/read.c @@ -23,13 +23,19 @@ #include #include #include -#include +#include #include GRUB_MOD_LICENSE ("GPLv3+"); +static const struct grub_arg_option options[] = + { + {"silent", 's', 0, N_("Do not echo input"), 0, 0}, + {0, 0, 0, 0, 0, 0} + }; + static char * -grub_getline (void) +grub_getline (int silent) { int i; char *line; @@ -48,7 +54,7 @@ grub_getline (void) break; line[i] = c; - if (grub_isprint (c)) + if (!silent && grub_isprint (c)) grub_printf ("%c", c); i++; tmp = grub_realloc (line, 1 + i + sizeof('\0')); @@ -65,9 +71,12 @@ grub_getline (void) } static grub_err_t -grub_cmd_read (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) +grub_cmd_read (grub_extcmd_context_t ctxt, int argc, char **args) { - char *line = grub_getline (); + + struct grub_arg_list *state = ctxt->state; + + char *line = grub_getline (state[0].set); if (! line) return grub_errno; if (argc > 0) @@ -77,16 +86,16 @@ grub_cmd_read (grub_command_t cmd __attribute__ ((unused)), int argc, char **arg return 0; } -static grub_command_t cmd; +static grub_extcmd_t cmd; GRUB_MOD_INIT(read) { - cmd = grub_register_command ("read", grub_cmd_read, - N_("[ENVVAR]"), - N_("Set variable with user input.")); + cmd = grub_register_extcmd ("read", grub_cmd_read, 0, + N_("[-s] [ENVVAR]"), + N_("Set variable with user input."), options); } GRUB_MOD_FINI(read) { - grub_unregister_command (cmd); + grub_unregister_extcmd (cmd); } -- 2.27.0