Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1n3t1f-00065X-3g for mharc-grub-devel@gnu.org; Sun, 02 Jan 2022 00:03:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3t1b-00065I-Qj for grub-devel@gnu.org; Sun, 02 Jan 2022 00:03:20 -0500 Received: from [2607:f8b0:4864:20::f32] (port=36830 helo=mail-qv1-xf32.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n3t1Z-0005wG-K4 for grub-devel@gnu.org; Sun, 02 Jan 2022 00:03:19 -0500 Received: by mail-qv1-xf32.google.com with SMTP id kc16so28155400qvb.3 for ; Sat, 01 Jan 2022 21:03:15 -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=/dZ6aApAMDmUAD22AUr1Gcaf6rva5Lr8q6q0ZqHzvpI=; b=XuauFNl6rvpJa9HXM+jstcHNf7+1aEVqaABi6KO7HfGau8n1Hx5kHw0Z552cFZ0nAX mIHv7zv12SlGaAbk0e1fJ7f358EeJqNH2Per8+36VZJwcyg2p5SNh2t9yDb+/t+Wa4oH bxzwb0WZjQxgxRFi28NE4Q9ffQRwh6qqgTcIe1gNsVrHHp6SWkIaz5QTQn8VAY4Cr96d M63fnFR4TMpGYgPu+n7vbnqUVFkd6IP/w+L+K4lsQB4pQitYUptEadR2Zx1AfDYWdhaj 57udWOQOtggkjLZ/r1ZN/oQDUVBsFLjncgRw2Ype/dEGObwmhqEGCPuIZFT1YzdIkK7K Gdrg== 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=/dZ6aApAMDmUAD22AUr1Gcaf6rva5Lr8q6q0ZqHzvpI=; b=kb9yhfkzxUUtrHb74TiYKphEYNNR6pKx00lR9av/NyDzNzmNfVQHQySgqfeFrpPDiz 3kxneGto6uisYShEASR/2Ex3vRaQDEfun2lH55UuM67TUh7gQNwEEKuNWRtjK8FexKVP DD9mhslPnT0WC+IUbuJWQ8p7N/jd5vrp/d8uEDYAh69poBa+fPr6nOyHKOc8qyBfv9jU xvM61RmbCGOExQKK2kjcKYwmtOTz8+gR3O5M43lZqZdN3xkyi5C7eP3QYwW/H2EOxVRw 2e1PUMcwDLsp3CGCf3G/CU8kMGPPQLPS4u8XsSQdrVp4CayU6A1KMOER83XzCiysSdE4 uJZw== X-Gm-Message-State: AOAM530Daf9+8LyLyZyBtH4/YUfafD9X1llRfRtoFPFOLNooIthoZ8yJ jWcXKig/+mj6gzVf70ApJaqP5FNcpE5QIA== X-Google-Smtp-Source: ABdhPJzgcz8xK4V3/h1nLo/flyvFt8E/YlW4FWSTZHhmN1CVVWTfLblFLxa3b2bOpV6LDeqQn8p/yw== X-Received: by 2002:a0c:f70d:: with SMTP id w13mr37411231qvn.99.1641099794969; Sat, 01 Jan 2022 21:03:14 -0800 (PST) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id de38sm19854020qkb.5.2022.01.01.21.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jan 2022 21:03:14 -0800 (PST) From: Glenn Washburn To: Daniel Kiper , grub-devel@gnu.org Cc: Glenn Washburn Subject: [PATCH v4] misc: Allow selective disabling of debug facility names Date: Sat, 1 Jan 2022 23:02:59 -0600 Message-Id: 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::f32 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::f32; envelope-from=development@efficientek.com; helo=mail-qv1-xf32.google.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) 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: Sun, 02 Jan 2022 05:03:20 -0000 Sometimes you 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 --- Range-diff against v3: 1: 31439a7fb ! 1: b5165ba45 misc: Allow selective disabling of debug facility names @@ Metadata ## Commit message ## misc: Allow selective disabling of debug facility names - Sometimes you know only know which debug logging facility names you want to + Sometimes you 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 @@ docs/grub.texi: processed by commands @command{configfile} (@pxref{configfile}) -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 ++whitespace or @samp{,}. If the special facility named @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 @@ grub-core/kern/misc.c: __attribute__ ((alias("grub_printf"))); + 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 condition is at the start of debug or the start is on a word ++ * boundary, then enable debug. Else if found condition is prefixed with ++ * '-' and the start is on a word boundary, then disable debug. If none ++ * of these cases, ignore. + */ -+ if (found == debug) ++ if (found == debug || *(found - 1) == ',' || grub_isspace (*(found - 1))) + ret = 1; -+ else if (*(found-1) == '-' && ((found == debug + 1) || (*(found-2) == ',' -+ || grub_isspace (*(found-2))))) ++ 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; docs/grub.texi | 13 ++++++++++--- grub-core/kern/misc.c | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index 99d0a0149..22efbd297 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 named @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..b27818be4 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -162,16 +162,49 @@ __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 or the start is on a word + * boundary, then enable debug. Else if found condition is prefixed with + * '-' and the start is on a word boundary, then disable debug. If none + * of these cases, ignore. + */ + if (found == debug || *(found - 1) == ',' || grub_isspace (*(found - 1))) + ret = 1; + else if (*(found - 1) == '-' && ((found == debug + 1) || (*(found - 2) == ',' + || grub_isspace (*(found - 2))))) + ret = 0; + } + + return ret; } void -- 2.27.0