*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-
#include <sys/times.h>
#include <setjmp.h>
# include <assert.h>
# define bb_dev_null "/dev/null"
# define DEFAULT_SHELL "/proc/self/exe"
-# define CONFIG_BUSYBOX_EXEC_PATH "/proc/self/exe"
# define bb_banner "busybox standalone"
# define ENABLE_FEATURE_SH_STANDALONE 0
# define bb_msg_memory_exhausted "memory exhausted"
# define nonblock_safe_read(fd,buf,count) read(fd,buf,count)
# define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1])
# define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1])
-# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# define NORETURN __attribute__ ((__noreturn__))
static int find_applet_by_name(const char *applet)
{
return -1;
static void prs(const char *s)
{
if (*s)
- write(STDERR_FILENO, s, strlen(s));
+ xwrite_str(STDERR_FILENO, s);
}
static void prn(unsigned u)
/* fail but return to process next command */
-static void fail(void) ATTRIBUTE_NORETURN;
+static void fail(void) NORETURN;
static void fail(void)
{
longjmp(failpt, 1);
}
/* abort shell (or fail in subshell) */
-static void leave(void) ATTRIBUTE_NORETURN;
+static void leave(void) NORETURN;
static void leave(void)
{
DBGPRINTF(("LEAVE: leave called!\n"));
f = open(s, O_RDONLY);
if (f < 0) {
prs(s);
- err(": cannot open");
+ err(": can't open");
return 1;
}
}
PUSHIO(afile, f, filechar);
}
-static void onintr(int s ATTRIBUTE_UNUSED) /* ANSI C requires a parameter */
+static void onintr(int s UNUSED_PARAM) /* ANSI C requires a parameter */
{
signal(SIGINT, onintr);
intr = 1;
* shell: syntax (C version)
*/
-static void yyerror(const char *s) ATTRIBUTE_NORETURN;
+static void yyerror(const char *s) NORETURN;
static void yyerror(const char *s)
{
yynerrs = 1;
fail();
}
-static void zzerr(void) ATTRIBUTE_NORETURN;
+static void zzerr(void) NORETURN;
static void zzerr(void)
{
yyerror("syntax error");
while (setjmp(bc.brkpt))
if (isbreak)
goto broken;
+ /* Restore areanum value. It may be incremented by execute()
+ * below, and then "continue" may jump back to setjmp above */
+ areanum = a + 1;
+ freearea(areanum + 1);
brkset(&bc);
for (t1 = t->left; i-- && *wp != NULL;) {
setval(vp, *wp++);
while (setjmp(bc.brkpt))
if (isbreak)
goto broken;
+ /* Restore areanum value. It may be incremented by execute()
+ * below, and then "continue" may jump back to setjmp above */
+ areanum = a + 1;
+ freearea(areanum + 1);
brkset(&bc);
t1 = t->left;
while ((execute(t1, pin, pout, /* no_fork: */ 0) == 0) == (t->op_type == TWHILE))
DBGPRINTF3(("FORKEXEC: calling vfork()...\n"));
newpid = vfork();
if (newpid == -1) {
- DBGPRINTF(("FORKEXEC: ERROR, cannot vfork()!\n"));
+ DBGPRINTF(("FORKEXEC: ERROR, can't vfork()!\n"));
return -1;
}
if (iopp) {
if (bltin && bltin != doexec) {
prs(bltin_name);
- err(": cannot redirect shell command");
+ err(": can't redirect shell command");
if (forked)
_exit(-1);
return -1;
/* Builtin in pipe: disallowed */
/* TODO: allow "exec"? */
prs(bltin_name);
- err(": cannot run builtin as part of pipe");
+ err(": can't run builtin as part of pipe");
if (forked)
_exit(-1);
return -1;
if (u < 0) {
prs(cp);
- prs(": cannot ");
+ prs(": can't ");
warn(msg);
return 1;
}
return "not found";
}
exstat = 126; /* mimic bash */
- return "cannot execute";
+ return "can't execute";
}
/*
* built-in commands: doX
*/
-static int dohelp(struct op *t ATTRIBUTE_UNUSED, char **args ATTRIBUTE_UNUSED)
+static int dohelp(struct op *t UNUSED_PARAM, char **args UNUSED_PARAM)
{
int col;
const struct builtincmd *x;
- puts("\nBuilt-in commands:\n"
- "-------------------");
+ printf("\n"
+ "Built-in commands:\n"
+ "------------------\n");
col = 0;
x = builtincmds;
return EXIT_SUCCESS;
}
-static int dolabel(struct op *t ATTRIBUTE_UNUSED, char **args ATTRIBUTE_UNUSED)
+static int dolabel(struct op *t UNUSED_PARAM, char **args UNUSED_PARAM)
{
return 0;
}
-static int dochdir(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int dochdir(struct op *t UNUSED_PARAM, char **args)
{
const char *cp, *er;
return 1;
}
-static int doshift(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int doshift(struct op *t UNUSED_PARAM, char **args)
{
int n;
/*
* execute login and newgrp directly
*/
-static int dologin(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int dologin(struct op *t UNUSED_PARAM, char **args)
{
const char *cp;
return 1;
}
-static int doumask(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int doumask(struct op *t UNUSED_PARAM, char **args)
{
int i;
char *cp;
return 1;
}
-static int dodot(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int dodot(struct op *t UNUSED_PARAM, char **args)
{
int i;
const char *sp;
return -1;
}
-static int dowait(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int dowait(struct op *t UNUSED_PARAM, char **args)
{
int i;
char *cp;
return 0;
}
-static int doread(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int doread(struct op *t UNUSED_PARAM, char **args)
{
char *cp, **wp;
int nb = 0;
return nb <= 0;
}
-static int doeval(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int doeval(struct op *t UNUSED_PARAM, char **args)
{
return RUN(awordlist, args + 1, wdchar);
}
-static int dotrap(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int dotrap(struct op *t UNUSED_PARAM, char **args)
{
int n, i;
int resetsig;
return n * m;
}
-static int dobreak(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int dobreak(struct op *t UNUSED_PARAM, char **args)
{
return brkcontin(args[1], 1);
}
-static int docontinue(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int docontinue(struct op *t UNUSED_PARAM, char **args)
{
return brkcontin(args[1], 0);
}
/* NOTREACHED */
}
-static int doexit(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int doexit(struct op *t UNUSED_PARAM, char **args)
{
char *cp;
return 0;
}
-static int doexport(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int doexport(struct op *t UNUSED_PARAM, char **args)
{
rdexp(args + 1, export, EXPORT);
return 0;
}
-static int doreadonly(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int doreadonly(struct op *t UNUSED_PARAM, char **args)
{
rdexp(args + 1, ronly, RONLY);
return 0;
err(": bad identifier");
}
-static int doset(struct op *t ATTRIBUTE_UNUSED, char **args)
+static int doset(struct op *t UNUSED_PARAM, char **args)
{
struct var *vp;
char *cp;
cp = args[1];
if (cp == NULL) {
for (vp = vlist; vp; vp = vp->next)
- varput(vp->name, 1);
+ varput(vp->name, STDOUT_FILENO);
return 0;
}
if (*cp == '-') {
static void varput(char *s, int out)
{
if (isalnum(*s) || *s == '_') {
- write(out, s, strlen(s));
- write(out, "\n", 1);
+ xwrite_str(out, s);
+ xwrite(out, "\n", 1);
}
}
#endif
}
-static int dotimes(struct op *t ATTRIBUTE_UNUSED, char **args ATTRIBUTE_UNUSED)
+static int dotimes(struct op *t UNUSED_PARAM, char **args UNUSED_PARAM)
{
struct tms buf;
unsigned clk_tck = sysconf(_SC_CLK_TCK);
switch (c) {
case '=':
if (isdigit(*s)) {
- err("cannot use ${...=...} with $n");
+ err("can't use ${...=...} with $n");
gflg = 1;
break;
}