Changeset a346ebba in rtems


Ignore:
Timestamp:
Sep 26, 2018, 7:04:43 AM (13 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
57a7ecde
Parents:
2da93bcb
git-author:
Sebastian Huber <sebastian.huber@…> (09/26/18 07:04:43)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/01/18 10:32:50)
Message:

telnetd: Remove CONFIGURE_MAXIMUM_PTYS

Add a rtems_telnetd_config_table::client_maximum member to the Telnet
configuration.

Close #3526.
Close #3528.

Location:
cpukit
Files:
3 edited

Legend:

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

    r2da93bcb ra346ebba  
    154154   */
    155155  const uint32_t rtems_libio_number_iops = RTEMS_ARRAY_SIZE(rtems_libio_iops);
    156 #endif
    157 
    158 /**
    159  * This macro specifies the number of PTYs that can be concurrently
    160  * active.
    161  */
    162 #ifndef CONFIGURE_MAXIMUM_PTYS
    163   #define CONFIGURE_MAXIMUM_PTYS 0
    164 #endif
    165 
    166 /**
    167  * This variable contains the maximum number of PTYs that can be
    168  * concurrently active.
    169  */
    170 #ifdef CONFIGURE_INIT
    171   int rtems_telnetd_maximum_ptys = CONFIGURE_MAXIMUM_PTYS;
    172 #else
    173   extern int rtems_telnetd_maximum_ptys;
    174156#endif
    175157
     
    34753457#endif
    34763458
     3459#ifdef CONFIGURE_MAXIMUM_PTYS
     3460  #warning "The CONFIGURE_MAXIMUM_PTYS configuration option is obsolete since RTEMS 5.1"
     3461#endif
     3462
    34773463#ifdef CONFIGURE_TERMIOS_DISABLED
    34783464  #warning "The CONFIGURE_TERMIOS_DISABLED configuration option is obsolete since RTEMS 5.1"
  • cpukit/include/rtems/telnetd.h

    r2da93bcb ra346ebba  
    8686   */
    8787  bool keep_stdio;
     88
     89  /**
     90   * @brief Maximum number of clients which can connect to the system at a
     91   * time.
     92   *
     93   * Use 0 for the default value.
     94   */
     95  uint16_t client_maximum;
    8896} rtems_telnetd_config_table;
    8997
  • cpukit/telnetd/telnetd.c

    r2da93bcb ra346ebba  
    6363#define PARANOIA
    6464
     65typedef struct telnetd_context telnetd_context;
     66
    6567struct shell_args {
    6668  rtems_pty_context  pty;
    67   void              *arg;
    6869  char               peername[16];
    69   char               delete_myself;
     70  telnetd_context   *ctx;
     71};
     72
     73struct telnetd_context {
     74  rtems_telnetd_config_table config;
     75  uint16_t                   active_clients;
    7076};
    7177
     
    8692
    8793/***********************************************************/
    88 static rtems_telnetd_config_table *telnetd_config;
     94static telnetd_context telnetd_instance;
    8995
    9096/*
     
    103109
    104110static struct shell_args *grab_a_Connection(
     111  telnetd_context *ctx,
    105112  int des_socket,
    106113  uni_sa *srv,
     
    109116)
    110117{
    111   struct shell_args *args = NULL;
     118  struct shell_args *args;
    112119  socklen_t size_adr = sizeof(srv->sin);
    113120  int acp_sock;
     121
     122  if (ctx->active_clients >= ctx->config.client_maximum) {
     123    return NULL;
     124  }
    114125
    115126  args = malloc(sizeof(*args));
    116127  if (args == NULL) {
    117128    perror("telnetd:malloc");
    118     goto bailout;
     129    return NULL;
    119130  }
    120131
    121132  acp_sock = accept(des_socket,&srv->sa,&size_adr);
    122 
    123133  if (acp_sock<0) {
    124134    perror("telnetd:accept");
    125     goto bailout;
     135    free(args);
     136    return NULL;
    126137  };
    127138
     
    129140    syslog( LOG_DAEMON | LOG_ERR, "telnetd: unable to obtain PTY");
    130141    /* NOTE: failing 'do_get_pty()' closed the socket */
    131     goto bailout;
     142    free(args);
     143    return NULL;
    132144  }
    133145
     
    142154#endif
    143155
    144 bailout:
    145 
     156  ++ctx->active_clients;
     157  args->ctx = ctx;
    146158  return args;
    147159}
    148160
    149161
    150 static void release_a_Connection(char *devname, char *peername, FILE **pstd, int n)
     162static void release_a_Connection(telnetd_context *ctx, const char *devname,
     163  const char *peername, FILE **pstd, int n)
    151164{
    152165
     
    157170      devname );
    158171#endif
     172
     173  --ctx->active_clients;
    159174
    160175  while (--n>=0)
     
    193208  struct shell_args *arg = NULL;
    194209  rtems_id           task_id;
     210  telnetd_context   *ctx = task_argument;
    195211
    196212  if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
     
    219235   */
    220236  do {
    221     if (telnetd_config->keep_stdio) {
     237    if (ctx->config.keep_stdio) {
    222238      bool start = true;
    223239      char device_name [32];
    224240
    225241      ttyname_r( 1, device_name, sizeof( device_name));
    226       if (telnetd_config->login_check != NULL) {
     242      if (ctx->config.login_check != NULL) {
    227243        start = rtems_shell_login_prompt(
    228244          stdin,
    229245          stderr,
    230246          device_name,
    231           telnetd_config->login_check
     247          ctx->config.login_check
    232248        );
    233249      }
    234250      if (start) {
    235         telnetd_config->command( device_name, arg->arg);
     251        ctx->config.command( device_name, ctx->config.arg);
    236252      } else {
    237253        syslog(
     
    242258      }
    243259    } else {
    244       arg = grab_a_Connection(des_socket, &srv, peername, sizeof(peername));
     260      arg = grab_a_Connection(ctx, des_socket, &srv, peername,
     261        sizeof(peername));
    245262
    246263      if (arg == NULL) {
     
    250267      }
    251268
    252       arg->arg = telnetd_config->arg;
    253269      strncpy(arg->peername, peername, sizeof(arg->peername));
    254270
    255271      task_id = telnetd_spawn_task(
    256272        arg->pty.name,
    257         telnetd_config->priority,
    258         telnetd_config->stack_size,
     273        ctx->config.priority,
     274        ctx->config.stack_size,
    259275        spawned_shell,
    260276        arg
     
    276292        if ( !(dummy=fopen(arg->pty.name,"r+")) )
    277293          perror("Unable to dummy open the pty, losing a slot :-(");
    278         release_a_Connection(arg->pty.name, peername, &dummy, 1);
     294        release_a_Connection(ctx, arg->pty.name, peername, &dummy, 1);
    279295        free(arg);
    280296        sleep(2); /* don't accept connections too fast */
     
    294310rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table* config)
    295311{
     312  telnetd_context *ctx = &telnetd_instance;
    296313  rtems_id task_id;
    297 
    298   if (telnetd_config != NULL) {
    299     fprintf(stderr, "telnetd already started\n");
    300     return RTEMS_RESOURCE_IN_USE;
    301   }
    302314
    303315  if (config->command == NULL) {
     
    306318  }
    307319
    308   telnetd_config = calloc(1, sizeof(*telnetd_config));
    309   if (telnetd_config == NULL) {
    310     fprintf(stderr, "telnetd cannot alloc telnetd config table\n");
    311     return RTEMS_NO_MEMORY;
    312   }
    313 
    314   *telnetd_config = *config;
     320  if (ctx->config.command != NULL) {
     321    fprintf(stderr, "telnetd already started\n");
     322    return RTEMS_RESOURCE_IN_USE;
     323  }
     324
     325  ctx->config = *config;
    315326
    316327  /* Check priority */
    317328#ifdef RTEMS_NETWORKING
    318   if (telnetd_config->priority <= 0) {
    319     telnetd_config->priority = rtems_bsdnet_config.network_task_priority;
    320   }
    321 #endif
    322   if (telnetd_config->priority < 2) {
    323     telnetd_config->priority = 100;
     329  if (ctx->config.priority == 0) {
     330    ctx->config.priority = rtems_bsdnet_config.network_task_priority;
     331  }
     332#endif
     333  if (ctx->config.priority == 0) {
     334    ctx->config.priority = 100;
    324335  }
    325336
    326337  /* Check stack size */
    327   if (telnetd_config->stack_size <= 0) {
    328     telnetd_config->stack_size = (size_t)32 * 1024;
     338  if (ctx->config.stack_size == 0) {
     339    ctx->config.stack_size = (size_t)32 * 1024;
     340  }
     341
     342  if (ctx->config.client_maximum == 0) {
     343    ctx->config.client_maximum = 5;
    329344  }
    330345
     
    332347  task_id = telnetd_spawn_task(
    333348    "TNTD",
    334     telnetd_config->priority,
    335     telnetd_config->stack_size,
     349    ctx->config.priority,
     350    ctx->config.stack_size,
    336351    rtems_task_telnetd,
    337     0
     352    ctx
    338353  );
    339354  if (task_id == RTEMS_ID_NONE) {
    340     free(telnetd_config);
    341     telnetd_config = NULL;
     355    ctx->config.command = NULL;
    342356    return RTEMS_IO_ERROR;
    343357  }
    344358
    345359  /* Print status */
    346   if (!telnetd_config->keep_stdio) {
     360  if (!ctx->config.keep_stdio) {
    347361    fprintf(
    348362      stderr,
    349363      "telnetd started with stacksize = %u and priority = %d\n",
    350       (unsigned) telnetd_config->stack_size,
    351       (unsigned) telnetd_config->priority
     364      (unsigned) ctx->config.stack_size,
     365      (unsigned) ctx->config.priority
    352366    );
    353367  }
     
    365379  int                  i=0;
    366380  struct shell_args  *arg = targ;
     381  telnetd_context    *ctx = arg->ctx;
    367382  bool login_failed = false;
    368383  bool start = true;
     
    396411
    397412  /* call their routine */
    398   if (telnetd_config->login_check != NULL) {
     413  if (ctx->config.login_check != NULL) {
    399414    start = rtems_shell_login_prompt(
    400415      stdin,
    401416      stderr,
    402417      arg->pty.name,
    403       telnetd_config->login_check
     418      ctx->config.login_check
    404419    );
    405420    login_failed = !start;
    406421  }
    407422  if (start) {
    408     telnetd_config->command( arg->pty.name, arg->arg);
     423    ctx->config.command( arg->pty.name, ctx->config.arg);
    409424  }
    410425
     
    422437
    423438cleanup:
    424   release_a_Connection(arg->pty.name, arg->peername, nstd, i);
     439  release_a_Connection(ctx, arg->pty.name, arg->peername, nstd, i);
    425440  free(arg);
    426441}
Note: See TracChangeset for help on using the changeset viewer.