66 int ( * terminate ) (
int rc ) ) {
107 if (
len && ( line[
len - 1 ] ==
'\r' ) )
111 if (
len && ( line[
len - 1 ] ==
'\\' ) ) {
136 if ( terminate (
rc ) )
147 }
while ( script_offset < image->
len );
220 static const char ipxe_magic[] =
"#!ipxe";
221 static const char gpxe_magic[] =
"#!gpxe";
222 static_assert (
sizeof ( ipxe_magic ) ==
sizeof ( gpxe_magic ) );
223 char test[
sizeof ( ipxe_magic ) - 1
228 DBGC (
image,
"Too short to be a script\n" );
234 if ( ! ( ( (
memcmp (
test, ipxe_magic,
sizeof (
test ) - 1 ) == 0 ) ||
237 DBGC (
image,
"Invalid magic signature\n" );
337 DBGC (
image,
"[%04zx] No such label :%s\n",
#define EINVAL
Invalid argument.
struct arbelprm_rc_send_wqe rc
int printf(const char *fmt,...)
Write a formatted string to the console.
userptr_t data
Raw file image.
int parse_key(char *text, unsigned int *key)
Parse key.
int optind
Current option index.
static int script_exec(struct image *image)
Execute script.
off_t memchr_user(userptr_t userptr, off_t offset, int c, size_t len)
Find character in user buffer.
#define ENOEXEC
Exec format error.
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
struct image_type script_image_type __image_type(PROBE_NORMAL)
Script image type.
An executable image type.
#define ENOENT
No such file or directory.
#define PROBE_NORMAL
Normal image probe priority.
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
#define static_assert(x)
Assert a condition at build time.
void shell_stop(int stop)
Set shell stop state.
static struct option_descriptor goto_opts[]
"goto" option list
struct image * image
Image (weak reference, nullified when image is freed)
char * name
Name of this image type.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define ENOMEM
Not enough space.
Stop processing current command line.
struct image_tag current_image
Parse command-line options.
unsigned long timeout
Timeout.
#define __unused
Declare a variable or data structure as unused.
#define MAX_ARGUMENTS
No maximum number of arguments.
static int terminate_on_label_found(int rc)
Terminate script processing when label is found.
char * concat_args(char **args)
Concatenate arguments.
char * strerror(int errno)
Retrieve string representation of error number.
static void(* free)(struct refcnt *refcnt))
size_t len
Length of raw file image.
Command line option parsing.
int isspace(int character)
Check to see if character is a space.
static int script_exec_line(struct image *image, size_t offset, const char *label __unused, const char *command)
Execute script line.
int prompt(const char *text, unsigned long timeout, int key)
Prompt for keypress.
static int goto_exec(int argc, char **argv)
"goto" command
static struct option_descriptor prompt_opts[]
"prompt" option list
static int script_probe(struct image *image)
Probe script image.
const char * name
Name of the command.
int shell_stopped(int stop)
Test and consume shell stop state.
#define ENOTTY
Inappropriate I/O control operation.
int strcmp(const char *first, const char *second)
Compare strings.
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Option requires an argument.
Stop processing commands.
A command-line option descriptor.
static int terminate_on_exit_or_failure(int rc)
Terminate script processing on shell exit or command failure.
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
static int prompt_exec(int argc, char **argv)
"prompt" command
uint16_t offset
Offset to command line.
static size_t script_offset
Offset within current script.
struct command goto_command __command
"goto" command
static int goto_find_label(struct image *image, size_t offset, const char *label, const char *command __unused)
Check for presence of label.
static const char * goto_label
Current "goto" label.
static union @438 opts
"cert<xxx>" option list
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
#define NULL
NULL pointer (VOID *)
unsigned int key
Key to wait for.
static struct command_descriptor prompt_cmd
"prompt" command descriptor
uint8_t system[ETH_ALEN]
System identifier.
static struct command_descriptor goto_cmd
"goto" command descriptor
static int process_script(struct image *image, int(*process_line)(struct image *image, size_t offset, const char *label, const char *command), int(*terminate)(int rc))
Process script lines.