2001-08-09 Fernando-Ruiz Casas <correo@fernando-ruiz.com>

* shell/Makefile.am, shell/README, shell/cmds.c, shell/shell.c,
	shell/shell.h: Updates.
This commit is contained in:
Joel Sherrill
2001-08-09 22:08:46 +00:00
parent bd520203a0
commit 70d689aed4
12 changed files with 292 additions and 206 deletions

View File

@@ -1,3 +1,8 @@
2001-08-09 Fernando-Ruiz Casas <correo@fernando-ruiz.com>
* shell/Makefile.am, shell/README, shell/cmds.c, shell/shell.c,
shell/shell.h: Updates.
2001-08-09 Keith Outwater <vac4050@cae597.rsc.raytheon.com>
* monitor/mon-command.c: Add support for partial command matching.

View File

@@ -9,7 +9,7 @@ include_rtemsdir = $(includedir)/rtems
LIBNAME = libshell-tmp
LIB = $(ARCH)/$(LIBNAME).a
C_FILES = cmds.c shell.c pty.c
C_FILES = cmds.c shell.c
C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
include_rtems_HEADERS = shell.h
@@ -39,6 +39,6 @@ all-local: $(ARCH) $(PREINSTALL_FILES) $(OBJS) $(LIB)
.PRECIOUS: $(LIB)
EXTRA_DIST = README shell.c cmds.c pty.c shell.h
EXTRA_DIST = README shell.c cmds.c shell.h
include $(top_srcdir)/../../../automake/local.am

View File

@@ -19,10 +19,7 @@ NOTES:
2. You only need a termios dev to start a new session, add your new commands
and enjoy it.
3. If you have tcp/ip inited you can start telnetd daemon.
You need register pseudo-terminals driver into device drivers table.
16 ptyX termios device terminales are created into /dev/.
Calling rtems_initialize_telnetd() starts the daemon.
3. Telnetd daemon uses this (browse libnetworking/rtems_telnetd)
Enjoy it.
FUTURE:

View File

