iPXE
shell.c File Reference

Minimal command shell. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <readline/readline.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/shell.h>
#include <config/branding.h>

Go to the source code of this file.

Data Structures

struct  shell_options
 "shell" options More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static int help_exec (int argc __unused, char **argv __unused)
 "help" command
 COMMAND (help, help_exec)
 "help" command
int shell (void)
 Start command shell.
static int shell_exec (int argc, char **argv)
 "shell" command
 COMMAND (shell, shell_exec)
 "shell" command

Variables

static const char shell_prompt [] = PRODUCT_SHORT_NAME "> "
 The shell prompt string.
static struct option_descriptor shell_opts [] = {}
 "shell" option list
static struct command_descriptor shell_cmd
 "shell" command descriptor

Detailed Description

Minimal command shell.

Definition in file shell.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ help_exec()

int help_exec ( int argc __unused,
char **argv __unused )
static

"help" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 54 of file shell.c.

54 {
55 struct command *command;
56 unsigned int hpos = 0;
57
58 printf ( "\nAvailable commands:\n\n" );
60 hpos += printf ( " %s", command->name );
61 if ( hpos > ( 16 * 4 ) ) {
62 printf ( "\n" );
63 hpos = 0;
64 } else {
65 while ( hpos % 16 ) {
66 printf ( " " );
67 hpos++;
68 }
69 }
70 }
71 printf ( "\n\nType \"<command> --help\" for further information\n\n" );
72 return 0;
73}
#define COMMANDS
Definition command.h:23
A command-line command.
Definition command.h:10
const char * name
Name of the command.
Definition command.h:12
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References __unused, COMMANDS, for_each_table_entry, command::name, and printf().

Referenced by COMMAND().

◆ COMMAND() [1/2]

COMMAND ( help ,
help_exec  )

"help" command

References help_exec().

◆ shell()

int shell ( void )

Start command shell.

Definition at line 82 of file shell.c.

82 {
83 struct readline_history history;
84 char *line;
85 int rc = 0;
86
87 /* Initialise shell history */
88 memset ( &history, 0, sizeof ( history ) );
89
90 /* Read and execute commands */
91 do {
92 readline_history ( shell_prompt, NULL, &history, 0, &line );
93 if ( line ) {
94 rc = system ( line );
95 free ( line );
96 }
98
99 /* Discard shell history */
100 history_free ( &history );
101
102 return rc;
103}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
uint8_t system[ETH_ALEN]
System identifier.
Definition eth_slow.h:13
int shell_stopped(int stop)
Test and consume shell stop state.
Definition exec.c:228
void * memset(void *dest, int character, size_t len) __nonnull
void history_free(struct readline_history *history)
Free history buffer.
Definition readline.c:232
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 void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
static const char shell_prompt[]
The shell prompt string.
Definition shell.c:45
@ SHELL_STOP_COMMAND_SEQUENCE
Stop processing commands.
Definition shell.h:30
A readline history buffer.
Definition readline.h:32

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

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

◆ shell_exec()

int shell_exec ( int argc,
char ** argv )
static

"shell" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 122 of file shell.c.

122 {
123 struct shell_options opts;
124 int rc;
125
126 /* Parse options */
127 if ( ( rc = parse_options ( argc, argv, &shell_cmd, &opts ) ) != 0 )
128 return rc;
129
130 /* Start shell */
131 if ( ( rc = shell() ) != 0 )
132 return rc;
133
134 return 0;
135}
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
int shell(void)
Start command shell.
Definition shell.c:82
static struct command_descriptor shell_cmd
"shell" command descriptor
Definition shell.c:112
"shell" options
Definition shell.c:106

References opts, parse_options(), rc, shell(), and shell_cmd.

Referenced by COMMAND().

◆ COMMAND() [2/2]

COMMAND ( shell ,
shell_exec  )

"shell" command

References shell(), and shell_exec().

Variable Documentation

◆ shell_prompt

const char shell_prompt[] = PRODUCT_SHORT_NAME "> "
static

The shell prompt string.

Definition at line 45 of file shell.c.

Referenced by shell().

◆ shell_opts

struct option_descriptor shell_opts[] = {}
static

"shell" option list

Definition at line 109 of file shell.c.

109{};

◆ shell_cmd

struct command_descriptor shell_cmd
static
Initial value:
=
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109
static struct option_descriptor shell_opts[]
"shell" option list
Definition shell.c:109

"shell" command descriptor

Definition at line 112 of file shell.c.

Referenced by shell_exec().