Commit Graph

348 Commits

Author SHA1 Message Date
Chris Johns
8f3973fe8d libmisc/shell: Check the shell command pointers when adding a command 2021-08-21 12:49:36 +10:00
Ryan Long
4127a6c056 main_edit.c: get rid of malloc warning
A warning was present when building RTEMS that stated that the argument
for malloc() exceeded the maximum object size. To get rid of this, I
  changed many places where 'int' was being used to 'size_t'.
2021-06-09 11:52:24 -05:00
Ryan Long
2deba0240e main_help.c: Do not care what char is returned by getchar()
CID 1437650: Unchecked return value from library in rtems_shell_help().

Closes #4291
2021-05-28 12:15:50 -05:00
Ryan Long
f29b312ea4 main_cp.c: Ignore return value from stat()
CID 26051: Unchecked return value from library in main_cp().

Closes #4365
2021-05-28 12:15:50 -05:00
Ryan Long
8cf30c41d9 main_rtrace.c: Add error return when malloc fails
CID 1399709: Dereference after null check in
rtems_trace_buffering_shell_save().

Closes #4329
2021-04-29 09:48:00 -05:00
Ryan Long
0b2366024d print-ls.c: Unused value (CID #1255346)
CID 1255346: Unused value in rtems_shell_ls_printacol().

Closes #4340
2021-04-08 17:58:19 -05:00
Ryan Long
fbc764403f main_cp.c: Unused value (CID #1255344)
CID 1255344: Unused value in copy().

Closes #4339
2021-04-08 17:58:19 -05:00
Vijay Kumar Banerjee
2a13ad389a cpukit: Remove libnetworking
Update #3850
2021-04-07 16:15:38 -06:00
Ryan Long
fbab8325a9 main_help.c: Unchecked return value from library (CID #1437650)
CID 1437650: Unchecked return value from library in rtems_shell_help().

Closes #4291
2021-03-08 14:04:10 -06:00
Ryan Long
8e34aa3b7b main_chmod.c: Fix Unchecked return value from library (CID #1063856)
CID 1063856: Unchecked return value from library in
rtems_shell_main_chmod().

Closes #4281
2021-03-08 14:04:10 -06:00
Ryan Long
3246fa42e2 main_edit.c: Fix Unchecked return value (CID #1255318)
CID 1255318: Unchecked return value in display_line().

Updates #4257
2021-03-08 14:04:10 -06:00
Ryan Long
fa25b73ac1 shell.c: Fix Dereference before null check (CID #1467420)
CID 1467420: Dereference before null check in rtems_shell_line_editor().

Closes #4254
2021-02-18 13:34:33 -06:00
Christian Mauderer
1618e69f0e shell: Add i2c and spi commands
This adds some commands that are usefull for debugging simple serial
interfaces.

Even if they are a complete re-implementation, the i2c* commands use a
simmilar call like the Linux i2c tools.
2020-12-14 10:48:57 +01:00
Sebastian Huber
501bd46fd6 shell: Rename "IO" typedef for better Doxygen
An automatic link from every place in the documentation which mentions
"IO" to this dd command internal "IO" typedef is not really nice.
2020-12-02 07:45:53 +01:00
Frank Kühndel
1dbd1079a5 shell/main_edit.c: Fix string truncation warning
Using strlcpy() instead of strncpy():

1) Prevents the compiler warnings
2) Ensures, the string is NUL terminated.
3) Avoids that strncpy() unnecessary fills the unused part of the buffer with
   0 bytes.

(Note that realpath() also returns NULL if the file does not exist - that
happens always if someone creates a new file with the editor of the shell.)
2020-10-15 19:14:52 +02:00
Frank Kühndel
b03c103dbd shell/main_edit.c: Fix use of wrong constant
realpath() requires a buffer of size PATH_MAX and not of size
FILENAME_MAX according to 'man realpath (3)'.
2020-10-15 19:14:52 +02:00
Frank Kühndel
529402f597 shell/shell.c: Fix illegal string copy
This is an illegal use of strcpy() because one is not allowed to
use this function with overlapping source and destination buffers;
whereas memmove() is explicitly designed to handle such cases.

The copiler warning was:

../../../cpukit/libmisc/shell/shell.c:626:13: warning:
'strcpy' accessing between 1 and 2147483645 bytes at offsets
0 and [1, 2147483647] may overlap up to 2147483644 bytes at
offset [1, 2147483644] [-Wrestrict]
2020-10-15 19:14:48 +02:00
Frank Kühndel
2361b2c8cb shell/shell.c: Fix an implicit type cast
With some compiler warnings enabled, the implicit cast may trigger
a compiler warning. The explicit cast avoids this.
2020-10-15 19:12:15 +02:00
Frank Kühndel
a479686c11 shell: Remove not functioning fdisk mount/unmount
The shell has an 'fdisk' command which has sub-commands 'mount' and 'unmount'.
These two sub-commands have a bug which causes them to be not able
to mount anything. This proposed patch removes the buggy file
cpukit/libblock/src/bdpart-mount.c and the mount/unmount commands
from 'fdisk' as bug fix. The 'fdisk' command itself is not removed.
The reasons for removing the sub-commands (instead of fixing the issue) are:

  1) The bug has been introduced on 2010-May-31 with commit
     29e92b090c. Since ten years no one
     can use this feature, nor has anybody complained about it.

  2) Besides of the 'fdisk' 'mount' sub-command, the shell has the
     usual 'mount' and 'unmount' commands which can serve as
     substitutes.

  3) There are additional minor issues (see further down) which needed to
     be addressed when the file will be kept.

