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 ("$BSDSUniX$")
 
 CTASSERT (MAXSHELLCMDLEN >=MAXINTERP+3)
 
int exec_shell_imgact (struct image_params *imgp)
 
 EXEC_SET (shell, shell_execsw)
 

Variables

static struct execsw shell_execsw = { exec_shell_imgact, "#!" }
 

Macro Definition Documentation

#define SHELLMAGIC   0x2123 /* #! */

Definition at line 41 of file imgact_shell.c.

Referenced by exec_shell_imgact().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
CTASSERT ( MAXSHELLCMDLEN >=MAXINTERP+  3)

Referenced by sys_setlogin().

Here is the caller graph for this function:

EXEC_SET ( shell  ,
shell_execsw   
)
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 100 of file imgact_shell.c.

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

Here is the call graph for this function:

Variable Documentation

struct execsw shell_execsw = { exec_shell_imgact, "#!" }
static

Definition at line 257 of file imgact_shell.c.