Commit Graph

91 Commits

Author SHA1 Message Date
Gedare Bloom
0149e6e749 spdx: add 2-BSD SPDX tags on relicensed files
Updates the recently merged relicensed files with the 2-Clause BSD
SPDX annotation.

Closes #5208.
2025-03-01 04:14:54 +00:00
Gedare Bloom
23fa41ecae cpukit: relicense shell and telnetd files
These files are mostly authored by Fernando Ruiz Casas.

Updates #3053.
2025-02-07 15:01:13 +00:00
yang.zhang
6f604aec83 libmisc/shell: Only restore terminal settings on exit when captured
Signed-off-by: yang.zhang <zhangyang01@kylinos.cn>
2024-11-15 00:35:26 +00:00
Kinsey Moore
d0e9ec85b0 cpukit/libmisc/shell: Remove shell prompt carriage return
This removes the carriage return printed before the shell prompt as it
can cause other output to be overwritten unexpectedly. This was
discovered when using the "cat" shell command on a file whose content
contained no trailing \n\r and was short enough to be entirely swallowed
by the prompt.
2024-10-25 02:44:37 +00:00
Kinsey Moore
174b69afd6 cpukit/shell: Add window size retrieval control
This adds an environment variable that can be used to enable or disable
window size retrieval for the RTEMS shell. This will also disable window
size retrieval upon failure while allowing the user to re-enable it.
2024-07-18 00:10:15 +00:00
Kinsey Moore
8eb4932b13 cpukit/shell: Account for tick rate in timeouts
On systems that don't provide a proper terminal or have broken window
size detection, the RTEMS shell can take a long time execute commands if
the kernel tick interval is longer than 1ms. This updates the shell
window size retrieval timeout code to account for the kernel tick
interval bringing the experienced timeout from 12.5ms to 1.25ms when
using the default kernel tick interval (10ms).
2024-07-18 00:10:15 +00:00
Chris Johns
7260887fa9 libmisc/shell: Work around tmux bug in row and column
- Extend the timeout to 150 msec for long remote sessions

- Improve the performance of the detection

Closes #4975
Closes #4977
2023-12-13 18:13:16 +11:00
Chris Johns
8425e679c1 libmisc/shell: Support terminal size as env variables
Closes #4763
2022-11-23 07:00:08 +11:00
Sebastian Huber
23426257c6 shell: Add rtems_shell_run_main_loop()
In contrast to rtems_shell_main_loop(), this new function does not
perform all sorts of initialization based on environment settings.  For
example, due to the use of isatty() in rtems_shell_main_loop() it is
impossible to run an interactive shell through a socket connection.
2022-04-06 16:26:52 +02:00
Sebastian Huber
a800e4de12 shell: Move rtems_shell_init_environment() call
Move rtems_shell_init_environment() call to rtems_shell_set_shell_env()
since this function uses the POSIX key.
2022-04-06 16:26:52 +02:00
Sebastian Huber
3407a3b1bc shell: Add and use SHELL_MAGIC 2022-04-06 16:26:52 +02:00
Sebastian Huber
e765cfb450 shell: Simplify rtems_shell_dup_current_env()
Do not assign members already provided by the global environment.
2022-04-06 16:26:52 +02:00
Sebastian Huber
1a8ad7e68f shell: Refactor rtems_shell_main_loop()
Disentangle the shell main loop from setup and teardown code.  Move main
loop into shell_main_loop().
2022-04-06 16:26:52 +02:00
Sebastian Huber
9320c7ecaa shell: Move line editor output check
Move call to isatty() to caller of rtems_shell_line_editor().  This
avoids a dependency on isatty() in rtems_shell_line_editor().
2022-04-06 16:26:52 +02:00
Joel Sherrill
5f8c41c389 Update email address of Fernando Ruiz Casas to <fruizcasas@gmail.com>
This was requested to be executed prior to relicensing to BSD-2.
2022-04-05 13:13:31 -05:00
Sebastian Huber
b837c83869 shell: Avoid potential stack corruption
The rtems_shell_init() passed the address of a stack variable
(exit_code) to rtems_shell_run().  If wait == false, then the stack
variable goes out of scope but may be accessed by the created shell
thread.

The rtems_shell_script() was affected by the same problem.

Close #4629.
2022-03-16 07:35:27 +01: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
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
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
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
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
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
Sebastian Huber
3fe215502a Remove superfluous <rtems/system.h> includes 2019-03-14 13:13:27 +01: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
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
a2097c56ad shell: Avoid __DATE__ and adjust welcome message
The use of __DATE__ prevents reproducible builds.
2014-12-05 13:09:11 +01:00
Sebastian Huber
ffd5285844 shell: Inherit UID and GID if no login check
Use the UID and GID of the executing user for the real and effective UID
and GID of the shell task in case no login check is present.  This
prevents privilege escalation via shell scripts.
2014-11-20 10:30:25 +01:00
Sebastian Huber
5c141d6a25 shell: Add and use rtems_shell_execute_cmd() 2014-11-20 10:30:25 +01:00
Sebastian Huber
7840b66f74 shell: Add initial commands and aliases only once
Make tables read-only.
2014-11-20 10:30:25 +01:00
Sebastian Huber
bac3d6df35 shell: Rename HALT to SHUTDOWN command
Use a normal command for shutdown via exit().
2014-11-20 10:30:24 +01:00
Sebastian Huber
fa028bb2ef shell: Do chroot() after successful login 2014-11-20 10:30:24 +01:00
Sebastian Huber
373ccbb938 shell: Use exiting once initialization
Avoid TOCTOU issues.  Avoid pull in of global buffers.
2014-11-20 10:30:24 +01:00
Joel Sherrill
06ac8b7122 shell.c: Add cast to match printf() expectations for width specifier 2014-09-04 09:08:05 -05:00
Chris Johns
bb581906a6 shell: Add rtems_shell_dup_current_env to get a default env.
Remove rtems_current_shell_env as this is dangerous because
the env can be NULL if used outside of a valid shell with the
POSIX key to an env set up.