What follows below is the precise bug description.

The bug is in function rtems_bdpart_mount() which is only be used
by the 'fdisk' shell command to mount all partitions of a disk with a
single command:

> fdisk DISK_NAME mount
>         mounts the file system of each partition of the disk
>
> fdisk DISK_NAME unmount
>         unmounts the file system of each partition of the disk

The whole command does not work because in file
cpukit/libblock/src/bdpart-mount.c line 103 specifies the file system type
of each partition to be "msdos". Yet, "msdos" does not exist. The name
must be "dosfs".

Beside of this fundamental problem, there are more issues with the code
in bdpart-mount.c:

  1) The function returns RTEMS_SUCCESSFUL despite the mount always fails.

  2) The reason for errors is not written to the terminal.

  3) The directory '/mnt' is created but not deleted later on (failure or not).

  3) There is no documentation about this special 'fdisk' feature in the
     RTEMS Shell Guide ('fdisk' is mentioned but its documentation is a
     bit short):
     https://docs.rtems.org/branches/master/shell/
     file_and_directory.html#fdisk-format-disk

  4) Only "msdos" formatted partitions can be mounted and all partitions
     are mounted read-only. This is hard coded and cannot be changed by
     options. Moreover, there is no information about this to the user of
     the shell (i.e. using 'fdisk' mount requires insider knowledge).

How to reproduce:

  1) For testing, I use the 'testsuites/samples/fileio.exe' sample with qemu:

> cd rtems
> env QEMU_AUDIO_DRV="none" qemu-system-arm -net none -nographic \
> -M realview-pbx-a9 -m 256M -kernel \
> build/arm/realview_pbx_a9_qemu/testsuites/samples/fileio.exe

  2) Type any key to stop the timer and enter the sample tool.
     Type 's' to enter the shell, login as 'root' with the password
     shown in the terminal.

  3) Type the following shell commands (they create a RAM disk,
     partition it, register it, format it and try to mount it):

> mkrd
> fdisk /dev/rda fat32 16 write mbr
> fdisk /dev/rda register
> mkdos /dev/rda1
> fdisk /dev/rda mount

  4) The last line above is the command which fails - without an error
  message. There exists a '/mnt' directory but no '/mnt/rda1' directory
  as it should be:

> ls -la /mnt

  5) If you change line 103 of 'cpukit/libblock/src/bdpart-mount.c'
     from "msdos" to "dosfs", compile and build the executable and
     re-run the above test, '/mnt/rda1' exists (but the file system
     is mounted read-only).

Close #4131
2020-10-12 13:18:27 +02:00
Frank Kühndel
ffc928b9a2 Fixing bug in line editing of the shell with CTRL-U.
This patch fixes a tiny bug in the command line editing of the RTEMS shell.
Typing CTRL-U in the shell should remove all characters left of the cursor.
After pressing CTRL-U, the current implementation does wrongly place the cursor
at the end of the line instead at its beginning.

To reproduce the bug, start the shell and type 'abc123' (no <RETURN>):

> ~/src/rtems $ qemu-system-arm -net none -nographic -M realview-pbx-a9 \
  -m 256M -kernel build/arm/realview_pbx_a9_qemu/testsuites/libtests/dl10.exe