@@ -334,10 +334,13 @@ int main_chdir (int argc, char *argv[]) {
/*-----------------------------------------------------------*/
int main_mkdir (int argc, char *argv[]) {
char *dir;
dir=NULL;
if (argc>1) dir=argv[1];
if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
printf("mkdir '%s' failed:%s\n",dir,strerror(errno));
int n;
n=1;
while (n<argc) {
dir=argv[n++];
if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
printf("mkdir '%s' failed:%s\n",dir,strerror(errno));
};
};
return errno;
}
@@ -345,9 +348,12 @@ int main_mkdir (int argc, char *argv[]) {
int main_rmdir (int argc, char *argv[])
{
char *dir;
dir=NULL;
if (argc>1) dir=argv[1];
if (rmdir(dir)) printf("rmdir '%s' failed:%s\n",dir,strerror(errno));
int n;
n=1;
while (n<argc) {
dir=argv[n++];
if (rmdir(dir)) printf("rmdir '%s' failed:%s\n",dir,strerror(errno));
};
return errno;
}
/*-----------------------------------------------------------*/
@@ -383,43 +389,11 @@ int main_rm (int argc, char *argv[])
return 0;
}
/*-----------------------------------------------------------*/
/* date - print or set time and date */
static int set_time(char *t)
{
rtems_time_of_day tod;
FILE * rtc;
int len;
if ( rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod) != RTEMS_SUCCESSFUL )
memset( &tod, 0, sizeof(tod) );
/* JRS
*
* This code that was used to parse the command line was taken
* from an inappropriate source. It has been removed and needs
* to be replaced.
*/
if (!_TOD_Validate(&tod)) {
fprintf(stderr, "Invalid date value\n");
} else {
rtems_clock_set(&tod);
rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod);
rtc=fopen("/dev/rtc","r+");
if (rtc) {
fwrite(&tod,sizeof(tod),1,rtc);
fclose(rtc);
};
};
return 1;
}
/* date - print time and date */
int main_date(int argc,char *argv[])
{
time_t t;
if (argc == 2)
set_time(argv[1]);
time(&t);
printf("%s", ctime(&t));
return 0;
@@ -528,7 +502,7 @@ void register_cmds(void) {
/* misc. topic */
shell_add_cmd ("logoff","misc","logoff from the system" ,main_logoff);
shell_alias_cmd("logoff","exit");
shell_add_cmd ("date" ,"misc","date [[MMDDYY]hhmm[ss]]" ,main_date);
shell_add_cmd ("date" ,"misc","date" ,main_date);
shell_add_cmd ("reset","misc","reset the BSP" ,main_reset);
shell_add_cmd ("alias","misc","alias old new" ,main_alias);
shell_add_cmd ("tty" ,"misc","show ttyname" ,main_tty );

View File

@@ -16,6 +16,7 @@
#include "config.h"
#endif
#undef __STRICT_ANSI__ /* fileno() */
#include <stdio.h>
#include <rtems.h>
@@ -29,6 +30,7 @@
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <pwd.h>
@@ -222,7 +224,8 @@ int shell_help(int argc,char * argv[]) {
shell_topic_t *topic;
shell_cmd_t * shell_cmd=shell_first_cmd;
if (argc<2) {
printf("help: TOPIC? The topics are\n");
printf("help: ('r' repeat last cmd - 'e' edit last cmd)\n"
" TOPIC? The topics are\n");
topic=shell_first_topic;
col=0;
while (topic) {
@@ -275,11 +278,16 @@ int shell_help(int argc,char * argv[]) {
return 0;
}
/* ----------------------------------------------- *
* TODO:Change to bash readline() better.
* TODO: Add improvements. History, edit vi or emacs, ...
* ----------------------------------------------- */
int shell_scanline(char * line,int size,FILE * in,FILE * out) {
int c,col;
col=0;
if (*line) {
col=strlen(line);
if (out) fprintf(out,"%s",line);
};
tcdrain(fileno(in ));
tcdrain(fileno(out));
for (;;) {
line[col]=0;
@@ -343,6 +351,31 @@ void cat_file(FILE * out,char * name) {
};
}
void write_file(char * name,char * content) {
FILE * fd;
fd=fopen(name,"w");
if (fd) {
fwrite(content,1,strlen(content),fd);
fclose(fd);
};
}
void init_issue(void) {
static char issue_inited=FALSE;
struct stat buf;
if (issue_inited) return;
issue_inited=TRUE;
getpwnam("root"); /* dummy call to init /etc dir */
if (stat("/etc/issue",&buf))
write_file("/etc/issue",
"Welcome to @V\\n"
"Login into @S(@L)\\n");
if (stat("/etc/issue.net",&buf))
write_file("/etc/issue.net",
"Welcome to %v\n"
"running on %m\n");
}
int shell_login(FILE * in,FILE * out) {
FILE * fd;
int c;
@@ -351,6 +384,7 @@ int shell_login(FILE * in,FILE * out) {
char name[128];
char pass[128];
struct passwd * passwd;
init_issue();
setuid(0);
setgid(0);
rtems_current_user_env->euid=
@@ -359,7 +393,47 @@ int shell_login(FILE * in,FILE * out) {
if((current_shell_env->devname[5]!='p')||
(current_shell_env->devname[6]!='t')||
(current_shell_env->devname[7]!='y')) {
cat_file(out,"/etc/issue");
fd=fopen("/etc/issue","r");
if (fd) {
while ((c=fgetc(fd))!=EOF) {
if (c=='@') {
switch(c=fgetc(fd)) {
case 'L':fprintf(out,"%s",current_shell_env->devname);
break;
case 'B':fprintf(out,"0");
break;
case 'T':
case 'D':time(&t);
fprintf(out,"%s",ctime(&t));
break;
case 'S':fprintf(out,"RTEMS");
break;
case 'V':fprintf(out,"%s\n%s",_RTEMS_version,_Copyright_Notice);
break;
case '@':fprintf(out,"@");
break;
default :fprintf(out,"@%c",c);
break;
};
} else
if (c=='\\') {
switch(c=fgetc(fd)) {
case '\\':fprintf(out,"\\");
break;
case 'b':fprintf(out,"\b"); break;
case 'f':fprintf(out,"\f"); break;
case 'n':fprintf(out,"\n"); break;
case 'r':fprintf(out,"\r"); break;
case 's':fprintf(out," "); break;
case 't':fprintf(out,"\t"); break;
case '@':fprintf(out,"@"); break;
};
} else {
fputc(c,out);
};
};
fclose(fd);
}
} else {
fd=fopen("/etc/issue.net","r");
if (fd) {
@@ -397,6 +471,8 @@ int shell_login(FILE * in,FILE * out) {
};
};
times=0;
strcpy(name,"");
strcpy(pass,"");
for (;;) {
times++;
if (times>3) break;
@@ -406,22 +482,26 @@ int shell_login(FILE * in,FILE * out) {
if (!shell_scanline(pass,sizeof(pass),in,NULL)) break;
if (out) fprintf(out,"\n");
if ((passwd=getpwnam(name))) {
setuid(passwd->pw_uid);
setgid(passwd->pw_gid);
rtems_current_user_env->euid=
rtems_current_user_env->egid=0;
chown(current_shell_env->devname,passwd->pw_uid,0);
rtems_current_user_env->euid=passwd->pw_uid;
rtems_current_user_env->egid=passwd->pw_gid;
if (!strcmp(passwd->pw_passwd,"*")) {
/* /etc/shadow */
return 0;
} else {
/* crypt() */
return 0;
if (strcmp(passwd->pw_passwd,"!")) { /* valid user */
setuid(passwd->pw_uid);
setgid(passwd->pw_gid);
rtems_current_user_env->euid=
rtems_current_user_env->egid=0;
chown(current_shell_env->devname,passwd->pw_uid,0);
rtems_current_user_env->euid=passwd->pw_uid;
rtems_current_user_env->egid=passwd->pw_gid;
if (!strcmp(passwd->pw_passwd,"*")) {
/* /etc/shadow */
return 0;
} else {
/* crypt() */
return 0;
};
};
};
if (out) fprintf(out,"Login incorrect\n");
strcpy(name,"");
strcpy(pass,"");
};
return -1;
}
@@ -486,6 +566,7 @@ rtems_task shell_shell(rtems_task_argument task_argument) {
if (!stdout) {
fprintf(stderr,"shell:unable to open stdout.%s:%s\n",devname,strerror(errno));
};
setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
stderr=fopen(devname,"r+");
if (!stderr) {
printf("shell:unable to open stderr.%s:%s\n",devname,strerror(errno));
@@ -497,13 +578,19 @@ rtems_task shell_shell(rtems_task_argument task_argument) {
};
shell_add_cmd(NULL,NULL,NULL,NULL); /* init the chain list*/
do {
/* Set again root user and root filesystem, side effect of set_priv..*/
sc=rtems_libio_set_private_env();
if (sc!=RTEMS_SUCCESSFUL) {
rtems_error(sc,"rtems_libio_set_private_env():");
rtems_task_delete(RTEMS_SELF);
};
if (!shell_login(stdin,stdout)) {
cat_file(stdout,"/etc/motd");
strcpy(last_cmd,"");
strcpy(cmd,"");
printf("\n"
"RTEMS SHELL (Version 1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",devname);
chdir("/");
"RTEMS SHELL (Ver.1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",devname);
chdir("/"); /* XXX: chdir to getpwent homedir */
shell_env->exit_shell=FALSE;
for (;;) {
/* Prompt section */
@@ -513,7 +600,11 @@ rtems_task shell_shell(rtems_task_argument task_argument) {
/* getcmd section */
if (!shell_scanline(cmd,sizeof(cmd),stdin,stdout)) break; /*EOF*/
/* evaluate cmd section */
if (!strcmp(cmd,"r")) { /* repeat last command, forced, not automatic */
if (!strcmp(cmd,"e")) { /* edit last command */
strcpy(cmd,last_cmd);
continue;
} else
if (!strcmp(cmd,"r")) { /* repeat last command */
strcpy(cmd,last_cmd);
} else
if (strcmp(cmd,"")) { /* only for get a new prompt */
@@ -536,6 +627,7 @@ rtems_task shell_shell(rtems_task_argument task_argument) {
};
/* end exec cmd section */
if (shell_env->exit_shell) break;
cmd[0]=0;
};
printf("\nGoodbye from RTEMS SHELL :-(\n");
};
@@ -588,4 +680,3 @@ rtems_status_code shell_init (char * task_name,
shell_env->forever =forever;
return rtems_task_start(task_id,shell_shell,(rtems_task_argument) shell_env);
}
/* ----------------------------------------------- */

View File

@@ -1,4 +1,15 @@
/*
*
* Instantatiate a new terminal shell.
*
* Author:
*
* WORK: fernando.ruiz@ctv.es
* HOME: correo@fernando-ruiz.com
*
* Thanks at:
* Chris John
*
* $Id$
*/
@@ -53,6 +64,7 @@ typedef struct {
int shell_scanline(char * line,int size,FILE * in,FILE * out) ;
void cat_file(FILE * out,char *name);
void write_file(char *name,char * content);
rtems_status_code shell_init(char * task_name ,
rtems_unsigned32 task_stacksize,/*0 default*/
@@ -64,42 +76,6 @@ rtems_status_code shell_init(char * task_name ,
extern shell_env_t global_shell_env,
* current_shell_env;
/*--------*/
/* pty.c */
/*--------*/
char * get_pty(int socket);
rtems_device_driver pty_initialize(
rtems_device_major_number major,
rtems_device_minor_number minor,
void *arg);
rtems_device_driver pty_open(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
rtems_device_driver pty_close(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
rtems_device_driver pty_read(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
rtems_device_driver pty_write(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
rtems_device_driver pty_control(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
#define PTY_DRIVER_TABLE_ENTRY \
{ pty_initialize , pty_open , pty_close , \
pty_read , pty_write , pty_control }
/*--------*/
/* cmds.c */
/*--------*/
int str2int(char * s);

View File

@@ -1,3 +1,8 @@
2001-08-09 Fernando-Ruiz Casas <correo@fernando-ruiz.com>
* shell/Makefile.am, shell/README, shell/cmds.c, shell/shell.c,
shell/shell.h: Updates.
2001-08-09 Keith Outwater <vac4050@cae597.rsc.raytheon.com>
* monitor/mon-command.c: Add support for partial command matching.

View File

@@ -9,7 +9,7 @@ include_rtemsdir = $(includedir)/rtems
LIBNAME = libshell-tmp
LIB = $(ARCH)/$(LIBNAME).a
C_FILES = cmds.c shell.c pty.c
C_FILES = cmds.c shell.c
C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
include_rtems_HEADERS = shell.h
@@ -39,6 +39,6 @@ all-local: $(ARCH) $(PREINSTALL_FILES) $(OBJS) $(LIB)
.PRECIOUS: $(LIB)
EXTRA_DIST = README shell.c cmds.c pty.c shell.h
EXTRA_DIST = README shell.c cmds.c shell.h
include $(top_srcdir)/../../../automake/local.am

View File

@@ -19,10 +19,7 @@ NOTES:
2. You only need a termios dev to start a new session, add your new commands
and enjoy it.
3. If you have tcp/ip inited you can start telnetd daemon.
You need register pseudo-terminals driver into device drivers table.
16 ptyX termios device terminales are created into /dev/.
Calling rtems_initialize_telnetd() starts the daemon.
3. Telnetd daemon uses this (browse libnetworking/rtems_telnetd)
Enjoy it.
FUTURE:

View File

@@ -334,10 +334,13 @@ int main_chdir (int argc, char *argv[]) {
/*-----------------------------------------------------------*/
int main_mkdir (int argc, char *argv[]) {
char *dir;
dir=NULL;
if (argc>1) dir=argv[1];
if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
printf("mkdir '%s' failed:%s\n",dir,strerror(errno));
int n;
n=1;
while (n<argc) {
dir=argv[n++];
if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
printf("mkdir '%s' failed:%s\n",dir,strerror(errno));
};
};
return errno;
}
@@ -345,9 +348,12 @@ int main_mkdir (int argc, char *argv[]) {
int main_rmdir (int argc, char *argv[])
{
char *dir;
dir=NULL;
if (argc>1) dir=argv[1];
if (rmdir(dir)) printf("rmdir '%s' failed:%s\n",dir,strerror(errno));
int n;
n=1;
while (n<argc) {
dir=argv[n++];
if (rmdir(dir)) printf("rmdir '%s' failed:%s\n",dir,strerror(errno));
};
return errno;
}
/*-----------------------------------------------------------*/
@@ -383,43 +389,11 @@ int main_rm (int argc, char *argv[])
return 0;
}
/*-----------------------------------------------------------*/
/* date - print or set time and date */
static int set_time(char *t)
{
rtems_time_of_day tod;
FILE * rtc;
int len;
if ( rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod) != RTEMS_SUCCESSFUL )
memset( &tod, 0, sizeof(tod) );
/* JRS
*
* This code that was used to parse the command line was taken
* from an inappropriate source. It has been removed and needs
* to be replaced.
*/
if (!_TOD_Validate(&tod)) {
fprintf(stderr, "Invalid date value\n");
} else {
rtems_clock_set(&tod);
rtems_clock_get(RTEMS_CLOCK_GET_TOD,&tod);
rtc=fopen("/dev/rtc","r+");
if (rtc) {
fwrite(&tod,sizeof(tod),1,rtc);
fclose(rtc);
};
};
return 1;
}
/* date - print time and date */
int main_date(int argc,char *argv[])
{
time_t t;
if (argc == 2)
set_time(argv[1]);
time(&t);
printf("%s", ctime(&t));
return 0;
@@ -528,7 +502,7 @@ void register_cmds(void) {
/* misc. topic */
shell_add_cmd ("logoff","misc","logoff from the system" ,main_logoff);
shell_alias_cmd("logoff","exit");
shell_add_cmd ("date" ,"misc","date [[MMDDYY]hhmm[ss]]" ,main_date);
shell_add_cmd ("date" ,"misc","date" ,main_date);
shell_add_cmd ("reset","misc","reset the BSP" ,main_reset);
shell_add_cmd ("alias","misc","alias old new" ,main_alias);
shell_add_cmd ("tty" ,"misc","show ttyname" ,main_tty );

View File

@@ -16,6 +16,7 @@
#include "config.h"
#endif
#undef __STRICT_ANSI__ /* fileno() */
#include <stdio.h>
#include <rtems.h>
@@ -29,6 +30,7 @@
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <pwd.h>
@@ -222,7 +224,8 @@ int shell_help(int argc,char * argv[]) {
shell_topic_t *topic;
shell_cmd_t * shell_cmd=shell_first_cmd;
if (argc<2) {
printf("help: TOPIC? The topics are\n");
printf("help: ('r' repeat last cmd - 'e' edit last cmd)\n"
" TOPIC? The topics are\n");
topic=shell_first_topic;
col=0;
while (topic) {
@@ -275,11 +278,16 @@ int shell_help(int argc,char * argv[]) {
return 0;
}
/* ----------------------------------------------- *
* TODO:Change to bash readline() better.
* TODO: Add improvements. History, edit vi or emacs, ...
* ----------------------------------------------- */
int shell_scanline(char * line,int size,FILE * in,FILE * out) {
int c,col;
col=0;
if (*line) {
col=strlen(line);
if (out) fprintf(out,"%s",line);
};
tcdrain(fileno(in ));
tcdrain(fileno(out));
for (;;) {
line[col]=0;
@@ -343,6 +351,31 @@ void cat_file(FILE * out,char * name) {
};
}
void write_file(char * name,char * content) {
FILE * fd;
fd=fopen(name,"w");
if (fd) {
fwrite(content,1,strlen(content),fd);
fclose(fd);
};
}
void init_issue(void) {
static char issue_inited=FALSE;
struct stat buf;
if (issue_inited) return;
issue_inited=TRUE;
getpwnam("root"); /* dummy call to init /etc dir */
if (stat("/etc/issue",&buf))
write_file("/etc/issue",
"Welcome to @V\\n"
"Login into @S(@L)\\n");
if (stat("/etc/issue.net",&buf))
write_file("/etc/issue.net",
"Welcome to %v\n"
"running on %m\n");
}
int shell_login(FILE * in,FILE * out) {
FILE * fd;
int c;
@@ -351,6 +384,7 @@ int shell_login(FILE * in,FILE * out) {
char name[128];
char pass[128];
struct passwd * passwd;
init_issue();
setuid(0);
setgid(0);
rtems_current_user_env->euid=
@@ -359,7 +393,47 @@ int shell_login(FILE * in,FILE * out) {
if((current_shell_env->devname[5]!='p')||
(current_shell_env->devname[6]!='t')||
(current_shell_env->devname[7]!='y')) {
cat_file(out,"/etc/issue");
fd=fopen("/etc/issue","r");
if (fd) {
while ((c=fgetc(fd))!=EOF) {
if (c=='@') {
switch(c=fgetc(fd)) {
case 'L':fprintf(out,"%s",current_shell_env->devname);
break;
case 'B':fprintf(out,"0");
break;
case 'T':
case 'D':time(&t);
fprintf(out,"%s",ctime(&t));
break;
case 'S':fprintf(out,"RTEMS");
break;
case 'V':fprintf(out,"%s\n%s",_RTEMS_version,_Copyright_Notice);
break;
case '@':fprintf(out,"@");
break;
default :fprintf(out,"@%c",c);
break;
};
} else
if (c=='\\') {
switch(c=fgetc(fd)) {
case '\\':fprintf(out,"\\");
break;
case 'b':fprintf(out,"\b"); break;
case 'f':fprintf(out,"\f"); break;
case 'n':fprintf(out,"\n"); break;
case 'r':fprintf(out,"\r"); break;
case 's':fprintf(out," "); break;
case 't':fprintf(out,"\t"); break;
case '@':fprintf(out,"@"); break;
};
} else {
fputc(c,out);
};
};
fclose(fd);
}
} else {
fd=fopen("/etc/issue.net","r");
if (fd) {
@@ -397,6 +471,8 @@ int shell_login(FILE * in,FILE * out) {
};
};
times=0;
strcpy(name,"");
strcpy(pass,"");
for (;;) {
times++;
if (times>3) break;
@@ -406,22 +482,26 @@ int shell_login(FILE * in,FILE * out) {
if (!shell_scanline(pass,sizeof(pass),in,NULL)) break;
if (out) fprintf(out,"\n");
if ((passwd=getpwnam(name))) {
setuid(passwd->pw_uid);
setgid(passwd->pw_gid);
rtems_current_user_env->euid=
rtems_current_user_env->egid=0;
chown(current_shell_env->devname,passwd->pw_uid,0);
rtems_current_user_env->euid=passwd->pw_uid;
rtems_current_user_env->egid=passwd->pw_gid;
if (!strcmp(passwd->pw_passwd,"*")) {
/* /etc/shadow */
return 0;
} else {
/* crypt() */
return 0;
if (strcmp(passwd->pw_passwd,"!")) { /* valid user */
setuid(passwd->pw_uid);
setgid(passwd->pw_gid);
rtems_current_user_env->euid=
rtems_current_user_env->egid=0;
chown(current_shell_env->devname,passwd->pw_uid,0);
rtems_current_user_env->euid=passwd->pw_uid;
rtems_current_user_env->egid=passwd->pw_gid;
if (!strcmp(passwd->pw_passwd,"*")) {
/* /etc/shadow */
return 0;
} else {
/* crypt() */
return 0;
};
};
};
if (out) fprintf(out,"Login incorrect\n");
strcpy(name,"");
strcpy(pass,"");
};
return -1;
}
@@ -486,6 +566,7 @@ rtems_task shell_shell(rtems_task_argument task_argument) {
if (!stdout) {
fprintf(stderr,"shell:unable to open stdout.%s:%s\n",devname,strerror(errno));
};
setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
stderr=fopen(devname,"r+");
if (!stderr) {
printf("shell:unable to open stderr.%s:%s\n",devname,strerror(errno));
@@ -497,13 +578,19 @@ rtems_task shell_shell(rtems_task_argument task_argument) {
};
shell_add_cmd(NULL,NULL,NULL,NULL); /* init the chain list*/
do {
/* Set again root user and root filesystem, side effect of set_priv..*/
sc=rtems_libio_set_private_env();
if (sc!=RTEMS_SUCCESSFUL) {
rtems_error(sc,"rtems_libio_set_private_env():");
rtems_task_delete(RTEMS_SELF);
};
if (!shell_login(stdin,stdout)) {
cat_file(stdout,"/etc/motd");
strcpy(last_cmd,"");
strcpy(cmd,"");
printf("\n"
"RTEMS SHELL (Version 1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",devname);
chdir("/");
"RTEMS SHELL (Ver.1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",devname);
chdir("/"); /* XXX: chdir to getpwent homedir */
shell_env->exit_shell=FALSE;
for (;;) {
/* Prompt section */
@@ -513,7 +600,11 @@ rtems_task shell_shell(rtems_task_argument task_argument) {
/* getcmd section */
if (!shell_scanline(cmd,sizeof(cmd),stdin,stdout)) break; /*EOF*/
/* evaluate cmd section */
if (!strcmp(cmd,"r")) { /* repeat last command, forced, not automatic */
if (!strcmp(cmd,"e")) { /* edit last command */
strcpy(cmd,last_cmd);
continue;
} else
if (!strcmp(cmd,"r")) { /* repeat last command */
strcpy(cmd,last_cmd);
} else
if (strcmp(cmd,"")) { /* only for get a new prompt */
@@ -536,6 +627,7 @@ rtems_task shell_shell(rtems_task_argument task_argument) {
};
/* end exec cmd section */
if (shell_env->exit_shell) break;
cmd[0]=0;
};
printf("\nGoodbye from RTEMS SHELL :-(\n");
};
@@ -588,4 +680,3 @@ rtems_status_code shell_init (char * task_name,
shell_env->forever =forever;
return rtems_task_start(task_id,shell_shell,(rtems_task_argument) shell_env);
}
/* ----------------------------------------------- */

View File

@@ -1,4 +1,15 @@
/*
*
* Instantatiate a new terminal shell.
*
* Author:
*
* WORK: fernando.ruiz@ctv.es
* HOME: correo@fernando-ruiz.com
*
* Thanks at:
* Chris John
*
* $Id$
*/
@@ -53,6 +64,7 @@ typedef struct {
int shell_scanline(char * line,int size,FILE * in,FILE * out) ;
void cat_file(FILE * out,char *name);
void write_file(char *name,char * content);
rtems_status_code shell_init(char * task_name ,
rtems_unsigned32 task_stacksize,/*0 default*/
@@ -64,42 +76,6 @@ rtems_status_code shell_init(char * task_name ,
extern shell_env_t global_shell_env,
* current_shell_env;
/*--------*/
/* pty.c */
/*--------*/
char * get_pty(int socket);
rtems_device_driver pty_initialize(
rtems_device_major_number major,
rtems_device_minor_number minor,
void *arg);
rtems_device_driver pty_open(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
rtems_device_driver pty_close(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
rtems_device_driver pty_read(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
rtems_device_driver pty_write(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
rtems_device_driver pty_control(
rtems_device_major_number major,
rtems_device_minor_number minor,
void * arg);
#define PTY_DRIVER_TABLE_ENTRY \
{ pty_initialize , pty_open , pty_close , \
pty_read , pty_write , pty_control }
/*--------*/
/* cmds.c */
/*--------*/
int str2int(char * s);