Changeset 95036a45 in rtems


Ignore:
Timestamp:
08/08/20 08:07:32 (4 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
5
Children:
e95c00a7
Parents:
534f9dbe
Message:

shell: Only clear std handles when the shell task exits

Clearing the std file handles when the main loop exited crashes
telnetd as it reuses its session threads.

Closes #3859

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/shell/shell.c

    r534f9dbe r95036a45  
    235235  if (eno != 0)
    236236    rtems_error(0, "pthread_setspecific(shell_current_env_key): clear");
    237 
    238   /*
    239    * Clear stdin and stdout file pointers of they will be closed
    240    */
     237}
     238
     239/*
     240 * Clear stdin, stdout and stderr file pointers so they will not be closed.
     241 */
     242static void rtems_shell_clear_shell_std_handles(void)
     243{
    241244  stdin = NULL;
    242245  stdout = NULL;
     246  stderr = NULL;
    243247}
    244248
     
    776780  if ( !shell_env ) {
    777781    printk( "shell_env is NULL\n" );
     782
    778783    return;
    779784  }
     
    798803  rtems_id           wake_on_end = shell_env->wake_on_end;
    799804  rtems_shell_main_loop( shell_env );
     805  rtems_shell_clear_shell_std_handles();
    800806  if (wake_on_end != RTEMS_INVALID_ID)
    801807    rtems_event_send (wake_on_end, RTEMS_EVENT_1);
     
    873879      stdout = stderr;
    874880  } else if (strcmp(shell_env->output, "/dev/null") == 0) {
     881    if (stdout == NULL) {
     882      fprintf(stderr, "shell: stdout is NULLs\n");
     883      rtems_shell_clear_shell_env();
     884      return false;
     885    }
    875886    fclose (stdout);
    876887  } else {
     
    907918
    908919  if (!input_file) {
     920    if (stdin == NULL) {
     921      fprintf(stderr, "shell: stdin is NULLs\n");
     922      if (stdoutToClose != NULL)
     923        fclose(stdoutToClose);
     924      rtems_shell_clear_shell_env();
     925      return false;
     926    }
    909927    /* Make a raw terminal, Linux Manuals */
    910928    if (tcgetattr(fileno(stdin), &previous_term) >= 0) {
     
    968986         */
    969987        if (shell_env->login_check != NULL) {
    970           result = rtems_shell_login(shell_env, stdin,stdout);
     988          result = rtems_shell_login(shell_env, stdin, stdout);
    971989        } else {
    972990          setuid(shell_env->uid);
Note: See TracChangeset for help on using the changeset viewer.