37#include <sys/sysproto.h>
39#include <sys/imgact.h>
40#include <sys/kernel.h>
42#if BYTE_ORDER == LITTLE_ENDIAN
43#define SHELLMAGIC 0x2123
45#define SHELLMAGIC 0x2321
53#if MAXSHELLCMDLEN > PAGE_SIZE
54#error "MAXSHELLCMDLEN is larger than a single page!"
104 const char *image_header = imgp->image_header;
105 const char *ihp, *interpb, *interpe, *maxp, *optb, *opte, *fname;
112 if (((
const short *)image_header)[0] !=
SHELLMAGIC)
119 if (imgp->interpreted & IMGACT_SHELL)
122 imgp->interpreted |= IMGACT_SHELL;
130 error = VOP_GETATTR(imgp->vp, &vattr, imgp->proc->p_ucred);
138 maxp = &image_header[MIN(vattr.va_size, MAXSHELLCMDLEN)];
139 ihp = &image_header[2];
146 while (ihp < maxp && ((*ihp ==
' ') || (*ihp ==
'\t')))
149 while (ihp < maxp && ((*ihp !=
' ') && (*ihp !=
'\t') && (*ihp !=
'\n')
153 if (interpb == interpe)
155 if (interpe - interpb >= MAXINTERP)
156 return (ENAMETOOLONG);
163 while (ihp < maxp && ((*ihp ==
' ') || (*ihp ==
'\t')))
166 while (ihp < maxp && ((*ihp !=
'\n') && (*ihp !=
'\0')))
171 while (--ihp > optb && ((*ihp ==
' ') || (*ihp ==
'\t')))
174 if (imgp->args->fname != NULL) {
175 fname = imgp->args->fname;
178 sname = sbuf_new_auto();
192 offset = interpe - interpb + 1;
194 offset += opte - optb + 1;
195 offset += strlen(fname) + 1;
196 length = (imgp->args->argc == 0) ? 0 :
197 strlen(imgp->args->begin_argv) + 1;
212 if (imgp->args->argc == 0)
213 imgp->args->argc = 1;
220 length = interpe - interpb;
221 bcopy(interpb, imgp->args->begin_argv, length);
222 *(imgp->args->begin_argv + length) =
'\0';
225 length = opte - optb;
226 bcopy(optb, imgp->args->begin_argv + offset, length);
227 *(imgp->args->begin_argv + offset + length) =
'\0';
228 offset += length + 1;
237 error = copystr(fname, imgp->args->begin_argv + offset,
238 imgp->args->stringspace, NULL);
241 imgp->interpreter_name = imgp->args->begin_argv;
CTASSERT(MAXSHELLCMDLEN >=MAXINTERP+3)
EXEC_SET(shell, shell_execsw)
int exec_shell_imgact(struct image_params *imgp)
static struct execsw shell_execsw
static const struct execsw ** execsw
int exec_args_adjust_args(struct image_args *args, size_t consume, ssize_t extend)
int sbuf_finish(struct sbuf *s)
void sbuf_delete(struct sbuf *s)
int sbuf_printf(struct sbuf *s, const char *fmt,...)
char * sbuf_data(struct sbuf *s)