Changeset b980f363 in rtems
- Timestamp:
- Sep 25, 2018, 1:07:35 PM (15 months ago)
- Branches:
- master
- Children:
- 0413b14
- Parents:
- ac9f808
- git-author:
- Sebastian Huber <sebastian.huber@…> (09/25/18 13:07:35)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (10/01/18 10:28:10)
- Location:
- cpukit
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/include/rtems/pty.h
rac9f808 rb980f363 17 17 #endif 18 18 19 #include <rtems .h>19 #include <rtems/termiostypes.h> 20 20 21 /* Number of ptys to setup */ 22 extern size_t rtems_pty_maximum_ptys; 21 #define RTEMS_PTY_SB_MAX 16 23 22 24 /* Return the devname for a free pty slot. 25 * If no slot available (socket>=0) 26 * then the socket argument is closed 27 */ 28 char * rtems_pty_get(int socket); 23 typedef struct { 24 rtems_termios_device_context base; 25 rtems_termios_tty *ttyp; 26 tcflag_t c_cflag; 27 int socket; 28 int last_cr; 29 unsigned iac_mode; 30 unsigned char sb_buf[RTEMS_PTY_SB_MAX]; 31 int sb_ind; 32 int width; 33 int height; 34 char name[sizeof("/dev/pty18446744073709551615")]; 35 } rtems_pty_context; 29 36 30 31 /* OBSOLETE */ 32 #define get_pty rtems_pty_get 33 34 rtems_device_driver pty_initialize( 35 rtems_device_major_number major, 36 rtems_device_minor_number minor, 37 void *arg); 38 rtems_device_driver pty_open( 39 rtems_device_major_number major, 40 rtems_device_minor_number minor, 41 void * arg); 42 rtems_device_driver pty_close( 43 rtems_device_major_number major, 44 rtems_device_minor_number minor, 45 void * arg); 46 rtems_device_driver pty_read( 47 rtems_device_major_number major, 48 rtems_device_minor_number minor, 49 void * arg); 50 rtems_device_driver pty_write( 51 rtems_device_major_number major, 52 rtems_device_minor_number minor, 53 void * arg); 54 rtems_device_driver pty_control( 55 rtems_device_major_number major, 56 rtems_device_minor_number minor, 57 void * arg); 58 59 60 #define PTY_DRIVER_TABLE_ENTRY \ 61 { pty_initialize , pty_open , pty_close , \ 62 pty_read , pty_write , pty_control } 63 64 /* Internal functions */ 65 66 int telnet_pty_initialize(void); 67 68 int telnet_pty_finalize(void); 69 70 char *telnet_get_pty(int); 37 char *telnet_get_pty(rtems_pty_context *ctx, int socket); 71 38 72 39 #ifdef __cplusplus -
cpukit/telnetd/pty.c
rac9f808 rb980f363 30 30 31 31 /*-----------------------------------------*/ 32 #include <termios.h>33 #include <rtems/termiostypes.h>34 32 #include <sys/ttycom.h> 35 #include <rtems.h>36 #include <rtems/libio.h>37 #include <rtems/bspIo.h>38 33 #include <rtems/pty.h> 34 #include <rtems/seterr.h> 39 35 #include <errno.h> 40 36 #include <sys/socket.h> 41 37 /*-----------------------------------------*/ 38 #include <inttypes.h> 42 39 #include <stdio.h> 43 40 #include <stdlib.h> … … 64 61 #define IAC_EOR 239 65 62 66 #define SB_MAX 16 67 68 extern int rtems_telnetd_maximum_ptys; 69 70 struct pty_tt; 71 typedef struct pty_tt pty_t; 72 73 struct pty_tt { 74 char devname[17]; 75 struct rtems_termios_tty *ttyp; 76 tcflag_t c_cflag; 77 int opened; 78 int socket; 79 int last_cr; 80 unsigned iac_mode; 81 unsigned char sb_buf[SB_MAX]; 82 int sb_ind; 83 int width; 84 int height; 63 #define SB_MAX RTEMS_PTY_SB_MAX 64 65 static bool ptyPollInitialize(rtems_termios_tty *, 66 rtems_termios_device_context *, struct termios *, 67 rtems_libio_open_close_args_t *); 68 static void ptyShutdown(rtems_termios_tty *, 69 rtems_termios_device_context *, rtems_libio_open_close_args_t *); 70 static void ptyPollWrite(rtems_termios_device_context *, const char *, size_t); 71 static int ptyPollRead(rtems_termios_device_context *); 72 static bool ptySetAttributes(rtems_termios_device_context *, 73 const struct termios *); 74 static int my_pty_control(rtems_termios_device_context *, 75 ioctl_command_t, void *); 76 77 static const rtems_termios_device_handler pty_handler = { 78 .first_open = ptyPollInitialize, 79 .last_close = ptyShutdown, 80 .poll_read = ptyPollRead, 81 .write = ptyPollWrite, 82 .set_attributes = ptySetAttributes, 83 .ioctl = my_pty_control 85 84 }; 86 85 87 88 static int telnet_pty_inited=FALSE;89 static pty_t *telnet_ptys;90 91 static rtems_device_major_number pty_major;92 93 86 static 94 int send_iac( int minor,unsigned char mode,unsigned char option)87 int send_iac(rtems_pty_context *pty, unsigned char mode, unsigned char option) 95 88 { 96 89 unsigned char buf[3]; … … 99 92 buf[1]=mode; 100 93 buf[2]=option; 101 return write( telnet_ptys[minor].socket,buf,sizeof(buf));94 return write(pty->socket, buf, sizeof(buf)); 102 95 } 103 96 … … 107 100 */ 108 101 109 char * telnet_get_pty(int socket) 110 { 111 int ndx; 112 113 if (telnet_pty_inited) { 114 #if 0 115 if ( rtems_telnetd_maximum_ptys < 5 ) 116 rtems_telnetd_maximum_ptys = 5; 117 118 telnet_ptys = malloc( rtems_telnetd_maximum_ptys * sizeof (pty_t) ); 119 #endif 120 if ( !telnet_ptys ) { 121 return NULL; 122 } 123 124 for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) { 125 126 if (telnet_ptys[ndx].socket<0) { 127 struct timeval t; 128 /* set a long polling interval to save CPU time */ 129 t.tv_sec=2; 130 t.tv_usec=00000; 131 setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t)); 132 telnet_ptys[ndx].socket=socket; 133 134 /* inform the client that we will echo */ 135 send_iac(ndx, IAC_WILL, 1); 136 137 return telnet_ptys[ndx].devname; 138 }; 139 }; 102 char *telnet_get_pty(rtems_pty_context *pty, int socket) 103 { 104 rtems_status_code sc; 105 struct timeval t; 106 107 memset(pty, 0, sizeof(*pty)); 108 snprintf(pty->name, sizeof(pty->name), "/dev/pty%" PRIuPTR, (uintptr_t)pty); 109 rtems_termios_device_context_initialize(&pty->base, "pty"); 110 pty->socket = socket; 111 sc = rtems_termios_device_install(pty->name, &pty_handler, NULL, &pty->base); 112 if (sc != RTEMS_SUCCESSFUL) { 113 close(socket); 114 return NULL; 140 115 } 141 close(socket); 142 return NULL; 143 } 144 116 117 /* set a long polling interval to save CPU time */ 118 t.tv_sec=2; 119 t.tv_usec=00000; 120 setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t)); 121 122 /* inform the client that we will echo */ 123 send_iac(pty, IAC_WILL, 1); 124 125 return pty->name; 126 } 145 127 146 128 /*-----------------------------------------------------------*/ … … 156 138 157 139 static int 158 handleSB( pty_t *pty)140 handleSB(rtems_pty_context *pty) 159 141 { 160 142 switch (pty->sb_buf[0]) { … … 175 157 } 176 158 177 static int read_pty(int minor)159 static int ptyPollRead(rtems_termios_device_context *base) 178 160 { /* Characters written to the client side*/ 161 rtems_pty_context *pty = (rtems_pty_context *)base; 179 162 unsigned char value; 180 163 unsigned int omod; 181 164 int count; 182 165 int result; 183 pty_t *pty=telnet_ptys+minor;184 166 185 167 count=read(pty->socket,&value,sizeof(value)); … … 273 255 case IAC_WILL: 274 256 if (value==34){ 275 send_iac( minor,IAC_DONT, 34); /*LINEMODE*/276 send_iac( minor,IAC_DO , 1); /*ECHO */257 send_iac(pty,IAC_DONT, 34); /*LINEMODE*/ 258 send_iac(pty,IAC_DO , 1); /*ECHO */ 277 259 } else if (value==31) { 278 send_iac( minor,IAC_DO , 31); /*NAWS */260 send_iac(pty,IAC_DO , 31); /*NAWS */ 279 261 #if DEBUG & DEBUG_DETAIL 280 262 printk("replied DO NAWS\n"); 281 263 #endif 282 264 } else { 283 send_iac( minor,IAC_DONT,value);265 send_iac(pty,IAC_DONT,value); 284 266 } 285 267 return -1; … … 288 270 case IAC_DO : 289 271 if (value==3) { 290 send_iac( minor,IAC_WILL, 3); /* GO AHEAD*/272 send_iac(pty,IAC_WILL, 3); /* GO AHEAD*/ 291 273 } else if (value==1) { 292 send_iac( minor,IAC_WILL, 1); /* ECHO */274 send_iac(pty,IAC_WILL, 1); /* ECHO */ 293 275 } else { 294 send_iac( minor,IAC_WONT,value);276 send_iac(pty,IAC_WONT,value); 295 277 }; 296 278 return -1; 297 279 case IAC_WONT: 298 280 if (value==1) { 299 send_iac( minor,IAC_WILL, 1);281 send_iac(pty,IAC_WILL, 1); 300 282 } else { /* ECHO */ 301 send_iac( minor,IAC_WONT,value);283 send_iac(pty,IAC_WONT,value); 302 284 } 303 285 return -1; … … 323 305 324 306 /*-----------------------------------------------------------*/ 325 static int ptySetAttributes(int minor,const struct termios *t);326 static int ptyPollInitialize(int major,int minor,void * arg) ;327 static int ptyShutdown(int major,int minor,void * arg) ;328 static ssize_t ptyPollWrite(int minor, const char * buf, size_t len) ;329 static int ptyPollRead(int minor) ;330 static const rtems_termios_callbacks * pty_get_termios_handlers(int polled) ;331 /*-----------------------------------------------------------*/332 307 /* Set the 'Hardware' */ 333 308 /*-----------------------------------------------------------*/ 309 static bool 310 ptySetAttributes(rtems_termios_device_context *base, const struct termios *t) 311 { 312 rtems_pty_context *pty = (rtems_pty_context *)base; 313 pty->c_cflag = t->c_cflag; 314 return true; 315 } 316 /*-----------------------------------------------------------*/ 317 static bool 318 ptyPollInitialize(rtems_termios_tty *ttyp, 319 rtems_termios_device_context *base, struct termios *t, 320 rtems_libio_open_close_args_t *args) 321 { 322 rtems_pty_context *pty = (rtems_pty_context *)base; 323 pty->ttyp = ttyp; 324 pty->iac_mode = 0; 325 pty->sb_ind = 0; 326 pty->width = 0; 327 pty->height = 0; 328 return ptySetAttributes(&pty->base, t); 329 } 330 /*-----------------------------------------------------------*/ 331 static void 332 ptyShutdown(rtems_termios_tty *ttyp, 333 rtems_termios_device_context *base, rtems_libio_open_close_args_t *arg) 334 { 335 rtems_pty_context *pty = (rtems_pty_context *)base; 336 close(pty->socket); 337 } 338 /*-----------------------------------------------------------*/ 339 /* Write Characters into pty device */ 340 /*-----------------------------------------------------------*/ 341 static void 342 ptyPollWrite(rtems_termios_device_context *base, const char *buf, size_t len) 343 { 344 rtems_pty_context *pty = (rtems_pty_context *)base; 345 346 while (len > 0) { 347 ssize_t n = write(pty->socket, buf, len); 348 if (n <= 0) { 349 break; 350 } 351 352 buf += (size_t)n; 353 len -= (size_t)n; 354 } 355 } 356 334 357 static int 335 ptySetAttributes(int minor,const struct termios *t) { 336 if (minor<rtems_telnetd_maximum_ptys) { 337 telnet_ptys[minor].c_cflag=t->c_cflag; 338 } else { 339 return -1; 340 }; 341 return 0; 342 } 343 /*-----------------------------------------------------------*/ 344 static int 345 ptyPollInitialize(int major,int minor,void * arg) { 346 rtems_libio_open_close_args_t * args = (rtems_libio_open_close_args_t*)arg; 347 struct termios t; 348 if (minor<rtems_telnetd_maximum_ptys) { 349 if (telnet_ptys[minor].socket<0) return -1; 350 telnet_ptys[minor].opened=TRUE; 351 telnet_ptys[minor].ttyp= (struct rtems_termios_tty *) args->iop->data1; 352 telnet_ptys[minor].iac_mode=0; 353 telnet_ptys[minor].sb_ind=0; 354 telnet_ptys[minor].width=0; 355 telnet_ptys[minor].height=0; 356 t.c_cflag=B9600|CS8;/* termios default */ 357 return ptySetAttributes(minor,&t); 358 } else { 359 return -1; 360 } 361 } 362 /*-----------------------------------------------------------*/ 363 static int 364 ptyShutdown(int major,int minor,void * arg) { 365 if (minor<rtems_telnetd_maximum_ptys) { 366 telnet_ptys[minor].opened=FALSE; 367 if (telnet_ptys[minor].socket>=0) close(telnet_ptys[minor].socket); 368 telnet_ptys[minor].socket=-1; 369 chown(telnet_ptys[minor].devname,2,0); 370 } else { 371 return -1; 372 } 373 return 0; 374 } 375 /*-----------------------------------------------------------*/ 376 /* Write Characters into pty device */ 377 /*-----------------------------------------------------------*/ 378 static ssize_t 379 ptyPollWrite(int minor, const char * buf, size_t len) { 380 size_t count; 381 if (minor<rtems_telnetd_maximum_ptys) { 382 if (telnet_ptys[minor].socket<0) 383 return -1; 384 count=write(telnet_ptys[minor].socket,buf,len); 385 } else { 386 count=-1; 387 } 388 return count; 389 } 390 /*-----------------------------------------------------------*/ 391 static int 392 ptyPollRead(int minor) { 393 int result; 394 395 if (minor<rtems_telnetd_maximum_ptys) { 396 if (telnet_ptys[minor].socket<0) 397 return -1; 398 result=read_pty(minor); 399 return result; 400 } 401 return -1; 402 } 403 /*-----------------------------------------------------------*/ 404 /* pty_initialize 405 * 406 * This routine initializes the pty IO driver. 407 * 408 * Input parameters: NONE 409 * 410 * Output parameters: NONE 411 * 412 * Return values: 413 */ 414 /*-----------------------------------------------------------*/ 415 static 416 rtems_device_driver my_pty_initialize( 417 rtems_device_major_number major, 418 rtems_device_minor_number minor, 419 void *arg 420 ) 421 { 422 int ndx; 423 rtems_status_code status; 424 425 if ( rtems_telnetd_maximum_ptys < 5 ) 426 rtems_telnetd_maximum_ptys = 5; 427 428 telnet_ptys = malloc( rtems_telnetd_maximum_ptys * sizeof (pty_t) ); 429 430 /* 431 * Set up ptys 432 */ 433 434 for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) { 435 /* devname is included in the structure */ 436 sprintf(telnet_ptys[ndx].devname,"/dev/pty%02X",ndx); 437 telnet_ptys[ndx].ttyp = NULL; 438 telnet_ptys[ndx].c_cflag = CS8|B9600; 439 telnet_ptys[ndx].socket = -1; 440 telnet_ptys[ndx].opened = FALSE; 441 telnet_ptys[ndx].sb_ind = 0; 442 telnet_ptys[ndx].width = 0; 443 telnet_ptys[ndx].height = 0; 444 445 } 446 447 /* 448 * Register the devices 449 */ 450 for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) { 451 status = rtems_io_register_name(telnet_ptys[ndx].devname, major, ndx); 452 if (status != RTEMS_SUCCESSFUL) 453 rtems_fatal_error_occurred(status); 454 chmod(telnet_ptys[ndx].devname,0660); 455 chown(telnet_ptys[ndx].devname,2,0); /* tty,root*/ 456 }; 457 syslog( 458 LOG_KERN | LOG_INFO, 459 "/dev/pty%X../dev/pty%X (%d) pseudo-terminals registered.\n", 460 0, 461 rtems_telnetd_maximum_ptys - 1, 462 rtems_telnetd_maximum_ptys 463 ); 464 465 return RTEMS_SUCCESSFUL; 466 } 467 468 static int pty_do_finalize(void) 469 { 470 int ndx; 471 rtems_status_code status; 472 473 if ( !telnet_pty_inited ) 474 return 0; 475 476 for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) { 477 if (telnet_ptys[ndx].opened) { 478 fprintf(stderr, 479 "There are still opened PTY devices, unable to proceed\n"); 480 return -1; 481 } 482 } 483 if (RTEMS_SUCCESSFUL != rtems_io_unregister_driver(pty_major)) { 484 fprintf(stderr,"Unable to remove this driver\n"); 485 return -1; 486 } 487 for (ndx=0;ndx<rtems_telnetd_maximum_ptys;ndx++) { 488 /* rtems_io_register_name() actually creates a node in the filesystem 489 * (mknod()) 490 */ 491 status = (rtems_status_code)unlink(telnet_ptys[ndx].devname); 492 if (status != RTEMS_SUCCESSFUL) 493 perror("removing pty device node from file system"); 494 else { 495 telnet_ptys[ndx].devname[0] = '\0'; 496 } 497 }; 498 499 free ( telnet_ptys ); 500 501 fprintf(stderr,"PTY driver unloaded successfully\n"); 502 telnet_pty_inited=FALSE; 503 return 0; 504 } 505 506 /* 507 * Open entry point 508 */ 509 510 static 511 rtems_device_driver my_pty_open( 512 rtems_device_major_number major, 513 rtems_device_minor_number minor, 514 void * arg 515 ) 516 { 517 rtems_status_code sc; 518 sc = rtems_termios_open(major,minor,arg,pty_get_termios_handlers(FALSE)); 519 return sc; 520 } 521 522 /* 523 * Close entry point 524 */ 525 526 static 527 rtems_device_driver my_pty_close( 528 rtems_device_major_number major, 529 rtems_device_minor_number minor, 530 void * arg 531 ) 532 { 533 return rtems_termios_close(arg); 534 } 535 536 /* 537 * read bytes from the pty 538 */ 539 540 static 541 rtems_device_driver my_pty_read( 542 rtems_device_major_number major, 543 rtems_device_minor_number minor, 544 void * arg 545 ) 546 { 547 return rtems_termios_read(arg); 548 } 549 550 /* 551 * write bytes to the pty 552 */ 553 554 static 555 rtems_device_driver my_pty_write( 556 rtems_device_major_number major, 557 rtems_device_minor_number minor, 558 void * arg 559 ) 560 { 561 return rtems_termios_write(arg); 562 } 563 564 /* 565 * IO Control entry point 566 */ 567 568 static 569 rtems_device_driver my_pty_control( 570 rtems_device_major_number major, 571 rtems_device_minor_number minor, 572 void * arg 573 ) 574 { 575 rtems_libio_ioctl_args_t *args = (rtems_libio_ioctl_args_t*)arg; 576 struct winsize *wp = (struct winsize*)args->buffer; 577 pty_t *p = &telnet_ptys[minor]; 578 579 switch (args->command) { 580 358 my_pty_control(rtems_termios_device_context *base, 359 ioctl_command_t request, void *buffer) 360 { 361 rtems_pty_context *p = (rtems_pty_context *)base; 362 struct winsize *wp = buffer; 363 364 switch (request) { 581 365 case TIOCGWINSZ: 582 583 366 wp->ws_row = p->height; 584 367 wp->ws_col = p->width; 585 args->ioctl_return=0;586 368 #if DEBUG & DEBUG_WH 587 369 fprintf(stderr, … … 590 372 wp->ws_row); 591 373 #endif 592 593 return RTEMS_SUCCESSFUL; 594 374 break; 595 375 case TIOCSWINSZ: 596 376 #if DEBUG & DEBUG_WH … … 603 383 p->height = wp->ws_row; 604 384 p->width = wp->ws_col; 605 args->ioctl_return=0; 606 607 return RTEMS_SUCCESSFUL; 608 385 break; 609 386 default: 610 611 break;387 rtems_set_errno_and_return_minus_one(EINVAL); 388 break; 612 389 } 613 390 614 return rtems_termios_ioctl(arg); 615 } 616 617 static rtems_driver_address_table drvPty = { 618 my_pty_initialize, 619 my_pty_open, 620 my_pty_close, 621 my_pty_read, 622 my_pty_write, 623 my_pty_control 624 }; 625 626 /*-----------------------------------------------------------*/ 627 static const rtems_termios_callbacks pty_poll_callbacks = { 628 ptyPollInitialize, /* FirstOpen */ 629 ptyShutdown, /* LastClose */ 630 ptyPollRead, /* PollRead */ 631 ptyPollWrite, /* Write */ 632 ptySetAttributes, /* setAttributes */ 633 NULL, /* stopRemoteTX */ 634 NULL, /* StartRemoteTX */ 635 0 /* outputUsesInterrupts */ 636 }; 637 /*-----------------------------------------------------------*/ 638 static const rtems_termios_callbacks * pty_get_termios_handlers(int polled) { 639 return &pty_poll_callbacks; 640 } 641 /*-----------------------------------------------------------*/ 642 643 static int pty_do_initialize(void) 644 { 645 if ( !telnet_pty_inited ) { 646 if (RTEMS_SUCCESSFUL==rtems_io_register_driver(0, &drvPty, &pty_major)) 647 telnet_pty_inited=TRUE; 648 else 649 fprintf(stderr,"WARNING: registering the PTY driver FAILED\n"); 650 } 651 return telnet_pty_inited; 652 } 653 654 int telnet_pty_initialize(void) 655 { 656 return pty_do_initialize(); 657 } 658 659 int telnet_pty_finalize(void) 660 { 661 return pty_do_finalize(); 662 } 391 return 0; 392 } -
cpukit/telnetd/telnetd.c
rac9f808 rb980f363 65 65 #define PARANOIA 66 66 67 extern char *telnet_get_pty(int socket);68 extern int telnet_pty_initialize(void);69 70 67 struct shell_args { 71 char *devname;72 void *arg;73 char peername[16];74 char delete_myself;68 rtems_pty_context pty; 69 void *arg; 70 char peername[16]; 71 char delete_myself; 75 72 }; 76 73 … … 108 105 ) = telnetd_dflt_spawn; 109 106 110 static char*grab_a_Connection(107 static struct shell_args *grab_a_Connection( 111 108 int des_socket, 112 109 uni_sa *srv, … … 115 112 ) 116 113 { 117 char *rval = 0;114 struct shell_args *args = NULL; 118 115 socklen_t size_adr = sizeof(srv->sin); 119 116 int acp_sock; 117 118 args = malloc(sizeof(*args)); 119 if (args == NULL) { 120 perror("telnetd:malloc"); 121 goto bailout; 122 } 120 123 121 124 acp_sock = accept(des_socket,&srv->sa,&size_adr); … … 126 129 }; 127 130 128 if ( !(rval=telnet_get_pty(acp_sock))) {131 if (telnet_get_pty(&args->pty, acp_sock) == NULL) { 129 132 syslog( LOG_DAEMON | LOG_ERR, "telnetd: unable to obtain PTY"); 130 133 /* NOTE: failing 'do_get_pty()' closed the socket */ … … 139 142 "telnetd: accepted connection from %s on %s", 140 143 peername, 141 rval);144 args->pty.name); 142 145 #endif 143 146 144 147 bailout: 145 148 146 return rval;149 return args; 147 150 } 148 151 … … 161 164 if (pstd[n]) fclose(pstd[n]); 162 165 166 unlink(devname); 163 167 } 164 168 … … 187 191 int des_socket; 188 192 uni_sa srv; 189 char *devname;190 193 char peername[16]; 191 194 int i=1; … … 244 247 } 245 248 } else { 246 devname= grab_a_Connection(des_socket, &srv, peername, sizeof(peername));247 248 if ( !devname) {249 arg = grab_a_Connection(des_socket, &srv, peername, sizeof(peername)); 250 251 if (arg == NULL) { 249 252 /* if something went wrong, sleep for some time */ 250 253 sleep(10); … … 252 255 } 253 256 254 arg = malloc( sizeof(*arg) );255 256 arg->devname = devname;257 257 arg->arg = telnetd_config->arg; 258 258 strncpy(arg->peername, peername, sizeof(arg->peername)); 259 259 260 260 telnetd_task_id = telnetd_spawn_task( 261 devname,261 arg->pty.name, 262 262 telnetd_config->priority, 263 263 telnetd_config->stack_size, … … 279 279 */ 280 280 281 if ( !(dummy=fopen( devname,"r+")) )281 if ( !(dummy=fopen(arg->pty.name,"r+")) ) 282 282 perror("Unable to dummy open the pty, losing a slot :-("); 283 release_a_Connection( devname, peername, &dummy, 1);283 release_a_Connection(arg->pty.name, peername, &dummy, 1); 284 284 free(arg); 285 285 sleep(2); /* don't accept connections too fast */ … … 314 314 fprintf(stderr, "telnetd cannot alloc telnetd config table\n"); 315 315 return RTEMS_NO_MEMORY; 316 }317 318 319 if ( !telnet_pty_initialize() ) {320 fprintf(stderr, "telnetd cannot initialize PTY driver\n");321 free(telnetd_config);322 telnetd_config = NULL;323 return RTEMS_IO_ERROR;324 316 } 325 317 … … 397 389 /* redirect stdio */ 398 390 for (i=0; i<3; i++) { 399 if ( !(nstd[i]=fopen(arg-> devname,"r+")) ) {391 if ( !(nstd[i]=fopen(arg->pty.name,"r+")) ) { 400 392 perror("unable to open stdio"); 401 393 goto cleanup; … … 419 411 stdin, 420 412 stderr, 421 arg-> devname,413 arg->pty.name, 422 414 telnetd_config->login_check 423 415 ); … … 425 417 } 426 418 if (start) { 427 telnetd_config->command( arg-> devname, arg->arg);419 telnetd_config->command( arg->pty.name, arg->arg); 428 420 } 429 421 … … 441 433 442 434 cleanup: 443 release_a_Connection(arg-> devname, arg->peername, nstd, i);435 release_a_Connection(arg->pty.name, arg->peername, nstd, i); 444 436 free(arg); 445 437 }
Note: See TracChangeset
for help on using the changeset viewer.