iPXE
|
Command execution. More...
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include <assert.h>
#include <ipxe/tables.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/settings.h>
#include <ipxe/shell.h>
Go to the source code of this file.
Data Structures | |
struct | echo_options |
"echo" options More... | |
struct | exit_options |
"exit" options More... | |
struct | isset_options |
"isset" options More... | |
struct | iseq_options |
"iseq" options More... | |
struct | sleep_options |
"sleep" options More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
int | execv (const char *command, char *const argv[]) |
Execute command. More... | |
static int | split_command (char *command, char **tokens) |
Split command line into tokens. More... | |
static int | process_on_success (int rc) |
Process next command only if previous command succeeded. More... | |
static int | process_on_failure (int rc) |
Process next command only if previous command failed. More... | |
static int | process_always (int rc __unused) |
Process next command regardless of status from previous command. More... | |
static int | command_terminator (char **tokens, int(**process_next)(int rc)) |
Find command terminator. More... | |
void | shell_stop (int stop) |
Set shell stop state. More... | |
int | shell_stopped (int stop) |
Test and consume shell stop state. More... | |
static int | expand_tokens (int argc, char **tokens, char **argv) |
Expand settings within a token list. More... | |
static void | free_tokens (char **argv) |
Free an expanded token list. More... | |
int | system (const char *command) |
Execute command line. More... | |
char * | concat_args (char **args) |
Concatenate arguments. More... | |
static int | echo_exec (int argc, char **argv) |
"echo" command More... | |
static int | exit_exec (int argc, char **argv) |
"exit" command More... | |
static int | isset_exec (int argc, char **argv) |
"isset" command More... | |
static int | iseq_exec (int argc, char **argv) |
"iseq" command More... | |
static int | sleep_exec (int argc, char **argv) |
"sleep" command More... | |
Variables | |
static int | stop_state |
Shell stop state. More... | |
static struct option_descriptor | echo_opts [] |
"echo" option list More... | |
static struct command_descriptor | echo_cmd |
"echo" command descriptor More... | |
struct command echo_command | __command |
"echo" command More... | |
static struct option_descriptor | exit_opts [] = {} |
"exit" option list More... | |
static struct command_descriptor | exit_cmd |
"exit" command descriptor More... | |
static struct option_descriptor | isset_opts [] = {} |
"isset" option list More... | |
static struct command_descriptor | isset_cmd |
"isset" command descriptor More... | |
static struct option_descriptor | iseq_opts [] = {} |
"iseq" option list More... | |
static struct command_descriptor | iseq_cmd |
"iseq" command descriptor More... | |
static struct option_descriptor | sleep_opts [] = {} |
"sleep" option list More... | |
static struct command_descriptor | sleep_cmd |
"sleep" command descriptor More... | |
Command execution.
Definition in file exec.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
int execv | ( | const char * | command, |
char *const | argv[] | ||
) |
Execute command.
command | Command name |
argv | Argument list |
rc | Return status code |
Execute the named command. Unlike a traditional POSIX execv(), this function returns the exit status of the command.
Definition at line 60 of file exec.c.
References cmd, COMMANDS, DBG, done, EINVAL, ENOEXEC, errno, for_each_table_entry, NULL, printf(), rc, reset_getopt(), and strcmp().
Referenced by system(), and time_exec().
|
static |
Split command line into tokens.
command | Command line |
tokens | Token list to populate, or NULL |
count | Number of tokens |
Splits the command line into whitespace-delimited tokens. If tokens
is non-NULL, any whitespace in the command line will be replaced with NULs.
Definition at line 121 of file exec.c.
References command, count, and isspace().
Referenced by system().
|
static |
Process next command only if previous command succeeded.
rc | Status of previous command |
process | Process next command |
Definition at line 152 of file exec.c.
References rc.
Referenced by command_terminator().
|
static |
Process next command only if previous command failed.
rc | Status of previous command |
process | Process next command |
Definition at line 162 of file exec.c.
References rc.
Referenced by command_terminator().
|
static |
Process next command regardless of status from previous command.
rc | Status of previous command |
process | Process next command |
Definition at line 172 of file exec.c.
Referenced by command_terminator().
|
static |
Find command terminator.
tokens | Token list |
process_next | "Should next command be processed?" function |
argc | Argument count |
Definition at line 183 of file exec.c.
References NULL, process_always(), process_on_failure(), process_on_success(), and strcmp().
Referenced by system().
void shell_stop | ( | int | stop | ) |
Set shell stop state.
stop | Shell stop state |
Definition at line 217 of file exec.c.
References stop_state.
Referenced by exit_exec(), goto_exec(), and imgexec().
int shell_stopped | ( | int | stop | ) |
Test and consume shell stop state.
stop | Shell stop state to consume |
stopped | Shell had been stopped |
Definition at line 227 of file exec.c.
References stop_state.
Referenced by shell(), system(), and terminate_on_exit_or_failure().
|
static |
Expand settings within a token list.
argc | Argument count |
tokens | Token list |
argv | Argument list to fill in |
rc | Return status code |
Definition at line 248 of file exec.c.
References assert(), ENOMEM, expand_settings(), free, and NULL.
Referenced by system().
|
static |
int system | ( | const char * | command | ) |
Execute command line.
command | Command line |
rc | Return status code |
Execute the named command and arguments.
Definition at line 287 of file exec.c.
References command_terminator(), count, ENOMEM, execv(), expand_tokens(), free, free_tokens(), NULL, rc, SHELL_STOP_COMMAND, shell_stopped(), split_command(), and strdup().
char* concat_args | ( | char ** | args | ) |
Concatenate arguments.
args | Argument list (NULL-terminated) |
string | Concatenated arguments |
The returned string is allocated with malloc(). The caller is responsible for eventually free()ing this string.
Definition at line 358 of file exec.c.
References assert(), len, NULL, sprintf, string, strlen(), and zalloc().
Referenced by dynui_exec(), echo_exec(), imgsingle_exec(), item_exec(), param_exec(), prompt_exec(), and set_value().
|
static |
"echo" command
argc | Argument count |
argv | Argument list |
rc | Return status code |
Definition at line 409 of file exec.c.
References concat_args(), echo_cmd, ENOMEM, free, optind, opts, parse_options(), printf(), and rc.
|
static |
"exit" command
argc | Argument count |
argv | Argument list |
rc | Return status code |
Definition at line 453 of file exec.c.
References exit_cmd, optind, opts, parse_integer(), parse_options(), rc, shell_stop(), and SHELL_STOP_COMMAND_SEQUENCE.
|
static |
"isset" command
argc | Argument count |
argv | Argument list |
rc | Return status code |
Definition at line 497 of file exec.c.
References ENOENT, isset_cmd, optind, opts, parse_options(), and rc.
|
static |
"iseq" command
argc | Argument count |
argv | Argument list |
rc | Return status code |
Definition at line 533 of file exec.c.
References ERANGE, iseq_cmd, optind, opts, parse_options(), rc, and strcmp().
|
static |
"sleep" command
argc | Argument count |
argv | Argument list |
rc | Return status code |
Definition at line 569 of file exec.c.
References ECANCELED, optind, opts, parse_integer(), parse_options(), rc, seconds, sleep(), and sleep_cmd.
|
static |
Shell stop state.
Definition at line 48 of file exec.c.
Referenced by shell_stop(), and shell_stopped().
|
static |
"echo" option list
|
static |
"echo" command descriptor
Definition at line 398 of file exec.c.
Referenced by echo_exec().
struct command sleep_command __command |
"echo" command
"sleep" command
"iseq" command
"isset" command
"exit" command
|
static |
|
static |
"exit" command descriptor
Definition at line 443 of file exec.c.
Referenced by exit_exec().
|
static |
|
static |
"isset" command descriptor
Definition at line 487 of file exec.c.
Referenced by isset_exec().
|
static |
|
static |
"iseq" command descriptor
Definition at line 522 of file exec.c.
Referenced by iseq_exec().
|
static |
|
static |
"sleep" command descriptor
Definition at line 559 of file exec.c.
Referenced by sleep_exec().