git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Multiuser, Capabilities and Access Controls (#54)
[lunaix-os.git]
/
lunaix-os
/
usr
/
sh
/
sh.c
diff --git
a/lunaix-os/usr/sh/sh.c
b/lunaix-os/usr/sh/sh.c
index c2c8347f3f7d6969fd03f838b7b5607dadbe0e7e..764404b0910a54fe50c33891b20967388c3de20e 100644
(file)
--- a/
lunaix-os/usr/sh/sh.c
+++ b/
lunaix-os/usr/sh/sh.c
@@
-113,6
+113,7
@@
sigint_handle(int signum)
void
sh_exec(const char** argv)
{
void
sh_exec(const char** argv)
{
+ static int prev_exit;
const char* envp[] = { 0 };
char* name = argv[0];
if (!strcmp(name, "cd")) {
const char* envp[] = { 0 };
char* name = argv[0];
if (!strcmp(name, "cd")) {
@@
-121,15
+122,27
@@
sh_exec(const char** argv)
return;
}
return;
}
+ if (!strcmp(name, "?")) {
+ printf("%d\n", prev_exit);
+ return;
+ }
+
+ char buffer[1024];
+ strcpy(buffer, "/bin/");
+ strcpy(&buffer[5], name);
+
pid_t p;
pid_t p;
+ int res;
if (!(p = fork())) {
if (!(p = fork())) {
- if (execve(
name
, argv, envp)) {
+ if (execve(
buffer
, argv, envp)) {
sh_printerr();
}
_exit(1);
}
setpgid(p, getpgid());
sh_printerr();
}
_exit(1);
}
setpgid(p, getpgid());
- waitpid(p, NULL, 0);
+ waitpid(p, &res, 0);
+
+ prev_exit = WEXITSTATUS(res);
}
static char*
}
static char*
@@
-169,7
+182,7
@@
sh_loop()
while (1) {
getcwd(pwd, 512);
while (1) {
getcwd(pwd, 512);
- printf("
[%s]$
", pwd);
+ printf("
%s #
", pwd);
int sz = read(stdin, buf, 511);
if (sz < 0) {
int sz = read(stdin, buf, 511);
if (sz < 0) {
@@
-182,8
+195,7
@@
sh_loop()
// currently, this shell only support single argument
if (!parse_cmdline(buf, argv)) {
// currently, this shell only support single argument
if (!parse_cmdline(buf, argv)) {
- printf("\n");
- goto cont;
+ continue;
}
// cmd=="exit"
}
// cmd=="exit"
@@
-191,9
+203,7
@@
sh_loop()
break;
}
break;
}
- sh_exec((const char**)argv);
- cont:
- printf("\n");
+ sh_exec((const char**)argv);
}
}
}
}