RTEMS 6.1-rc2
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions | Variables
shell.c File Reference

Instantatiate a new terminal shell. More...

#include <stdio.h>
#include <time.h>
#include <rtems.h>
#include <rtems/error.h>
#include <rtems/libio.h>
#include <rtems/libio_.h>
#include <rtems/shell.h>
#include <rtems/shellconfig.h>
#include <rtems/console.h>
#include "internal.h"
#include <termios.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <pwd.h>
#include <pthread.h>
#include <assert.h>

Data Structures

struct  rtems_shell_env_key_handle
 

Macros

#define SHELL_STD_DEBUG   0
 
#define shell_std_debug(...)
 
#define SHELL_MAGIC   rtems_build_name('S', 'E', 'N', 'V')
 
#define RTEMS_SHELL_MAXIMUM_ARGUMENTS   (128)
 
#define RTEMS_SHELL_CMD_SIZE   (128)
 
#define RTEMS_SHELL_CMD_COUNT   (32)
 
#define RTEMS_SHELL_PROMPT_SIZE   (128)
 

Typedefs

typedef struct rtems_shell_env_key_handle rtems_shell_env_key_handle
 

Functions

void rtems_shell_init_environment (void)
 
rtems_shell_env_trtems_shell_get_current_env (void)
 
void rtems_shell_dup_current_env (rtems_shell_env_t *copy)
 
bool rtems_shell_run_main_loop (rtems_shell_env_t *shell_env, bool interactive, FILE *line_editor_output)
 Runs the shell main loop.
 
bool rtems_shell_main_loop (rtems_shell_env_t *shell_env)
 
rtems_status_code rtems_shell_init (const char *task_name, size_t task_stacksize, rtems_task_priority task_priority, const char *devname, bool forever, bool wait, rtems_shell_login_check_t login_check)
 
rtems_status_code rtems_shell_script (const char *task_name, size_t task_stacksize, rtems_task_priority task_priority, const char *input, const char *output, bool output_append, bool wait, bool echo)
 

Variables

const rtems_shell_env_t rtems_global_shell_env
 

Detailed Description

Instantatiate a new terminal shell.

Function Documentation

◆ rtems_shell_init()

rtems_status_code rtems_shell_init ( const char *  task_name,
size_t  task_stacksize,
rtems_task_priority  task_priority,
const char *  devname,
bool  forever,
bool  wait,
rtems_shell_login_check_t  login_check 
)

Initialise the shell creating tasks to login and run the shell sessions.

Parameters
task_nameName of the shell task.
task_stacksizeThe size of the stack. If 0 the default size is used.
task_priorityThe priority the shell runs at.
foreverRepeat logins.
waitCaller should block until shell exits.
login_checkUser login check function, NULL disables login checks.

◆ rtems_shell_run_main_loop()

bool rtems_shell_run_main_loop ( rtems_shell_env_t shell_env,
bool  interactive,
FILE *  line_editor_output 
)

Runs the shell main loop.

The caller shall initialize the shell environment. It is recommended that the caller duplicates the current shell environment using rtems_shell_dup_current_env() and then performs the required customization. Shell commands will use the stdin, stdout, and stderr file streams set up by the caller.

Parameters
interactiveindicates if the shell main loop interfaces with an interactive user. For an interactive user, a welcome message using "/etc/motd" is presented and command prompt is displayed.
[in,out]line_editor_outputis the optional line editor output file stream. It may be NULL, to disable the line editor output.
Returns
Returns true, if no error occurred and a shell exit was requested, otherwise false.

◆ rtems_shell_script()

rtems_status_code rtems_shell_script ( const char *  task_name,
size_t  task_stacksize,
rtems_task_priority  task_priority,
const char *  input,
const char *  output,
bool  output_append,
bool  wait,
bool  echo 
)

Run a shell script creating a shell tasks to execute the command under.

Parameters
task_nameName of the shell task.
task_stacksizeThe size of the stack. If 0 the default size is used.
task_priorityThe priority the shell runs at.
inputThe file of commands. Can be 'stdin' to use stdin.
outputThe output file to write commands to. Can be 'stdout', 'stderr' or '/dev/null'.
output_appendAppend the output to the file or truncate the file. Create if it does not exist.
waitWait for the script to finish.

Variable Documentation

◆ rtems_global_shell_env

const rtems_shell_env_t rtems_global_shell_env
Initial value:
= {
.magic = SHELL_MAGIC,
.managed = false,
.devname = CONSOLE_DEVICE_NAME,
.taskname = "RTSH",
.exit_shell = false,
.forever = true,
.echo = false,
.cwd = "/",
.input = NULL,
.output = NULL,
.output_append = false,
.parent_stdin = NULL,
.parent_stdout = NULL,
.parent_stderr = NULL,
.wake_on_end = RTEMS_ID_NONE,
.exit_code = NULL,
.login_check = NULL,
.uid = 0,
.gid = 0
}
#define CONSOLE_DEVICE_NAME
Definition: console.h:51
#define RTEMS_ID_NONE
This constant represents an invalid RTEMS object identifier.
Definition: types.h:105
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54