* "tar: A lone zero block at N", where N = kilobyte
* where EOF was met (not EOF block, actual EOF!),
* and tar will exit with error code 0.
- * We will mimic exit(0), although we will not mimic
+ * We will mimic exit(EXIT_SUCCESS), although we will not mimic
* the message and we don't check whether we indeed
* saw zero block directly before this. */
if (i == 0)
/* tar gz/bz autodetect: check for gz/bz2 magic.
* If it is the very first block, and we see the magic,
* we can switch to get_header_tar_gz/bz2/lzma().
- * Needs seekable fd. I wish recv(MSG_PEEK) would work
+ * Needs seekable fd. I wish recv(MSG_PEEK) works
* on any fd... */
if (not_first)
goto err;
#if ENABLE_FEATURE_TAR_GZIP
- if (tar.name[0] == 0x1f && tar.name[1] == 0x8b) { /* gzip */
+ if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */
get_header_ptr = get_header_tar_gz;
} else
#endif
}
file_header->link_target = NULL;
if (!linkname && parse_names && tar.linkname[0]) {
- /* we trash magic[0] here, it's ok */
- tar.linkname[sizeof(tar.linkname)] = '\0';
- file_header->link_target = xstrdup(tar.linkname);
+ file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
/* FIXME: what if we have non-link object with link_target? */
/* Will link_target be free()ed? */
}
file_header->name = NULL;
if (!longname && parse_names) {
/* we trash mode[0] here, it's ok */
- tar.name[sizeof(tar.name)] = '\0';
+ //tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain
+ tar.mode[0] = '\0';
if (tar.prefix[0]) {
/* and padding[0] */
- tar.prefix[sizeof(tar.prefix)] = '\0';
+ //tar.prefix[sizeof(tar.prefix)] = '\0'; - gcc 4.3.0 would complain
+ tar.padding[0] = '\0';
file_header->name = concat_path_file(tar.prefix, tar.name);
} else
file_header->name = xstrdup(tar.name);
#ifdef MSHDEBUG
static int mshdbg = MSHDEBUG;
-#define DBGPRINTF(x) if (mshdbg>0) printf x
-#define DBGPRINTF0(x) if (mshdbg>0) printf x
-#define DBGPRINTF1(x) if (mshdbg>1) printf x
-#define DBGPRINTF2(x) if (mshdbg>2) printf x
-#define DBGPRINTF3(x) if (mshdbg>3) printf x
-#define DBGPRINTF4(x) if (mshdbg>4) printf x
-#define DBGPRINTF5(x) if (mshdbg>5) printf x
-#define DBGPRINTF6(x) if (mshdbg>6) printf x
-#define DBGPRINTF7(x) if (mshdbg>7) printf x
-#define DBGPRINTF8(x) if (mshdbg>8) printf x
-#define DBGPRINTF9(x) if (mshdbg>9) printf x
+#define DBGPRINTF(x) if (mshdbg > 0) printf x
+#define DBGPRINTF0(x) if (mshdbg > 0) printf x
+#define DBGPRINTF1(x) if (mshdbg > 1) printf x
+#define DBGPRINTF2(x) if (mshdbg > 2) printf x
+#define DBGPRINTF3(x) if (mshdbg > 3) printf x
+#define DBGPRINTF4(x) if (mshdbg > 4) printf x
+#define DBGPRINTF5(x) if (mshdbg > 5) printf x
+#define DBGPRINTF6(x) if (mshdbg > 6) printf x
+#define DBGPRINTF7(x) if (mshdbg > 7) printf x
+#define DBGPRINTF8(x) if (mshdbg > 8) printf x
+#define DBGPRINTF9(x) if (mshdbg > 9) printf x
static int mshdbg_rc = 0;
#define RCPRINTF(x) ((void)0)
-#endif /* MSHDEBUG */
+#endif /* MSHDEBUG */
#if ENABLE_FEATURE_EDITING_FANCY_PROMPT
* shell
*/
-#define LINELIM 2100
-#define NPUSH 8 /* limit to input nesting */
+#define LINELIM 2100
+#define NPUSH 8 /* limit to input nesting */
#undef NOFILE
-#define NOFILE 20 /* Number of open files */
-#define NUFILE 10 /* Number of user-accessible files */
-#define FDBASE 10 /* First file usable by Shell */
+#define NOFILE 20 /* Number of open files */
+#define NUFILE 10 /* Number of user-accessible files */
+#define FDBASE 10 /* First file usable by Shell */
/*
* values returned by wait
/*
* library and system definitions
*/
-typedef void xint; /* base type of jmp_buf, for not broken compilers */
+typedef void xint; /* base type of jmp_buf, for not broken compilers */
/*
* shell components
{ NULL , NULL },
};
-static struct op *scantree(struct op *);
static struct op *dowholefile(int /*, int*/);
/* Globals */
static char **dolv;
static int dolc;
-static int exstat;
+static uint8_t exstat;
static smallint gflg; /* (seems to be a parse error indicator) */
static smallint interactive; /* Is this an interactive shell */
static smallint execflg;
return;
}
- DBGPRINTF(("NODE: %p, left %p, right %p\n", head, head->left,
+ DBGPRINTF(("NODE: %p, left %p, right %p\n", head, head->left,
head->right));
if (head->left)
static void prs(const char *s)
{
if (*s)
- write(2, s, strlen(s));
+ write(STDERR_FILENO, s, strlen(s));
}
static void prn(unsigned u)
{
if (*s) {
prs(s);
- exstat = -1;
+ if (!exstat)
+ exstat = 255;
}
prs("\n");
if (FLAG['e'])
}
+#ifdef UNUSED
struct op *scantree(struct op *head)
{
struct op *dotnode;
return NULL;
}
+#endif
static void onecommand(void)
// longjmps away (at "Run builtin" below), leaving t->op_words clobbered!
// See http://bugs.busybox.net/view.php?id=846.
// Now we do not touch t->op_words, but separately pass wp as param list
- // to builtins
+ // to builtins
DBGPRINTF(("FORKEXEC: bltin %p, no_fork %d, owp %p\n", bltin,
no_fork, owp));
/* Don't fork if it is a lone builtin (not in pipe)
if (t->op_type == TPAREN)
_exit(execute(t->left, NOPIPE, NOPIPE, /* no_fork: */ 1));
if (wp[0] == NULL)
- _exit(0);
+ _exit(EXIT_SUCCESS);
cp = rexecve(wp[0], wp, makenv(0, NULL));
prs(wp[0]);
prs(" - core dumped");
if (rv >= ARRAY_SIZE(signame) || signame[rv])
prs("\n");
- rv = -1;
+ rv |= 0x80;
} else
rv = WAITVAL(s);
}
if (tp != global_env.linep)
*tp++ = '/';
strcpy(tp, c);
- //for (i = 0; (*tp++ = c[i++]) != '\0';)
- // continue;
DBGPRINTF3(("REXECVE: global_env.linep is %s\n", global_env.linep));
switch (errno) {
case ENOEXEC:
+ /* File is executable but file format isnt recognized */
+ /* Run it as a shell script */
+ /* (execve above didnt do it itself, unlike execvp) */
*v = global_env.linep;
v--;
tp = *v;
- *v = global_env.linep;
+ *v = (char*)DEFAULT_SHELL;
execve(DEFAULT_SHELL, v, envp);
*v = tp;
return "no shell";
return "argument list too long";
}
}
- return errno == ENOENT ? "not found" : "cannot execute";
+ if (errno == ENOENT) {
+ exstat = 127; /* standards require this */
+ return "not found";
+ }
+ exstat = 126; /* mimic bash */
+ return "cannot execute";
}
/*
}
for (wp = args + 1; *wp; wp++) {
for (cp = global_env.linep; !nl && cp < elinep - 1; cp++) {
- nb = nonblock_safe_read(0, cp, sizeof(*cp));
+ nb = nonblock_safe_read(STDIN_FILENO, cp, sizeof(*cp));
if (nb != sizeof(*cp))
break;
nl = (*cp == '\n');
prs(argument_list[0]);
prs(": ");
err(cp);
- _exit(1);
+ _exit(EXIT_FAILURE);
}
dname[NAME_MAX] = '\0';
while ((de = readdir(dirp)) != NULL) {
/* XXX Hmmm... What this could be? (abial) */
- /*
- if (ent[j].d_ino == 0)
- continue;
+ /* if (ent[j].d_ino == 0) continue;
*/
strncpy(dname, de->d_name, NAME_MAX);
if (dname[0] == '.')
static void ioecho(char c)
{
if (FLAG['v'])
- write(2, &c, sizeof c);
+ write(STDERR_FILENO, &c, sizeof c);
}
static void pushio(struct ioarg *argp, int (*fn) (struct ioarg *))
while (size == 0 || position >= size) {
size = read_line_input(current_prompt, filechar_cmdbuf, BUFSIZ, line_input_state);
if (size < 0) /* Error/EOF */
- exit(0);
+ exit(EXIT_SUCCESS);
position = 0;
/* if Ctrl-C, size == 0 and loop will repeat */
}
}
/*
- * remap fd into Shell's fd space
+ * Remap fd into shell's fd space
*/
static int remap(int fd)
{
/* Shell is non-interactive, activate printf-based debug */
#ifdef MSHDEBUG
- mshdbg = (int) (((char) (mshdbg_var->value[0])) - '0');
+ mshdbg = mshdbg_var->value[0] - '0';
if (mshdbg < 0)
mshdbg = 0;
#endif
name = *++argv;
if (newfile(name))
- exit(1); /* Exit on error */
+ exit(EXIT_FAILURE); /* Exit on error */
}
}
if (filteropts) for (opt = strtok(filteropts, ","); opt; opt = strtok(NULL, ",")) {
char *opteq = strchr(opt, '=');
if (opteq) {
+ int val, idx;
static const char options[] ALIGN1 =
/* 0 */ "rsize\0"
/* 1 */ "wsize\0"
/* 18 */ "proto\0"
/* 19 */ "namlen\0"
/* 20 */ "addr\0";
- int val = xatoi_u(opteq + 1);
- *opteq = '\0';
- switch (index_in_strings(options, opt)) {
+
+ *opteq++ = '\0';
+ idx = index_in_strings(options, opt);
+ switch (idx) {
+ case 12: // "mounthost"
+ mounthost = xstrndup(opteq,
+ strcspn(opteq, " \t\n\r,"));
+ continue;
+ case 18: // "proto"
+ if (!strncmp(opteq, "tcp", 3))
+ tcp = 1;
+ else if (!strncmp(opteq, "udp", 3))
+ tcp = 0;
+ else
+ bb_error_msg("warning: unrecognized proto= option");
+ continue;
+ case 20: // "addr" - ignore
+ continue;
+ }
+
+ val = xatoi_u(opteq);
+ switch (idx) {
case 0: // "rsize"
data.rsize = val;
- break;
+ continue;
case 1: // "wsize"
data.wsize = val;
- break;
+ continue;
case 2: // "timeo"
data.timeo = val;
- break;
+ continue;
case 3: // "retrans"
data.retrans = val;
- break;
+ continue;
case 4: // "acregmin"
data.acregmin = val;
- break;
+ continue;
case 5: // "acregmax"
data.acregmax = val;
- break;
+ continue;
case 6: // "acdirmin"
data.acdirmin = val;
- break;
+ continue;
case 7: // "acdirmax"
data.acdirmax = val;
- break;
+ continue;
case 8: // "actimeo"
data.acregmin = val;
data.acregmax = val;
data.acdirmin = val;
data.acdirmax = val;
- break;
+ continue;
case 9: // "retry"
retry = val;
- break;
+ continue;
case 10: // "port"
port = val;
- break;
+ continue;
case 11: // "mountport"
mountport = val;
- break;
- case 12: // "mounthost"
- mounthost = xstrndup(opteq+1,
- strcspn(opteq+1," \t\n\r,"));
- break;
+ continue;
case 13: // "mountprog"
mountprog = val;
- break;
+ continue;
case 14: // "mountvers"
mountvers = val;
- break;
+ continue;
case 15: // "nfsprog"
nfsprog = val;
- break;
+ continue;
case 16: // "nfsvers"
case 17: // "vers"
nfsvers = val;
- break;
- case 18: // "proto"
- if (!strncmp(opteq+1, "tcp", 3))
- tcp = 1;
- else if (!strncmp(opteq+1, "udp", 3))
- tcp = 0;
- else
- bb_error_msg("warning: unrecognized proto= option");
- break;
+ continue;
case 19: // "namlen"
- if (nfs_mount_version >= 2)
+ //if (nfs_mount_version >= 2)
data.namlen = val;
- else
- bb_error_msg("warning: option namlen is not supported\n");
- break;
- case 20: // "addr" - ignore
- break;
+ //else
+ // bb_error_msg("warning: option namlen is not supported\n");
+ continue;
default:
bb_error_msg("unknown nfs mount parameter: %s=%d", opt, val);
goto fail;
}
}
- else {
+ else { /* not of the form opt=val */
static const char options[] ALIGN1 =
"bg\0"
"fg\0"