2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>

* telnetd/pty.c, telnetd/telnetd.c, telnetd/telnetd.h: Style clean up.
	Now works on gen5200/icecube.
This commit is contained in:
Joel Sherrill
2007-11-26 23:10:25 +00:00
parent fa920f122d
commit edcb9827dc
4 changed files with 154 additions and 127 deletions

View File

@@ -1,3 +1,8 @@
2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
* telnetd/pty.c, telnetd/telnetd.c, telnetd/telnetd.h: Style clean up.
Now works on gen5200/icecube.
2007-11-26 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/src/printk.c, score/src/objectget.c: Fix spacing.

View File

@@ -112,15 +112,18 @@ char * telnet_get_pty(int socket)
int ndx;
if (telnet_pty_inited) {
#if 0
if ( rtems_telnetd_maximum_ptys < 5 )
rtems_telnetd_maximum_ptys = 5;
telnet_ptys = malloc( rtems_telnetd_maximum_ptys * sizeof (pty_t) );
#endif
if ( !telnet_ptys ) {
return NULL;
}
for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) {
if (telnet_ptys[ndx].socket<0) {
struct timeval t;
/* set a long polling interval to save CPU time */
@@ -428,6 +431,11 @@ rtems_device_driver my_pty_initialize(
int ndx;
rtems_status_code status;
if ( rtems_telnetd_maximum_ptys < 5 )
rtems_telnetd_maximum_ptys = 5;
telnet_ptys = malloc( rtems_telnetd_maximum_ptys * sizeof (pty_t) );
/*
* Set up ptys
*/

View File

@@ -75,8 +75,15 @@ typedef union uni_sa {
static int sockpeername(int sock, char *buf, int bufsz);
static int initialize_telnetd();
static int telnetd_askForPassword;
void * telnetd_dflt_spawn(const char *name, unsigned priority, unsigned stackSize, void (*fn)(void*), void *fnarg);
void * telnetd_dflt_spawn(
const char *name,
unsigned priority,
unsigned stackSize,
void (*fn)(void*),
void *fnarg
);
/***********************************************************/
rtems_id telnetd_task_id =0;
@@ -85,18 +92,18 @@ rtems_task_priority telnetd_task_priority=0;
int telnetd_dont_spawn =0;
void (*telnetd_shell)(char *, void*)=0;
void *telnetd_shell_arg =0;
void * (*telnetd_spawn_task)(const char *, unsigned, unsigned, void (*)(void*), void *) = telnetd_dflt_spawn;
void * (*telnetd_spawn_task)(
const char *, unsigned, unsigned, void (*)(void*), void *) = telnetd_dflt_spawn;
static char *grab_a_Connection(int des_socket, uni_sa *srv, char *peername, int sz)
{
char *rval = 0;
#if 0
socklen_t
socklen_t size_adr = sizeof(srv->sin);
#else
/* 4.6 doesn't have socklen_t */
uint32_t
uint32_t size_adr = sizeof(srv->sin);
#endif
size_adr = sizeof(srv->sin);
int acp_sock;
acp_sock = accept(des_socket,&srv->sa,&size_adr);
@@ -146,15 +153,13 @@ static void release_a_Connection(char *devname, char *peername, FILE **pstd, int
static int sockpeername(int sock, char *buf, int bufsz)
{
uni_sa peer;
int rval = sock < 0;
#if 0
socklen_t
socklen_t len = sizeof(peer.sin);
#else
/* 4.6 doesn't have socklen_t */
uint32_t
uint32_t len = sizeof(peer.sin);
#endif
len = sizeof(peer.sin);
int rval = sock < 0;
if ( !rval )
rval = getpeername(sock, &peer.sa, &len);
@@ -224,7 +229,7 @@ struct shell_args *arg;
continue;
}
if ( telnetd_dont_spawn ) {
if ( 0 == check_passwd(peername) )
if ( !telnetd_askForPassword || (0 == check_passwd(peername)) )
telnetd_shell(devname, telnetd_shell_arg);
} else {
arg = malloc( sizeof(*arg) );
@@ -233,8 +238,8 @@ struct shell_args *arg;
arg->arg = telnetd_shell_arg;
strncpy(arg->peername, peername, sizeof(arg->peername));
if ( !telnetd_spawn_task(&devname[5], telnetd_task_priority, telnetd_stack_size, spawned_shell, arg) ) {
if ( !telnetd_spawn_task( &devname[5], telnetd_task_priority,
telnetd_stack_size, spawned_shell, arg) ) {
FILE *dummy;
if ( telnetd_spawn_task != telnetd_dflt_spawn ) {
@@ -256,6 +261,7 @@ struct shell_args *arg;
}
}
} while(1);
/* TODO: how to free the connection semaphore? But then -
* stopping the daemon is probably only needed during
* development/debugging.
@@ -265,13 +271,15 @@ struct shell_args *arg;
close(des_socket);
telnetd_task_id=0;
}
/***********************************************************/
static int initialize_telnetd(void) {
if (telnetd_task_id ) return RTEMS_RESOURCE_IN_USE;
if (telnetd_stack_size<=0 ) telnetd_stack_size =32000;
if ( !telnetd_spawn_task("TNTD", telnetd_task_priority, RTEMS_MINIMUM_STACK_SIZE, rtems_task_telnetd, 0) ) {
if ( !telnetd_spawn_task("TNTD", telnetd_task_priority,
RTEMS_MINIMUM_STACK_SIZE, rtems_task_telnetd, 0) ) {
return -1;
}
return 0;
@@ -283,7 +291,8 @@ int rtems_telnetd_initialize(
void *arg,
int dontSpawn,
size_t stack,
rtems_task_priority priority
rtems_task_priority priority,
int askForPassword
)
{
rtems_status_code sc;
@@ -309,6 +318,8 @@ int rtems_telnetd_initialize(
return 1;
}
telnetd_askForPassword = askForPassword;
if (cmd)
telnetd_shell = cmd;
telnetd_shell_arg = arg;
@@ -323,6 +334,7 @@ int rtems_telnetd_initialize(
sc = initialize_telnetd();
if (sc != RTEMS_SUCCESSFUL) return sc;
printf("rtems_telnetd() started with stacksize=%u,priority=%d\n",
(unsigned)telnetd_stack_size,(int)telnetd_task_priority);
return 0;
@@ -365,16 +377,15 @@ struct shell_args *arg = targ;
stdout = nstd[1];
stderr = nstd[2];
#if 0
printk("STDOUT is now %x (%x) (FD %i/%i)\n",stdout,nstd[1],fileno(stdout),fileno(nstd[1]));
printk("STDOUT is now %x (%x) (FD %i/%i)\n",
stdout,nstd[1],fileno(stdout),fileno(nstd[1]));
printf("hello\n");
write(fileno(stdout),"hellofd\n",8);
#endif
/* call their routine */
if ( 0 == check_passwd(arg->peername) )
if ( !telnetd_askForPassword || (0 == check_passwd(arg->peername)) )
telnetd_shell(arg->devname, arg->arg);
stdin = ostd[0];
@@ -444,7 +455,6 @@ struct wrap_delete_args *pwa = malloc(sizeof(*pwa));
/* convenience routines for CEXP (retrieve stdio descriptors
* from reent structure)
*
*/
#ifdef stdin
static __inline__ FILE *

View File

@@ -26,13 +26,17 @@ extern "C" {
* FALSE to create another task for the shell.
* stack - stack size of spawned task
* priority - initial priority of spawned task
* askForPassword - TRUE if telnetd asks for password
* FALSE to invoke "cmd" with no password check.
* This may be OK if "cmd" includes its own check.
*/
int rtems_telnetd_initialize(
void (*cmd)(char *, void *),
void *arg,
int dontSpawn,
size_t stack,
rtems_task_priority priority
rtems_task_priority priority,
int askForPassword
);
#ifdef __cplusplus