Changeset 629faf9 in rtems for cpukit


Ignore:
Timestamp:
Oct 9, 2018, 12:47:02 PM (12 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
2548d14
Parents:
477bca2
git-author:
Sebastian Huber <sebastian.huber@…> (10/09/18 12:47:02)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/10/18 12:06:27)
Message:

telnetd: Remove keep stdio feature

The Telnet service started via rtems_telnetd_start() had a keep stdio
feature. This just created a task and executed the command function in
a loop. For this kind of service we do not library support. This can
be done by an application task on its own. Remove this feature and
provide only the real Telnet server functionality.

Use syslog() for error and status messages.

Add test program for the Telnet server.

Close #3542.

Location:
cpukit
Files:
2 edited

Legend:

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

    r477bca2 r629faf9  
    6060   * @brief Task priority.
    6161   *
    62    * If this parameter is equal to zero, then the priority of network task is
    63    * used or 100 if this priority is less than two.
     62   * Use 0 for the default value.
    6463   */
    6564  rtems_task_priority priority;
     
    6766  /**
    6867   * @brief Task stack size.
     68   *
     69   * Use 0 for the default value.
    6970   */
    7071  size_t stack_size;
     
    7879
    7980  /**
    80    * @brief Keep standard IO of the caller.
     81   * @brief This is an obsolete configuration option.
    8182   *
    82    * Telnet takes over the standard input, output and error associated with
    83    * task, if this parameter is set to @c true.  In this case, it will @b not
    84    * listen on any sockets.  When this parameter is @c false, Telnet will
    85    * create other tasks for the shell which listen on sockets.
     83   * It must be set to false, otherwise rtems_telnetd_start() will do nothing
     84   * and returns with a status of RTEMS_NOT_IMPLEMENTED.
    8685   */
    8786  bool keep_stdio;
     
    9796
    9897/**
    99  * @brief Start the Telnet subsystem with the provided configuration.
     98 * @brief Starts the Telnet server using the provided configuration.
     99 *
     100 * @retval RTEMS_SUCCESSFUL Successful operation.
     101 * @retval RTEMS_INVALID_ADDRESS The command function in the configuration is
     102 *   @c NULL.
     103 * @retval RTEMS_RESOURCE_IN_USE The Telnet server was already started.
     104 * @retval RTEMS_NOT_IMPLEMENTED The keep stdio configuration option is true.
     105 * @retval RTEMS_UNSATISFIED Not enough resources to start the Telnet server or
     106 *   task priority in configuration is invalid.
    100107 */
    101108rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table *config);
  • cpukit/telnetd/telnetd.c

    r477bca2 r629faf9  
    235235   */
    236236  do {
    237     if (ctx->config.keep_stdio) {
    238       bool start = true;
    239       char device_name [32];
    240 
    241       ttyname_r( 1, device_name, sizeof( device_name));
    242       if (ctx->config.login_check != NULL) {
    243         start = rtems_shell_login_prompt(
    244           stdin,
    245           stderr,
    246           device_name,
    247           ctx->config.login_check
    248         );
     237    arg = grab_a_Connection(ctx, des_socket, &srv, peername,
     238      sizeof(peername));
     239
     240    if (arg == NULL) {
     241      /* if something went wrong, sleep for some time */
     242      sleep(10);
     243      continue;
     244    }
     245
     246    strncpy(arg->peername, peername, sizeof(arg->peername));
     247
     248    task_id = telnetd_spawn_task(
     249      arg->pty.name,
     250      ctx->config.priority,
     251      ctx->config.stack_size,
     252      spawned_shell,
     253      arg
     254    );
     255    if (task_id == RTEMS_ID_NONE) {
     256      FILE *dummy;
     257
     258      if ( telnetd_spawn_task != telnetd_dflt_spawn ) {
     259        fprintf(stderr,"Telnetd: Unable to spawn child task\n");
    249260      }
    250       if (start) {
    251         ctx->config.command( device_name, ctx->config.arg);
    252       } else {
    253         syslog(
    254           LOG_AUTHPRIV | LOG_WARNING,
    255           "telnetd: to many wrong passwords entered from %s",
    256           device_name
    257         );
    258       }
    259     } else {
    260       arg = grab_a_Connection(ctx, des_socket, &srv, peername,
    261         sizeof(peername));
    262 
    263       if (arg == NULL) {
    264         /* if something went wrong, sleep for some time */
    265         sleep(10);
    266         continue;
    267       }
    268 
    269       strncpy(arg->peername, peername, sizeof(arg->peername));
    270 
    271       task_id = telnetd_spawn_task(
    272         arg->pty.name,
    273         ctx->config.priority,
    274         ctx->config.stack_size,
    275         spawned_shell,
    276         arg
    277       );
    278       if (task_id == RTEMS_ID_NONE) {
    279         FILE *dummy;
    280 
    281         if ( telnetd_spawn_task != telnetd_dflt_spawn ) {
    282           fprintf(stderr,"Telnetd: Unable to spawn child task\n");
    283         }
    284 
    285         /* hmm - the pty driver slot can only be
    286          * released by opening and subsequently
    287          * closing the PTY - this also closes
    288          * the underlying socket. So we mock up
    289          * a stream...
    290          */
    291 
    292         if ( !(dummy=fopen(arg->pty.name,"r+")) )
    293           perror("Unable to dummy open the pty, losing a slot :-(");
    294         release_a_Connection(ctx, arg->pty.name, peername, &dummy, 1);
    295         free(arg);
    296         sleep(2); /* don't accept connections too fast */
    297       }
     261
     262      /* hmm - the pty driver slot can only be
     263       * released by opening and subsequently
     264       * closing the PTY - this also closes
     265       * the underlying socket. So we mock up
     266       * a stream...
     267       */
     268
     269      if ( !(dummy=fopen(arg->pty.name,"r+")) )
     270        perror("Unable to dummy open the pty, losing a slot :-(");
     271      release_a_Connection(ctx, arg->pty.name, peername, &dummy, 1);
     272      free(arg);
     273      sleep(2); /* don't accept connections too fast */
    298274    }
    299275  } while(1);
     
    314290
    315291  if (config->command == NULL) {
    316     fprintf(stderr, "telnetd setup with invalid command\n");
    317     return RTEMS_IO_ERROR;
     292    syslog(LOG_DAEMON | LOG_ERR, "telnetd: configuration with invalid command");
     293    return RTEMS_INVALID_ADDRESS;
    318294  }
    319295
    320296  if (ctx->config.command != NULL) {
    321     fprintf(stderr, "telnetd already started\n");
     297    syslog(LOG_DAEMON | LOG_ERR, "telnetd: already started");
    322298    return RTEMS_RESOURCE_IN_USE;
    323299  }
     
    354330  if (task_id == RTEMS_ID_NONE) {
    355331    ctx->config.command = NULL;
    356     return RTEMS_IO_ERROR;
    357   }
    358 
    359   /* Print status */
    360   if (!ctx->config.keep_stdio) {
    361     fprintf(
    362       stderr,
    363       "telnetd started with stacksize = %u and priority = %d\n",
    364       (unsigned) ctx->config.stack_size,
    365       (unsigned) ctx->config.priority
    366     );
    367   }
    368 
     332    syslog(LOG_DAEMON | LOG_ERR, "telnetd: cannot create server task");
     333    return RTEMS_UNSATISFIED;
     334  }
     335
     336  syslog(LOG_DAEMON | LOG_INFO, "telnetd: started successfully");
    369337  return RTEMS_SUCCESSFUL;
    370338}
Note: See TracChangeset for help on using the changeset viewer.