iPXE
Enumerations | Functions
shell.h File Reference

Minimal command shell. More...

Go to the source code of this file.

Enumerations

enum  shell_stop_state { SHELL_CONTINUE = 0, SHELL_STOP_COMMAND = 1, SHELL_STOP_COMMAND_SEQUENCE = 2 }
 Shell stop states. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void shell_stop (int stop)
 Set shell stop state. More...
 
int shell_stopped (int stop)
 Test and consume shell stop state. More...
 
int shell (void)
 Start command shell. More...
 

Detailed Description

Minimal command shell.

Definition in file shell.h.

Enumeration Type Documentation

◆ shell_stop_state

Shell stop states.

Enumerator
SHELL_CONTINUE 

Continue processing.

SHELL_STOP_COMMAND 

Stop processing current command line.

This is the stop state entered by commands that change the flow of execution, such as "goto".

SHELL_STOP_COMMAND_SEQUENCE 

Stop processing commands.

This is the stop state entered by commands that terminate the flow of execution, such as "exit".

Definition at line 13 of file shell.h.

13  {
14  /** Continue processing */
15  SHELL_CONTINUE = 0,
16  /**
17  * Stop processing current command line
18  *
19  * This is the stop state entered by commands that change the flow
20  * of execution, such as "goto".
21  */
23  /**
24  * Stop processing commands
25  *
26  * This is the stop state entered by commands that terminate
27  * the flow of execution, such as "exit".
28  */
30 };
Continue processing.
Definition: shell.h:15
Stop processing current command line.
Definition: shell.h:22
Stop processing commands.
Definition: shell.h:29

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ shell_stop()

void shell_stop ( int  stop)

Set shell stop state.

Parameters
stopShell stop state

Definition at line 217 of file exec.c.

217  {
218  stop_state = stop;
219 }
static int stop_state
Shell stop state.
Definition: exec.c:48

References stop_state.

Referenced by exit_exec(), goto_exec(), and imgexec().

◆ shell_stopped()

int shell_stopped ( int  stop)

Test and consume shell stop state.

Parameters
stopShell stop state to consume
stoppedShell had been stopped

Definition at line 227 of file exec.c.

227  {
228  int stopped;
229 
230  /* Test to see if we need to stop */
231  stopped = ( stop_state >= stop );
232 
233  /* Consume stop state */
234  if ( stop_state <= stop )
235  stop_state = 0;
236 
237  return stopped;
238 }
static int stop_state
Shell stop state.
Definition: exec.c:48

References stop_state.

Referenced by shell(), system(), and terminate_on_exit_or_failure().

◆ shell()

int shell ( void  )

Start command shell.

Definition at line 84 of file shell.c.

84  {
85  struct readline_history history;
86  char *line;
87  int rc = 0;
88 
89  /* Initialise shell history */
90  memset ( &history, 0, sizeof ( history ) );
91 
92  /* Read and execute commands */
93  do {
94  readline_history ( shell_prompt, NULL, &history, 0, &line );
95  if ( line ) {
96  rc = system ( line );
97  free ( line );
98  }
100 
101  /* Discard shell history */
102  history_free ( &history );
103 
104  return rc;
105 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A readline history buffer.
Definition: readline.h:31
int readline_history(const char *prompt, const char *prefill, struct readline_history *history, unsigned long timeout, char **line)
Read line from console (with history)
Definition: readline.c:258
static const char shell_prompt[]
The shell prompt string.
Definition: shell.c:44
int shell_stopped(int stop)
Test and consume shell stop state.
Definition: exec.c:227
void history_free(struct readline_history *history)
Free history buffer.
Definition: readline.c:232
Stop processing commands.
Definition: shell.h:29
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint8_t system[ETH_ALEN]
System identifier.
Definition: eth_slow.h:24
void * memset(void *dest, int character, size_t len) __nonnull

References free, history_free(), memset(), NULL, rc, readline_history(), shell_prompt, SHELL_STOP_COMMAND_SEQUENCE, shell_stopped(), and system.

Referenced by interrupt(), ipxe(), and shell_exec().