git: ac6a9fed6cd1 - stable/14 - ps(1): Complete libxo transition

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Thu, 01 May 2025 19:51:23 UTC
The branch stable/14 has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=ac6a9fed6cd117fb504823056b8b8226f1acdf45

commit ac6a9fed6cd117fb504823056b8b8226f1acdf45
Author:     Yan-Hao Wang <yanhaowang@FreeBSD.org>
AuthorDate: 2024-10-12 15:06:59 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-05-01 19:35:07 +0000

    ps(1): Complete libxo transition
    
    Reviewed by:    des
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D41422
    
    (cherry picked from commit e17a2944a6e08478b9c073ba62c46f6714af16a2)
---
 bin/ps/keyword.c | 14 +++++++-------
 bin/ps/print.c   |  1 -
 bin/ps/ps.c      | 13 +++++++------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index 7996bc000e03..4d93cd152f43 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -42,7 +42,6 @@ static char sccsid[] = "@(#)keyword.c	8.5 (Berkeley) 4/2/94";
 #include <sys/sysctl.h>
 #include <sys/user.h>
 
-#include <err.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -256,7 +255,8 @@ showkey(void)
 	}
 	xo_emit("\n");
 	xo_close_list("key");
-	xo_finish();
+	if (xo_finish() < 0)
+		xo_err(1, "stdout");
 }
 
 void
@@ -297,7 +297,7 @@ parsefmt(const char *p, int user)
 				continue;
 		}
 		if ((vent = malloc(sizeof(struct varent))) == NULL)
-			errx(1, "malloc failed");
+			xo_errx(1, "malloc failed");
 		vent->header = v->header;
 		if (hp) {
 			hp = strdup(hp);
@@ -306,13 +306,13 @@ parsefmt(const char *p, int user)
 		}
 		vent->var = malloc(sizeof(*vent->var));
 		if (vent->var == NULL)
-			errx(1, "malloc failed");
+			xo_errx(1, "malloc failed");
 		memcpy(vent->var, v, sizeof(*vent->var));
 		STAILQ_INSERT_TAIL(&varlist, vent, next_ve);
 	}
 	free(tempstr1);
 	if (STAILQ_EMPTY(&varlist)) {
-		warnx("no valid keywords; valid keywords:");
+		xo_warnx("no valid keywords; valid keywords:");
 		showkey();
 		exit(1);
 	}
@@ -351,7 +351,7 @@ findvar(char *p, int user, char **header)
 			rflen = strlen(v->alias) + strlen(hp) + 2;
 			realfmt = malloc(rflen);
 			if (realfmt == NULL)
-				errx(1, "malloc failed");
+				xo_errx(1, "malloc failed");
 			snprintf(realfmt, rflen, "%s=%s", v->alias, hp);
 			parsefmt(realfmt, user);
 			free(realfmt);
@@ -359,7 +359,7 @@ findvar(char *p, int user, char **header)
 		return ((VAR *)NULL);
 	}
 	if (!v) {
-		warnx("%s: keyword not found", p);
+		xo_warnx("%s: keyword not found", p);
 		eval = 1;
 	}
 	if (header)
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 8972cb14758b..1ed6afe995c5 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -47,7 +47,6 @@ static char sccsid[] = "@(#)print.c	8.6 (Berkeley) 4/16/94";
 #include <sys/sysctl.h>
 #include <sys/vmmeter.h>
 
-#include <err.h>
 #include <grp.h>
 #include <jail.h>
 #include <langinfo.h>
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 897b4ccd9a92..98d95eb08aa7 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -59,7 +59,6 @@ static char sccsid[] = "@(#)ps.c	8.4 (Berkeley) 4/2/94";
 #include <sys/mount.h>
 
 #include <ctype.h>
-#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <grp.h>
@@ -670,7 +669,8 @@ main(int argc, char *argv[])
 
 	if (nkept == 0) {
 		printheader();
-		xo_finish();
+		if (xo_finish() < 0)
+			xo_err(1, "stdout");
 		exit(1);
 	}
 
@@ -755,7 +755,8 @@ main(int argc, char *argv[])
 	}
 	xo_close_list("process");
 	xo_close_container("process-information");
-	xo_finish();
+	if (xo_finish() < 0)
+		xo_err(1, "stdout");
 
 	free_list(&gidlist);
 	free_list(&jidlist);
@@ -825,14 +826,14 @@ addelem_jid(struct listinfo *inf, const char *elem)
 	int tempid;
 
 	if (*elem == '\0') {
-		warnx("Invalid (zero-length) jail id");
+		xo_warnx("Invalid (zero-length) jail id");
 		optfatal = 1;
 		return (0);		/* Do not add this value. */
 	}
 
 	tempid = jail_getid(elem);
 	if (tempid < 0) {
-		warnx("Invalid %s: %s", inf->lname, elem);
+		xo_warnx("Invalid %s: %s", inf->lname, elem);
 		optfatal = 1;
 		return (0);
 	}
@@ -1493,7 +1494,7 @@ usage(void)
 {
 #define	SINGLE_OPTS	"[-aCcde" OPT_LAZY_f "HhjlmrSTuvwXxZ]"
 
-	(void)xo_error("%s\n%s\n%s\n%s\n%s\n",
+	xo_error("%s\n%s\n%s\n%s\n%s\n",
 	    "usage: ps [--libxo] " SINGLE_OPTS " [-O fmt | -o fmt]",
 	    "          [-G gid[,gid...]] [-J jid[,jid...]] [-M core] [-N system]",
 	    "          [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]",