Changeset 6d3ec58a in rtems for cpukit/telnetd


Ignore:
Timestamp:
Oct 9, 2018, 1:31:46 PM (14 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
1c567c5
Parents:
2548d14
git-author:
Sebastian Huber <sebastian.huber@…> (10/09/18 13:31:46)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/10/18 12:06:28)
Message:

telnetd: Simplify task spawn function

Use the minimum task size for the telnet server task since it has to
deal only with simple socket operations.

Update #3543.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/telnetd/telnetd.c

    r2548d14 r6d3ec58a  
    8383static int sockpeername(int sock, char *buf, int bufsz);
    8484
    85 rtems_id telnetd_dflt_spawn(
    86   const char *name,
    87   unsigned priority,
    88   unsigned stackSize,
    89   void (*fn)(void*),
    90   void *fnarg
    91 );
    92 
    9385/***********************************************************/
    9486static telnetd_context telnetd_instance;
    95 
    96 /*
    97  * chrisj: this variable was global and with no declared interface in a header
    98  *         file and with no means to set it so I have stopped it being global;
    99  *         if this breaks any user they will have be to provide a formal
    100  *         interface to get this change reverted.
    101  */
    102 static const rtems_id (*telnetd_spawn_task)(
    103   const char *,
    104   unsigned,
    105   unsigned,
    106   void (*)(void*),
    107   void *
    108 ) = telnetd_dflt_spawn;
    10987
    11088static struct shell_args *grab_a_Connection(
     
    194172}
    195173
     174static rtems_id telnetd_spawn_task(
     175  rtems_name name,
     176  rtems_task_priority priority,
     177  size_t stack_size,
     178  rtems_task_entry entry,
     179  void *arg
     180)
     181{
     182  rtems_status_code sc;
     183  rtems_id task_id;
     184
     185  sc = rtems_task_create(
     186    name,
     187    priority,
     188    stack_size,
     189    RTEMS_DEFAULT_MODES,
     190    RTEMS_FLOATING_POINT,
     191    &task_id
     192  );
     193  if (sc != RTEMS_SUCCESSFUL) {
     194    return RTEMS_ID_NONE;
     195  }
     196
     197  (void)rtems_task_start(task_id, entry, (rtems_task_argument) arg);
     198  return task_id;
     199}
     200
    196201static void
    197 spawned_shell(void *arg);
     202spawned_shell(rtems_task_argument arg);
    198203
    199204/***********************************************************/
    200205static void
    201 rtems_task_telnetd(void *task_argument)
     206telnetd_server_task(rtems_task_argument targ)
    202207{
    203208  int                des_socket;
     
    208213  struct shell_args *arg = NULL;
    209214  rtems_id           task_id;
    210   telnetd_context   *ctx = task_argument;
     215  telnetd_context   *ctx = (telnetd_context *) targ;
    211216
    212217  if ((des_socket=socket(PF_INET,SOCK_STREAM,0))<0) {
     
    247252
    248253    task_id = telnetd_spawn_task(
    249       arg->pty.name,
     254      rtems_build_name('T', 'N', 'T', 'a'),
    250255      ctx->config.priority,
    251256      ctx->config.stack_size,
     
    256261      FILE *dummy;
    257262
    258       if ( telnetd_spawn_task != telnetd_dflt_spawn ) {
    259         fprintf(stderr,"Telnetd: Unable to spawn child task\n");
    260       }
    261 
    262263      /* hmm - the pty driver slot can only be
    263264       * released by opening and subsequently
     
    320321  }
    321322
    322   /* Spawn task */
    323323  task_id = telnetd_spawn_task(
    324     "TNTD",
     324    rtems_build_name('T', 'N', 'T', 'D'),
    325325    ctx->config.priority,
    326     ctx->config.stack_size,
    327     rtems_task_telnetd,
     326    RTEMS_MINIMUM_STACK_SIZE,
     327    telnetd_server_task,
    328328    ctx
    329329  );
     
    340340/* utility wrapper */
    341341static void
    342 spawned_shell(void *targ)
     342spawned_shell(rtems_task_argument targ)
    343343{
    344344  rtems_status_code    sc;
     
    346346  FILE                *ostd[3]={ stdin, stdout, stderr };
    347347  int                  i=0;
    348   struct shell_args  *arg = targ;
     348  struct shell_args  *arg = (struct shell_args *) targ;
    349349  telnetd_context    *ctx = arg->ctx;
    350350  bool login_failed = false;
     
    408408  free(arg);
    409409}
    410 
    411 struct wrap_delete_args {
    412   void (*t)(void *);
    413   void           *a;
    414 };
    415 
    416 static rtems_task
    417 wrap_delete(rtems_task_argument arg)
    418 {
    419   struct wrap_delete_args     *pwa = (struct wrap_delete_args *)arg;
    420   register void              (*t)(void *) = pwa->t;
    421   register void               *a   = pwa->a;
    422 
    423   /* free argument before calling function (which may never return if
    424    * they choose to delete themselves)
    425    */
    426   free(pwa);
    427   t(a);
    428   rtems_task_exit();
    429 }
    430 
    431 rtems_id
    432 telnetd_dflt_spawn(const char *name, unsigned int priority, unsigned int stackSize, void (*fn)(void *), void* fnarg)
    433 {
    434   rtems_status_code        sc;
    435   rtems_id                 task_id = RTEMS_ID_NONE;
    436   char                     nm[4] = {'X','X','X','X' };
    437   struct wrap_delete_args *pwa = malloc(sizeof(*pwa));
    438 
    439   strncpy(nm, name, 4);
    440 
    441   if ( !pwa ) {
    442     perror("Telnetd: no memory\n");
    443     return RTEMS_ID_NONE;
    444   }
    445 
    446   pwa->t = fn;
    447   pwa->a = fnarg;
    448 
    449   if ((sc=rtems_task_create(
    450     rtems_build_name(nm[0], nm[1], nm[2], nm[3]),
    451       (rtems_task_priority)priority,
    452       stackSize,
    453       RTEMS_DEFAULT_MODES,
    454       RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT,
    455       &task_id)) ||
    456     (sc=rtems_task_start(
    457       task_id,
    458       wrap_delete,
    459       (rtems_task_argument)pwa))) {
    460         free(pwa);
    461         rtems_error(sc,"Telnetd: spawning task failed");
    462         return RTEMS_ID_NONE;
    463   }
    464   return task_id;
    465 }
Note: See TracChangeset for help on using the changeset viewer.