From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1muHOm-0001E7-Qq for mharc-grub-devel@gnu.org; Mon, 06 Dec 2021 12:03:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1muHOl-00016w-9n for grub-devel@gnu.org; Mon, 06 Dec 2021 12:03:31 -0500 Received: from [2607:f8b0:4864:20::729] (port=46889 helo=mail-qk1-x729.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1muHOi-0005vk-2M for grub-devel@gnu.org; Mon, 06 Dec 2021 12:03:30 -0500 Received: by mail-qk1-x729.google.com with SMTP id a11so11758927qkh.13 for ; Mon, 06 Dec 2021 09:03:27 -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=tgYltCiTOAQtuMlCKFXaxOJvfFEEs+oXyhs67qu9m5U=; b=mjra99Gliz/c2gk+70IJdmzJe4zDyloBPtRdowhfptCmZSqsEThLGQD04KgaIcBByD cp2RuhV9SpzGxT8R/alSMF9ssjWklxQwere0eLXpIvEmtM4WPPPOPTyNK74nGKo4V0ja w1X5X8cu/UE1DH606V/EZjUUu+gKbzyl4IyK67SnXybg68XgeuJV1SiWuZDHA0EH6UA1 joboKmQUbQhDKvyP9eRrOCEPg6l6OkIhT7PxoKwycqwA45yldj7dPxHT1c7dHS7+7LA5 yxMB0ngZaQXtbiccj6owYhu+G5kx+uZ+NvvOpFk+ulZrBM7aT1XTEV+nhuB++0HjILx4 fJWQ== 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=tgYltCiTOAQtuMlCKFXaxOJvfFEEs+oXyhs67qu9m5U=; b=wC4B+EEYfr6Psnwz7+9PDafwTMefWUVZsvrpJf/2YlTZbir3Sx6H6BTB+C9hQjnjht OAwAjSCfqz+y5koG7TZOpAzjBofpOkWxzYXSC+24Ml7xi9LPf7u4uZaMcgCNijdQZ1jz KODfsyEQ74h1rXAzp8UFZ7IzZusLfzhGgr/E3KvJfuW41vyuCdYy9RJ3p+kDfz7ubdAu RK64NQnXrj1PTKLjPhmK18cBD0kiC7H6ztmst0ZIIAzlYHms0WhfDW21hWsA29INezFa Zrj6ErhNnalf5TIvAJgzZz9r0hdqs+7rq5w5TBF25wHRVVBPOSHpidKVY3jPrk4dpqJr Slvg== X-Gm-Message-State: AOAM532c9fLusNOv/9ezZCssLbxIbN1BT/bXxHNo2poJZDxDH1ZEY8Ht ee4KRZfWnhVavZCdSg74YqqmeQ== X-Google-Smtp-Source: ABdhPJxOpazPyyKRql7TFcuzEFCjFn9JppfH2uHhc3Jaao3iN5FasVfHcNKqmwLIMSjq/E7YDwGPrQ== X-Received: by 2002:a05:620a:bd6:: with SMTP id s22mr34498529qki.348.1638810206550; Mon, 06 Dec 2021 09:03:26 -0800 (PST) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id g19sm7704155qtg.82.2021.12.06.09.03.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 09:03:26 -0800 (PST) From: Glenn Washburn To: Daniel Kiper , grub-devel@gnu.org Cc: Michael Schierl , Glenn Washburn Subject: [PATCH v2] misc: Allow selective disabling of debug facility names Date: Mon, 6 Dec 2021 11:03:12 -0600 Message-Id: <20211206170312.811318-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::729 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::729; envelope-from=development@efficientek.com; helo=mail-qk1-x729.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, PDS_HP_HELO_NORDNS=0.001, 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: Mon, 06 Dec 2021 17:03:31 -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 --- docs/grub.texi | 13 ++++++++++--- grub-core/kern/misc.c | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 46 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..9f676b73e 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -162,16 +162,48 @@ __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")) + { + ret = 1; + if (debug[3] == '\0') + return 1; + } - return 0; + clen = grub_strlen (condition); + found = debug; + 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 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. + */ + 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