From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ePSg6-0001V4-Px for mharc-grub-devel@gnu.org; Thu, 14 Dec 2017 07:31:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePSg4-0001Uw-LO for grub-devel@gnu.org; Thu, 14 Dec 2017 07:31:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePSg1-0000ao-GP for grub-devel@gnu.org; Thu, 14 Dec 2017 07:31:52 -0500 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]:35236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ePSg1-0000a4-9o for grub-devel@gnu.org; Thu, 14 Dec 2017 07:31:49 -0500 Received: by mail-wr0-x235.google.com with SMTP id g53so5026746wra.2 for ; Thu, 14 Dec 2017 04:31:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=cAWmq9GNaI4C57yTafwqn9XP3FWPX0uU0bjiYe1UdP8=; b=WXaRpbs+gClkrNk/epMswwMuRbm99B3M9hCqMjKOrdMzNWNAQHsttksy5RnX6wo4n/ xjuIT+PXpe0rkjktCj1Td69SeKVYdoBKXeE3DQT8zaO584x5mmbxZw2eTKJtYWmPXGOx P2+G4WjDgUaDc6ymWojw62yyG8AUwAkh9UF6OJYPFOEyH8sVEs7xv2WOt+Se46H/qzY/ ne/8MV6T3KJE0DKAlo9RpPNOFuNDVaM1C/1J1fxmjFK9D1K6bbSCD1FkUyUHjFz0j73j uPPA/UIqH+ngTywPW8bUePVZzZjtjOSTN1TNe//tj5J3xzfrJl8srUsM0Tcq5qUAD7Z+ Rkyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=cAWmq9GNaI4C57yTafwqn9XP3FWPX0uU0bjiYe1UdP8=; b=aq5qBMbniEWTPLjLnCkCi/2+uvLSg83CxcNFn5n00EWFfInIBHBXjPOt4yGQGyf17h dRc9bQHrThcYKcnDjpEtGg8Huf7iHK7/1Kb+fQSK+Z0tAOkyum/DpWxFvXtHQhYBJrU6 /JnZX+3Ngvd2Uun+H1ptEN+GeOWrUWk5aqW/wDMrREQdB5y3DO2+1sbuCvmgKPbKcVeB c0CNDb9/oKeNDg7PkRvIPr9CXaEjLQ9sUWc5jarvupsxp+xuMERnuxbmeZMjtPbKO1Xu wS77RyYp6cX8ov1dFyE0h0OhTowKeH6IIcAsmcS1BVsEEbqvly42JMy4TtAAlGFfmR9o GgYA== X-Gm-Message-State: AKGB3mI9v3MUt2am5Pll5jfsZpBlPxtutUPZdysvDJ1ZskMyqupxeHWT DF7/HhG576JQfwuAph/aJe9zRY+o X-Google-Smtp-Source: ACJfBovITuXq/mn0MKuiGvyErNZxv6E1d2JywNnh15QkMIqXYnTVaFukD1oz36ta23AMKDh8wh0hmg== X-Received: by 10.223.186.20 with SMTP id o20mr5857040wrg.75.1513254707892; Thu, 14 Dec 2017 04:31:47 -0800 (PST) Received: from localhost.localdomain ([109.231.236.7]) by smtp.gmail.com with ESMTPSA id k5sm6022356wmg.21.2017.12.14.04.31.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Dec 2017 04:31:47 -0800 (PST) Sender: Carlo Caione From: Carlo Caione To: grub-devel@gnu.org, linux@endlessm.com Cc: Daniel Drake Subject: [PATCH] search: add optional --quiet parameter Date: Thu, 14 Dec 2017 12:31:23 +0000 Message-Id: <20171214123123.11620-1-carlo@caione.org> X-Mailer: git-send-email 2.14.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::235 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Dec 2017 12:31:53 -0000 From: Daniel Drake Currently when you search for a file, if no result is found it prints an error message. That's not ideal when the file is optional, so add a --quiet arg to silence this. --- grub-core/commands/search.c | 6 +++--- grub-core/commands/search_wrap.c | 8 +++++--- include/grub/search.h | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c index 7dd32e445..73d69b1d1 100644 --- a/grub-core/commands/search.c +++ b/grub-core/commands/search.c @@ -261,7 +261,7 @@ try (struct search_ctx *ctx) } void -FUNC_NAME (const char *key, const char *var, int no_floppy, +FUNC_NAME (const char *key, const char *var, int no_floppy, int quiet, char **hints, unsigned nhints) { struct search_ctx ctx = { @@ -292,7 +292,7 @@ FUNC_NAME (const char *key, const char *var, int no_floppy, else try (&ctx); - if (grub_errno == GRUB_ERR_NONE && ctx.count == 0) + if (!quiet && grub_errno == GRUB_ERR_NONE && ctx.count == 0) grub_error (GRUB_ERR_FILE_NOT_FOUND, "no such device: %s", key); } @@ -303,7 +303,7 @@ grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc, if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected")); - FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0, (args + 2), + FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0, 0, (args + 2), argc > 2 ? argc - 2 : 0); return grub_errno; diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c index d7fd26b94..c921cc8a7 100644 --- a/grub-core/commands/search_wrap.c +++ b/grub-core/commands/search_wrap.c @@ -40,6 +40,7 @@ static const struct grub_arg_option options[] = N_("Set a variable to the first device found."), N_("VARNAME"), ARG_TYPE_STRING}, {"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0}, + {"quiet", 'q', 0, N_("Don't print error if no match."), 0, 0}, {"hint", 'h', GRUB_ARG_OPTION_REPEATABLE, N_("First try the device HINT. If HINT ends in comma, " "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING}, @@ -73,6 +74,7 @@ enum options SEARCH_FS_UUID, SEARCH_SET, SEARCH_NO_FLOPPY, + SEARCH_QUIET, SEARCH_HINT, SEARCH_HINT_IEEE1275, SEARCH_HINT_BIOS, @@ -182,13 +184,13 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) if (state[SEARCH_LABEL].set) grub_search_label (id, var, state[SEARCH_NO_FLOPPY].set, - hints, nhints); + state[SEARCH_QUIET].set, hints, nhints); else if (state[SEARCH_FS_UUID].set) grub_search_fs_uuid (id, var, state[SEARCH_NO_FLOPPY].set, - hints, nhints); + state[SEARCH_QUIET].set, hints, nhints); else if (state[SEARCH_FILE].set) grub_search_fs_file (id, var, state[SEARCH_NO_FLOPPY].set, - hints, nhints); + state[SEARCH_QUIET].set, hints, nhints); else grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type"); diff --git a/include/grub/search.h b/include/grub/search.h index d80347df3..4c645a2b0 100644 --- a/include/grub/search.h +++ b/include/grub/search.h @@ -20,10 +20,10 @@ #define GRUB_SEARCH_HEADER 1 void grub_search_fs_file (const char *key, const char *var, int no_floppy, - char **hints, unsigned nhints); + int quiet, char **hints, unsigned nhints); void grub_search_fs_uuid (const char *key, const char *var, int no_floppy, - char **hints, unsigned nhints); + int quiet, char **hints, unsigned nhints); void grub_search_label (const char *key, const char *var, int no_floppy, - char **hints, unsigned nhints); + int quiet, char **hints, unsigned nhints); #endif -- 2.14.1