From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mvb2i-000127-E6 for mharc-grub-devel@gnu.org; Fri, 10 Dec 2021 03:14:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvb2g-0000vG-HZ for grub-devel@gnu.org; Fri, 10 Dec 2021 03:14:10 -0500 Received: from [2607:f8b0:4864:20::733] (port=41659 helo=mail-qk1-x733.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mvb2e-0007n3-8v for grub-devel@gnu.org; Fri, 10 Dec 2021 03:14:10 -0500 Received: by mail-qk1-x733.google.com with SMTP id t83so7049128qke.8 for ; Fri, 10 Dec 2021 00:14:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7dEWvJQV++ETaex+7uVvJbqrj9qQv5RtyYSoTDFKz8M=; b=NfNqoxg9cgZf+w978qLaHI40O+ZJOnLX8T5xujN2gNO4J6RLuFxiPpoqvGk9vQ32xG MeAZ0HiT8W53gS1qEIyLQvGpWUNXs1LSwncsGlD5jCH2gghAN37BIroG3+zXdUfXbTCT stJEVvk+8xGObyrnhTALktQ1tGLNIfoABy5QVH1IhH/trHRuOSkWM1EXuqG9OXom+d6R mTw3E6PGqZswOBH5sLlxj9BVhddJLJBEzZcK2C4TA8d/8pQmKJKyWyIt/TN0JUGXk/7K S0i/AVploWpuUPFw/80BM+5H67/8A08WicUPvQ/CIuI8rtyZxtRVK2bzySx7gnC45GxY CMQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7dEWvJQV++ETaex+7uVvJbqrj9qQv5RtyYSoTDFKz8M=; b=Bn1z0/PxuzWNvrFAxYQeWC6AOhVkLfsrWSfXxpsAqSaugZ9riJMglkEv5ARq1WJ4rO c7RlOAHIvYgu45rqinRj1sr5vcvV91egfoF7geK+mbadfp/7+w4SmrLv3YAK93valspd At2g6Wj6DHcQbHPJRSGIBw4bpvVrgPjxDATgSqfcsh1D8O64M/Pklbw+rv/7++Es5LQf 3IlhH+VoNybrN4UT5TAi0iUzY0Bet6mTuCDJjlsOLnByRSFTuR+jSSOIFI8naokt5aKT 1Z8PNDHCmGi9qIslmxXNkBYMSC9RL1wuLhAqgRf3y/2hWpJJnxpkUMIFbkD+baHVSBoa QCbQ== X-Gm-Message-State: AOAM530Qn39orAiV+JshLtet4M5PWhlbqAg51Bu02l64NqrgoclmP2jP MNzNqocRzJsFpAeQrBxuavkzMg== X-Google-Smtp-Source: ABdhPJy2wYRUFhOj1bJQtfrjoCjNakvwMBcEJ3WtLB7S/A8MgwnINlo15PDEpOQEA2AfXLqNmE52HA== X-Received: by 2002:a37:b53:: with SMTP id 80mr18619865qkl.91.1639124047003; Fri, 10 Dec 2021 00:14:07 -0800 (PST) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id de13sm907778qkb.81.2021.12.10.00.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 00:14:06 -0800 (PST) From: Glenn Washburn To: Daniel Kiper , grub-devel@gnu.org Cc: Michael Schierl , Glenn Washburn Subject: [PATCH v3] misc: Allow selective disabling of debug facility names Date: Fri, 10 Dec 2021 02:13:52 -0600 Message-Id: <20211210081352.1128144-1-development@efficientek.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::733 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::733; envelope-from=development@efficientek.com; helo=mail-qk1-x733.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Dec 2021 08:14:10 -0000 Sometimes you know only know which debug logging facility names you want to turn off, not necessarily all the ones you want enabled. This patch allows the debug string to contain facility names in the $debug variable which are prefixed with a "-" to disable debug log messages for that conditional. Say you want all debug logging on except for btrfs and scripting, then do: "set debug=all,-btrfs,-scripting" Note, that only the last occurence of the facility name with or without a leading "-" is considered. So simply appending ",-facilityname" to the $debug variable will disable that conditional. To illustrate, the command "set debug=all,-btrfs,-scripting,btrfs" will enable btrfs. Also, add documentation explaining this new behavior. Signed-off-by: Glenn Washburn --- Changes since v2: * Fix issue where a facility at the start of the string wouldn't be matched --- Range-diff against v2: 1: ef2662d0b ! 1: 31439a7fb misc: Allow selective disabling of debug facility names @@ grub-core/kern/misc.c: __attribute__ ((alias("grub_printf"))); - return 1; + if (grub_strword (debug, "all")) + { -+ ret = 1; + if (debug[3] == '\0') + return 1; ++ ret = 1; + } - return 0; + clen = grub_strlen (condition); -+ found = debug; ++ found = debug-1; + while(1) + { + found = grub_strstr (found+1, condition); @@ grub-core/kern/misc.c: __attribute__ ((alias("grub_printf"))); + continue; + + /* -+ * If found condition is prefixed with '-' and the start is on a word ++ * If found condition is at the start of debug, then enable debug. Else ++ * if found condition is prefixed with '-' and the start is on a word + * boundary, then disable debug. Otherwise, if the start is on a word -+ * boundary, enable debug. If neither, ignore. ++ * boundary, enable debug. If none of these cases, ignore. + */ -+ if (*(found-1) == '-' && ((found == debug + 1) || (*(found-2) == ',' ++ if (found == debug) ++ ret = 1; ++ else if (*(found-1) == '-' && ((found == debug + 1) || (*(found-2) == ',' + || grub_isspace (*(found-2))))) + ret = 0; + else if (*(found-1) == ',' || grub_isspace (*(found-1))) docs/grub.texi | 13 ++++++++++--- grub-core/kern/misc.c | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index 99d0a0149..d13aa6600 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -3388,9 +3388,16 @@ processed by commands @command{configfile} (@pxref{configfile}) or @command{norm @subsection debug This variable may be set to enable debugging output from various components -of GRUB. The value is a list of debug facility names separated by -whitespace or @samp{,}, or @samp{all} to enable all available debugging -output. The facility names are the first argument to grub_dprintf. Consult +of GRUB. The value is an ordered list of debug facility names separated by +whitespace or @samp{,}. If the special facility names @samp{all} is present +then debugging output of all facility names is enabled at the start of +processing the value of this variable. A facility's debug output can then be +disabled by prefixing its name with a @samp{-}. The last occurence facility +name with or without a leading @samp{-} takes precendent over any previous +occurence. This allows the easy enabling or disabling of facilities by +appending a @samp{,} and then the facility name with or without the leading +@samp{-}, which will preserve the state of the rest of the facilities. +The facility names are the first argument to grub_dprintf. Consult the source for more details. diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index 11b8592c8..fda69fe00 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -162,16 +162,51 @@ __attribute__ ((alias("grub_printf"))); int grub_debug_enabled (const char * condition) { - const char *debug; + const char *debug, *found; + grub_size_t clen; + int ret = 0; debug = grub_env_get ("debug"); if (!debug) return 0; - if (grub_strword (debug, "all") || grub_strword (debug, condition)) - return 1; + if (grub_strword (debug, "all")) + { + if (debug[3] == '\0') + return 1; + ret = 1; + } - return 0; + clen = grub_strlen (condition); + found = debug-1; + while(1) + { + found = grub_strstr (found+1, condition); + + if (found == NULL) + break; + + /* Found condition is not a whole word, so ignore it */ + if (*(found + clen) != '\0' && *(found + clen) != ',' + && !grub_isspace (*(found + clen))) + continue; + + /* + * If found condition is at the start of debug, then enable debug. Else + * if found condition is prefixed with '-' and the start is on a word + * boundary, then disable debug. Otherwise, if the start is on a word + * boundary, enable debug. If none of these cases, ignore. + */ + if (found == debug) + ret = 1; + else if (*(found-1) == '-' && ((found == debug + 1) || (*(found-2) == ',' + || grub_isspace (*(found-2))))) + ret = 0; + else if (*(found-1) == ',' || grub_isspace (*(found-1))) + ret = 1; + } + + return ret; } void -- 2.27.0