projects
/
oweals
/
busybox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox
[oweals/busybox.git]
/
shell
/
bbsh.c
diff --git
a/shell/bbsh.c
b/shell/bbsh.c
index 99e4f61fbe9986feb60792106d56dc984fae7c1b..83132f928f415ec844655b42798220d6c775f115 100644
(file)
--- a/
shell/bbsh.c
+++ b/
shell/bbsh.c
@@
-1,5
+1,5
@@
/* vi: set ts=4 :
/* vi: set ts=4 :
- *
+ *
* bbsh - busybox shell
*
* Copyright 2006 Rob Landley <rob@landley.net>
* bbsh - busybox shell
*
* Copyright 2006 Rob Landley <rob@landley.net>
@@
-36,7
+36,7
@@
echo `echo hello#comment " woot` and more
*/
echo `echo hello#comment " woot` and more
*/
-#include "
busybox
.h"
+#include "
libbb
.h"
// A single executable, its arguments, and other information we know about it.
#define BBSH_FLAG_EXIT 1
// A single executable, its arguments, and other information we know about it.
#define BBSH_FLAG_EXIT 1
@@
-51,10
+51,10
@@
// What we know about a single process.
struct command {
struct command *next;
// What we know about a single process.
struct command {
struct command *next;
- int flags; // exit, suspend, && ||
+ int flags; // exit, suspend, && ||
int pid; // pid (or exit code)
int argc;
int pid; // pid (or exit code)
int argc;
- char *argv[
0
];
+ char *argv[];
};
// A collection of processes piped into/waiting on each other.
};
// A collection of processes piped into/waiting on each other.
@@
-68,7
+68,7
@@
struct pipeline {
static void free_list(void *list, void (*freeit)(void *data))
{
static void free_list(void *list, void (*freeit)(void *data))
{
- while(list) {
+ while
(list) {
void **next = (void **)list;
void *list_next = *next;
freeit(list);
void **next = (void **)list;
void *list_next = *next;
freeit(list);
@@
-90,7
+90,7
@@
static char *parse_word(char *start, struct command **cmd)
// Grab next word. (Add dequote and envvar logic here)
end = start;
// Grab next word. (Add dequote and envvar logic here)
end = start;
-
while (*end && !isspace(*end)) end++
;
+
end = skip_non_whitespace(end)
;
(*cmd)->argv[(*cmd)->argc++] = xstrndup(start, end-start);
// Allocate more space if there's no room for NULL terminator.
(*cmd)->argv[(*cmd)->argc++] = xstrndup(start, end-start);
// Allocate more space if there's no room for NULL terminator.
@@
-125,9
+125,9
@@
static char *parse_pipeline(char *cmdline, struct pipeline *line)
return 0;
}
return 0;
}
- // Allocate next command structure if necessary
+ // Allocate next command structure if necessary
if (!*cmd) *cmd = xzalloc(sizeof(struct command)+8*sizeof(char *));
if (!*cmd) *cmd = xzalloc(sizeof(struct command)+8*sizeof(char *));
-
+
// Parse next argument and add the results to argv[]
end = parse_word(start, cmd);
// Parse next argument and add the results to argv[]
end = parse_word(start, cmd);
@@
-138,7
+138,7
@@
static char *parse_pipeline(char *cmdline, struct pipeline *line)
start++;
break;
}
start++;
break;
}
- // handle | & < > >> << || &&
+ // handle | & < > >> << || &&
}
break;
}
}
break;
}
@@
-159,16
+159,16
@@
static int run_pipeline(struct pipeline *line)
// Handle local commands. This is totally fake and plastic.
if (cmd->argc==2 && !strcmp(cmd->argv[0],"cd"))
chdir(cmd->argv[1]);
// Handle local commands. This is totally fake and plastic.
if (cmd->argc==2 && !strcmp(cmd->argv[0],"cd"))
chdir(cmd->argv[1]);
- else if(!strcmp(cmd->argv[0],"exit"))
- exit(cmd->argc>1 ? atoi(cmd->argv[1]) : 0);
+ else if
(!strcmp(cmd->argv[0],"exit"))
+ exit(cmd->argc>1 ? atoi(cmd->argv[1]) : 0);
else {
int status;
pid_t pid=fork();
else {
int status;
pid_t pid=fork();
- if(!pid) {
- run_applet_
by_name
(cmd->argv[0],cmd->argc,cmd->argv);
+ if
(!pid) {
+ run_applet_
and_exit
(cmd->argv[0],cmd->argc,cmd->argv);
execvp(cmd->argv[0],cmd->argv);
execvp(cmd->argv[0],cmd->argv);
- printf("No %s",cmd->argv[0]);
- exit(
1
);
+ printf("No %s",
cmd->argv[0]);
+ exit(
EXIT_FAILURE
);
} else waitpid(pid, &status, 0);
}
} else waitpid(pid, &status, 0);
}
@@
-179,7
+179,7
@@
static void free_cmd(void *data)
{
struct command *cmd=(struct command *)data;
{
struct command *cmd=(struct command *)data;
- while(cmd->argc) free(cmd->argv[--cmd->argc]);
+ while
(cmd->argc) free(cmd->argv[--cmd->argc]);
}
}
@@
-198,25
+198,26
@@
static void handle(char *command)
}
}
}
}
-int bbsh_main(int argc, char *argv[])
+int bbsh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int bbsh_main(int argc UNUSED_PARAM, char **argv)
{
char *command=NULL;
FILE *f;
{
char *command=NULL;
FILE *f;
- getopt32(arg
c, arg
v, "c:", &command);
+ getopt32(argv, "c:", &command);
- f = argv[optind] ? xfopen
(argv[optind],"r"
) : NULL;
+ f = argv[optind] ? xfopen
_for_read(argv[optind]
) : NULL;
if (command) handle(command);
else {
unsigned cmdlen=0;
for (;;) {
if (command) handle(command);
else {
unsigned cmdlen=0;
for (;;) {
- if(!f) putchar('$');
- if
(1 > getline(&command, &cmdlen,f ?
: stdin)) break;
+ if
(!f) putchar('$');
+ if
(1 > getline(&command, &cmdlen, f ? f
: stdin)) break;
handle(command);
}
if (ENABLE_FEATURE_CLEAN_UP) free(command);
}
handle(command);
}
if (ENABLE_FEATURE_CLEAN_UP) free(command);
}
-
+
return 1;
}
return 1;
}