FreeBSD kernel kern code
imgact_shell.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/vnode.h>
#include <sys/proc.h>
#include <sys/sbuf.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/exec.h>
#include <sys/imgact.h>
#include <sys/kernel.h>
Include dependency graph for imgact_shell.c:

Go to the source code of this file.

Macros

#define SHELLMAGIC   0x2123 /* #! */
 

Functions

 __FBSDID ("$FreeBSD$")
 
 CTASSERT (MAXSHELLCMDLEN >=MAXINTERP+3)
 
int exec_shell_imgact (struct image_params *imgp)
 
 EXEC_SET (shell, shell_execsw)
 

Variables

static struct execsw shell_execsw
 

Macro Definition Documentation

◆ SHELLMAGIC

#define SHELLMAGIC   0x2123 /* #! */

Definition at line 43 of file imgact_shell.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ CTASSERT()

CTASSERT ( MAXSHELLCMDLEN >=MAXINTERP+  3)

Referenced by sys_setlogin().

Here is the caller graph for this function:

◆ EXEC_SET()

EXEC_SET ( shell  ,
shell_execsw   
)

◆ exec_shell_imgact()

int exec_shell_imgact ( struct image_params *  imgp)

Shell interpreter image activator. An interpreter name beginning at imgp->args->begin_argv is the minimal successful exit requirement.

If the given file is a shell-script, then the first line will start with the two characters ‘#!’ (aka SHELLMAGIC), followed by the name of the shell-interpreter to run, followed by zero or more tokens.

The interpreter is then started up such that it will see: arg[0] -> The name of interpreter as specified after ‘#!’ in the first line of the script. The interpreter name must not be longer than MAXSHELLCMDLEN bytes. arg[1] -> If there are any additional tokens on the first line, then we add a new arg[1], which is a copy of the rest of that line. The copy starts at the first token after the interpreter name. We leave it to the interpreter to parse the tokens in that value. arg[x] -> the full pathname of the script. This will either be arg[2] or arg[1], depending on whether or not tokens were found after the interpreter name. arg[x+1] -> all the arguments that were specified on the original command line.

This processing is described in the execve(2) man page.

Definition at line 102 of file imgact_shell.c.

References exec_args_adjust_args(), sbuf_data(), sbuf_delete(), sbuf_finish(), sbuf_printf(), and SHELLMAGIC.

Here is the call graph for this function:

Variable Documentation

◆ shell_execsw

struct execsw shell_execsw
static
Initial value:
= {
.ex_imgact = exec_shell_imgact,
.ex_name = "#!"
}
int exec_shell_imgact(struct image_params *imgp)
Definition: imgact_shell.c:102

Definition at line 251 of file imgact_shell.c.