Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F171370263
D55362.id180680.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
19 KB
Referenced Files
None
Subscribers
None
D55362.id180680.diff
View Options
diff --git a/usr.bin/fstat/Makefile b/usr.bin/fstat/Makefile
--- a/usr.bin/fstat/Makefile
+++ b/usr.bin/fstat/Makefile
@@ -1,7 +1,7 @@
PROG= fstat
SRCS= fstat.c fuser.c main.c
LINKS= ${BINDIR}/fstat ${BINDIR}/fuser
-LIBADD= procstat
+LIBADD= procstat xo
MAN= fuser.1 fstat.1
diff --git a/usr.bin/fstat/fstat.1 b/usr.bin/fstat/fstat.1
--- a/usr.bin/fstat/fstat.1
+++ b/usr.bin/fstat/fstat.1
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd November 19, 2020
+.Dd May 28, 2026
.Dt FSTAT 1
.Os
.Sh NAME
@@ -33,6 +33,7 @@
.Nd identify active files
.Sh SYNOPSIS
.Nm
+.Op Fl -libxo
.Op Fl fmnsv
.Op Fl M Ar core
.Op Fl N Ar system
@@ -52,6 +53,13 @@
.Pp
The following options are available:
.Bl -tag -width "-N system"
+.It Fl -libxo
+Generate output via
+.Xr libxo 3
+in a selection of different human and machine readable formats.
+See
+.Xr xo_options 7
+for details on command line arguments.
.It Fl f
Restrict examination to files open in the same file systems as
the named file arguments, or to the file system containing the
@@ -327,6 +335,8 @@
.Xr ps 1 ,
.Xr sockstat 1 ,
.Xr systat 1 ,
+.Xr libxo 3 ,
+.Xr xo_parse_args 3 ,
.Xr tcp 4 ,
.Xr unix 4 ,
.Xr iostat 8 ,
diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c
--- a/usr.bin/fstat/fstat.c
+++ b/usr.bin/fstat/fstat.c
@@ -56,9 +56,12 @@
#include <string.h>
#include <unistd.h>
#include <netdb.h>
+#include <libxo/xo.h>
#include "functions.h"
+#define FSTAT_XO_VERSION "1"
+
static int fsflg, /* show files on same filesystem as file(s) argument */
pflg, /* show files open by a particular pid */
sflg, /* show socket details */
@@ -106,6 +109,10 @@
int arg, ch, what;
int cnt, i;
+ argc = xo_parse_args(argc, argv);
+ if (argc < 0)
+ exit(1);
+
arg = 0;
what = KERN_PROC_PROC;
nlistf = memf = NULL;
@@ -130,7 +137,7 @@
if (pflg++)
usage();
if (!isdigit(*optarg)) {
- warnx("-p requires a process id");
+ xo_warnx("-p requires a process id");
usage();
}
what = KERN_PROC_PID;
@@ -143,7 +150,7 @@
if (uflg++)
usage();
if (!(passwd = getpwnam(optarg)))
- errx(1, "%s: unknown uid", optarg);
+ xo_errx(1, "%s: unknown uid", optarg);
what = KERN_PROC_UID;
arg = passwd->pw_uid;
break;
@@ -176,35 +183,48 @@
else
procstat = procstat_open_sysctl();
if (procstat == NULL)
- errx(1, "procstat_open()");
+ xo_errx(1, "procstat_open()");
p = procstat_getprocs(procstat, what, arg, &cnt);
if (p == NULL)
- errx(1, "procstat_getprocs()");
+ xo_errx(1, "procstat_getprocs()");
+ xo_set_version(FSTAT_XO_VERSION);
+ xo_open_container("fstat-information");
/*
* Print header.
*/
- if (nflg)
- printf("%s",
-"USER CMD PID FD DEV INUM MODE SZ|DV R/W");
- else
- printf("%s",
-"USER CMD PID FD MOUNT INUM MODE SZ|DV R/W");
+ if (nflg) {
+ xo_emit("{T:/%-9s}{T:/%-13s}{T:/%-6s}{T:/%-4s}{T:/%-7s}{T:/%-11s}{T:/%-5s}{T:/%-6s}{T:/%-s}",
+ "USER", "CMD", "PID", "FD", "DEV",
+ "INUM", "MODE", "SZ|DV ", "R/W");
+ } else {
+ xo_emit("{T:/%-9s}{T:/%-13s}{T:/%-6s}{T:/%-3s}{T:/%-11s}{T:/%-5s}{T:/%-13s}{T:/%-6s}{T:/%-3s}",
+ "USER", "CMD", "PID", "FD", "MOUNT",
+ "INUM", "MODE", "SZ|DV", "R/W");
+ }
if (checkfile && fsflg == 0)
- printf(" NAME\n");
+ xo_emit(" {T:/NAME}\n");
else
- putchar('\n');
+ xo_emit("\n");
/*
* Go through the process list.
*/
+ xo_open_list("processes");
for (i = 0; i < cnt; i++) {
if (p[i].ki_stat == SZOMB)
continue;
+ xo_open_instance("process");
dofiles(procstat, &p[i]);
+ xo_close_instance("process");
}
+ xo_close_list("processes");
+ xo_close_container("fstat-information");
+
procstat_freeprocs(procstat, p);
procstat_close(procstat);
+ if (xo_finish() < 0)
+ xo_err(1, "stdout");
return (0);
}
@@ -221,11 +241,21 @@
pid = kp->ki_pid;
cmd = kp->ki_comm;
+ xo_emit("{e:user/%-8.8s/%s}", uname);
+ xo_emit("{e:command/%-10s/%s}", cmd);
+ xo_emit("{e:pid/%5d/%d}", pid);
+
head = procstat_getfiles(procstat, kp, mflg);
if (head == NULL)
return;
- STAILQ_FOREACH(fst, head, next)
+
+ xo_open_list("files");
+ STAILQ_FOREACH(fst, head, next){
+ xo_open_instance("file");
print_file_info(procstat, fst, uname, cmd, pid);
+ xo_close_instance("file");
+ }
+ xo_close_list("files");
procstat_freefiles(procstat, head);
}
@@ -264,23 +294,25 @@
/*
* Print entry prefix.
*/
- printf("%-8.8s %-10s %5d", uname, cmd, pid);
- if (fst->fs_uflags & PS_FST_UFLAG_TEXT)
- printf(" text");
- else if (fst->fs_uflags & PS_FST_UFLAG_CDIR)
- printf(" wd");
- else if (fst->fs_uflags & PS_FST_UFLAG_RDIR)
- printf(" root");
- else if (fst->fs_uflags & PS_FST_UFLAG_TRACE)
- printf(" tr");
- else if (fst->fs_uflags & PS_FST_UFLAG_MMAP)
- printf(" mmap");
- else if (fst->fs_uflags & PS_FST_UFLAG_JAIL)
- printf(" jail");
- else if (fst->fs_uflags & PS_FST_UFLAG_CTTY)
- printf(" ctty");
- else
- printf(" %4d", fst->fs_fd);
+ xo_emit("{d:user/%-8.8s/%s} {d:command/%-10s/%s} {d:pid/%5d/%d}", uname,
+ cmd, pid);
+ if (fst->fs_uflags & PS_FST_UFLAG_TEXT) {
+ xo_emit("{:fd/%5s}", "text");
+ } else if (fst->fs_uflags & PS_FST_UFLAG_CDIR) {
+ xo_emit("{:fd/%5s}", "wd");
+ } else if (fst->fs_uflags & PS_FST_UFLAG_RDIR) {
+ xo_emit("{:fd/%5s}", "root");
+ } else if (fst->fs_uflags & PS_FST_UFLAG_TRACE) {
+ xo_emit("{:fd/%5s}", "tr");
+ } else if (fst->fs_uflags & PS_FST_UFLAG_MMAP) {
+ xo_emit("{:fd/%5s}", "mmap");
+ } else if (fst->fs_uflags & PS_FST_UFLAG_JAIL) {
+ xo_emit("{:fd/%5s}", "jail");
+ } else if (fst->fs_uflags & PS_FST_UFLAG_CTTY) {
+ xo_emit("{:fd/%5s}", "ctty");
+ } else {
+ xo_emit("{:fd/%5d}", fst->fs_fd);
+ }
/*
* Print type-specific data.
@@ -300,10 +332,10 @@
print_pts_info(procstat, fst);
break;
case PS_FST_TYPE_KQUEUE:
- printf(" [kqueue]");
+ xo_emit("{:file_type/ [kqueue]/kqueue}");
break;
case PS_FST_TYPE_MQUEUE:
- printf(" [mqueue]");
+ xo_emit("{:file_type/ [mqueue]/mqueue}");
break;
case PS_FST_TYPE_SHM:
print_shm_info(procstat, fst);
@@ -312,22 +344,22 @@
print_sem_info(procstat, fst);
break;
case PS_FST_TYPE_PROCDESC:
- printf(" [procdesc]");
+ xo_emit("{:file_type/ [procdesc]/procdesc}");
break;
case PS_FST_TYPE_DEV:
break;
case PS_FST_TYPE_EVENTFD:
- printf(" [eventfd]");
+ xo_emit("{:file_type/ [eventfd]/eventfd}");
break;
default:
if (vflg)
- fprintf(stderr,
- "unknown file type %d for file %d of pid %d\n",
- fst->fs_type, fst->fs_fd, pid);
+ xo_warnx(
+ "unknown file type %d for file %d of pid %d",
+ fst->fs_type, fst->fs_fd, pid);
}
if (filename && !fsflg)
- printf(" %s", filename);
- putchar('\n');
+ xo_emit(" {:filename/%s}", filename);
+ xo_emit("\n");
}
static char *
@@ -399,15 +431,21 @@
int error;
static int isopen;
+ xo_open_container("socket");
error = procstat_get_socket_info(procstat, fst, &sock, errbuf);
if (error != 0) {
- printf("* error");
+ xo_emit("* {:socket_error/error}");
+ xo_close_container("socket");
return;
}
if (sock.type > STYPEMAX)
- printf("* %s ?%d", sock.dname, sock.type);
+ xo_emit("* {:socket_domain/%s} {:socket_type/?%d}",
+ sock.dname, sock.type);
+
else
- printf("* %s %s", sock.dname, stypename[sock.type]);
+ xo_emit("* {:socket_domain/%s} {:socket_type/%s}",
+ sock.dname, stypename[sock.type]);
+
/*
* protocol specific formatting
@@ -425,21 +463,21 @@
if (!isopen)
setprotoent(++isopen);
if ((pe = getprotobynumber(sock.proto)) != NULL)
- printf(" %s", pe->p_name);
+ xo_emit(" {:protocol_name/%s}", pe->p_name);
else
- printf(" %d", sock.proto);
+ xo_emit(" {:protocol_number/%d}", sock.proto);
if (sock.so_pcb != 0)
- printf(" %lx", (u_long)sock.so_pcb);
+ xo_emit(" {:pcb_address/%lx}", (u_long)sock.so_pcb);
if (!sflg)
break;
- printf(" %s <-> %s",
+ xo_emit(" {:src-address/%s} <-> {:dst-address/%s}",
addr_to_string(&sock.sa_local, src_addr, sizeof(src_addr)),
addr_to_string(&sock.sa_peer, dst_addr, sizeof(dst_addr)));
break;
case AF_UNIX:
/* print address of pcb and connected pcb */
if (sock.so_pcb != 0) {
- printf(" %lx", (u_long)sock.so_pcb);
+ xo_emit(" {:pcb_address/%lx}", (u_long)sock.so_pcb);
if (sock.unp_conn) {
char shoconn[4], *cp;
@@ -450,8 +488,9 @@
if (!(sock.so_snd_sb_state & SBS_CANTSENDMORE))
*cp++ = '>';
*cp = '\0';
- printf(" %s %lx", shoconn,
- (u_long)sock.unp_conn);
+ xo_emit(" {:connection_status/%s} {:connected_pcb_address/%lx}",
+ shoconn, (u_long)sock.unp_conn);
+
}
}
if (!sflg)
@@ -470,12 +509,14 @@
else
addr_to_string(&sock.sa_peer,
src_addr, sizeof(src_addr));
- printf(" %s", src_addr);
+ xo_emit(" {:unix_socket_path/%s}", src_addr);
break;
default:
/* print protocol number and socket address */
- printf(" %d %lx", sock.proto, (u_long)sock.so_addr);
+ xo_emit(" {:protocol_number/%d} {:socket_address/%lx}",
+ sock.proto, (u_long)sock.so_addr);
}
+ xo_close_container("socket");
}
static void
@@ -487,12 +528,16 @@
error = procstat_get_pipe_info(procstat, fst, &ps, errbuf);
if (error != 0) {
- printf("* error");
+ xo_emit("* {:type/error}");
return;
}
- printf("* pipe %8lx <-> %8lx", (u_long)ps.addr, (u_long)ps.peer);
- printf(" %6zd", ps.buffer_cnt);
- print_access_flags(fst->fs_fflags);
+ xo_open_container("pipe");
+ xo_emit("* {:type/pipe} {:pipe-addr/%8lx/%lx} <-> {:peer-addr/%8lx/%lx}",
+ (u_long)ps.addr, (u_long)ps.peer);
+ xo_emit(" {:buffer-count/%6zd/%zd}", ps.buffer_cnt);
+ print_access_flags(fst->fs_fflags);
+ xo_close_container("pipe");
+
}
static void
@@ -504,16 +549,18 @@
error = procstat_get_pts_info(procstat, fst, &pts, errbuf);
if (error != 0) {
- printf("* error");
+ xo_emit("* {:type/error}");
return;
}
- printf("* pseudo-terminal master ");
+ xo_open_container("pts");
+ xo_emit("* {:type/pseudo-terminal master} ");
if (nflg || !*pts.devname) {
- printf("%#10jx", (uintmax_t)pts.dev);
+ xo_emit("{:device/%#10jx/%#jx}", (uintmax_t)pts.dev);
} else {
- printf("%10s", pts.devname);
+ xo_emit("{:device/%10s/%s}", pts.devname);
}
print_access_flags(fst->fs_fflags);
+ xo_close_container("pts");
}
static void
@@ -526,18 +573,26 @@
error = procstat_get_sem_info(procstat, fst, &sem, errbuf);
if (error != 0) {
- printf("* error");
+ xo_emit("* {:type/error}");
return;
}
+ xo_open_container("sem");
if (nflg) {
- printf(" ");
+ xo_emit("{:mount/%13s/%s}", "");
(void)snprintf(mode, sizeof(mode), "%o", sem.mode);
} else {
- printf(" %-15s", fst->fs_path != NULL ? fst->fs_path : "-");
+ xo_emit(" {:mount/%-15s/%s}",
+ fst->fs_path != NULL ? fst->fs_path : "-");
strmode(sem.mode, mode);
+
+ size_t len = strlen(mode);
+ if(len > 0 && mode[len - 1] == ' ')
+ mode[len - 1] = '\0';
+
}
- printf(" %10s %6u", mode, sem.value);
+ xo_emit(" {:mode/%10s/%s} {:value/%6u/%u}", mode, sem.value);
print_access_flags(fst->fs_fflags);
+ xo_close_container("sem");
}
static void
@@ -550,18 +605,24 @@
error = procstat_get_shm_info(procstat, fst, &shm, errbuf);
if (error != 0) {
- printf("* error");
+ xo_emit("* {:type/error}");
return;
}
+ xo_open_container("shm");
if (nflg) {
- printf(" ");
+ xo_emit("{:mount/%13s/%s}", "");
(void)snprintf(mode, sizeof(mode), "%o", shm.mode);
} else {
- printf(" %-15s", fst->fs_path != NULL ? fst->fs_path : "-");
+ xo_emit(" {:mount/%-15s/%s}", fst->fs_path != NULL ? fst->fs_path : "-");
strmode(shm.mode, mode);
+
+ size_t len = strlen(mode);
+ if(len > 0 && mode[len - 1] == ' ')
+ mode[len - 1] = '\0';
}
- printf(" %10s %6ju", mode, shm.size);
+ xo_emit(" {:mode/%10s/%s} {:size/%6ju/%ju}", mode, shm.size);
print_access_flags(fst->fs_fflags);
+ xo_close_container("shm");
}
static void
@@ -581,15 +642,18 @@
badtype = "bad";
else if (vn.vn_type == PS_FST_VTYPE_VNON)
badtype = "none";
+ xo_open_container("vnode");
if (badtype != NULL) {
- printf(" - - %10s -", badtype);
+ xo_emit(" {:mount/%-8s/%s} {:inode/%-8s/%s} {:mode/%-5s/%s} {:size/%s}",
+ "-", "-", badtype, "-");
+ xo_close_container("vnode");
return;
}
if (nflg)
- printf(" %#5jx", (uintmax_t)vn.vn_fsid);
+ xo_emit(" {:mount/%#5jx/%#jx}", (uintmax_t)vn.vn_fsid);
else if (vn.vn_mntdir != NULL)
- (void)printf(" %-8s", vn.vn_mntdir);
+ xo_emit(" {:mount/%-8s/%s}", vn.vn_mntdir);
/*
* Print access mode.
@@ -599,17 +663,18 @@
else {
strmode(vn.vn_mode, mode);
}
- (void)printf(" %6jd %10s", (intmax_t)vn.vn_fileid, mode);
+ xo_emit(" {:inode/%6jd/%jd} {t:mode/%10s/%s}", (intmax_t)vn.vn_fileid, mode);
if (vn.vn_type == PS_FST_VTYPE_VBLK || vn.vn_type == PS_FST_VTYPE_VCHR) {
if (nflg || !*vn.vn_devname)
- printf(" %#6jx", (uintmax_t)vn.vn_dev);
+ xo_emit(" {:device/%#6jx/%#jx}", (uintmax_t)vn.vn_dev);
else {
- printf(" %6s", vn.vn_devname);
+ xo_emit(" {:device/%6s/%s}", vn.vn_devname);
}
} else
- printf(" %6ju", (uintmax_t)vn.vn_size);
+ xo_emit(" {:size/%6ju/%ju}", (uintmax_t)vn.vn_size);
print_access_flags(fst->fs_fflags);
+ xo_close_container("vnode");
}
static void
@@ -622,7 +687,7 @@
strcat(rw, "r");
if (flags & PS_FST_FFLAG_WRITE)
strcat(rw, "w");
- printf(" %2s", rw);
+ xo_emit(" {:access_flags/%2s}", rw);
}
int
@@ -632,11 +697,11 @@
DEVS *cur;
if (stat(filename, &statbuf)) {
- warn("%s", filename);
+ xo_warn("%s", filename);
return (0);
}
if ((cur = malloc(sizeof(DEVS))) == NULL)
- err(1, NULL);
+ xo_err(1, NULL);
cur->next = devs;
devs = cur;
@@ -649,7 +714,7 @@
static void
usage(void)
{
- (void)fprintf(stderr,
+ xo_error(
"usage: fstat [-fmnv] [-M core] [-N system] [-p pid] [-u user] [file ...]\n");
exit(1);
}
diff --git a/usr.bin/fstat/fuser.1 b/usr.bin/fstat/fuser.1
--- a/usr.bin/fstat/fuser.1
+++ b/usr.bin/fstat/fuser.1
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 18, 2020
+.Dd May 28, 2026
.Dt FUSER 1
.Os
.Sh NAME
@@ -30,6 +30,7 @@
.Nd list IDs of all processes that have one or more files open
.Sh SYNOPSIS
.Nm
+.Op Fl -libxo
.Op Fl cfkmu
.Op Fl M Ar core
.Op Fl N Ar system
@@ -54,6 +55,13 @@
.Pp
The following options are available:
.Bl -tag -width indent
+.It Fl -libxo
+Generate output via
+.Xr libxo 3
+in a selection of different human and machine readable formats.
+See
+.Xr xo_parse_args 3
+for details on command line arguments.
.It Fl c
Treat files as mount points and report on any files open in the file system.
.It Fl f
@@ -120,6 +128,8 @@
.Xr fstat 1 ,
.Xr ps 1 ,
.Xr systat 1 ,
+.Xr libxo 3 ,
+.Xr xo_parse_args 3 ,
.Xr iostat 8 ,
.Xr pstat 8 ,
.Xr vmstat 8
diff --git a/usr.bin/fstat/fuser.c b/usr.bin/fstat/fuser.c
--- a/usr.bin/fstat/fuser.c
+++ b/usr.bin/fstat/fuser.c
@@ -37,6 +37,7 @@
#include <err.h>
#include <fcntl.h>
#include <libprocstat.h>
+#include <libxo/xo.h>
#include <limits.h>
#include <paths.h>
#include <pwd.h>
@@ -48,6 +49,7 @@
#include "functions.h"
+#define FUSER_XO_VERSION "1"
/*
* File access mode flags table.
*/
@@ -115,8 +117,7 @@
static void
usage(void)
{
-
- fprintf(stderr,
+ xo_error(
"usage: fuser [-cfhkmu] [-M core] [-N system] [-s signal] file ...\n");
exit(EX_USAGE);
}
@@ -125,14 +126,26 @@
printflags(struct consumer *cons)
{
unsigned int i;
+ char flagbuf[NUFLAGS + NFFLAGS + 1];
+ int pos;
assert(cons);
+ pos = 0;
for (i = 0; i < NUFLAGS; i++)
if ((cons->uflags & uflags[i].flag) != 0)
- fputc(uflags[i].ch, stderr);
+ flagbuf[pos++] = uflags[i].ch;
for (i = 0; i < NFFLAGS; i++)
if ((cons->flags & fflags[i].flag) != 0)
- fputc(fflags[i].ch, stderr);
+ flagbuf[pos++] = fflags[i].ch;
+ flagbuf[pos] = '\0';
+
+ if (pos > 0) {
+ if (xo_get_style(NULL) == XO_STYLE_TEXT) {
+ fprintf(stderr, "%s", flagbuf);
+ } else {
+ xo_emit("{:flags/%s}", flagbuf);
+ }
+ }
}
/*
@@ -145,7 +158,7 @@
assert(path);
if (stat(path, &sb) != 0) {
- warn("%s", path);
+ xo_warn("%s", path);
return (1);
}
reqfile->fileid = sb.st_ino;
@@ -166,6 +179,10 @@
int ch, sig;
unsigned int i, cnt, nfiles;
+ argc = xo_parse_args(argc, argv);
+ if (argc < 0)
+ exit(1);
+
sig = SIGKILL; /* Default to kill. */
nlistf = NULL;
memf = NULL;
@@ -198,7 +215,7 @@
break;
case 's':
if (str2sig(optarg, &sig) != 0)
- errx(EX_USAGE, "invalid signal: %s", optarg);
+ xo_errx(EX_USAGE, "invalid signal: %s", optarg);
break;
case 'h':
/* PASSTHROUGH */
@@ -219,24 +236,28 @@
*/
reqfiles = malloc(argc * sizeof(struct reqfile));
if (reqfiles == NULL)
- err(EX_OSERR, "malloc()");
+ xo_err(EX_OSERR, "malloc()");
nfiles = 0;
while (argc--)
if (!addfile(*(argv++), &reqfiles[nfiles]))
nfiles++;
if (nfiles == 0)
- errx(EX_IOERR, "files not accessible");
+ xo_errx(EX_IOERR, "files not accessible");
if (memf != NULL)
procstat = procstat_open_kvm(nlistf, memf);
else
procstat = procstat_open_sysctl();
if (procstat == NULL)
- errx(1, "procstat_open()");
+ xo_errx(1, "procstat_open()");
procs = procstat_getprocs(procstat, KERN_PROC_PROC, 0, &cnt);
if (procs == NULL)
- errx(1, "procstat_getprocs()");
+ xo_errx(1, "procstat_getprocs()");
+
+ xo_set_version(FUSER_XO_VERSION);
+ xo_open_container("fuser-information");
+ xo_open_list("files");
/*
* Walk through process table and look for matching files.
*/
@@ -245,26 +266,56 @@
dofiles(procstat, &procs[i], reqfiles, nfiles);
for (i = 0; i < nfiles; i++) {
- fprintf(stderr, "%s:", reqfiles[i].name);
- fflush(stderr);
+ xo_open_instance("file");
+
+ if (xo_get_style(NULL) == XO_STYLE_TEXT) {
+ fprintf(stderr, "%s:", reqfiles[i].name);
+ fflush(stderr);
+ } else {
+ xo_emit("{:filename/%s}", reqfiles[i].name);
+ }
+
+ xo_open_list("consumers");
STAILQ_FOREACH(consumer, &reqfiles[i].consumers, next) {
if (consumer->flags != 0) {
- fprintf(stdout, "%6d", consumer->pid);
- fflush(stdout);
+ xo_open_instance("consumer");
+ if (xo_get_style(NULL) == XO_STYLE_TEXT) {
+ fprintf(stdout, "%6d", consumer->pid);
+ fflush(stdout);
+ } else {
+ xo_emit("{:pid/%d}", consumer->pid);
+ }
printflags(consumer);
- if ((flags & UFLAG) != 0)
- fprintf(stderr, "(%s)",
- user_from_uid(consumer->uid, 0));
+ if ((flags & UFLAG) != 0){
+ const char *username = user_from_uid(consumer->uid, 0);
+ if (xo_get_style(NULL) == XO_STYLE_TEXT) {
+ fprintf(stderr, "(%s)", username);
+ } else {
+ xo_emit("{:username/%s}", username);
+ }
+ }
if ((flags & KFLAG) != 0)
kill(consumer->pid, sig);
- fflush(stderr);
+ if (xo_get_style(NULL) == XO_STYLE_TEXT)
+ fflush(stderr);
+ xo_close_instance("consumer");
}
}
- (void)fprintf(stderr, "\n");
+ xo_close_list("consumers");
+ if (xo_get_style(NULL) == XO_STYLE_TEXT) {
+ fprintf(stderr, "\n");
+ }
+ xo_close_instance("file");
}
+ xo_close_list("files");
+ xo_close_container("fuser-information");
+
procstat_freeprocs(procstat, procs);
procstat_close(procstat);
free(reqfiles);
+
+ if(xo_finish() < 0)
+ xo_err(1, "stdout");
return (0);
}
@@ -325,7 +376,7 @@
*/
cons = calloc(1, sizeof(struct consumer));
if (cons == NULL) {
- warn("malloc()");
+ xo_warn("malloc()");
continue;
}
cons->uid = kp->ki_uid;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Sep 11, 6:03 PM (7 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38722453
Default Alt Text
D55362.id180680.diff (19 KB)
Attached To
Mode
D55362: Add libxo flags to fstat and fuser
Attached
Detach File
Event Timeline
Log In to Comment