Changeset 65c65bb in rtems-libbsd for rtemsbsd/telnetd


Ignore:
Timestamp:
Jul 1, 2016, 5:49:52 AM (4 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
b96abfd647154f10ea8f7fac68e25676636eded5, 7f47f2784138109b8363804c2aecd3d83231ab0f, f1f03620800b14146977d78fb4322d80da04b53a, freebsd-9.3, 90a9fd66e0a85d8520bbb4bbcb72bfd274965961
Children:
4dec435
Parents:
fc26479
Message:

Add telnetd as service to rc.conf.

Location:
rtemsbsd/telnetd
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • rtemsbsd/telnetd/telnetd.c

    rfc26479 r65c65bb  
    8888
    8989/***********************************************************/
    90 static rtems_id telnetd_task_id = RTEMS_ID_NONE;
    91 
    92 rtems_id (*telnetd_spawn_task)(
     90static rtems_telnetd_config_table* telnetd_config;
     91static rtems_id                    telnetd_task_id;
     92
     93/*
     94 * chrisj: this variable was global and with no declared interface in a header
     95 *         file and with no means to set it so I have stopped it being global;
     96 *         if this breaks any user they will have be to provide a formal
     97 *         interface to get this change reverted.
     98 */
     99static const rtems_id (*telnetd_spawn_task)(
    93100  const char *,
    94101  unsigned,
     
    208215
    209216  /* we don't redirect stdio as this probably
    210    * was started from the console anyways..
     217   * was started from the console anyway ..
    211218   */
    212219  do {
    213     if (rtems_telnetd_config.keep_stdio) {
     220    if (telnetd_config->keep_stdio) {
    214221      bool start = true;
    215222      char device_name [32];
    216223
    217224      ttyname_r( 1, device_name, sizeof( device_name));
    218       if (rtems_telnetd_config.login_check != NULL) {
     225      if (telnetd_config->login_check != NULL) {
    219226        start = rtems_shell_login_prompt(
    220227          stdin,
    221228          stderr,
    222229          device_name,
    223           rtems_telnetd_config.login_check
     230          telnetd_config->login_check
    224231        );
    225232      }
    226233      if (start) {
    227         rtems_telnetd_config.command( device_name, arg->arg);
     234        telnetd_config->command( device_name, arg->arg);
    228235      } else {
    229236        syslog(
     
    245252
    246253      arg->devname = devname;
    247       arg->arg = rtems_telnetd_config.arg;
     254      arg->arg = telnetd_config->arg;
    248255      strncpy(arg->peername, peername, sizeof(arg->peername));
    249256
    250257      telnetd_task_id = telnetd_spawn_task(
    251258        devname,
    252         rtems_telnetd_config.priority,
    253         rtems_telnetd_config.stack_size,
     259        telnetd_config->priority,
     260        telnetd_config->stack_size,
    254261        spawned_shell,
    255262        arg
     
    288295}
    289296
    290 rtems_status_code rtems_telnetd_initialize( void)
    291 {
    292   if (telnetd_task_id != RTEMS_ID_NONE) {
     297rtems_status_code rtems_telnetd_start(const rtems_telnetd_config_table* config)
     298{
     299  if (telnetd_config != NULL) {
    293300    fprintf(stderr, "telnetd already started\n");
    294301    return RTEMS_RESOURCE_IN_USE;
    295302  }
    296303
    297   if (rtems_telnetd_config.command == NULL) {
     304  if (config->command == NULL) {
    298305    fprintf(stderr, "telnetd setup with invalid command\n");
    299306    return RTEMS_IO_ERROR;
    300307  }
    301308
     309  telnetd_config = calloc(1, sizeof(*telnetd_config));
     310  if (telnetd_config == NULL) {
     311    fprintf(stderr, "telnetd cannot alloc telnetd config table\n");
     312    return RTEMS_NO_MEMORY;
     313  }
     314
     315
    302316  if ( !telnet_pty_initialize() ) {
    303317    fprintf(stderr, "telnetd cannot initialize PTY driver\n");
     318    free(telnetd_config);
     319    telnetd_config = NULL;
    304320    return RTEMS_IO_ERROR;
    305321  }
    306322
     323  *telnetd_config = *config;
     324
    307325  /* Check priority */
    308   if (rtems_telnetd_config.priority < 2) {
    309     rtems_telnetd_config.priority = 100;
     326  if (telnetd_config->priority < 2) {
     327    telnetd_config->priority = 100;
    310328  }
    311329
    312330  /* Check stack size */
    313   if (rtems_telnetd_config.stack_size <= 0) {
    314     rtems_telnetd_config.stack_size = (size_t)32 * 1024;
     331  if (telnetd_config->stack_size <= 0) {
     332    telnetd_config->stack_size = (size_t)32 * 1024;
    315333  }
    316334
     
    318336  telnetd_task_id = telnetd_spawn_task(
    319337    "TNTD",
    320     rtems_telnetd_config.priority,
    321     rtems_telnetd_config.stack_size,
     338    telnetd_config->priority,
     339    telnetd_config->stack_size,
    322340    rtems_task_telnetd,
    323341    0
    324342  );
    325343  if (telnetd_task_id == RTEMS_ID_NONE) {
     344    free(telnetd_config);
     345    telnetd_config = NULL;
    326346    return RTEMS_IO_ERROR;
    327347  }
    328348
    329349  /* Print status */
    330   if (!rtems_telnetd_config.keep_stdio) {
     350  if (!telnetd_config->keep_stdio) {
    331351    fprintf(
    332352      stderr,
    333353      "telnetd started with stacksize = %u and priority = %d\n",
    334       (unsigned) rtems_telnetd_config.stack_size,
    335       (unsigned) rtems_telnetd_config.priority
     354      (unsigned) telnetd_config->stack_size,
     355      (unsigned) telnetd_config->priority
    336356    );
    337357  }
     
    387407
    388408  /* call their routine */
    389   if (rtems_telnetd_config.login_check != NULL) {
     409  if (telnetd_config->login_check != NULL) {
    390410    start = rtems_shell_login_prompt(
    391411      stdin,
    392412      stderr,
    393413      arg->devname,
    394       rtems_telnetd_config.login_check
     414      telnetd_config->login_check
    395415    );
    396416    login_failed = !start;
    397417  }
    398418  if (start) {
    399     rtems_telnetd_config.command( arg->devname, arg->arg);
     419    telnetd_config->command( arg->devname, arg->arg);
    400420  }
    401421
Note: See TracChangeset for help on using the changeset viewer.