summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJennifer Averett <jennifer.averett@oarcorp.com>2012-10-16 13:38:09 -0500
committerJennifer Averett <jennifer.averett@oarcorp.com>2012-10-16 13:38:09 -0500
commit99ae4eb50f2bcc9d836a43e8d319e72266d75d10 (patch)
tree2768b7bd8e164bace8d10d83295f685b3ddac08c
parentAdd if_nametoindex() (diff)
downloadrtems-libbsd-99ae4eb50f2bcc9d836a43e8d319e72266d75d10.tar.bz2
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.
-rw-r--r--freebsd-userspace/Makefile2
-rw-r--r--freebsd-userspace/commands/sbin/ifconfig/ifconfig.c21
-rw-r--r--freebsd-userspace/commands/sbin/ping/ping.c46
-rw-r--r--freebsd-userspace/commands/sbin/route/route.c21
-rw-r--r--freebsd-userspace/include/err.h13
-rw-r--r--freebsd-userspace/rtems/rtems-shell.c14
6 files changed, 112 insertions, 5 deletions
diff --git a/freebsd-userspace/Makefile b/freebsd-userspace/Makefile
index 7b31a3fc..566e742b 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 3c1a16f4..fc170f8d 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 6014b743..004280cc 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 d3f20bc1..8099d4c4 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 0bf9d593..90c93da7 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 00000000..d1bc6631
--- /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);
+}
+
+