[rtems-libbsd commit] route command: Clean up kernal symbol accesses

Joel Sherrill joel at rtems.org
Tue Oct 23 16:09:59 UTC 2012


Module:    rtems-libbsd
Branch:    master
Commit:    0fa7dabe89f31a61899f1fd2527e1e89a9fdf0d4
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=0fa7dabe89f31a61899f1fd2527e1e89a9fdf0d4

Author:    Joel Sherrill <joel.sherrill at oarcorp.com>
Date:      Mon Oct 22 10:53:17 2012 -0500

route command: Clean up kernal symbol accesses

---

 freebsd-userspace/Makefile                         |    1 +
 freebsd-userspace/commands/usr.bin/netstat/if.c    |    6 +++++
 freebsd-userspace/commands/usr.bin/netstat/main.c  |   22 ++++++++++++-------
 freebsd-userspace/commands/usr.bin/netstat/mbuf.c  |    4 +-
 .../commands/usr.bin/netstat/netstat.h             |   14 ++++++++++++
 freebsd-userspace/commands/usr.bin/netstat/unix.c  |    6 +++-
 6 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/freebsd-userspace/Makefile b/freebsd-userspace/Makefile
index a51e98b..c763bc8 100644
--- a/freebsd-userspace/Makefile
+++ b/freebsd-userspace/Makefile
@@ -142,6 +142,7 @@ C_FILES += lib/libmemstat/memstat_uma.c
 # libutil
 C_FILES += lib/libutil/expand_number.c
 C_FILES += lib/libutil/humanize_number.c
+C_FILES += lib/libutil/trimdomain.c
 
 # libipsec files
 C_FILES += lib/libipsec/pfkey_dump.c
diff --git a/freebsd-userspace/commands/usr.bin/netstat/if.c b/freebsd-userspace/commands/usr.bin/netstat/if.c
index b487e10..ca751c4 100644
--- a/freebsd-userspace/commands/usr.bin/netstat/if.c
+++ b/freebsd-userspace/commands/usr.bin/netstat/if.c
@@ -398,10 +398,12 @@ intpr(int interval1, u_long ifnetaddr, void (*pfunc)(char *))
 				break;
 #endif
 
+#ifndef __rtems__
 			case AF_APPLETALK:
 				printf("atalk:%-12.12s ",atalk_print(sa,0x10) );
 				printf("%-11.11s  ",atalk_print(sa,0x0b) );
 				break;
+#endif
 			case AF_LINK:
 				{
 				struct sockaddr_dl *sdl =
@@ -710,11 +712,15 @@ loop:
 	fflush(stdout);
 	if ((noutputs != 0) && (--noutputs == 0))
 		exit(0);
+#ifndef __rtems__
 	oldmask = sigblock(sigmask(SIGALRM));
 	while (!signalled)
 		sigpause(0);
 	signalled = NO;
 	sigsetmask(oldmask);
+#else
+	#warning "Add BSD Signals wrapper"
+#endif
 	line++;
 	first = 0;
 	if (line == 21)
diff --git a/freebsd-userspace/commands/usr.bin/netstat/main.c b/freebsd-userspace/commands/usr.bin/netstat/main.c
index f191604..4ea12a6 100644
--- a/freebsd-userspace/commands/usr.bin/netstat/main.c
+++ b/freebsd-userspace/commands/usr.bin/netstat/main.c
@@ -69,9 +69,7 @@ __FBSDID("$FreeBSD$");
 #include <ctype.h>
 #include <err.h>
 #include <errno.h>
-#ifndef __rtems__
 #include <kvm.h>
-#endif
 #include <limits.h>
 #include <netdb.h>
 #include <nlist.h>
@@ -284,12 +282,14 @@ struct protox pfkeyprotox[] = {
 };
 #endif
 
+#ifndef __rtems__
 struct protox atalkprotox[] = {
 	{ N_DDPCB,	N_DDPSTAT,	1,	atalkprotopr,
 	  ddp_stats,	NULL,		"ddp",	0,	0 },
 	{ -1,		-1,		0,	NULL,
 	  NULL,		NULL,		NULL,	0,	0 }
 };
+#endif
 #ifdef NETGRAPH
 struct protox netgraphprotox[] = {
 	{ N_NGSOCKS,	-1,		1,	netgraphprotopr,
@@ -322,16 +322,18 @@ struct protox *protoprotox[] = {
 #ifdef IPX
 					 ipxprotox,
 #endif
+#ifndef __rtems__
 					 atalkprotox, NULL };
+#else
+				};
+#endif
 
 static void printproto(struct protox *, const char *);
 static void usage(void);
 static struct protox *name2protox(const char *);
 static struct protox *knownname(const char *);
 
-#ifndef __rtems__
 static kvm_t *kvmd;
-#endif
 static char *nlistf = NULL, *memf = NULL;
 
 int	Aflag;		/* show addresses of protocol control block */
@@ -528,7 +530,6 @@ main(int argc, char *argv[])
 	}
 #endif
 
-#ifndef __rtems__
 	/*
 	 * Discard setgid privileges if not the running kernel so that bad
 	 * guys can't print interesting stuff from kernel memory.
@@ -551,7 +552,6 @@ main(int argc, char *argv[])
 			mbpr(NULL, 0);
 		exit(0);
 	}
-#endif
 #if 0
 	/*
 	 * Keep file descriptors open to avoid overhead
@@ -566,9 +566,7 @@ main(int argc, char *argv[])
 	 * used for the queries, which is slower.
 	 */
 #endif
-#ifndef __rtems__
 	kread(0, NULL, 0);
-#endif
 	if (iflag && !sflag) {
 		intpr(interval, nl[N_IFNET].n_value, NULL);
 		exit(0);
@@ -625,17 +623,21 @@ main(int argc, char *argv[])
 			printproto(tp, tp->pr_name);
 	}
 #endif /* IPX */
+#ifndef __rtems__
 	if (af == AF_APPLETALK || af == AF_UNSPEC)
 		for (tp = atalkprotox; tp->pr_name; tp++)
 			printproto(tp, tp->pr_name);
+#endif
 #ifdef NETGRAPH
 	if (af == AF_NETGRAPH || af == AF_UNSPEC)
 		for (tp = netgraphprotox; tp->pr_name; tp++)
 			printproto(tp, tp->pr_name);
 #endif /* NETGRAPH */
+#ifndef __rtems__
 	if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
 		unixpr(nl[N_UNP_COUNT].n_value, nl[N_UNP_GENCNT].n_value,
 		    nl[N_UNP_DHEAD].n_value, nl[N_UNP_SHEAD].n_value);
+#endif
 	exit(0);
 }
 
@@ -703,6 +705,10 @@ printproto(tp, name)
 		(*pr)(off, name, af, tp->pr_protocol);
 }
 
+#ifdef __rtems__
+#define _POSIX2_LINE_MAX 128
+#endif
+
 #ifndef __rtems__
 /*
  * Read kernel memory, return 0 on success.
diff --git a/freebsd-userspace/commands/usr.bin/netstat/mbuf.c b/freebsd-userspace/commands/usr.bin/netstat/mbuf.c
index 268fd86..418c761 100644
--- a/freebsd-userspace/commands/usr.bin/netstat/mbuf.c
+++ b/freebsd-userspace/commands/usr.bin/netstat/mbuf.c
@@ -56,9 +56,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/sysctl.h>
 
 #include <err.h>
-#ifndef __rtems__
 #include <kvm.h>
-#endif
 #include <memstat.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -119,6 +117,8 @@ mbpr(void *kvmd, u_long mbaddr)
 				    memstat_strerror(error));
 			goto out;
 		}
+#else
+		;
 #endif
 	}
 
diff --git a/freebsd-userspace/commands/usr.bin/netstat/netstat.h b/freebsd-userspace/commands/usr.bin/netstat/netstat.h
index 7594464..2c40156 100644
--- a/freebsd-userspace/commands/usr.bin/netstat/netstat.h
+++ b/freebsd-userspace/commands/usr.bin/netstat/netstat.h
@@ -35,6 +35,10 @@
  */
 
 #include <sys/cdefs.h>
+#ifdef __rtems__
+#define __BSD_VISIBLE 1
+#include <freebsd/sys/types.h>
+#endif
 
 extern int	Aflag;	/* show addresses of protocol control block */
 extern int	aflag;	/* show all sockets (including servers) */
@@ -63,7 +67,11 @@ extern int	unit;	/* unit number for above */
 extern int	af;	/* address family */
 extern int	live;	/* true if we are examining a live system */
 
+#ifdef __rtems__
+#define kread(_x, _y, _z) (0)
+#else
 int	kread(u_long addr, void *buf, size_t size);
+#endif
 const char *plural(uintmax_t);
 const char *plurales(uintmax_t);
 const char *pluralies(uintmax_t);
@@ -126,6 +134,12 @@ char	*ipx_phost(struct sockaddr *);
 char	*ns_phost(struct sockaddr *);
 void	upHex(char *);
 
+#ifdef __rtems__
+#define routename rtems_shell_netstats_routername
+#define netname rtems_shell_netstats_netname
+#define sotoxsocket rtems_shell_netstats_sotoxsocket
+#endif
+
 char	*routename(in_addr_t);
 char	*netname(in_addr_t, u_long);
 char	*atalk_print(struct sockaddr *, int);
diff --git a/freebsd-userspace/commands/usr.bin/netstat/unix.c b/freebsd-userspace/commands/usr.bin/netstat/unix.c
index 2e18c9a..15bea05 100644
--- a/freebsd-userspace/commands/usr.bin/netstat/unix.c
+++ b/freebsd-userspace/commands/usr.bin/netstat/unix.c
@@ -72,9 +72,7 @@ __FBSDID("$FreeBSD$");
 #include <stdio.h>
 #include <stdlib.h>
 #include <strings.h>
-#ifndef __rtems__
 #include <kvm.h>
-#endif
 #include "netstat.h"
 
 static	void unixdomainpr(struct xunpcb *, struct xsocket *);
@@ -204,7 +202,9 @@ fail:
 #undef COPYOUT
 #undef KREAD
 }
+#endif
 
+#ifndef __rtems__
 void
 unixpr(u_long count_off, u_long gencnt_off, u_long dhead_off, u_long shead_off)
 {
@@ -253,7 +253,9 @@ unixpr(u_long count_off, u_long gencnt_off, u_long dhead_off, u_long shead_off)
 		free(buf);
 	}
 }
+#endif
 
+#ifndef __rtems__
 static void
 unixdomainpr(struct xunpcb *xunp, struct xsocket *so)
 {




More information about the vc mailing list