> *** BEGIN OF TEST libdl (RTL) 10 ***
> *** TEST VERSION: 6.0.0.d9bdf166644f612dd628fe4951c12c6f8e94ba5f
> *** TEST STATE: USER_INPUT
> *** TEST BUILD: RTEMS_DEBUG RTEMS_NETWORKING RTEMS_POSIX_API RTEMS_SMP
> *** TEST TOOLS: 10.2.1 20200904 \
  (RTEMS 6, RSB 31f936a7b74d60bda609a9960c6e1a705ba54974, Newlib a0d7982)
> RTL (libdl) commands: dl, rtl
>
> RTEMS Shell on /dev/foobar. Use 'help' to list commands.
> SHLL [/] # abc123

Then move the cursor onto the '1' by hitting three times the <ARROW-LEFT> key.
Next type <CTRL>-U:

> SHLL [/] # 123

Note that the cursor is at the end of the line (after '3') instead of correctly
at the beginning (on the '1'), now.

Continuing typing 'echo ' incorrectly results in the output:

> SHLL [/] # 123echo 123

The patch changes this behavior so that the cursor in the second last step will
be on the '1' and typing 'echo ' will then correctly reflected as:

> SHLL [/] # echo 123

Close #4097.
2020-09-28 14:16:06 +02:00
eadler
208ebf2099 dd(1): Use a local swapbytes() function.
swab(3) has restrict qualifiers for src and dst.
Avoid relying on undefined overlapping swab behavior.

Obtained From: OpenBSD
2020-08-20 14:03:20 +02:00
Chris Johns
20b1bdba72 shell: Only clear std handles when the shell task exits
Clearing the std file handles when the main loop exited crashes
telnetd as it reuses its session threads.
2020-08-08 18:12:26 +10:00
Sebastian Huber
1af8e45bb7 rtems: Add rtems_get_copyright_notice()
Update #3973.
2020-05-06 07:47:34 +02:00
Sebastian Huber
4b9b6ddb9f Use rtems_get_version_string()
Update #3970.
2020-05-06 07:39:09 +02:00
Sebastian Huber
cfe8f7a9b7 doxygen: Switch @brief and @ingroup
This order change fixes the Latex documentation build via Doxygen.
2020-04-28 09:04:00 +02:00
Sebastian Huber
80cf60efec Canonicalize config.h include
Use the following variant which was already used by most source files:

  #ifdef HAVE_CONFIG_H
  #include "config.h"
  #endif
2020-04-16 07:30:00 +02:00
Chris Johns
d007cc2cee libmisc/shell: Fix the handling of joel scripts in telnet
- Fix the passing of std[in/out] to child threads
- Fix deleting of managed memory in the key destructor
- Only set the key in the main loop thread
- Only allocate a shell env outside of the main loop
- Fix memory leak if the task start fails
- Remove error level from shell env, it cannot be returned this way. Add
  exit_code but the API is broken so it cannot be returned.

Closes #3859
2020-04-15 08:30:30 +10:00
Sebastian Huber
38207a31e4 Move feature macro before "config.h" include
This allows to use header includes in "config.h" to reduce the build
configuration checks.

Update #3818.
2019-11-19 16:05:54 +01:00
Sebastian Huber
cc060f0b35 shell: Avoid rtems_error()
Do not use the rtems_error() function since this function pulls in
exit() and abort().  The abort() function pulls in raise() which pulls
in the whole POSIX signals support.  This change saves about 16KiB of
text/rodata on ARM Thumb-2 systems.
2019-05-14 11:11:51 +02:00
Joel Sherrill
c319945f53 main_edit.c: Use strncpy() to eliminate potential buffer overflow. 2019-03-14 08:21:44 -05:00
Sebastian Huber
3fe215502a Remove superfluous <rtems/system.h> includes 2019-03-14 13:13:27 +01:00
Jonathan Brandmeyer
2e8a66d13f shell: Correct argument order of mfill
Close #3720.
2019-03-08 07:39:42 +01:00
Sebastian Huber
7bde91bd5f Fix format warnings due to ino_t changes 2019-01-10 09:06:56 +01:00
Sebastian Huber
9c12bcfdc5 Fix format warnings 2019-01-07 09:49:16 +01:00
Sebastian Huber
a7e89962df drvmgr: Improve LP64 compatibility 2018-12-27 09:00:59 +01:00
Sebastian Huber
d53862a30b rtems: Deprecate region_information_block
The region_information_block typedef as no corresponding API.  It has no
proper namespace prefix.  A user can do nothing with it.

