Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Jun 2014 23:30:10 GMT
From:      zkorchev@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r269834 - soc2014/zkorchev/freebsd_head/usr.bin/fstat
Message-ID:  <201406212330.s5LNUAiv019746@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: zkorchev
Date: Sat Jun 21 23:30:10 2014
New Revision: 269834
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=269834

Log:
  fstat fixes

Modified:
  soc2014/zkorchev/freebsd_head/usr.bin/fstat/fstat.1
  soc2014/zkorchev/freebsd_head/usr.bin/fstat/fstat.c

Modified: soc2014/zkorchev/freebsd_head/usr.bin/fstat/fstat.1
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/fstat/fstat.1	Sat Jun 21 22:53:21 2014	(r269833)
+++ soc2014/zkorchev/freebsd_head/usr.bin/fstat/fstat.1	Sat Jun 21 23:30:10 2014	(r269834)
@@ -71,8 +71,6 @@
 .It Fl N
 Extract the name list from the specified system instead of the default,
 which is the kernel image the system has booted from.
-.It Fl O
-Output the results in JSON format.
 .It Fl m
 Include memory-mapped files in the listing; normally these are excluded
 due to the extra processing required.

Modified: soc2014/zkorchev/freebsd_head/usr.bin/fstat/fstat.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/usr.bin/fstat/fstat.c	Sat Jun 21 22:53:21 2014	(r269833)
+++ soc2014/zkorchev/freebsd_head/usr.bin/fstat/fstat.c	Sat Jun 21 23:30:10 2014	(r269834)
@@ -54,7 +54,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <netdb.h>
-#include <sol.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 #include "functions.h"
 
@@ -65,7 +67,7 @@
 static int	nflg;	/* (numerical) display f.s. and rdev as dev_t */
 static int	mflg;	/* include memory-mapped files */
 static int	vflg;	/* be verbose */
