From patchwork Wed Mar 19 21:51:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 14023178 X-Patchwork-Delegate: dsahern@gmail.com Received: from maynard.decadent.org.uk (maynard.decadent.org.uk [65.21.191.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B31722135C1 for ; Wed, 19 Mar 2025 21:51:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.21.191.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742421072; cv=none; b=YZ6Wy9EYQpNbeu8Ax+7BwEVBcoc/CgMXb4QBalCueKqKEQ2Sdbw1StGLeorV0v0ZHl5q1hMja+DuBRiTRwvMJuVVzQ0vgxX/4M6P10tWtSa4TQaELdQJsNzuybygnsLbiJToV913TehxK4lM28bb1SwKNDzCpzZ/aBQ7qBokoTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742421072; c=relaxed/simple; bh=tzIoAGCH1Y1W7YZr8XV1x/E0ijK83jlaKqCdA8ijs98=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=NNYiC1tMgUAPJvxR3dYIItHlaqMKCM0evrKsrRjUCsR5kSl0OWpvV9RTVN2o36M8PuDdS6eN4fPLkTYaFSL4AJX/MwNjfY1QaDK5UbqSzb6vdEZbLtDqJZueGfcExmIcDhTc5inXu5FFf6NC/Fynf57fSnlWk1vpVvD7ysUl6Cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=decadent.org.uk; arc=none smtp.client-ip=65.21.191.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=decadent.org.uk Received: from [2a02:578:851f:1502:391e:c5f5:10e2:b9a3] (helo=deadeye) by maynard with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tv1JW-009oef-1X; Wed, 19 Mar 2025 21:51:02 +0000 Received: from ben by deadeye with local (Exim 4.98) (envelope-from ) id 1tv1JV-00000002bKa-0ivC; Wed, 19 Mar 2025 22:51:01 +0100 Date: Wed, 19 Mar 2025 22:51:01 +0100 From: Ben Hutchings To: netdev@vger.kernel.org Cc: 1088739@bugs.debian.org Subject: [PATCH iproute2 1/2] color: Introduce and use default_color_opt() function Message-ID: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline X-SA-Exim-Connect-IP: 2a02:578:851f:1502:391e:c5f5:10e2:b9a3 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on maynard); SAEximRunCond expanded to false X-Patchwork-Delegate: dsahern@gmail.com As a preparatory step for supporting the NO_COLOR environment variable, replace the direct use of CONF_COLOR with a default_color_opt() function which initially returns CONF_COLOR. Signed-off-by: Ben Hutchings --- bridge/bridge.c | 2 +- include/color.h | 1 + ip/ip.c | 2 +- lib/color.c | 5 +++++ tc/tc.c | 2 +- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bridge/bridge.c b/bridge/bridge.c index f8b5646a..d993ba19 100644 --- a/bridge/bridge.c +++ b/bridge/bridge.c @@ -103,7 +103,7 @@ static int batch(const char *name) int main(int argc, char **argv) { - int color = CONF_COLOR; + int color = default_color_opt(); while (argc > 1) { const char *opt = argv[1]; diff --git a/include/color.h b/include/color.h index 17ec56f3..b543c267 100644 --- a/include/color.h +++ b/include/color.h @@ -20,6 +20,7 @@ enum color_opt { COLOR_OPT_ALWAYS = 2 }; +int default_color_opt(void); bool check_enable_color(int color, int json); bool matches_color(const char *arg, int *val); int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...); diff --git a/ip/ip.c b/ip/ip.c index c7151fbd..e4b71bde 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -166,7 +166,7 @@ int main(int argc, char **argv) const char *libbpf_version; char *batch_file = NULL; char *basename; - int color = CONF_COLOR; + int color = default_color_opt(); /* to run vrf exec without root, capabilities might be set, drop them * if not needed as the first thing. diff --git a/lib/color.c b/lib/color.c index cd0f9f75..5c4cc329 100644 --- a/lib/color.c +++ b/lib/color.c @@ -81,6 +81,11 @@ static void enable_color(void) set_color_palette(); } +int default_color_opt(void) +{ + return CONF_COLOR; +} + bool check_enable_color(int color, int json) { if (json || color == COLOR_OPT_NEVER) diff --git a/tc/tc.c b/tc/tc.c index beb88111..0fc658c8 100644 --- a/tc/tc.c +++ b/tc/tc.c @@ -254,7 +254,7 @@ int main(int argc, char **argv) { const char *libbpf_version; char *batch_file = NULL; - int color = CONF_COLOR; + int color = default_color_opt(); int ret; while (argc > 1) { From patchwork Wed Mar 19 21:51:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 14023209 X-Patchwork-Delegate: dsahern@gmail.com Received: from maynard.decadent.org.uk (maynard.decadent.org.uk [65.21.191.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF0A0219E8C for ; Wed, 19 Mar 2025 21:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.21.191.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742421122; cv=none; b=pXbwnGO+s3z4RV0+/g0oqfdQN5/OH6u05CZoM0ENrl2+SKa3DyxIcsWtoUg+xvCUepLJbCGgx64ugkmaVNtQLGXUGm7OSnndkuPpO69qaLbDUsLMD468kDOpuk4lClAiSFvv5yMUDrFh6rdmdXUxfDntHm+c3rc48Dtbe3dsDY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742421122; c=relaxed/simple; bh=fovONEDMtM7seNcbOra/8SfscccH4qtd4sJJZ0rt9Ho=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Gt6I8cZscgXIDqm3z7FsDhhRyZVU4TxRm9CUrAxBu4VY+qKje6eoT89Oxag2NpBBzI1JRQH5ygGt34R85jIXxVoYEFj03TQaH8J0aeZk74oaNbeJakmXw1uVM8u4qlzRn3nVQWFT8v1oop77R7B0bKcHOoXbqcF+HzoWA4eahzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=decadent.org.uk; arc=none smtp.client-ip=65.21.191.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=decadent.org.uk Received: from [2a02:578:851f:1502:391e:c5f5:10e2:b9a3] (helo=deadeye) by maynard with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tv1KQ-009oev-2Z; Wed, 19 Mar 2025 21:51:58 +0000 Received: from ben by deadeye with local (Exim 4.98) (envelope-from ) id 1tv1KP-00000002bLb-2qAw; Wed, 19 Mar 2025 22:51:57 +0100 Date: Wed, 19 Mar 2025 22:51:57 +0100 From: Ben Hutchings To: netdev@vger.kernel.org Cc: 1088739@bugs.debian.org Subject: [PATCH iproute2 2/2] color: Handle NO_COLOR environment variable in default_color_opt() Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2a02:578:851f:1502:391e:c5f5:10e2:b9a3 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on maynard); SAEximRunCond expanded to false X-Patchwork-Delegate: dsahern@gmail.com The NO_COLOR environment variable is a widely supported way for users to disable coloured text output. See . In case iproute2 is configured to use colours by default, allow this to be overridden by setting NO_COLOR. This is done in default_color_opt() so that colours can still be explicitly enabled with a command-line option. Signed-off-by: Ben Hutchings --- lib/color.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/color.c b/lib/color.c index 5c4cc329..3c6db08d 100644 --- a/lib/color.c +++ b/lib/color.c @@ -83,6 +83,13 @@ static void enable_color(void) int default_color_opt(void) { + const char *no_color; + + /* If NO_COLOR has a non-empty value, coloured output is never wanted */ + no_color = getenv("NO_COLOR"); + if (no_color && *no_color) + return COLOR_OPT_NEVER; + return CONF_COLOR; }