[PATCH] shell: Add a ping command.
This patch adds a ping command to the RTEMS shell. It pings for a count of 5 or so and then stops because there is not ^C in the RTEMS shell. A flood ping also works with the -c option. As stated in the commit message some options work and some do not and I suspect the age of our TCP/IP stack is the reason. I have added doco to the patch but I have not built the doco because of the hassle on MacOS. This code needs to be changed to not use select and so avoid the issue of more than 64 fd's open. ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH] shell: Add a ping command.
The ping code is taken from a recent FreeBSD release. Some options have been tested, other not tested or do not work. This could be due to the age of our TCP/IP stack. This version of ping will not work if more than 64 file descriptors are open at once because the select FD size is 64 as set in newlib. --- cpukit/libmisc/Makefile.am |2 +- cpukit/libmisc/shell/main_ping.c | 1976 cpukit/libmisc/shell/shellconfig.h |7 + cpukit/libmisc/shell/sysexits.h| 116 +++ doc/shell/network.t| 311 +- 5 files changed, 2390 insertions(+), 22 deletions(-) create mode 100644 cpukit/libmisc/shell/main_ping.c create mode 100644 cpukit/libmisc/shell/sysexits.h diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am index 421ddef..bcf8ff0 100644 --- a/cpukit/libmisc/Makefile.am +++ b/cpukit/libmisc/Makefile.am @@ -84,7 +84,7 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \ shell/main_mallocinfo.c shell/main_mdump.c shell/main_medit.c \ shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \ shell/main_mmove.c shell/main_msdosfmt.c \ -shell/main_mv.c shell/main_perioduse.c \ +shell/main_mv.c shell/main_perioduse.c shell/main_ping.c \ shell/main_pwd.c shell/main_rm.c shell/main_rmdir.c shell/main_sleep.c \ shell/main_stackuse.c shell/main_tty.c shell/main_umask.c \ shell/main_unmount.c shell/main_blksync.c shell/main_whoami.c \ diff --git a/cpukit/libmisc/shell/main_ping.c b/cpukit/libmisc/shell/main_ping.c new file mode 100644 index 000..a13d726 --- /dev/null +++ b/cpukit/libmisc/shell/main_ping.c @@ -0,0 +1,1976 @@ +#ifdef __rtems__ +#define __need_getopt_newlib +#include +#endif +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Muuss. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + *may be used to endorse or promote products derived from this software + *without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if !__rtems__ +#ifndef lint +static const char copyright[] = +"@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; +#endif /* not lint */ +#endif +#include +__FBSDID("$FreeBSD$"); + +/* + * P I N G . C + * + * Using the Internet Control Message Protocol (ICMP) "ECHO" facility, + * measure round-trip-delays and packet loss across network paths. + * + * Author - + * Mike Muuss + * U. S. Army Ballistic Research Laboratory + * December, 1983 + * + * Status - + * Public Domain. Distribution Unlimited. + * Bugs - + * More statistics could always be gathered. + * This program has to run SUID to ROOT to access the ICMP socket. + */ + +#include /* NB: we rely on this for */ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#ifdef IPSEC +#include +#endif /*IPSEC*/ + +#include +//#include +#include +#include +#include +#include +#include +#include +#include +//#include +#include + +#include "err.h" +#include "sysexits.h" +#include + +#defineINADDR_LEN ((int)sizeof(in_addr_t)) +#defineTIMEVAL_LEN ((int)sizeof(struct tv32)) +#defineMASK_LEN(ICMP_MASKLEN - ICMP_MINLEN) +#defineTS_LEN (ICMP_TSLEN - ICMP_MINLEN) +#defineDEFDATALEN 56 /* defau
[PATCH] libmisc: Add a stdio redirector helper.
This module makes it easy to redirect and capture stdout, stderr or any other fd in your application. The captured data can be sent off board, for example using syslog, or buffered and displayed in a web page. --- cpukit/Makefile.am | 2 + cpukit/libmisc/Makefile.am | 4 + cpukit/libmisc/redirector/stdio-redirect.c | 333 + cpukit/libmisc/redirector/stdio-redirect.h | 115 ++ cpukit/preinstall.am | 4 + 5 files changed, 458 insertions(+) create mode 100644 cpukit/libmisc/redirector/stdio-redirect.c create mode 100644 cpukit/libmisc/redirector/stdio-redirect.h diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index 2693d46..93b07c8 100644 --- a/cpukit/Makefile.am +++ b/cpukit/Makefile.am @@ -175,6 +175,8 @@ include_rtems_HEADERS += libmisc/mouse/serial_mouse.h ## libqos include_rtems_HEADERS += libqos/qreslib.h +## redirector +include_rtems_HEADERS += libmisc/redirector/stdio-redirect.h ## shell if LIBSHELL include_rtems_HEADERS += libmisc/shell/shell.h diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am index bcf8ff0..1091109 100644 --- a/cpukit/libmisc/Makefile.am +++ b/cpukit/libmisc/Makefile.am @@ -71,6 +71,10 @@ noinst_LIBRARIES += libmouse.a libmouse_a_SOURCES = mouse/mouse_parser.c mouse/serial_mouse.c EXTRA_DIST += mouse/README +## redirector +noinst_LIBRARIES += libredirector.a +libredirector_a_SOURCES = redirector/stdio-redirect.c redirector/stdio-redirect.h + ## shell if LIBSHELL noinst_LIBRARIES += libshell.a diff --git a/cpukit/libmisc/redirector/stdio-redirect.c b/cpukit/libmisc/redirector/stdio-redirect.c new file mode 100644 index 000..e6610cb --- /dev/null +++ b/cpukit/libmisc/redirector/stdio-redirect.c @@ -0,0 +1,333 @@ +/* + * Copyright (C) 2014 Chris Johns (chr...@rtems.org) + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution. + * + * This software with is provided ``as is'' and with NO WARRANTY. + */ + +/* + * RTEMS std redirector. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "stdio-redirect.h" + +#define RTEMS_STDIO_REDIRECT_LOCK_ATTRIBS \ + (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | \ + RTEMS_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL) + +#define RTEMS_STDIO_REDIRECT_RUNNING (1 << 0) +#define RTEMS_STDIO_REDIRECT_FINISHED (1 << 1) + +static bool +rtems_stdio_redirect_lock(rtems_stdio_redirect_t* sr) +{ + rtems_status_code sc = rtems_semaphore_obtain (sr->lock, + RTEMS_WAIT, + RTEMS_NO_TIMEOUT); + if (sc != RTEMS_SUCCESSFUL) + { +fprintf(stderr, "error: stdio-redirect: lock failed: %s\n", rtems_status_text(sc)); +return false; + } + return true; +} + +static bool +rtems_stdio_redirect_unlock(rtems_stdio_redirect_t* sr) +{ + rtems_status_code sc = rtems_semaphore_release (sr->lock); + if (sc != RTEMS_SUCCESSFUL) + { +fprintf(stderr, "error: stdio-redirect: unlock failed: %s\n", rtems_status_text(sc)); +return false; + } + return true; +} + +static bool +rtems_stdio_redirect_write (rtems_stdio_redirect_t* sr, const char* buf, ssize_t len) +{ + if (!rtems_stdio_redirect_lock(sr)) +return false; + + if (sr->buffer) + { +if (len >= sr->buffer_size) +{ + ssize_t offset = len - sr->buffer_size; + memcpy (sr->buffer, buf + offset, sr->buffer_size); + sr->in = 0; + sr->full = true; +} +else +{ + if ((sr->in + len) > sr->buffer_size) + { +ssize_t bytes = sr->buffer_size - sr->in; +memcpy (sr->buffer + sr->in, buf, bytes); +buf += bytes; +len -= bytes; +sr->in = 0; +sr->full = true; + } + else + { +memcpy (sr->buffer + sr->in, buf, len); +sr->in += len; + } +} + } + + if (sr->handler) +sr->handler(buf, len); + + return rtems_stdio_redirect_lock(sr); +} + +static rtems_task +rtems_stdio_redirect_reader(rtems_task_argument arg) +{ + rtems_stdio_redirect_t* sr = (rtems_stdio_redirect_t*) arg; + + while (sr->state & RTEMS_STDIO_REDIRECT_RUNNING) + { +ssize_t r = read (sr->pipe[0], sr->input, sr->input_size); + +if (r <= 0) + break; + +if (sr->echo) + write (sr->fd_dup, sr->input, r); + +if (!rtems_stdio_redirect_write (sr, sr->input, r)) + break; + } + + sr->state |= RTEMS_STDIO_REDIRECT_FINISHED; + + rtems_task_delete(RTEMS_SELF); +} + +rtems_stdio_redirect_t* +rtems_stdio_redirect_open(int fd, + rtems_task_priority priority, + size_t stack_size, + ssize_t input_size, + ssi
[PATCH] shell: Add an md5 hash command for files.
This command lets you get an MD5 hash for a file in an RTEMS file system. --- cpukit/libmisc/Makefile.am | 6 +- cpukit/libmisc/shell/main_md5.c| 110 cpukit/libmisc/shell/shellconfig.h | 6 ++ doc/shell/file.t | 206 + 4 files changed, 258 insertions(+), 70 deletions(-) create mode 100644 cpukit/libmisc/shell/main_md5.c diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am index 1091109..eaf1ffe 100644 --- a/cpukit/libmisc/Makefile.am +++ b/cpukit/libmisc/Makefile.am @@ -85,9 +85,9 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \ shell/main_cp.c shell/main_cpuuse.c shell/main_date.c shell/main_dir.c \ shell/main_echo.c shell/main_exit.c shell/main_halt.c shell/main_help.c \ shell/main_id.c shell/main_logoff.c shell/main_ln.c shell/main_ls.c \ -shell/main_mallocinfo.c shell/main_mdump.c shell/main_medit.c \ -shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \ -shell/main_mmove.c shell/main_msdosfmt.c \ +shell/main_mallocinfo.c shell/main_md5.c shell/main_mdump.c \ +shell/main_medit.c shell/main_mfill.c shell/main_mkdir.c \ +shell/main_mount.c shell/main_mmove.c shell/main_msdosfmt.c \ shell/main_mv.c shell/main_perioduse.c shell/main_ping.c \ shell/main_pwd.c shell/main_rm.c shell/main_rmdir.c shell/main_sleep.c \ shell/main_stackuse.c shell/main_tty.c shell/main_umask.c \ diff --git a/cpukit/libmisc/shell/main_md5.c b/cpukit/libmisc/shell/main_md5.c new file mode 100644 index 000..b0d1833 --- /dev/null +++ b/cpukit/libmisc/shell/main_md5.c @@ -0,0 +1,110 @@ +/* + * MD5 Shell Command Implmentation + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define BUFFER_SIZE (4 * 1024) + +static int rtems_shell_main_md5( + int argc, + char *argv[]) +{ + uint8_t* buffer; + uint8_t hash[16]; + size_t h; + + buffer = malloc(BUFFER_SIZE); + if (!buffer) + { +printf("error: no memory\n"); +return 1; + } + + --argc; + ++argv; + + while (argc) + { +struct stat sb; +MD5_CTX md5; +int in; + +if (stat(*argv, &sb) < 0) +{ +free(buffer); +printf("error: stat of %s: %s\n", *argv, strerror(errno)); +return 1; +} + +in = open(*argv, O_RDONLY); +if (in < 0) +{ +free(buffer); +printf("error: opening %s: %s\n", *argv, strerror(errno)); +return 1; +} + +MD5Init(&md5); + +while (sb.st_size) +{ + ssize_t size = sb.st_size > BUFFER_SIZE ? BUFFER_SIZE : sb.st_size; + + if (read(in, buffer, size) != size) + { +close(in); +free(buffer); +printf("error: reading %s: %s\n", *argv, strerror(errno)); +return 1; + } + + MD5Update(&md5, buffer, size); + + sb.st_size -= size; +} + +MD5Final(hash, &md5); + +close(in); + +printf("MD5 (%s) = ", *argv); +for (h = 0; h < sizeof(hash); ++h) + printf("%02x", (int) hash[h]); +printf("\n"); + +--argc; +++argv; + } + + free(buffer); + + return 0; +} + +rtems_shell_cmd_t rtems_shell_MD5_Command = { + "md5", /* name */ + "md5 [file ...]", /* usage */ + "files", /* topic */ + rtems_shell_main_md5, /* command */ + NULL, /* alias */ + NULL /* next */ +}; diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h index 988bf88..eacfac2 100644 --- a/cpukit/libmisc/shell/shellconfig.h +++ b/cpukit/libmisc/shell/shellconfig.h @@ -71,6 +71,7 @@ extern rtems_shell_cmd_t rtems_shell_DD_Command; extern rtems_shell_cmd_t rtems_shell_HEXDUMP_Command; extern rtems_shell_cmd_t rtems_shell_DEBUGRFS_Command; extern rtems_shell_cmd_t rtems_shell_DF_Command; +extern rtems_shell_cmd_t rtems_shell_MD5_Command; extern rtems_shell_cmd_t rtems_shell_RTC_Command; @@ -382,6 +383,11 @@ extern rtems_shell_alias_t *rtems_shell_Initial_aliases[]; defined(CONFIGURE_SHELL_COMMAND_DF) &rtems_shell_DF_Command, #endif +#if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \ + !defined(CONFIGURE_SHELL_NO_COMMAND_MD5)) || \ +defined(CONFIGURE_SHELL_COMMAND_MD5) + &rtems_shell_MD5_Command, +#endif /* * RTEMS Related commands diff --git a/doc/shell/file.t b/doc/shell/file.t index eb38fe3..2db057d 100644 --- a/doc/shell/file.t +++ b/doc/shell/file.t @@ -36,6 +36,7 @@ The RTEMS shell has the following file and directory commands: @item @code{mkrfs} - format RFS file system @item @code{cd} - alias for chdir @item @code{df} - display file system disk space usage +@item @code{
ls broken in shell.
Hello, It looks like 'ls' is broken in the shell. On sparc/sis running fileio, selecting 's' for shell, logging in and then 'ls' exits the simulator. I saw this with mksh and assumed something was not working with mksh however this now looks like something in 'ls'. With mksh I traced the fault to the heap free call in mksh that failed on the heap check. I have not looked into the fileio failure. Chris ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: ls broken in shell.
Time for your wrapper call generator. Wrap malloc and free. Cod easily be freeing something that was never allocated or a pointer that was incremented. Another guess is a pointer that was not initialized to NULL and ls thinks it should be freed. On September 14, 2014 6:55:26 PM CDT, Chris Johns wrote: >Hello, > >It looks like 'ls' is broken in the shell. On sparc/sis running fileio, > >selecting 's' for shell, logging in and then 'ls' exits the simulator. >I >saw this with mksh and assumed something was not working with mksh >however this now looks like something in 'ls'. With mksh I traced the >fault to the heap free call in mksh that failed on the heap check. I >have not looked into the fileio failure. > >Chris >___ >devel mailing list >devel@rtems.org >http://lists.rtems.org/mailman/listinfo/devel ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: ls broken in shell.
On 15/09/2014 9:59 am, Joel Sherrill wrote: Time for your wrapper call generator. Wrap malloc and free. Cod easily be freeing something that was never allocated or a pointer that was incremented. Hmmm getting automake and friends to support a trace link ... I have some things on between now and the end of the year. ;) Another guess is a pointer that was not initialized to NULL and ls thinks it should be freed. The check failed in a free call from memory in the mksh it released after ls returned. It was like something corrupted the memory. I have not looked at the fileio example and have no time at the moment so just raised the issue. Chris ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH] doc: Sort the shell file commands into alphabetical order.
--- doc/shell/file.t | 3039 -- 1 file changed, 1559 insertions(+), 1480 deletions(-) diff --git a/doc/shell/file.t b/doc/shell/file.t index 2db057d..bda3d3d 100644 --- a/doc/shell/file.t +++ b/doc/shell/file.t @@ -11,32 +11,33 @@ The RTEMS shell has the following file and directory commands: @itemize @bullet -@item @code{umask} - Set file mode creation mask +@item @code{blksync} - sync the block driver +@item @code{cat} - display file contents +@item @code{cd} - alias for chdir +@item @code{chdir} - change the current directory +@item @code{chmod} - change permissions of a file +@item @code{chroot} - change the root directory @item @code{cp} - copy files -@item @code{mv} - move files -@item @code{pwd} - print work directory +@item @code{dd} - format disks +@item @code{debugrfs} - debug RFS file system +@item @code{df} - display file system disk space usage +@item @code{dir} - alias for ls +@item @code{fdisk} - format disks +@item @code{hexdump} - format disks +@item @code{ln} - make links @item @code{ls} - list files in the directory -@item @code{chdir} - change the current directory +@item @code{md5} - display file system disk space usage @item @code{mkdir} - create a directory -@item @code{rmdir} - remove empty directories -@item @code{ln} - make links +@item @code{mkdos} - DOSFS disk format @item @code{mknod} - make device special file -@item @code{chroot} - change the root directory -@item @code{chmod} - change permissions of a file -@item @code{cat} - display file contents -@item @code{msdosfmt} - format disk -@item @code{rm} - remove files +@item @code{mkrfs} - format RFS file system @item @code{mount} - mount disk +@item @code{mv} - move files +@item @code{pwd} - print work directory +@item @code{rmdir} - remove empty directories +@item @code{rm} - remove files +@item @code{umask} - Set file mode creation mask @item @code{unmount} - unmount disk -@item @code{blksync} - sync the block driver -@item @code{dd} - format disks -@item @code{hexdump} - format disks -@item @code{fdisk} - format disks -@item @code{dir} - alias for ls -@item @code{mkrfs} - format RFS file system -@item @code{cd} - alias for chdir -@item @code{df} - display file system disk space usage -@item @code{md5} - display file system disk space usage @end itemize @@ -51,20 +52,19 @@ command as well as providing an example usage. @c @c @page -@subsection umask - set file mode creation mask +@subsection blksync - sync the block driver -@pgindex umask +@pgindex blksync @subheading SYNOPSYS: @example -umask [new_umask] +blksync driver @end example @subheading DESCRIPTION: -This command sets the user file creation mask to @code{new_umask}. The -argument @code{new_umask} may be octal, hexadecimal, or decimal. +This command XXX @subheading EXIT STATUS: @@ -72,156 +72,68 @@ This command returns 0 on success and non-zero if an error is encountered. @subheading NOTES: -This command does not currently support symbolic mode masks. +NONE @subheading EXAMPLES: -The following is an example of how to use @code{umask}: +The following is an example of how to use @code{blksync}: @example -SHLL [/] $ umask -022 -SHLL [/] $ umask 0666 -0666 -SHLL [/] $ umask -0666 +EXAMPLE_TBD @end example @subheading CONFIGURATION: -@findex CONFIGURE_SHELL_NO_COMMAND_UMASK -@findex CONFIGURE_SHELL_COMMAND_UMASK +@findex CONFIGURE_SHELL_NO_COMMAND_BLKSYNC +@findex CONFIGURE_SHELL_COMMAND_BLKSYNC This command is included in the default shell command set. When building a custom command set, define -@code{CONFIGURE_SHELL_COMMAND_UMASK} to have this +@code{CONFIGURE_SHELL_COMMAND_BLKSYNC} to have this command included. This command can be excluded from the shell command set by -defining @code{CONFIGURE_SHELL_NO_COMMAND_UMASK} when all +defining @code{CONFIGURE_SHELL_NO_COMMAND_BLKSYNC} when all shell commands have been configured. @subheading PROGRAMMING INFORMATION: -@findex rtems_shell_rtems_main_umask +@findex rtems_shell_rtems_main_blksync -The @code{umask} is implemented by a C language function +The @code{blksync} is implemented by a C language function which has the following prototype: @example -int rtems_shell_rtems_main_umask( +int rtems_shell_rtems_main_blksync( intargc, char **argv ); @end example -The configuration structure for the @code{umask} has the +The configuration structure for the @code{blksync} has the following prototype: @example -extern rtems_shell_cmd_t rtems_shell_UMASK_Command; +extern rtems_shell_cmd_t rtems_shell_BLKSYNC_Command; @end example @c @c @c @page -@subsection cp - copy files +@subsection cat - display file contents -@pgindex cp +@pgindex cat @subheading SYNOPSYS: @example -cp [-R [-H | -L | -P]] [-f | -i] [-pv] src target -cp [-R [-H | -L] ] [-f | -i] [-NpPv] source_file ... target_directory +cat file1 [file2 .. fileN] @end example @subheading DESCRIPTION: -In the