git: 220800ca96ba - stable/14 - ps(1): Constify the format strings for canned displays
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 01 May 2025 19:51:38 UTC
The branch stable/14 has been updated by olce:
URL: https://cgit.FreeBSD.org/src/commit/?id=220800ca96bad51a4bbd26f4a21d633c71d8aaf9
commit 220800ca96bad51a4bbd26f4a21d633c71d8aaf9
Author: Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2025-04-01 12:50:26 +0000
Commit: Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-05-01 19:37:04 +0000
ps(1): Constify the format strings for canned displays
Now that removal of non-explicitly-requested duplicate columns work with
a O(n) algorithm, remove the ad-hoc optimization of crushing the canned
displays' formats after first use and constify their format strings.
No functional change intended.
This change could also be useful if/when allowing, e.g., to double
letters of canned displays to indicate their columns should not be
subject to automatic removal of duplicates (e.g., 'ps -ll').
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49614
(cherry picked from commit fd6b81712eb9a77bbe484954d18fe1fc4a27116b)
---
bin/ps/ps.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 20f737cbff6d..03454cb2b6ee 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -169,16 +169,16 @@ static void remove_redundant_columns(struct keyword_info *);
static void pidmax_init(void);
static void usage(void);
-static char dfmt[] = "pid,tt,state,time,command";
-static char jfmt[] = "user,pid,ppid,pgid,sid,jobc,state,tt,time,command";
-static char lfmt[] = "uid,pid,ppid,cpu,pri,nice,vsz,rss,mwchan,state,"
- "tt,time,command";
-static char o1[] = "pid";
-static char o2[] = "tt,state,time,command";
-static char ufmt[] = "user,pid,%cpu,%mem,vsz,rss,tt,state,start,time,command";
-static char vfmt[] = "pid,state,time,sl,re,pagein,vsz,rss,lim,tsiz,"
- "%cpu,%mem,command";
-static char Zfmt[] = "label";
+static const char dfmt[] = "pid,tt,state,time,command";
+static const char jfmt[] = "user,pid,ppid,pgid,sid,jobc,state,tt,time,command";
+static const char lfmt[] = "uid,pid,ppid,cpu,pri,nice,vsz,rss,mwchan,state,"
+ "tt,time,command";
+static const char o1[] = "pid";
+static const char o2[] = "tt,state,time,command";
+static const char ufmt[] = "user,pid,%cpu,%mem,vsz,rss,tt,state,start,time,command";
+static const char vfmt[] = "pid,state,time,sl,re,pagein,vsz,rss,lim,tsiz,"
+ "%cpu,%mem,command";
+static const char Zfmt[] = "label";
#define PS_ARGS "AaCcD:de" OPT_LAZY_f "G:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ"
@@ -341,7 +341,6 @@ main(int argc, char *argv[])
case 'j':
parsefmt(jfmt, &varlist, 0);
_fmt = 1;
- jfmt[0] = '\0';
break;
case 'L':
showkey();
@@ -349,7 +348,6 @@ main(int argc, char *argv[])
case 'l':
parsefmt(lfmt, &varlist, 0);
_fmt = 1;
- lfmt[0] = '\0';
break;
case 'M':
memf = optarg;
@@ -364,7 +362,6 @@ main(int argc, char *argv[])
parsefmt(o1, &varlist, 1);
parsefmt(optarg, &varlist, 1);
parsefmt(o2, &varlist, 1);
- o1[0] = o2[0] = '\0';
_fmt = 1;
break;
case 'o':
@@ -433,13 +430,11 @@ main(int argc, char *argv[])
parsefmt(ufmt, &varlist, 0);
sortby = SORTCPU;
_fmt = 1;
- ufmt[0] = '\0';
break;
case 'v':
parsefmt(vfmt, &varlist, 0);
sortby = SORTMEM;
_fmt = 1;
- vfmt[0] = '\0';
break;
case 'w':
if (wflag)
@@ -467,7 +462,6 @@ main(int argc, char *argv[])
break;
case 'Z':
parsefmt(Zfmt, &varlist, 0);
- Zfmt[0] = '\0';
break;
case '?':
default: