[rtems-libbsd commit] Added rtems exit code to ping, route, and ifconfig commands.

Jennifer Averett jennifer at rtems.org
Tue Oct 16 18:36:57 UTC 2012


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

Author:    Jennifer Averett <jennifer.averett at oarcorp.com>
Date:      Tue Oct 16 13:38:09 2012 -0500

Added rtems exit code to ping, route, and ifconfig commands.

The rtems shell commands should not exit but allow multiple
command attempts and some of the commands share code that
will exit.  For this reason a common exit routine was
provided and code added to err.h to address this.

allow access to it.

---

 freebsd-userspace/Makefile                         |    2 +
 .../commands/sbin/ifconfig/ifconfig.c              |   21 +++++++++-
 freebsd-userspace/commands/sbin/ping/ping.c        |   46 ++++++++++++++++++-
 freebsd-userspace/commands/sbin/route/route.c      |   21 +++++++++-
 freebsd-userspace/include/err.h                    |   13 ++++++
 freebsd-userspace/rtems/rtems-shell.c              |   14 ++++++
 6 files changed, 112 insertions(+), 5 deletions(-)

diff --git a/freebsd-userspace/Makefile b/freebsd-userspace/Makefile
index 7b31a3f..566e742 100644
--- a/freebsd-userspace/Makefile
+++ b/freebsd-userspace/Makefile
@@ -149,6 +149,8 @@ C_FILES += rtems/rtems-getprogname.c
 C_FILES += rtems/rtems-uthread_main_np.c
 C_FILES += rtems/rtems-uthread_kevent.c
 C_FILES += rtems/rtems-uthread_kqueue.c
+C_FILES += rtems/rtems-shell.c
+
 
 # ping command sources
 C_FILES += commands/sbin/ping/ping.c
diff --git a/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c b/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c
index 3c1a16f..fc170f8 100644
--- a/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c
+++ b/freebsd-userspace/commands/sbin/ifconfig/ifconfig.c
@@ -128,6 +128,25 @@ static struct afswtch *af_getbyfamily(int af);
 static void af_other_status(int);
 
 #ifdef __rtems__
+static int main_ifconfig(int argc, char *argv[]);
+static int rtems_shell_main_ifconfig(int argc, char *argv[])
+{
+  rtems_shell_globals_t  ifconfig_globals;
+  rtems_shell_globals = &ifconfig_globals;
+  memset (rtems_shell_globals, 0, sizeof (ifconfig_globals));
+  descr = NULL;
+  descrlen = 64;
+  newaddr = 1;
+  supmedia = 0;
+  printkeys = 0;	
+  ifconfig_globals.exit_code = 1;
+  if (setjmp (ifconfig_globals.exit_jmp) == 0)
+    return main_ifconfig ( argc, argv);
+  return ifconfig_globals.exit_code;
+}
+#endif
+
+#ifdef __rtems__
 static struct ifconfig_option *opts = NULL;
 
 void
@@ -1229,7 +1248,7 @@ ifconfig_ctor(void)
     "ifconfig",                    /* name */
     "ifconfig [args]",             /* usage */
     "net",                         /* topic */
-    main_ifconfig,                 /* command */
+    rtems_shell_main_ifconfig,     /* command */
     NULL,                          /* alias */
     NULL                           /* next */
   };
diff --git a/freebsd-userspace/commands/sbin/ping/ping.c b/freebsd-userspace/commands/sbin/ping/ping.c
index 6014b74..004280c 100644
--- a/freebsd-userspace/commands/sbin/ping/ping.c
+++ b/freebsd-userspace/commands/sbin/ping/ping.c
@@ -228,6 +228,37 @@ static void stopit(int);
 static void tvsub(struct timeval *, struct timeval *);
 static void usage(void) __dead2;
 
+#ifdef __rtems__
+static int main_ping(int argc, char *const *argv);
+static int rtems_shell_main_ping(int argc, char *argv[])
+{
+  rtems_shell_globals_t  ping_globals;
+  rtems_shell_globals = &ping_globals;
+  memset (rtems_shell_globals, 0, sizeof (ping_globals));
+  BBELL = '\a';
+  BSPACE = '\b';
+  DOT = '.';
+  icmp_type = ICMP_ECHO;
+  icmp_type_rsp = ICMP_ECHOREPLY;
+  phdr_len = 0;
+  sweepmin = 0;
+  sweepincr = 1;
+  interval = 1000;
+  waittime = MAXWAIT;
+  nrcvtimeout = 0;
+  tmin = 999999999.0;
+  tmax = 0.0;
+  tsum = 0.0;
+  tsumsq = 0.0;
+  ping_globals.exit_code = 1;
+  if (setjmp (ping_globals.exit_jmp) == 0)
+    return main_ping (argc, argv);
+  return ping_globals.exit_code;
+}
+#endif
+
+
+
 int
 #ifdef __rtems__
 main_ping(argc, argv)
@@ -519,11 +550,13 @@ main(argc, argv)
 			break;
 		default:
 			usage();
+
 		}
 	}
 
 	if (argc - optind != 1)
 		usage();
+
 	target = argv[optind];
 
 	switch (options & (F_MASK|F_TIME)) {
@@ -937,6 +970,13 @@ main(argc, argv)
 		}
 	}
 	finish();
+#ifdef __rtems__
+	/* RTEMS shell programs return -- they do not exit */
+	if (nreceived)
+		return(0);
+	else
+		return(2);
+#endif
 	/* NOTREACHED */
 	exit(0);	/* Make the compiler happy */
 }
@@ -1434,11 +1474,12 @@ finish()
 		    "round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\n",
 		    tmin, avg, tmax, sqrt(vari));
 	}
-
+#ifndef __rtems__
 	if (nreceived)
 		exit(0);
 	else
 		exit(2);
+#endif
 }
 
 #ifdef notdef
@@ -1737,7 +1778,6 @@ fill(bp, patp)
 static void
 usage()
 {
-
 	(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
 "usage: ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize]",
 "            [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]",
@@ -1757,7 +1797,7 @@ usage()
     "ping",                        /* name */
     "ping [args]",                 /* usage */
     "net",                         /* topic */
-    main_ping,                     /* command */
+    rtems_shell_main_ping,         /* command */
     NULL,                          /* alias */
     NULL                           /* next */
   };
diff --git a/freebsd-userspace/commands/sbin/route/route.c b/freebsd-userspace/commands/sbin/route/route.c
index d3f20bc..8099d4c 100644
--- a/freebsd-userspace/commands/sbin/route/route.c
+++ b/freebsd-userspace/commands/sbin/route/route.c
@@ -80,6 +80,7 @@ static const char rcsid[] =
 #endif
 #endif
 
+
 struct keytab {
 	char	*kt_cp;
 	int	kt_i;
@@ -124,6 +125,24 @@ extern	char *iso_ntoa();
 
 void usage(const char *) __dead2;
 
+#ifdef __rtems__
+
+static int main_route(int argc, char **argv);
+
+static int rtems_shell_main_route(int argc, char *argv[])
+{
+  rtems_shell_globals_t  route_globals;
+  rtems_shell_globals = &route_globals;
+  memset (rtems_shell_globals, 0, sizeof (route_globals));
+  route_globals.exit_code = 1;
+  if (setjmp (route_globals.exit_jmp) == 0)
+    return main_route ( argc, argv);
+  return route_globals.exit_code;
+}
+
+#endif
+
+
 void
 usage(cp)
 	const char *cp;
@@ -1703,7 +1722,7 @@ atalk_ntoa(struct at_addr at)
     "route",                       /* name */
     "route [args]",                /* usage */
     "net",                         /* topic */
-    main_route,                    /* command */
+    rtems_shell_main_route,        /* command */
     NULL,                          /* alias */
     NULL                           /* next */
   };
diff --git a/freebsd-userspace/include/err.h b/freebsd-userspace/include/err.h
index 0bf9d59..90c93da 100644
--- a/freebsd-userspace/include/err.h
+++ b/freebsd-userspace/include/err.h
@@ -52,6 +52,19 @@
 #include <sys/_types.h>
 #endif
 
+#ifdef __rtems__
+#include <setjmp.h>
+typedef struct  rtems_shell_globals_s {
+  jmp_buf exit_jmp;
+  int     exit_code;
+} rtems_shell_globals_t;
+extern rtems_shell_globals_t *rtems_shell_globals;
+void rtems_shell_exit (int code);
+
+#define exit rtems_shell_exit
+#endif
+
+
 __BEGIN_DECLS
 void	err(int, const char *, ...) __dead2 __printf0like(2, 3);
 void	verr(int, const char *, __va_list) __dead2 __printf0like(2, 0);
diff --git a/freebsd-userspace/rtems/rtems-shell.c b/freebsd-userspace/rtems/rtems-shell.c
new file mode 100644
index 0000000..d1bc663
--- /dev/null
+++ b/freebsd-userspace/rtems/rtems-shell.c
@@ -0,0 +1,14 @@
+
+
+#include <err.h>
+
+rtems_shell_globals_t *rtems_shell_globals;
+
+void
+rtems_shell_exit (int code)
+{
+  rtems_shell_globals->exit_code = code;
+  longjmp (rtems_shell_globals->exit_jmp, 1);
+}
+
+




More information about the vc mailing list