Clean up the usage of rtems_current_shell_env.
2014-06-04 22:32:55 +10:00
Sebastian Huber
5f0ab5cfb5 shell: Make rtems_global_shell_env public
Provide rtems_global_shell_env as a public read-only variable for
backward compatibility.
2014-05-28 17:39:27 +02:00
Chris Johns
c49985691f Change all references of rtems.com to rtems.org. 2014-03-21 08:10:47 +11:00
Christian Mauderer
6cd4a5ca2e cpukit/shell: Replace task variables with posix keys.
Use posix keys for current shell environment instead of task variables. With
this patch the shell needs one posix-key and one posix-key-value-pair
configured.

Update documentation for the shell.

Adapt samples/fileio:
- Add necessary objects.
- Add login function and custom device name for better testing of the shell.
2014-03-20 09:10:26 +01:00
Ric Claus
22e983771f Support additional shell keystrokes.
Emacs style keystrokes Ctrl-B, F, G, P, N, T and U are now supported as they
are in bash.  Also, commands invoked from the history are moved up in the
history buffer when they are executed.  Thus, the most recently executed
command is always just one up-arrow (or Ctrl-P) keystroke away.
2012-12-01 09:03:54 +01:00
Joel Sherrill
9b4422a251 Remove All CVS Id Strings Possible Using a Script
Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines
  next to each other after Id string line removed.
+ remove entire comment blocks which only exited to
  contain CVS Ids
+ If the processing left a blank line at the top of
  a file, it was removed.
2012-05-11 08:44:13 -05:00
Ralf Corsepius
94547d1d8b 2011-12-04 Ralf Corsépius <ralf.corsepius@rtems.org>
* libmisc/shell/print-ls.c: Include "internal.h".
	* libmisc/shell/pwcache.c: Make user_from_uid static.
	* libmisc/shell/shell.c: Make rtems_shell_init_env,
	rtems_shell_env_free, rtems_shell_line_editor,
	rtems_shell_init_issue, rtems_shell_task static.
	* libmisc/shell/shell_cmdset.c: Make rtems_shell_add_topic static.
	* libmisc/shell/shell_makeargs.c: Include <rtems/shell.h>.
	* libmisc/shell/write_file.c: Include <rtems/shell.h>.
2011-12-04 11:57:51 +00:00
Joel Sherrill
bab5c5fac0 2010-03-12 Joel Sherrill <joel.sherrill@oarcorp.com>
* ftpd/ftpd.c, httpd/asp.c, httpd/ejparse.c, httpd/emfdb.c,
	httpd/misc.c, httpd/um.c, httpd/webs.c, httpd/websuemf.c,
	libfs/src/dosfs/msdos_dir.c, libfs/src/dosfs/msdos_format.c,
	libfs/src/dosfs/msdos_misc.c, libfs/src/nfsclient/src/nfs.c,
	libmisc/capture/capture-cli.c, libmisc/monitor/mon-network.c,
	libmisc/shell/hexdump-odsyntax.c, libmisc/shell/main_ifconfig.c,
	libmisc/shell/shell.c, libmisc/shell/shell_makeargs.c,
	libmisc/uuid/parse.c, libnetworking/libc/gethostbydns.c,
	libnetworking/libc/gethostbyht.c, libnetworking/libc/gethostnamadr.c,
	libnetworking/libc/getnetnamadr.c, libnetworking/libc/inet_addr.c,
	libnetworking/libc/inet_network.c, libnetworking/libc/res_debug.c,
	libnetworking/libc/res_init.c, libnetworking/libc/res_query.c,
	libnetworking/rtems/rtems_mii_ioctl.c,
	score/src/objectgetnameasstring.c: Readdress use of ctype methods per
	recommendation from D.J. Delorie on the newlib mailing list. We
	should pass an unsigned char into these methods.
2010-03-12 16:26:16 +00:00
Joel Sherrill
8c161f958f 2010-01-20 Joel Sherrill <joel.sherrill@oarcorp.com>
Coverity Id 3
	* libmisc/shell/shell.c: Remove dead code path and fix warning.
2010-01-20 15:20:29 +00:00
Thomas Doerfler
8bca4fcaa4 Added format string to fprintf(). 2009-11-30 13:24:59 +00:00
Joel Sherrill
13c37ad39a 2009-11-23 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/shell/shell.c: Always duplicate the environment passed to us
	because we will delete it when the shell exits. If we do not
	duplicate it, we could end up freeing memory which was not allocated
	from the heap or double freeing it.
2009-11-23 21:56:50 +00:00
Joel Sherrill
6aa8b5132d 2009-05-03 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/shell/shell.c, libmisc/stackchk/check.c: Eliminate warnings.
2009-05-03 23:57:19 +00:00
Thomas Doerfler
cbd1e8799f adapt copyright statements 2009-04-14 08:50:03 +00:00