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.
This commit is contained in:
Jennifer Averett 2012-10-16 13:38:09 -05:00
parent 6bf758668b
commit 99ae4eb50f
6 changed files with 112 additions and 5 deletions

View File

@ -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

View File

@ -127,6 +127,25 @@ static struct afswtch *af_getbyname(const char *name);
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;
@ -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 */
};

View File

@ -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 */
};

View File

@ -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 */
};

View File

@ -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);

View File

@ -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);
}