diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-10-17 10:38:34 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-10-31 13:18:48 +0100 |
commit | d01564c473842adfd93148bb367fa0679f99e6b8 (patch) | |
tree | c838d184a92e6df21f32950392190e9b1842adf1 /freebsd | |
parent | Simplify getopt() to getopt_r() translation (diff) | |
download | rtems-libbsd-d01564c473842adfd93148bb367fa0679f99e6b8.tar.bz2 |
Move program control to thread structure
Diffstat (limited to '')
-rwxr-xr-x | freebsd-to-rtems.py | 3 | ||||
-rw-r--r-- | freebsd/include/err.h | 15 | ||||
-rw-r--r-- | freebsd/lib/libc/gen/err.c | 12 | ||||
-rw-r--r-- | freebsd/sbin/ifconfig/ifconfig.c | 38 | ||||
-rw-r--r-- | freebsd/sbin/ping/ping.c | 57 | ||||
-rw-r--r-- | freebsd/sbin/route/route.c | 30 | ||||
-rw-r--r-- | freebsd/sys/sys/proc.h | 1 | ||||
-rw-r--r-- | freebsd/sys/sys/systm.h | 2 | ||||
-rw-r--r-- | freebsd/usr.bin/netstat/main.c | 21 |
9 files changed, 74 insertions, 105 deletions
diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py index 73e6a5ea..1fadb58b 100755 --- a/freebsd-to-rtems.py +++ b/freebsd-to-rtems.py @@ -627,6 +627,7 @@ rtems.addRTEMSSourceFiles( 'rtems/rtems-bsd-panic.c', 'rtems/rtems-bsd-pci_bus.c', 'rtems/rtems-bsd-pci_cfgreg.c', + 'rtems/rtems-bsd-program.c', 'rtems/rtems-bsd-rwlock.c', 'rtems/rtems-bsd-shell.c', 'rtems/rtems-bsd-signal.c', @@ -643,10 +644,8 @@ rtems.addRTEMSSourceFiles( 'rtems/rtems-bsd-thread.c', 'rtems/rtems-bsd-timesupport.c', 'rtems/rtems-bsd-vm_glue.c', - 'rtems/rtems-getprogname.c', 'rtems/rtems-kvm.c', 'rtems/rtems-net-setup.c', - 'rtems/rtems-shell.c', 'rtems/rtems-syslog-initialize.c', 'rtems/rtems-syspoll.c', 'rtems/rtems-uthread_kevent.c', diff --git a/freebsd/include/err.h b/freebsd/include/err.h index 772d654f..65aff6f2 100644 --- a/freebsd/include/err.h +++ b/freebsd/include/err.h @@ -47,19 +47,6 @@ #include <sys/cdefs.h> #include <rtems/bsd/sys/_types.h> -#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); @@ -74,8 +61,10 @@ void warnc(int, const char *, ...) __printf0like(2, 3); void vwarnc(int, const char *, __va_list) __printf0like(2, 0); void warnx(const char *, ...) __printflike(1, 2); void vwarnx(const char *, __va_list) __printflike(1, 0); +#ifndef __rtems__ void err_set_file(void *); void err_set_exit(void (*)(int)); +#endif /* __rtems__ */ __END_DECLS #endif /* !_ERR_H_ */ diff --git a/freebsd/lib/libc/gen/err.c b/freebsd/lib/libc/gen/err.c index bbd5bffc..d2956c81 100644 --- a/freebsd/lib/libc/gen/err.c +++ b/freebsd/lib/libc/gen/err.c @@ -46,9 +46,16 @@ __FBSDID("$FreeBSD$"); #include "libc_private.h" +#ifndef __rtems__ static FILE *err_file; /* file to use for error output */ static void (*err_exit)(int); +#else /* __rtems__ */ +#include <machine/rtems-bsd-program.h> +#define err_file stderr +#define err_set_file(x) do { } while (0) +#endif /* __rtems__ */ +#ifndef __rtems__ /* * This is declared to take a `void *' so that the caller is not required * to include <stdio.h> first. However, it is really a `FILE *', and the @@ -68,6 +75,7 @@ err_set_exit(void (*ef)(int)) { err_exit = ef; } +#endif /* __rtems__ */ __weak_reference(_err, err); @@ -109,8 +117,10 @@ verrc(int eval, int code, const char *fmt, va_list ap) fprintf(err_file, ": "); } fprintf(err_file, "%s\n", strerror(code)); +#ifndef __rtems__ if (err_exit) err_exit(eval); +#endif /* __rtems__ */ exit(eval); } @@ -132,8 +142,10 @@ verrx(int eval, const char *fmt, va_list ap) if (fmt != NULL) vfprintf(err_file, fmt, ap); fprintf(err_file, "\n"); +#ifndef __rtems__ if (err_exit) err_exit(eval); +#endif /* __rtems__ */ exit(eval); } diff --git a/freebsd/sbin/ifconfig/ifconfig.c b/freebsd/sbin/ifconfig/ifconfig.c index c8a296ee..d983862d 100644 --- a/freebsd/sbin/ifconfig/ifconfig.c +++ b/freebsd/sbin/ifconfig/ifconfig.c @@ -115,25 +115,6 @@ 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 @@ -182,12 +163,23 @@ usage(void) } #ifdef __rtems__ -int -main_ifconfig(int argc, char *argv[]) -#else +#include <machine/rtems-bsd-program.h> + +static int main(int argc, char *argv[]); + +static int rtems_shell_main_ifconfig(int argc, char *argv[]) +{ + descr = NULL; + descrlen = 64; + newaddr = 1; + supmedia = 0; + printkeys = 0; + + return rtems_bsd_program_call_main("ifconfig", main, argc, argv); +} +#endif /* __rtems__ */ int main(int argc, char *argv[]) -#endif { int c, all, namesonly, downonly, uponly; const struct afswtch *afp = NULL; diff --git a/freebsd/sbin/ping/ping.c b/freebsd/sbin/ping/ping.c index 5adb9d5b..f1b4b912 100644 --- a/freebsd/sbin/ping/ping.c +++ b/freebsd/sbin/ping/ping.c @@ -218,44 +218,39 @@ static void tvsub(struct timeval *, struct timeval *); static void usage(void) __dead2; #ifdef __rtems__ -static int main_ping(int argc, char *const *argv); +#include <machine/rtems-bsd-program.h> + +static int main(int argc, char **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; + 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; + + return rtems_bsd_program_call_main("ping", main, argc, argv); } -#endif - - - +#endif /* __rtems__ */ int -#ifdef __rtems__ -main_ping(argc, argv) -#else main(argc, argv) -#endif int argc; +#ifndef __rtems__ char *const *argv; +#else /* __rtems__ */ + char **argv; +#endif /* __rtems__ */ { struct sockaddr_in from, sock_in; struct in_addr ifaddr; diff --git a/freebsd/sbin/route/route.c b/freebsd/sbin/route/route.c index 509c5952..964188ff 100644 --- a/freebsd/sbin/route/route.c +++ b/freebsd/sbin/route/route.c @@ -116,24 +116,6 @@ 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; @@ -147,11 +129,17 @@ usage(cp) } #ifdef __rtems__ +#include <machine/rtems-bsd-program.h> + +static int main(int argc, char **argv); + +static int rtems_shell_main_route(int argc, char *argv[]) +{ + return rtems_bsd_program_call_main("route", main, argc, argv); +} +#endif /* __rtems__ */ int -main_route(argc, argv) -#else main(argc, argv) -#endif int argc; char **argv; { diff --git a/freebsd/sys/sys/proc.h b/freebsd/sys/sys/proc.h index 5cd7b64c..6dbc88c5 100644 --- a/freebsd/sys/sys/proc.h +++ b/freebsd/sys/sys/proc.h @@ -201,6 +201,7 @@ struct thread { #ifdef __rtems__ rtems_chain_node td_node; Thread_Control *td_thread; + struct rtems_bsd_program_control *td_prog_ctrl; char td_name [16]; #endif /* __rtems__ */ #ifndef __rtems__ diff --git a/freebsd/sys/sys/systm.h b/freebsd/sys/sys/systm.h index 1349e6d0..e464356a 100644 --- a/freebsd/sys/sys/systm.h +++ b/freebsd/sys/sys/systm.h @@ -153,8 +153,10 @@ struct ucred; struct uio; struct _jmp_buf; +#ifndef __rtems__ int setjmp(struct _jmp_buf *); void longjmp(struct _jmp_buf *, int) __dead2; +#endif /* __rtems__ */ int dumpstatus(vm_offset_t addr, off_t count); int nullop(void); int eopnotsupp(void); diff --git a/freebsd/usr.bin/netstat/main.c b/freebsd/usr.bin/netstat/main.c index d1714b6d..dc413942 100644 --- a/freebsd/usr.bin/netstat/main.c +++ b/freebsd/usr.bin/netstat/main.c @@ -361,15 +361,14 @@ int unit; /* unit number for above */ int af; /* address family */ int live; /* true if we are examining a live system */ - #ifdef __rtems__ -static int main_netstat(int argc, char *argv[]); +#include <machine/rtems-bsd-program.h> + +static int main(int argc, char *argv[]); + static int rtems_shell_main_netstat(int argc, char *argv[]) { int i; - rtems_shell_globals_t netstat_globals; - rtems_shell_globals = &netstat_globals; - memset (rtems_shell_globals, 0, sizeof (netstat_globals)); i = 0; protox[i].pr_index = N_TCBINFO; @@ -728,19 +727,11 @@ static int rtems_shell_main_netstat(int argc, char *argv[]) #endif noutputs = 0; - netstat_globals.exit_code = 1; - if (setjmp (netstat_globals.exit_jmp) == 0) - return main_netstat (argc, argv); - return netstat_globals.exit_code; + return rtems_bsd_program_call_main("netstat", main, argc, argv); } -#endif - +#endif /* __rtems__ */ int -#ifdef __rtems__ -main_netstat(int argc, char *argv[]) -#else main(int argc, char *argv[]) -#endif { struct protox *tp = NULL; /* for printing cblocks & stats */ int ch; |