mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-11-08 00:40:21 +08:00
2000-05-24 Fernando Ruiz Casas <fernando.ruiz@ctv.es>
* monitor/mon-prmisc.c: Correct print line. * shell/Makefile.am: Added new file telnetd.c. * shell/telnetd.c, shell/telnetd.h, shell/pty.c: New files. * shell/shell.c, shell/cmds.c, shell/shell.h: Numerous improvments: - The shell_init has a new parameter 'forever' because in /dev/console you need that this process runs forever but in tcp/ip not. (respawn?) - A new task for every session opened trought tcp/ip telnet client. (the chargen,daytime and more are possible of implementation but I ask me if they are necesary) - Exit from the session delete the task and when the client fails too. - More cmds have been implemented. (very reduced version of these) umask, chmod, id, whoami, rm, cat, ... - A reduced line edit has been implemented. Ctrl-C abort the input, Ctrl-d in the first position gives EOF (logout). '\b' and DEL makes the rubout operation. I think that readline() for every session spents a lot of resources.
This commit is contained in:
1 parent
e565720aad
commit
b2712e35b9
19 files changed
+1400
-160
No files matched your search
@@ -1,3 +1,24 @@
|
||||
2000-05-24 Fernando Ruiz Casas <fernando.ruiz@ctv.es>
|
||||
|
||||
* monitor/mon-prmisc.c: Correct print line.
|
||||
* shell/Makefile.am: Added new file telnetd.c.
|
||||
* shell/telnetd.c, shell/telnetd.h, shell/pty.c: New files.
|
||||
* shell/shell.c, shell/cmds.c, shell/shell.h: Numerous improvments:
|
||||
- The shell_init has a new parameter 'forever' because in
|
||||
/dev/console you need that this process runs forever but in
|
||||
tcp/ip not. (respawn?)
|
||||
- A new task for every session opened trought tcp/ip telnet client.
|
||||
(the chargen,daytime and more are possible of implementation but
|
||||
I ask me if they are necesary)
|
||||
- Exit from the session delete the task and when the client fails too.
|
||||
- More cmds have been implemented. (very reduced version of these)
|
||||
umask, chmod, id, whoami, rm, cat, ...
|
||||
- A reduced line edit has been implemented.
|
||||
Ctrl-C abort the input,
|
||||
Ctrl-d in the first position gives EOF (logout).
|
||||
'\b' and DEL makes the rubout operation.
|
||||
I think that readline() for every session spents a lot of resources.
|
||||
|
||||
2001-04-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
|
||||
|
||||
* shell/cmds.c, shell/shell.c: Remove fileno-hacks.
|
||||
|
||||
@@ -108,8 +108,8 @@ rtems_monitor_dump_name(rtems_name name)
|
||||
for (i=0; i<sizeof(u.c); i++)
|
||||
length += rtems_monitor_dump_char(u.c[i]);
|
||||
#else
|
||||
for (i=sizeof(u.c)-1; i ; i--)
|
||||
length += rtems_monitor_dump_char(u.c[i]);
|
||||
for (i=0; i<sizeof(u.c); i++)
|
||||
length += rtems_monitor_dump_char(u.c[sizeof(u.c)-1-i]);
|
||||
#endif
|
||||
return length;
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ include_rtemsdir = $(includedir)/rtems
|
||||
LIBNAME = libshell-tmp
|
||||
LIB = $(ARCH)/$(LIBNAME).a
|
||||
|
||||
C_FILES = cmds.c shell.c
|
||||
C_FILES = cmds.c shell.c pty.c telnetd.c
|
||||
C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
|
||||
|
||||
include_rtems_HEADERS = shell.h
|
||||
include_rtems_HEADERS = shell.h telnetd.h
|
||||
|
||||
OBJS = $(C_O_FILES)
|
||||
|
||||
@@ -39,6 +39,6 @@ all-local: $(ARCH) $(PREINSTALL_FILES) $(OBJS) $(LIB)
|
||||
|
||||
.PRECIOUS: $(LIB)
|
||||
|
||||
EXTRA_DIST = README shell.c cmds.c shell.h
|
||||
EXTRA_DIST = README shell.c cmds.c pty.c telnetd.c shell.h telnetd.h
|
||||
|
||||
include $(top_srcdir)/../../../automake/local.am
|
||||
@@ -19,10 +19,12 @@ 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.
|
||||
Enjoy it.
|
||||
|
||||
FUTURE:
|
||||
|
||||
1. Adding new commands in cmds.c to give file manegement to shell.
|
||||
|
||||
2. Create a telnetd daemon. (pseudo-terminal needed)
|
||||
+114
-9
@@ -13,7 +13,7 @@
|
||||
* MINIX date.c is adapted to run here. Like a exercise only....
|
||||
*
|
||||
* TODO: A lot of improvements of course.
|
||||
* cat, cp, rm, mv, ...
|
||||
* cp, mv, ...
|
||||
* hexdump,
|
||||
*
|
||||
* More? Say me it, please...
|
||||
@@ -34,6 +34,8 @@
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
@@ -257,6 +259,10 @@ int main_ls(int argc, char *argv[])
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
struct stat stat_buf;
|
||||
struct passwd * pwd;
|
||||
struct group * grp;
|
||||
char * user;
|
||||
char * group;
|
||||
char sbuf[256];
|
||||
char nbuf[1024];
|
||||
int n,size;
|
||||
@@ -279,7 +285,11 @@ int main_ls(int argc, char *argv[])
|
||||
if (stat(nbuf, &stat_buf) == 0)
|
||||
{ /* AWFUL buts works...*/
|
||||
strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M",gmtime(&stat_buf.st_atime));
|
||||
printf("%c%c%c%c%c%c%c%c%c%c %3d rtems rtems %11d %s %s%c\n",
|
||||
pwd=getpwuid(stat_buf.st_uid);
|
||||
user=pwd?pwd->pw_name:"nouser";
|
||||
grp=getgrgid(stat_buf.st_gid);
|
||||
group=grp?grp->gr_name:"nogrp";
|
||||
printf("%c%c%c%c%c%c%c%c%c%c %3d %6.6s %6.6s %11d %s %s%c\n",
|
||||
(S_ISLNK(stat_buf.st_mode)?('l'):
|
||||
(S_ISDIR(stat_buf.st_mode)?('d'):('-'))),
|
||||
(stat_buf.st_mode & S_IRUSR)?('r'):('-'),
|
||||
@@ -292,6 +302,7 @@ int main_ls(int argc, char *argv[])
|
||||
(stat_buf.st_mode & S_IWOTH)?('w'):('-'),
|
||||
(stat_buf.st_mode & S_IXOTH)?('x'):('-'),
|
||||
(int)stat_buf.st_nlink,
|
||||
user,group,
|
||||
(int)stat_buf.st_size,
|
||||
sbuf,
|
||||
dp->d_name,
|
||||
@@ -352,6 +363,28 @@ int main_chroot(int argc,char * argv[]) {
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_cat (int argc, char *argv[])
|
||||
{
|
||||
int n;
|
||||
n=1;
|
||||
while (n<argc) cat_file(stdout,argv[n++]);
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_rm (int argc, char *argv[])
|
||||
{
|
||||
int n;
|
||||
n=1;
|
||||
while (n<argc) {
|
||||
if (unlink(argv[n])) {
|
||||
printf("error %s:rm %s\n",strerror(errno),argv[n]);
|
||||
return -1;
|
||||
};
|
||||
n++;
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
/* date - print or set time and date Author: Jan Looyen */
|
||||
/* MINIX 1.5 GPL'ed */
|
||||
|
||||
@@ -424,6 +457,67 @@ int main_date(int argc,char *argv[])
|
||||
printf("%s", ctime(&t));
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_logoff(int argc,char *argv[])
|
||||
{
|
||||
printf("logoff from the system...");
|
||||
current_shell_env->exit_shell=TRUE;
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_tty (int argc,char *argv[])
|
||||
{
|
||||
printf("%s\n",ttyname(fileno(stdin)));
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_whoami(int argc,char *argv[])
|
||||
{
|
||||
struct passwd * pwd;
|
||||
pwd=getpwuid(getuid());
|
||||
printf("%s\n",pwd?pwd->pw_name:"nobody");
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_id (int argc,char *argv[])
|
||||
{
|
||||
struct passwd * pwd;
|
||||
struct group * grp;
|
||||
pwd=getpwuid(getuid());
|
||||
grp=getgrgid(getgid());
|
||||
printf("uid=%d(%s),gid=%d(%s),",
|
||||
getuid(),pwd?pwd->pw_name:"",
|
||||
getgid(),grp?grp->gr_name:"");
|
||||
pwd=getpwuid(geteuid());
|
||||
grp=getgrgid(getegid());
|
||||
printf("euid=%d(%s),egid=%d(%s)\n",
|
||||
geteuid(),pwd?pwd->pw_name:"",
|
||||
getegid(),grp?grp->gr_name:"");
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_umask(int argc,char *argv[])
|
||||
{
|
||||
mode_t msk=umask(0);
|
||||
if (argc == 2) msk=str2int(argv[1]);
|
||||
umask(msk);
|
||||
msk=umask(0);
|
||||
printf("0%o\n",msk);
|
||||
umask(msk);
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_chmod(int argc,char *argv[])
|
||||
{
|
||||
int n;
|
||||
mode_t mode;
|
||||
if (argc > 2){
|
||||
mode=str2int(argv[1])&0777;
|
||||
n=2;
|
||||
while (n<argc) chmod(argv[n++],mode);
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*
|
||||
* with this you can call at all the rtems monitor commands.
|
||||
* Not all work fine but you can show the rtems status and more.
|
||||
@@ -442,6 +536,14 @@ int main_monitor(int argc,char * argv[]) {
|
||||
void register_cmds(void) {
|
||||
rtems_monitor_command_entry_t *command;
|
||||
extern rtems_monitor_command_entry_t rtems_monitor_commands[];
|
||||
/* monitor topic */
|
||||
command=rtems_monitor_commands;
|
||||
while (command) {
|
||||
if (strcmp("exit",command->command)) /*Exclude EXIT (alias quit)*/
|
||||
shell_add_cmd(command->command,"monitor",
|
||||
command->usage ,main_monitor);
|
||||
command=command->next;
|
||||
};
|
||||
/* dir[ectories] topic */
|
||||
shell_add_cmd ("ls" ,"dir","ls [dir] # list files in the directory" ,main_ls );
|
||||
shell_add_cmd ("chdir" ,"dir","chdir [dir] # change the current directory",main_chdir);
|
||||
@@ -449,14 +551,24 @@ void register_cmds(void) {
|
||||
shell_add_cmd ("mkdir" ,"dir","mkdir dir # make a directory" ,main_mkdir);
|
||||
shell_add_cmd ("pwd" ,"dir","pwd # print work directory" ,main_pwd );
|
||||
shell_add_cmd ("chroot","dir","chroot [dir] # change the root directory" ,main_chroot);
|
||||
shell_add_cmd ("cat" ,"dir","cat n1 [n2 [n3...]]# show the ascii contents",main_cat );
|
||||
shell_add_cmd ("rm" ,"dir","rm n1 [n2 [n3...]]# remove files" ,main_rm );
|
||||
shell_add_cmd ("chmod" ,"dir","chmod 0777 n1 n2... #change filemode" ,main_chmod);
|
||||
|
||||
shell_alias_cmd("ls" ,"dir");
|
||||
shell_alias_cmd("chdir" ,"cd");
|
||||
|
||||
/* 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 ("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 );
|
||||
shell_add_cmd ("whoami","misc","show current user" ,main_whoami);
|
||||
shell_add_cmd ("id" ,"misc","show uid,gid,euid,egid" ,main_id );
|
||||
shell_add_cmd ("umask" ,"misc","umask [new_umask]" ,main_umask );
|
||||
|
||||
|
||||
/* memory topic */
|
||||
shell_add_cmd ("mdump","mem" ,"mdump [adr [size]]" ,main_mdump);
|
||||
@@ -467,12 +579,5 @@ void register_cmds(void) {
|
||||
#ifdef MALLOC_STATS /* /rtems/s/src/lib/libc/malloc.c */
|
||||
shell_add_cmd ("malloc","mem","mem show memory malloc'ed" ,main_mem);
|
||||
#endif
|
||||
/* monitor topic */
|
||||
command=rtems_monitor_commands;
|
||||
while (command) {
|
||||
shell_add_cmd(command->command,"monitor",
|
||||
command->usage ,main_monitor);
|
||||
command=command->next;
|
||||
};
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
File diff suppressed because it is too large.
Load diff
+184
-62
File diff suppressed because it is too large.
Load diff
@@ -45,21 +45,61 @@ typedef struct {
|
||||
char * taskname;
|
||||
tcflag_t tcflag;
|
||||
/* user extensions */
|
||||
int exit_shell; /* logout */
|
||||
int forever ; /* repeat login */
|
||||
int errorlevel;
|
||||
int mdump_adr;
|
||||
} shell_env_t;
|
||||
|
||||
int shell_scanline(char * line,int size,FILE * in,FILE * out) ;
|
||||
void cat_file(FILE * out,char *name);
|
||||
|
||||
rtems_status_code shell_init(char * task_name ,
|
||||
rtems_unsigned32 task_stacksize,/*0 default*/
|
||||
rtems_task_priority task_priority ,
|
||||
char * devname ,
|
||||
tcflag_t tcflag );
|
||||
tcflag_t tcflag ,
|
||||
int forever );
|
||||
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/error.h>
|
||||
#include <rtems/shell.h>
|
||||
#include <rtems/telnetd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
/***********************************************************/
|
||||
rtems_id telnetd_task_id =0;
|
||||
rtems_unsigned32 telnetd_stack_size =16384;
|
||||
rtems_task_priority telnetd_task_priority=100;
|
||||
/***********************************************************/
|
||||
rtems_task rtems_task_telnetd(rtems_task_argument task_argument) {
|
||||
int des_socket,
|
||||
acp_socket;
|
||||
struct sockaddr_in srv;
|
||||
char * devname;
|
||||
int i=1;
|
||||
int size_adr;
|
||||
if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
|
||||
perror("socket");
|
||||
rtems_task_delete(RTEMS_SELF);
|
||||
};
|
||||
setsockopt(des_socket,SOL_SOCKET,0,&i,sizeof(i));
|
||||
memset(&srv,0,sizeof(srv));
|
||||
srv.sin_family=AF_INET;
|
||||
srv.sin_port=htons(23);
|
||||
size_adr=sizeof(srv);
|
||||
if ((bind(des_socket,(struct sockaddr *)&srv,size_adr))<0) {
|
||||
perror("bind");
|
||||
close(des_socket);
|
||||
rtems_task_delete(RTEMS_SELF);
|
||||
};
|
||||
if ((listen(des_socket,5))<0) {
|
||||
perror("listen");
|
||||
close(des_socket);
|
||||
rtems_task_delete(RTEMS_SELF);
|
||||
};
|
||||
do {
|
||||
acp_socket=accept(des_socket,(struct sockaddr*)&srv,&size_adr);
|
||||
if (acp_socket<0) {
|
||||
perror("accept");
|
||||
break;
|
||||
};
|
||||
if (devname = get_pty(acp_socket) ) {
|
||||
shell_init(&devname[5],
|
||||
telnetd_stack_size,
|
||||
telnetd_task_priority,
|
||||
devname,B9600|CS8,FALSE);
|
||||
} else {
|
||||
close(acp_socket);
|
||||
};
|
||||
} while(1);
|
||||
close(des_socket);
|
||||
rtems_task_delete(RTEMS_SELF);
|
||||
}
|
||||
/***********************************************************/
|
||||
int rtems_initialize_telnetd(void) {
|
||||
rtems_status_code sc;
|
||||
if (telnetd_task_id ) return RTEMS_RESOURCE_IN_USE;
|
||||
if (telnetd_stack_size<=0 ) telnetd_stack_size =16384;
|
||||
if (telnetd_task_priority<=2) telnetd_task_priority=100;
|
||||
sc=rtems_task_create(new_rtems_name("TLND"),
|
||||
100,RTEMS_MINIMUM_STACK_SIZE,
|
||||
RTEMS_DEFAULT_MODES,
|
||||
RTEMS_DEFAULT_ATTRIBUTES,
|
||||
&telnetd_task_id);
|
||||
if (sc!=RTEMS_SUCCESSFUL) {
|
||||
rtems_error(sc,"creating task telnetd");
|
||||
return (int)sc;
|
||||
};
|
||||
sc=rtems_task_start(telnetd_task_id,
|
||||
rtems_task_telnetd,
|
||||
(rtems_task_argument)NULL);
|
||||
if (sc!=RTEMS_SUCCESSFUL) {
|
||||
rtems_error(sc,"starting task telnetd");
|
||||
};
|
||||
return (int)sc;
|
||||
}
|
||||
/***********************************************************/
|
||||
int main_telnetd(int argc,char * argv[]) {
|
||||
rtems_status_code sc;
|
||||
if (telnetd_task_id) {
|
||||
printf("ERROR:telnetd already started\n");
|
||||
return 1;
|
||||
};
|
||||
if (argc>1) telnetd_stack_size =str2int(argv[1]);
|
||||
if (argc>2) telnetd_task_priority=str2int(argv[2]);
|
||||
sc=rtems_initialize_telnetd();
|
||||
if (sc!=RTEMS_SUCCESSFUL) return sc;
|
||||
printf("rtems_telnetd() started with stacksize=%u,priority=%d\n",
|
||||
telnetd_stack_size,telnetd_task_priority);
|
||||
return 0;
|
||||
}
|
||||
/***********************************************************/
|
||||
int register_telnetd(void) {
|
||||
shell_add_cmd("telnetd","telnet","telnetd [stacksize [tsk_priority]]",main_telnetd);
|
||||
return 0;
|
||||
}
|
||||
/***********************************************************/
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __TELNETD_H
|
||||
#define __TELNETD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int rtems_initialize_telnetd(void);
|
||||
int main_telnetd(int argc,char * argv[]);
|
||||
int register_telnetd(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/error.h>
|
||||
#include <rtems/shell.h>
|
||||
#include <rtems/telnetd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
/***********************************************************/
|
||||
rtems_id telnetd_task_id =0;
|
||||
rtems_unsigned32 telnetd_stack_size =16384;
|
||||
rtems_task_priority telnetd_task_priority=100;
|
||||
/***********************************************************/
|
||||
rtems_task rtems_task_telnetd(rtems_task_argument task_argument) {
|
||||
int des_socket,
|
||||
acp_socket;
|
||||
struct sockaddr_in srv;
|
||||
char * devname;
|
||||
int i=1;
|
||||
int size_adr;
|
||||
if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
|
||||
perror("socket");
|
||||
rtems_task_delete(RTEMS_SELF);
|
||||
};
|
||||
setsockopt(des_socket,SOL_SOCKET,0,&i,sizeof(i));
|
||||
memset(&srv,0,sizeof(srv));
|
||||
srv.sin_family=AF_INET;
|
||||
srv.sin_port=htons(23);
|
||||
size_adr=sizeof(srv);
|
||||
if ((bind(des_socket,(struct sockaddr *)&srv,size_adr))<0) {
|
||||
perror("bind");
|
||||
close(des_socket);
|
||||
rtems_task_delete(RTEMS_SELF);
|
||||
};
|
||||
if ((listen(des_socket,5))<0) {
|
||||
perror("listen");
|
||||
close(des_socket);
|
||||
rtems_task_delete(RTEMS_SELF);
|
||||
};
|
||||
do {
|
||||
acp_socket=accept(des_socket,(struct sockaddr*)&srv,&size_adr);
|
||||
if (acp_socket<0) {
|
||||
perror("accept");
|
||||
break;
|
||||
};
|
||||
if (devname = get_pty(acp_socket) ) {
|
||||
shell_init(&devname[5],
|
||||
telnetd_stack_size,
|
||||
telnetd_task_priority,
|
||||
devname,B9600|CS8,FALSE);
|
||||
} else {
|
||||
close(acp_socket);
|
||||
};
|
||||
} while(1);
|
||||
close(des_socket);
|
||||
rtems_task_delete(RTEMS_SELF);
|
||||
}
|
||||
/***********************************************************/
|
||||
int rtems_initialize_telnetd(void) {
|
||||
rtems_status_code sc;
|
||||
if (telnetd_task_id ) return RTEMS_RESOURCE_IN_USE;
|
||||
if (telnetd_stack_size<=0 ) telnetd_stack_size =16384;
|
||||
if (telnetd_task_priority<=2) telnetd_task_priority=100;
|
||||
sc=rtems_task_create(new_rtems_name("TLND"),
|
||||
100,RTEMS_MINIMUM_STACK_SIZE,
|
||||
RTEMS_DEFAULT_MODES,
|
||||
RTEMS_DEFAULT_ATTRIBUTES,
|
||||
&telnetd_task_id);
|
||||
if (sc!=RTEMS_SUCCESSFUL) {
|
||||
rtems_error(sc,"creating task telnetd");
|
||||
return (int)sc;
|
||||
};
|
||||
sc=rtems_task_start(telnetd_task_id,
|
||||
rtems_task_telnetd,
|
||||
(rtems_task_argument)NULL);
|
||||
if (sc!=RTEMS_SUCCESSFUL) {
|
||||
rtems_error(sc,"starting task telnetd");
|
||||
};
|
||||
return (int)sc;
|
||||
}
|
||||
/***********************************************************/
|
||||
int main_telnetd(int argc,char * argv[]) {
|
||||
rtems_status_code sc;
|
||||
if (telnetd_task_id) {
|
||||
printf("ERROR:telnetd already started\n");
|
||||
return 1;
|
||||
};
|
||||
if (argc>1) telnetd_stack_size =str2int(argv[1]);
|
||||
if (argc>2) telnetd_task_priority=str2int(argv[2]);
|
||||
sc=rtems_initialize_telnetd();
|
||||
if (sc!=RTEMS_SUCCESSFUL) return sc;
|
||||
printf("rtems_telnetd() started with stacksize=%u,priority=%d\n",
|
||||
telnetd_stack_size,telnetd_task_priority);
|
||||
return 0;
|
||||
}
|
||||
/***********************************************************/
|
||||
int register_telnetd(void) {
|
||||
shell_add_cmd("telnetd","telnet","telnetd [stacksize [tsk_priority]]",main_telnetd);
|
||||
return 0;
|
||||
}
|
||||
/***********************************************************/
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __TELNETD_H
|
||||
#define __TELNETD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int rtems_initialize_telnetd(void);
|
||||
int main_telnetd(int argc,char * argv[]);
|
||||
int register_telnetd(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,3 +1,24 @@
|
||||
2000-05-24 Fernando Ruiz Casas <fernando.ruiz@ctv.es>
|
||||
|
||||
* monitor/mon-prmisc.c: Correct print line.
|
||||
* shell/Makefile.am: Added new file telnetd.c.
|
||||
* shell/telnetd.c, shell/telnetd.h, shell/pty.c: New files.
|
||||
* shell/shell.c, shell/cmds.c, shell/shell.h: Numerous improvments:
|
||||
- The shell_init has a new parameter 'forever' because in
|
||||
/dev/console you need that this process runs forever but in
|
||||
tcp/ip not. (respawn?)
|
||||
- A new task for every session opened trought tcp/ip telnet client.
|
||||
(the chargen,daytime and more are possible of implementation but
|
||||
I ask me if they are necesary)
|
||||
- Exit from the session delete the task and when the client fails too.
|
||||
- More cmds have been implemented. (very reduced version of these)
|
||||
umask, chmod, id, whoami, rm, cat, ...
|
||||
- A reduced line edit has been implemented.
|
||||
Ctrl-C abort the input,
|
||||
Ctrl-d in the first position gives EOF (logout).
|
||||
'\b' and DEL makes the rubout operation.
|
||||
I think that readline() for every session spents a lot of resources.
|
||||
|
||||
2001-04-28 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
|
||||
|
||||
* shell/cmds.c, shell/shell.c: Remove fileno-hacks.
|
||||
|
||||
@@ -108,8 +108,8 @@ rtems_monitor_dump_name(rtems_name name)
|
||||
for (i=0; i<sizeof(u.c); i++)
|
||||
length += rtems_monitor_dump_char(u.c[i]);
|
||||
#else
|
||||
for (i=sizeof(u.c)-1; i ; i--)
|
||||
length += rtems_monitor_dump_char(u.c[i]);
|
||||
for (i=0; i<sizeof(u.c); i++)
|
||||
length += rtems_monitor_dump_char(u.c[sizeof(u.c)-1-i]);
|
||||
#endif
|
||||
return length;
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ include_rtemsdir = $(includedir)/rtems
|
||||
LIBNAME = libshell-tmp
|
||||
LIB = $(ARCH)/$(LIBNAME).a
|
||||
|
||||
C_FILES = cmds.c shell.c
|
||||
C_FILES = cmds.c shell.c pty.c telnetd.c
|
||||
C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
|
||||
|
||||
include_rtems_HEADERS = shell.h
|
||||
include_rtems_HEADERS = shell.h telnetd.h
|
||||
|
||||
OBJS = $(C_O_FILES)
|
||||
|
||||
@@ -39,6 +39,6 @@ all-local: $(ARCH) $(PREINSTALL_FILES) $(OBJS) $(LIB)
|
||||
|
||||
.PRECIOUS: $(LIB)
|
||||
|
||||
EXTRA_DIST = README shell.c cmds.c shell.h
|
||||
EXTRA_DIST = README shell.c cmds.c pty.c telnetd.c shell.h telnetd.h
|
||||
|
||||
include $(top_srcdir)/../../../automake/local.am
|
||||
@@ -19,10 +19,12 @@ 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.
|
||||
Enjoy it.
|
||||
|
||||
FUTURE:
|
||||
|
||||
1. Adding new commands in cmds.c to give file manegement to shell.
|
||||
|
||||
2. Create a telnetd daemon. (pseudo-terminal needed)
|
||||
+114
-9
@@ -13,7 +13,7 @@
|
||||
* MINIX date.c is adapted to run here. Like a exercise only....
|
||||
*
|
||||
* TODO: A lot of improvements of course.
|
||||
* cat, cp, rm, mv, ...
|
||||
* cp, mv, ...
|
||||
* hexdump,
|
||||
*
|
||||
* More? Say me it, please...
|
||||
@@ -34,6 +34,8 @@
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
@@ -257,6 +259,10 @@ int main_ls(int argc, char *argv[])
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
struct stat stat_buf;
|
||||
struct passwd * pwd;
|
||||
struct group * grp;
|
||||
char * user;
|
||||
char * group;
|
||||
char sbuf[256];
|
||||
char nbuf[1024];
|
||||
int n,size;
|
||||
@@ -279,7 +285,11 @@ int main_ls(int argc, char *argv[])
|
||||
if (stat(nbuf, &stat_buf) == 0)
|
||||
{ /* AWFUL buts works...*/
|
||||
strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M",gmtime(&stat_buf.st_atime));
|
||||
printf("%c%c%c%c%c%c%c%c%c%c %3d rtems rtems %11d %s %s%c\n",
|
||||
pwd=getpwuid(stat_buf.st_uid);
|
||||
user=pwd?pwd->pw_name:"nouser";
|
||||
grp=getgrgid(stat_buf.st_gid);
|
||||
group=grp?grp->gr_name:"nogrp";
|
||||
printf("%c%c%c%c%c%c%c%c%c%c %3d %6.6s %6.6s %11d %s %s%c\n",
|
||||
(S_ISLNK(stat_buf.st_mode)?('l'):
|
||||
(S_ISDIR(stat_buf.st_mode)?('d'):('-'))),
|
||||
(stat_buf.st_mode & S_IRUSR)?('r'):('-'),
|
||||
@@ -292,6 +302,7 @@ int main_ls(int argc, char *argv[])
|
||||
(stat_buf.st_mode & S_IWOTH)?('w'):('-'),
|
||||
(stat_buf.st_mode & S_IXOTH)?('x'):('-'),
|
||||
(int)stat_buf.st_nlink,
|
||||
user,group,
|
||||
(int)stat_buf.st_size,
|
||||
sbuf,
|
||||
dp->d_name,
|
||||
@@ -352,6 +363,28 @@ int main_chroot(int argc,char * argv[]) {
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_cat (int argc, char *argv[])
|
||||
{
|
||||
int n;
|
||||
n=1;
|
||||
while (n<argc) cat_file(stdout,argv[n++]);
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_rm (int argc, char *argv[])
|
||||
{
|
||||
int n;
|
||||
n=1;
|
||||
while (n<argc) {
|
||||
if (unlink(argv[n])) {
|
||||
printf("error %s:rm %s\n",strerror(errno),argv[n]);
|
||||
return -1;
|
||||
};
|
||||
n++;
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
/* date - print or set time and date Author: Jan Looyen */
|
||||
/* MINIX 1.5 GPL'ed */
|
||||
|
||||
@@ -424,6 +457,67 @@ int main_date(int argc,char *argv[])
|
||||
printf("%s", ctime(&t));
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_logoff(int argc,char *argv[])
|
||||
{
|
||||
printf("logoff from the system...");
|
||||
current_shell_env->exit_shell=TRUE;
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_tty (int argc,char *argv[])
|
||||
{
|
||||
printf("%s\n",ttyname(fileno(stdin)));
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_whoami(int argc,char *argv[])
|
||||
{
|
||||
struct passwd * pwd;
|
||||
pwd=getpwuid(getuid());
|
||||
printf("%s\n",pwd?pwd->pw_name:"nobody");
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_id (int argc,char *argv[])
|
||||
{
|
||||
struct passwd * pwd;
|
||||
struct group * grp;
|
||||
pwd=getpwuid(getuid());
|
||||
grp=getgrgid(getgid());
|
||||
printf("uid=%d(%s),gid=%d(%s),",
|
||||
getuid(),pwd?pwd->pw_name:"",
|
||||
getgid(),grp?grp->gr_name:"");
|
||||
pwd=getpwuid(geteuid());
|
||||
grp=getgrgid(getegid());
|
||||
printf("euid=%d(%s),egid=%d(%s)\n",
|
||||
geteuid(),pwd?pwd->pw_name:"",
|
||||
getegid(),grp?grp->gr_name:"");
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_umask(int argc,char *argv[])
|
||||
{
|
||||
mode_t msk=umask(0);
|
||||
if (argc == 2) msk=str2int(argv[1]);
|
||||
umask(msk);
|
||||
msk=umask(0);
|
||||
printf("0%o\n",msk);
|
||||
umask(msk);
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
int main_chmod(int argc,char *argv[])
|
||||
{
|
||||
int n;
|
||||
mode_t mode;
|
||||
if (argc > 2){
|
||||
mode=str2int(argv[1])&0777;
|
||||
n=2;
|
||||
while (n<argc) chmod(argv[n++],mode);
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
/*-----------------------------------------------------------*
|
||||
* with this you can call at all the rtems monitor commands.
|
||||
* Not all work fine but you can show the rtems status and more.
|
||||
@@ -442,6 +536,14 @@ int main_monitor(int argc,char * argv[]) {
|
||||
void register_cmds(void) {
|
||||
rtems_monitor_command_entry_t *command;
|
||||
extern rtems_monitor_command_entry_t rtems_monitor_commands[];
|
||||
/* monitor topic */
|
||||
command=rtems_monitor_commands;
|
||||
while (command) {
|
||||
if (strcmp("exit",command->command)) /*Exclude EXIT (alias quit)*/
|
||||
shell_add_cmd(command->command,"monitor",
|
||||
command->usage ,main_monitor);
|
||||
command=command->next;
|
||||
};
|
||||
/* dir[ectories] topic */
|
||||
shell_add_cmd ("ls" ,"dir","ls [dir] # list files in the directory" ,main_ls );
|
||||
shell_add_cmd ("chdir" ,"dir","chdir [dir] # change the current directory",main_chdir);
|
||||
@@ -449,14 +551,24 @@ void register_cmds(void) {
|
||||
shell_add_cmd ("mkdir" ,"dir","mkdir dir # make a directory" ,main_mkdir);
|
||||
shell_add_cmd ("pwd" ,"dir","pwd # print work directory" ,main_pwd );
|
||||
shell_add_cmd ("chroot","dir","chroot [dir] # change the root directory" ,main_chroot);
|
||||
shell_add_cmd ("cat" ,"dir","cat n1 [n2 [n3...]]# show the ascii contents",main_cat );
|
||||
shell_add_cmd ("rm" ,"dir","rm n1 [n2 [n3...]]# remove files" ,main_rm );
|
||||
shell_add_cmd ("chmod" ,"dir","chmod 0777 n1 n2... #change filemode" ,main_chmod);
|
||||
|
||||
shell_alias_cmd("ls" ,"dir");
|
||||
shell_alias_cmd("chdir" ,"cd");
|
||||
|
||||
/* 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 ("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 );
|
||||
shell_add_cmd ("whoami","misc","show current user" ,main_whoami);
|
||||
shell_add_cmd ("id" ,"misc","show uid,gid,euid,egid" ,main_id );
|
||||
shell_add_cmd ("umask" ,"misc","umask [new_umask]" ,main_umask );
|
||||
|
||||
|
||||
/* memory topic */
|
||||
shell_add_cmd ("mdump","mem" ,"mdump [adr [size]]" ,main_mdump);
|
||||
@@ -467,12 +579,5 @@ void register_cmds(void) {
|
||||
#ifdef MALLOC_STATS /* /rtems/s/src/lib/libc/malloc.c */
|
||||
shell_add_cmd ("malloc","mem","mem show memory malloc'ed" ,main_mem);
|
||||
#endif
|
||||
/* monitor topic */
|
||||
command=rtems_monitor_commands;
|
||||
while (command) {
|
||||
shell_add_cmd(command->command,"monitor",
|
||||
command->usage ,main_monitor);
|
||||
command=command->next;
|
||||
};
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
+184
-62
File diff suppressed because it is too large.
Load diff
@@ -45,21 +45,61 @@ typedef struct {
|
||||
char * taskname;
|
||||
tcflag_t tcflag;
|
||||
/* user extensions */
|
||||
int exit_shell; /* logout */
|
||||
int forever ; /* repeat login */
|
||||
int errorlevel;
|
||||
int mdump_adr;
|
||||
} shell_env_t;
|
||||
|
||||
int shell_scanline(char * line,int size,FILE * in,FILE * out) ;
|
||||
void cat_file(FILE * out,char *name);
|
||||
|
||||
rtems_status_code shell_init(char * task_name ,
|
||||
rtems_unsigned32 task_stacksize,/*0 default*/
|
||||
rtems_task_priority task_priority ,
|
||||
char * devname ,
|
||||
tcflag_t tcflag );
|
||||
tcflag_t tcflag ,
|
||||
int forever );
|
||||
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user