esh -> sh, clean up
* login should set some environment variables now * init should start terminals as login shells, so --single doesn't really mean "single user" any more, just sorta single terminal session * system() should work now since esh now accepts -c; not that vim is still going to be unhappy because it does crazy shit.
This commit is contained in:
parent
c06c3a483e
commit
98b6ae5867
@ -1,2 +1,3 @@
|
||||
|
||||
[1;33m = とあるOS いちご [strawberry] =[0m
|
||||
|
||||
|
@ -37,7 +37,7 @@ void start_terminal(char * arg) {
|
||||
if (!pid) {
|
||||
char * tokens[] = {
|
||||
"/bin/terminal",
|
||||
"-F",
|
||||
"-Fl",
|
||||
arg,
|
||||
NULL
|
||||
};
|
||||
@ -53,7 +53,7 @@ void start_terminal_no_freetype(char * arg) {
|
||||
if (!pid) {
|
||||
char * tokens[] = {
|
||||
"/bin/terminal",
|
||||
"-Fkb",
|
||||
"-Fklb",
|
||||
arg,
|
||||
NULL
|
||||
};
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include "lib/sha2.h"
|
||||
|
||||
#define LINE_LEN 1024
|
||||
|
||||
uint32_t child = 0;
|
||||
|
||||
void sig_int(int sig) {
|
||||
@ -70,17 +72,50 @@ int checkUserPass(char * user, char * pass) {
|
||||
|
||||
}
|
||||
|
||||
void set_username() {
|
||||
FILE * passwd = fopen("/etc/passwd", "r");
|
||||
char line[LINE_LEN];
|
||||
|
||||
int uid = syscall_getuid();
|
||||
|
||||
while (fgets(line, LINE_LEN, passwd) != NULL) {
|
||||
|
||||
line[strlen(line)-1] = '\0';
|
||||
|
||||
char *p, *tokens[10], *last;
|
||||
int i = 0;
|
||||
for ((p = strtok_r(line, ":", &last)); p;
|
||||
(p = strtok_r(NULL, ":", &last)), i++) {
|
||||
if (i < 511) tokens[i] = p;
|
||||
}
|
||||
tokens[i] = NULL;
|
||||
|
||||
if (atoi(tokens[2]) == uid) {
|
||||
setenv("USER", tokens[0], 1);
|
||||
}
|
||||
}
|
||||
fclose(passwd);
|
||||
}
|
||||
|
||||
void set_homedir() {
|
||||
char * user = getenv("USER");
|
||||
if (user) {
|
||||
char path[512];
|
||||
sprintf(path,"/home/%s", user);
|
||||
setenv("HOME",path,1);
|
||||
} else {
|
||||
setenv("HOME","/",1);
|
||||
}
|
||||
}
|
||||
|
||||
void set_path() {
|
||||
setenv("PATH", "/bin", 0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
|
||||
struct utsname u;
|
||||
uname(&u);
|
||||
|
||||
fprintf(stdout, "\n%s %s %s %s\n\n",
|
||||
u.sysname,
|
||||
u.nodename,
|
||||
u.release,
|
||||
u.version
|
||||
);
|
||||
system("uname -a");
|
||||
|
||||
syscall_signal(2, sig_int);
|
||||
syscall_signal(11, sig_segv);
|
||||
@ -111,13 +146,18 @@ int main(int argc, char ** argv) {
|
||||
continue;
|
||||
}
|
||||
|
||||
system("cat /etc/motd");
|
||||
|
||||
pid_t pid = getpid();
|
||||
|
||||
uint32_t f = fork();
|
||||
if (getpid() != pid) {
|
||||
/* TODO: Read appropriate shell from /etc/passwd */
|
||||
set_username();
|
||||
set_homedir();
|
||||
set_path();
|
||||
char * args[] = {
|
||||
"/bin/esh",
|
||||
"/bin/sh",
|
||||
NULL
|
||||
};
|
||||
syscall_setuid(uid);
|
||||
|
@ -39,6 +39,8 @@ size_t shell_history_offset = 0;
|
||||
size_t shell_scroll = 0;
|
||||
char shell_temp[1024];
|
||||
|
||||
int shell_interactive = 1;
|
||||
|
||||
int pid; /* Process ID of the shell */
|
||||
|
||||
char * shell_history_prev(size_t item);
|
||||
@ -820,10 +822,15 @@ _next:
|
||||
_done:
|
||||
|
||||
if (quoted) {
|
||||
draw_prompt_c();
|
||||
buffer_size = read_entry_continued(buffer);
|
||||
shell_history_append_line(buffer);
|
||||
continue;
|
||||
if (shell_interactive) {
|
||||
draw_prompt_c();
|
||||
buffer_size = read_entry_continued(buffer);
|
||||
shell_history_append_line(buffer);
|
||||
continue;
|
||||
} else {
|
||||
fprintf(stderr, "Syntax error: Unterminated quoted string.\n");
|
||||
return 127;
|
||||
}
|
||||
}
|
||||
|
||||
if (collected) {
|
||||
@ -863,7 +870,7 @@ _done:
|
||||
sprintf(cmd, "%s%s", "/bin/", argv[0]);
|
||||
file = fopen(cmd,"r");
|
||||
if (!file) {
|
||||
printf("Command not found: %s\n", argv[0]);
|
||||
fprintf(stderr, "%s: Command not found\n", argv[0]);
|
||||
free(cmd);
|
||||
return 1;
|
||||
}
|
||||
@ -871,7 +878,7 @@ _done:
|
||||
} else {
|
||||
file = fopen(argv[0], "r");
|
||||
if (!file) {
|
||||
printf("Command not found: %s\n", argv[0]);
|
||||
fprintf(stderr, "%s: Command not found\n", argv[0]);
|
||||
free(cmd);
|
||||
return 1;
|
||||
}
|
||||
@ -940,6 +947,19 @@ void sort_commands() {
|
||||
}
|
||||
}
|
||||
|
||||
void show_usage(int argc, char * argv[]) {
|
||||
printf(
|
||||
"Esh: The Experimental Shell\n"
|
||||
"\n"
|
||||
"usage: %s [-lha] [path]\n"
|
||||
"\n"
|
||||
" -c \033[4mcmd\033[0m \033[3mparse and execute cmd\033[0m\n"
|
||||
//-c cmd \033[...
|
||||
" -? \033[3mshow this help text\033[0m\n"
|
||||
"\n", argv[0]);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
|
||||
int nowait = 0;
|
||||
@ -953,23 +973,26 @@ int main(int argc, char ** argv) {
|
||||
getusername();
|
||||
gethostname();
|
||||
|
||||
FILE * motd = fopen("/etc/motd", "r");
|
||||
if (motd) {
|
||||
size_t s = 0;
|
||||
fseek(motd, 0, SEEK_END);
|
||||
s = ftell(motd);
|
||||
fseek(motd, 0, SEEK_SET);
|
||||
char * m = malloc(sizeof(char) * s);
|
||||
fread(m, s, 1, motd);
|
||||
fwrite(m, s, 1, stdout);
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
free(m);
|
||||
}
|
||||
|
||||
install_commands();
|
||||
add_path_contents();
|
||||
sort_commands();
|
||||
|
||||
if (argc > 1) {
|
||||
int index, c;
|
||||
while ((c = getopt(argc, argv, "c:?")) != -1) {
|
||||
switch (c) {
|
||||
case 'c':
|
||||
shell_interactive = 0;
|
||||
return shell_exec(optarg, strlen(optarg));
|
||||
case '?':
|
||||
show_usage(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shell_interactive = 1;
|
||||
|
||||
while (1) {
|
||||
draw_prompt(last_ret);
|
||||
char buffer[LINE_LEN] = {0};
|
@ -1776,7 +1776,7 @@ int main(int argc, char ** argv) {
|
||||
char * tokens[] = {"/bin/login",NULL};
|
||||
int i = execvp(tokens[0], tokens);
|
||||
} else {
|
||||
char * tokens[] = {"/bin/esh",NULL};
|
||||
char * tokens[] = {"/bin/sh",NULL};
|
||||
int i = execvp(tokens[0], tokens);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user