Close #3591.
2018-11-09 07:25:09 +01:00
Sebastian Huber
6cdaa850c8 shell: Use #include "..." for local header files
Update #3375.
2018-10-09 13:26:47 +02:00
Sebastian Huber
f004b2b8dc Use rtems_task_exit()
Update #3530.
Update #3533.
2018-10-02 10:22:15 +02:00
Sebastian Huber
2cec5acdf2 shell: Fix rtems_shell_init_env()
Do not discard a user provided task name in rtems_shell_init_env().
2018-03-12 11:24:44 +01:00
Chris Johns
2afb22b7e1 Remove make preinstall
A speciality of the RTEMS build system was the make preinstall step.  It
copied header files from arbitrary locations into the build tree.  The
header files were included via the -Bsome/build/tree/path GCC command
line option.

This has at least seven problems:

* The make preinstall step itself needs time and disk space.

* Errors in header files show up in the build tree copy.  This makes it
  hard for editors to open the right file to fix the error.

* There is no clear relationship between source and build tree header
  files.  This makes an audit of the build process difficult.

* The visibility of all header files in the build tree makes it
  difficult to enforce API barriers.  For example it is discouraged to
  use BSP-specifics in the cpukit.

* An introduction of a new build system is difficult.

* Include paths specified by the -B option are system headers.  This
  may suppress warnings.

* The parallel build had sporadic failures on some hosts.

This patch removes the make preinstall step.   All installed header
files are moved to dedicated include directories in the source tree.
Let @RTEMS_CPU@ be the target architecture, e.g. arm, powerpc, sparc,
etc.  Let @RTEMS_BSP_FAMILIY@ be a BSP family base directory, e.g.
erc32, imx, qoriq, etc.

The new cpukit include directories are:

* cpukit/include

* cpukit/score/cpu/@RTEMS_CPU@/include

* cpukit/libnetworking

The new BSP include directories are:

* bsps/include

* bsps/@RTEMS_CPU@/include

* bsps/@RTEMS_CPU@/@RTEMS_BSP_FAMILIY@/include

There are build tree include directories for generated files.

The include directory order favours the most general header file, e.g.
it is not possible to override general header files via the include path
order.

The "bootstrap -p" option was removed.  The new "bootstrap -H" option
should be used to regenerate the "headers.am" files.

Update #3254.
2018-01-25 08:45:26 +01:00
Sebastian Huber
4e100058cc sparc: Remove <bsp.h> from PCI shell command
Update #3254.
Update #3260.
2018-01-02 15:47:00 +01:00
Sebastian Huber
4a23aa4528 shell: Include <rtems/shell.h>
Prepare for header file move to common include directory.

Update #3254.
2017-12-13 09:04:27 +01:00
Sebastian Huber
7192313802 shell: Fix missing prototype warning 2017-09-28 13:18:52 +02:00
Sebastian Huber
1f22b26945 Include missing <limits.h>
Update #2132.
2017-08-25 10:59:52 +02:00
Sebastian Huber
b2ed712d26 Include missing <string.h>
Update #2133.
2017-08-25 10:58:58 +02:00
Sebastian Huber
93934f886f heap: Fix integer types
Update #3082.
2017-08-22 14:18:58 +02:00
Chris Johns
2465c0130b libmisc/shell: Make some internal shell functions public.
- Add 'rtems_shell_init_environment()' so a user can create the
  shell environment without needing to run a shell.
- Move 'rtems_shell_lookup_topic', 'rtems_shell_can_see_cmd',
  and 'rtems_shell_execute_cmd' from the internal interface to
  the public interface.

Closes #3096.
2017-08-14 14:50:55 +10:00
Sebastian Huber
787f51f5b3 Do not include <sys/ioctl.h> in kernel-space
Update #2833.
2017-06-07 13:02:08 +02:00
Sebastian Huber
6b42018eb6 shell: Fix format specifiers 2017-05-02 08:06:12 +02:00
Joel Sherrill
54bdf0c7e5 rtems/inttypes.h: New file. Uses contents from cpukit
Provide extentions to <inttpes.h> PRIxxx constants for more POSIX types.
Start with existing definitions found in RTEMS Project owned code
in cpukit/.

updates #2983.
2017-04-18 11:24:44 -05:00