-static int	Oflg;	/* use JSON as output format */
+static int	sol_format;	/* use libsol for output */
 
 typedef struct devs {
 	struct devs	*next;
@@ -77,7 +79,9 @@
 static DEVS *devs;
 static char *memf, *nlistf;
 
+#if defined(SOL_ON)
 static struct sol_stream sol_stream;
+#endif
 
 static int	getfname(const char *filename);
 static void	dofiles(struct procstat *procstat, struct kinfo_proc *p);
@@ -108,8 +112,7 @@
 	int cnt, i;
 
 	/* prevent unused variable warnings */
-	(void)sol_stream;
-	(void)Oflg;
+	(void)sol_format;
 
 	arg = 0;
 	what = KERN_PROC_PROC;
@@ -152,13 +155,6 @@
 		case 'v':
 			vflg = 1;
 			break;
-		case 'O':
-#if defined(SOL_ON)
-			Oflg = 1;
-#else
-			errx(1, "compiled without -O support");
-#endif
-			break;
 		case '?':
 		default:
 			usage();
@@ -191,11 +187,9 @@
 		errx(1, "procstat_getprocs()");
 
 #if defined(SOL_ON)
-	if (Oflg)
-	{
-		sol_init(&sol_stream, SOL_JSON);
+	sol_format = sol_init(&sol_stream);
+	if (sol_format)
 		sol_array_start(&sol_stream);
-	}
 	else
 #endif
 	{
@@ -224,7 +218,7 @@
 	}
 
 #if defined(SOL_ON)
-	if (Oflg) {
+	if (sol_format) {
 		sol_array_end(&sol_stream);
 		sol_term(&sol_stream);
 	}
@@ -253,7 +247,7 @@
 		return;
 	STAILQ_FOREACH(fst, head, next) {
 #if defined(SOL_ON)
-		if (Oflg) {
+		if (sol_format) {
 			sol_map_start(&sol_stream);
 			print_file_info(procstat, fst, uname, cmd, pid);
 			sol_map_end(&sol_stream);
@@ -298,18 +292,18 @@
 	}
 
 #if defined(SOL_ON)
-	if (Oflg)
+	if (sol_format)
 	{
-		sol_map_key(&sol_stream, "user", 4);
+		SOL_MAP_KEYL(&sol_stream, "user");
 		sol_string(&sol_stream, uname, strlen(uname));
 
-		sol_map_key(&sol_stream, "cmd", 3);
+		SOL_MAP_KEYL(&sol_stream, "cmd");
 		sol_string(&sol_stream, cmd, strlen(cmd));
 
-		sol_map_key(&sol_stream, "pid", 3);
+		SOL_MAP_KEYL(&sol_stream, "pid");
 		sol_integer(&sol_stream, pid);
 
-		sol_map_key(&sol_stream, "fd", 2);
+		SOL_MAP_KEYL(&sol_stream, "fd");
 		if (fst->fs_uflags & PS_FST_UFLAG_TEXT)
 			sol_string(&sol_stream, "text", 4);
 		else if (fst->fs_uflags & PS_FST_UFLAG_CDIR)
@@ -383,15 +377,15 @@
 	}
 	if (filename && !fsflg) {
 #if defined(SOL_ON)
-		if (Oflg) {
-			sol_map_key(&sol_stream, "name", 4);
+		if (sol_format) {
+			SOL_MAP_KEYL(&sol_stream, "name");
 			sol_string(&sol_stream, filename, strlen(filename));
 		}
 		else
 #endif
 			printf("  %s", filename);
 	}
-	if (!Oflg) putchar('\n');
+	if (!sol_format) putchar('\n');
 }
 
 static void
@@ -414,16 +408,16 @@
 
 	error = procstat_get_socket_info(procstat, fst, &sock, errbuf);
 	if (error != 0) {
-		if (!Oflg) printf("* error");
+		if (!sol_format) printf("* error");
 		return;
 	}
 #if defined(SOL_ON)
-	if (Oflg)
+	if (sol_format)
 	{
-		sol_map_key(&sol_stream, "socket", 6);
+		SOL_MAP_KEYL(&sol_stream, "socket");
 		sol_string(&sol_stream, sock.dname, strlen(sock.dname));
 
-		sol_map_key(&sol_stream, "type", 4);
+		SOL_MAP_KEYL(&sol_stream, "type");
 		if (sock.type > STYPEMAX)
 			sol_integer(&sol_stream, sock.type);
 		else
@@ -455,22 +449,22 @@
 		if (!isopen)
 			setprotoent(++isopen);
 #if defined(SOL_ON)
-		if (Oflg)
+		if (sol_format)
 		{
-			sol_map_key(&sol_stream, "proto", 5);
+			SOL_MAP_KEYL(&sol_stream, "proto");
 			if ((pe = getprotobynumber(sock.proto)) != NULL)
 				sol_string(&sol_stream, pe->p_name, strlen(pe->p_name));
 			else
 				sol_integer(&sol_stream, sock.proto);
 			if (sock.proto == IPPROTO_TCP ) {
 				if (sock.inp_ppcb != 0) {
-					sol_map_key(&sol_stream, "ppcb", 4);
-					sol_integer(&sol_stream, sock.inp_ppcb); // TODO hex?
+					SOL_MAP_KEYL(&sol_stream, "ppcb");
+					sol_uinteger(&sol_stream, sock.inp_ppcb);
 				}
 			}
 			else if (sock.so_pcb != 0) {
-				sol_map_key(&sol_stream, "pcb", 3);
-				sol_integer(&sol_stream, sock.so_pcb); // TODO hex?
+				SOL_MAP_KEYL(&sol_stream, "pcb");
+				sol_uinteger(&sol_stream, sock.so_pcb);
 			}
 		}
 		else
@@ -492,9 +486,9 @@
 		/* print address of pcb and connected pcb */
 		if (sock.so_pcb != 0) {
 #if defined(SOL_ON)
-			if (Oflg) {
-				sol_map_key(&sol_stream, "pcb", 3);
-				sol_integer(&sol_stream, sock.so_pcb); // TODO hex?
+			if (sol_format) {
+				SOL_MAP_KEYL(&sol_stream, "pcb");
+				sol_uinteger(&sol_stream, sock.so_pcb);
 			}
 			else
 #endif
@@ -511,11 +505,11 @@
 					*cp++ = '>';
 				*cp = '\0';
 #if defined(SOL_ON)
-				if (Oflg) {
-					sol_map_key(&sol_stream, "flow", 4);
+				if (sol_format) {
+					SOL_MAP_KEYL(&sol_stream, "flow");
 					sol_string(&sol_stream, shoconn, cp - shoconn);
-					sol_map_key(&sol_stream, "conn", 4);
-					sol_integer(&sol_stream, sock.unp_conn); // TODO hex?
+					SOL_MAP_KEYL(&sol_stream, "conn");
+					sol_uinteger(&sol_stream, sock.unp_conn);
 				}
 				else
 #endif
@@ -526,10 +520,10 @@
 	default:
 		/* print protocol number and socket address */
 #if defined(SOL_ON)
-		if (Oflg) {
-			sol_map_key(&sol_stream, "proto", 5);
+		if (sol_format) {
+			SOL_MAP_KEYL(&sol_stream, "proto");
 			sol_integer(&sol_stream, sock.proto);
-			sol_map_key(&sol_stream, "address", 7);
+			SOL_MAP_KEYL(&sol_stream, "address");
 			sol_integer(&sol_stream, sock.so_addr);
 		}
 		else
@@ -547,13 +541,13 @@
 
 	error = procstat_get_pipe_info(procstat, fst, &ps, errbuf);
 	if (error != 0) {
-		if (!Oflg) printf("* error");
+		if (!sol_format) printf("* error");
 		return;
 	}
 #if defined(SOL_ON)
-	if (Oflg)
+	if (sol_format)
 	{
-		sol_map_key(&sol_stream, "pipe", 4);
+		SOL_MAP_KEYL(&sol_stream, "pipe");
 		sol_array_start(&sol_stream);
 		sol_integer(&sol_stream, (u_long)ps.addr);
 		sol_integer(&sol_stream, (u_long)ps.peer);
@@ -577,17 +571,17 @@
 
 	error = procstat_get_pts_info(procstat, fst, &pts, errbuf);
 	if (error != 0) {
-		if (!Oflg) printf("* error");
+		if (!sol_format) printf("* error");
 		return;
 	}
 #if defined(SOL_ON)
-	if (Oflg)
+	if (sol_format)
 	{
 		if (nflg || !*pts.devname) {
-			sol_map_key(&sol_stream, "ptm", 3);
+			SOL_MAP_KEYL(&sol_stream, "ptm");
 			sol_integer(&sol_stream, pts.dev);
 		} else {
-			sol_map_key(&sol_stream, "ptmname", 7);
+			SOL_MAP_KEYL(&sol_stream, "ptmname");
 			sol_string(&sol_stream, pts.devname, strlen(pts.devname));
 		}
 	}
@@ -614,25 +608,25 @@
 
 	error = procstat_get_sem_info(procstat, fst, &sem, errbuf);
 	if (error != 0) {
-		if (!Oflg) printf("* error");
+		if (!sol_format) printf("* error");
 		return;
 	}
 #if defined(SOL_ON)
-	if (Oflg)
+	if (sol_format)
 	{
 		if (nflg) {
 			(void)snprintf(mode, sizeof(mode), "%o", sem.mode);
 		}
 		else {
 			if (fst->fs_path) {
-				sol_map_key(&sol_stream, "path", 4);
+				SOL_MAP_KEYL(&sol_stream, "path");
 				sol_string(&sol_stream, fst->fs_path, strlen(fst->fs_path));
 			}
 			strmode(sem.mode, mode);
 		}
-		sol_map_key(&sol_stream, "mode", 4);
+		SOL_MAP_KEYL(&sol_stream, "mode");
 		sol_string(&sol_stream, mode, strlen(mode));
-		sol_map_key(&sol_stream, "sem", 3);
+		SOL_MAP_KEYL(&sol_stream, "sem");
 		sol_integer(&sol_stream, sem.value);
 	}
 	else
@@ -660,25 +654,25 @@
 
 	error = procstat_get_shm_info(procstat, fst, &shm, errbuf);
 	if (error != 0) {
-		if (!Oflg) printf("* error");
+		if (!sol_format) printf("* error");
 		return;
 	}
 #if defined(SOL_ON)
-	if (Oflg)
+	if (sol_format)
 	{
 		if (nflg) {
 			(void)snprintf(mode, sizeof(mode), "%o", shm.mode);
 		}
 		else {
 			if (fst->fs_path) {
-				sol_map_key(&sol_stream, "path", 4);
+				SOL_MAP_KEYL(&sol_stream, "path");
 				sol_string(&sol_stream, fst->fs_path, strlen(fst->fs_path));
 			}
 			strmode(shm.mode, mode);
 		}
-		sol_map_key(&sol_stream, "mode", 4);
+		SOL_MAP_KEYL(&sol_stream, "mode");
 		sol_string(&sol_stream, mode, strlen(mode));
-		sol_map_key(&sol_stream, "shmsize", 7);
+		SOL_MAP_KEYL(&sol_stream, "shmsize");
 		sol_integer(&sol_stream, shm.size);
 	}
 	else
@@ -715,8 +709,8 @@
 		badtype = "none";
 	if (badtype != NULL) {
 #if defined(SOL_ON)
-		if (Oflg) {
-			sol_map_key(&sol_stream, "mode", 4);
+		if (sol_format) {
+			SOL_MAP_KEYL(&sol_stream, "mode");
 			sol_string(&sol_stream, badtype, strlen(badtype));
 		}
 		else
@@ -726,13 +720,13 @@
 	}
 
 #if defined(SOL_ON)
-	if (Oflg) {
+	if (sol_format) {
 		if (nflg) {
-			sol_map_key(&sol_stream, "dev", 3);
-			sol_integer(&sol_stream, vn.vn_fsid); // TODO hex?
+			SOL_MAP_KEYL(&sol_stream, "dev");
+			sol_uinteger(&sol_stream, vn.vn_fsid);
 		}
 		else if (vn.vn_mntdir != NULL) {
-			sol_map_key(&sol_stream, "mount", 5);
+			SOL_MAP_KEYL(&sol_stream, "mount");
 			sol_string(&sol_stream, vn.vn_mntdir, strlen(vn.vn_mntdir));
 		}
 	}
@@ -754,12 +748,12 @@
 		strmode(vn.vn_mode, mode);
 	}
 #if defined(SOL_ON)
-	if (Oflg)
+	if (sol_format)
 	{
-		sol_map_key(&sol_stream, "inode", 5);
+		SOL_MAP_KEYL(&sol_stream, "inode");
 		sol_integer(&sol_stream, vn.vn_fileid);
 
-		sol_map_key(&sol_stream, "mode", 4);
+		SOL_MAP_KEYL(&sol_stream, "mode");
 		sol_string(&sol_stream, mode, strlen(mode));
 	}
 	else
@@ -767,24 +761,24 @@
 		(void)printf(" %6jd %10s", (intmax_t)vn.vn_fileid, mode);
 
 #if defined(SOL_ON)
-	if (Oflg)
+	if (sol_format)
 	{
 		if (vn.vn_type == PS_FST_VTYPE_VBLK || vn.vn_type == PS_FST_VTYPE_VCHR) {
 			if (nflg || !*vn.vn_devname) {
-				sol_map_key(&sol_stream, "dev", 3);
-				sol_integer(&sol_stream, vn.vn_dev); // TODO hex?
+				SOL_MAP_KEYL(&sol_stream, "dev");
+				sol_uinteger(&sol_stream, vn.vn_dev);
 			}
 			else {
-				sol_map_key(&sol_stream, "devname", 7);
+				SOL_MAP_KEYL(&sol_stream, "devname");
 				sol_string(&sol_stream, vn.vn_devname, strlen(vn.vn_devname));
 			}
 		} else
-			sol_map_key(&sol_stream, "size", 4);
+			SOL_MAP_KEYL(&sol_stream, "size");
 			sol_integer(&sol_stream, vn.vn_size);
 	}
 	else
-	{
 #endif
+	{
 		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);
@@ -809,8 +803,8 @@
 	if (flags & PS_FST_FFLAG_WRITE)
 		strcat(rw, "w");
 #if defined(SOL_ON)
-	if (Oflg) {
-		sol_map_key(&sol_stream, "r/w", 3);
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "r/w");
 		sol_string(&sol_stream, rw, strlen(rw));
 	}
 	else
@@ -843,6 +837,6 @@
 usage(void)
 {
 	(void)fprintf(stderr,
- "usage: fstat [-fmnv] [-M core] [-N system] [-p pid] [-u user] [-O] [file ...]\n");
+ "usage: fstat [-fmnv] [-M core] [-N system] [-p pid] [-u user] [file ...]\n");
 	exit(1);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406212330.s5LNUAiv019746>