Changeset b980f363 in rtems


Ignore:
Timestamp:
Sep 25, 2018, 1:07:35 PM (15 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
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)
Message:

telnetd: Convert pty driver to new Termios API

Update #3526.

Location:
cpukit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/pty.h

    rac9f808 rb980f363  
    1717#endif 
    1818
    19 #include <rtems.h>     
     19#include <rtems/termiostypes.h>
    2020
    21 /* Number of ptys to setup */
    22 extern size_t rtems_pty_maximum_ptys;
     21#define RTEMS_PTY_SB_MAX 16
    2322
    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);
     23typedef 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;
    2936
    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);
     37char *telnet_get_pty(rtems_pty_context *ctx, int socket);
    7138
    7239#ifdef __cplusplus
  • cpukit/telnetd/pty.c

    rac9f808 rb980f363  
    3030
    3131/*-----------------------------------------*/
    32 #include <termios.h>
    33 #include <rtems/termiostypes.h>
    3432#include <sys/ttycom.h>
    35 #include <rtems.h>
    36 #include <rtems/libio.h>
    37 #include <rtems/bspIo.h>
    3833#include <rtems/pty.h>
     34#include <rtems/seterr.h>
    3935#include <errno.h>
    4036#include <sys/socket.h>
    4137/*-----------------------------------------*/
     38#include <inttypes.h>
    4239#include <stdio.h>
    4340#include <stdlib.h>
     
    6461#define IAC_EOR    239
    6562
    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
     65static bool ptyPollInitialize(rtems_termios_tty *,
     66  rtems_termios_device_context *, struct termios *,
     67  rtems_libio_open_close_args_t *);
     68static void ptyShutdown(rtems_termios_tty *,
     69  rtems_termios_device_context *, rtems_libio_open_close_args_t *);
     70static void ptyPollWrite(rtems_termios_device_context *, const char *, size_t);
     71static int ptyPollRead(rtems_termios_device_context *);
     72static bool ptySetAttributes(rtems_termios_device_context *,
     73  const struct termios *);
     74static int my_pty_control(rtems_termios_device_context *,
     75  ioctl_command_t, void *);
     76
     77static 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
    8584};
    8685
    87 
    88 static int    telnet_pty_inited=FALSE;
    89 static pty_t *telnet_ptys;
    90 
    91 static rtems_device_major_number pty_major;
    92 
    9386static
    94 int send_iac(int minor,unsigned char mode,unsigned char option)
     87int send_iac(rtems_pty_context *pty, unsigned char mode, unsigned char option)
    9588{
    9689  unsigned char buf[3];
     
    9992  buf[1]=mode;
    10093  buf[2]=option;
    101   return write(telnet_ptys[minor].socket,buf,sizeof(buf));
     94  return write(pty->socket, buf, sizeof(buf));
    10295}
    10396
     
    107100 */
    108101
    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     };
     102char *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;
    140115  }
    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}
    145127
    146128/*-----------------------------------------------------------*/
     
    156138
    157139static int
    158 handleSB(pty_t *pty)
     140handleSB(rtems_pty_context *pty)
    159141{
    160142  switch (pty->sb_buf[0]) {
     
    175157}
    176158
    177 static int read_pty(int minor)
     159static int ptyPollRead(rtems_termios_device_context *base)
    178160{ /* Characters written to the client side*/
     161   rtems_pty_context *pty = (rtems_pty_context *)base;
    179162   unsigned char  value;
    180163   unsigned int  omod;
    181164   int      count;
    182165   int      result;
    183    pty_t      *pty=telnet_ptys+minor;
    184166
    185167   count=read(pty->socket,&value,sizeof(value));
     
    273255       case IAC_WILL:
    274256           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    */
    277259           } else if (value==31) {
    278               send_iac(minor,IAC_DO  ,   31);  /*NAWS    */
     260              send_iac(pty,IAC_DO  ,   31);  /*NAWS    */
    279261#if DEBUG & DEBUG_DETAIL
    280262              printk("replied DO NAWS\n");
    281263#endif
    282264           } else {
    283               send_iac(minor,IAC_DONT,value);
     265              send_iac(pty,IAC_DONT,value);
    284266           }
    285267           return -1;
     
    288270       case IAC_DO  :
    289271           if (value==3) {
    290               send_iac(minor,IAC_WILL,    3);  /* GO AHEAD*/
     272              send_iac(pty,IAC_WILL,    3);  /* GO AHEAD*/
    291273           } else  if (value==1) {
    292               send_iac(minor,IAC_WILL,    1);  /* ECHO */
     274              send_iac(pty,IAC_WILL,    1);  /* ECHO */
    293275           } else {
    294               send_iac(minor,IAC_WONT,value);
     276              send_iac(pty,IAC_WONT,value);
    295277           };
    296278           return -1;
    297279       case IAC_WONT:
    298280           if (value==1) {
    299              send_iac(minor,IAC_WILL,    1);
     281             send_iac(pty,IAC_WILL,    1);
    300282           } else { /* ECHO */
    301              send_iac(minor,IAC_WONT,value);
     283             send_iac(pty,IAC_WONT,value);
    302284           }
    303285           return -1;
     
    323305
    324306/*-----------------------------------------------------------*/
    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 /*-----------------------------------------------------------*/
    332307/* Set the 'Hardware'                                        */
    333308/*-----------------------------------------------------------*/
     309static bool
     310ptySetAttributes(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/*-----------------------------------------------------------*/
     317static bool
     318ptyPollInitialize(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/*-----------------------------------------------------------*/
     331static void
     332ptyShutdown(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/*-----------------------------------------------------------*/
     341static void
     342ptyPollWrite(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
    334357static 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 
     358my_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) {
    581365    case TIOCGWINSZ:
    582 
    583366      wp->ws_row = p->height;
    584367      wp->ws_col = p->width;
    585       args->ioctl_return=0;
    586368#if DEBUG & DEBUG_WH
    587369      fprintf(stderr,
     
    590372          wp->ws_row);
    591373#endif
    592 
    593       return RTEMS_SUCCESSFUL;
    594 
     374      break;
    595375    case TIOCSWINSZ:
    596376#if DEBUG & DEBUG_WH
     
    603383      p->height = wp->ws_row;
    604384      p->width  = wp->ws_col;
    605       args->ioctl_return=0;
    606 
    607       return RTEMS_SUCCESSFUL;
    608 
     385      break;
    609386    default:
    610 
    611      break;
     387      rtems_set_errno_and_return_minus_one(EINVAL);
     388      break;
    612389  }
    613390
    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  
    6565#define PARANOIA
    6666
    67 extern char *telnet_get_pty(int socket);
    68 extern int   telnet_pty_initialize(void);
    69 
    7067struct 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;
    7572};
    7673
     
    108105) = telnetd_dflt_spawn;
    109106
    110 static char *grab_a_Connection(
     107static struct shell_args *grab_a_Connection(
    111108  int des_socket,
    112109  uni_sa *srv,
     
    115112)
    116113{
    117   char *rval = 0;
     114  struct shell_args *args = NULL;
    118115  socklen_t size_adr = sizeof(srv->sin);
    119116  int acp_sock;
     117
     118  args = malloc(sizeof(*args));
     119  if (args == NULL) {
     120    perror("telnetd:malloc");
     121    goto bailout;
     122  }
    120123
    121124  acp_sock = accept(des_socket,&srv->sa,&size_adr);
     
    126129  };
    127130
    128   if ( !(rval=telnet_get_pty(acp_sock)) ) {
     131  if (telnet_get_pty(&args->pty, acp_sock) == NULL) {
    129132    syslog( LOG_DAEMON | LOG_ERR, "telnetd: unable to obtain PTY");
    130133    /* NOTE: failing 'do_get_pty()' closed the socket */
     
    139142      "telnetd: accepted connection from %s on %s",
    140143      peername,
    141       rval);
     144      args->pty.name);
    142145#endif
    143146
    144147bailout:
    145148
    146   return rval;
     149  return args;
    147150}
    148151
     
    161164    if (pstd[n]) fclose(pstd[n]);
    162165
     166  unlink(devname);
    163167}
    164168
     
    187191  int                des_socket;
    188192  uni_sa             srv;
    189   char              *devname;
    190193  char               peername[16];
    191194  int                i=1;
     
    244247      }
    245248    } 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) {
    249252        /* if something went wrong, sleep for some time */
    250253        sleep(10);
     
    252255      }
    253256
    254       arg = malloc( sizeof(*arg) );
    255 
    256       arg->devname = devname;
    257257      arg->arg = telnetd_config->arg;
    258258      strncpy(arg->peername, peername, sizeof(arg->peername));
    259259
    260260      telnetd_task_id = telnetd_spawn_task(
    261         devname,
     261        arg->pty.name,
    262262        telnetd_config->priority,
    263263        telnetd_config->stack_size,
     
    279279         */
    280280
    281         if ( !(dummy=fopen(devname,"r+")) )
     281        if ( !(dummy=fopen(arg->pty.name,"r+")) )
    282282          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);
    284284        free(arg);
    285285        sleep(2); /* don't accept connections too fast */
     
    314314    fprintf(stderr, "telnetd cannot alloc telnetd config table\n");
    315315    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;
    324316  }
    325317
     
    397389  /* redirect stdio */
    398390  for (i=0; i<3; i++) {
    399     if ( !(nstd[i]=fopen(arg->devname,"r+")) ) {
     391    if ( !(nstd[i]=fopen(arg->pty.name,"r+")) ) {
    400392      perror("unable to open stdio");
    401393      goto cleanup;
     
    419411      stdin,
    420412      stderr,
    421       arg->devname,
     413      arg->pty.name,
    422414      telnetd_config->login_check
    423415    );
     
    425417  }
    426418  if (start) {
    427     telnetd_config->command( arg->devname, arg->arg);
     419    telnetd_config->command( arg->pty.name, arg->arg);
    428420  }
    429421
     
    441433
    442434cleanup:
    443   release_a_Connection(arg->devname, arg->peername, nstd, i);
     435  release_a_Connection(arg->pty.name, arg->peername, nstd, i);
    444436  free(arg);
    445437}
Note: See TracChangeset for help on using the changeset viewer.