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.
int shell_stopped (int stop)
 Test and consume shell stop state.
int shell (void)
 Start command shell.

Detailed Description

Minimal command shell.

Definition in file shell.h.


Enumeration Type Documentation

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.

                      {
        /** Continue processing */
        SHELL_CONTINUE = 0,
        /**
         * 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 = 1,
        /**
         * Stop processing commands
         *
         * This is the stop state entered by commands that terminate
         * the flow of execution, such as "exit".
         */
        SHELL_STOP_COMMAND_SEQUENCE = 2,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
void shell_stop ( int  stop)

Set shell stop state.

Parameters:
stopShell stop state

Definition at line 217 of file exec.c.

References stop_state.

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

                             {
        stop_state = stop;
}
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.

References stop_state.

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

                               {
        int stopped;

        /* Test to see if we need to stop */
        stopped = ( stop_state >= stop );

        /* Consume stop state */
        if ( stop_state <= stop )
                stop_state = 0;

        return stopped;
}
int shell ( void  )

Start command shell.

Definition at line 84 of file shell.c.

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().

                   {
        struct readline_history history;
        char *line;
        int rc = 0;

        /* Initialise shell history */
        memset ( &history, 0, sizeof ( history ) );

        /* Read and execute commands */
        do {
                readline_history ( shell_prompt, NULL, &history, &line );
                if ( line ) {
                        rc = system ( line );
                        free ( line );
                }
        } while ( ! shell_stopped ( SHELL_STOP_COMMAND_SEQUENCE ) );

        /* Discard shell history */
        history_free ( &history );

        return rc;
}