Esempio n. 1
0
/* What to do when we've been interrupted, and it is safe to handle it. */
void
throw_to_top_level ()
{
  int print_newline = 0;

  if (interrupt_state)
    {
      print_newline = 1;
      DELINTERRUPT;
    }

  if (interrupt_state)
    return;

  last_command_exit_value |= 128;

  /* Run any traps set on SIGINT. */
  run_interrupt_trap ();

  /* Cleanup string parser environment. */
  while (parse_and_execute_level)
    parse_and_execute_cleanup ();

#if defined (JOB_CONTROL)
  give_terminal_to (shell_pgrp);
#endif /* JOB_CONTROL */

#if defined (JOB_CONTROL) || defined (HAVE_POSIX_SIGNALS)
  /* This should not be necessary on systems using sigsetjmp/siglongjmp. */
  sigprocmask (SIG_SETMASK, &top_level_mask, (sigset_t *)NULL);
#endif

  reset_parser ();

#if defined (READLINE)
  if (interactive)
    bashline_reinitialize ();
#endif /* READLINE */

#if defined (PROCESS_SUBSTITUTION)
  unlink_fifo_list ();
#endif /* PROCESS_SUBSTITUTION */

  run_unwind_protects ();
  loop_level = continuing = breaking = 0;
  return_catch_flag = 0;

  if (interactive && print_newline)
    {
      fflush (stdout);
      fprintf (stderr, "\n");
      fflush (stderr);
    }

  /* An interrupted `wait' command in a script does not exit the script. */
  if (interactive || (interactive_shell && !shell_initialized) ||
      (print_newline && signal_is_trapped (SIGINT)))
    jump_to_top_level (DISCARD);
  else
    jump_to_top_level (EXITPROG);
}
Esempio n. 2
0
File: eval.c Progetto: xyzy/bash-4.3
/* Read and execute commands until EOF is reached.  This assumes that
   the input source has already been initialized. */
   int
   reader_loop ()
   {
    //printf("reader_loop  ------>  Start\n");
    int our_indirection_level;
    COMMAND * volatile current_command;

    USE_VAR(current_command);

    current_command = (COMMAND *)NULL;

    our_indirection_level = ++indirection_level;

    while (EOF_Reached == 0)
    {
      //printf("EOF_Reached == 0   =======>   Start\n");
      int code;

      code = setjmp_nosigs (top_level);

#if defined (PROCESS_SUBSTITUTION)
      unlink_fifo_list ();
#endif /* PROCESS_SUBSTITUTION */

      /* XXX - why do we set this every time through the loop? */
      if (interactive_shell && signal_is_ignored (SIGINT) == 0)
      {
        //printf("if (interactive_shell && signal_is_ignored (SIGINT) == 0)\n");
       set_signal_handler (SIGINT, sigint_sighandler);
      }

     if (code != NOT_JUMPED)
     {
      //printf("if (code != NOT_JUMPED)\n");
       indirection_level = our_indirection_level;

       switch (code)
       {
	      /* Some kind of throw to top_level has occurred. */
         case FORCE_EOF:
         case ERREXIT:
         case EXITPROG:
         //printf("case EXITPROG:\n");
         current_command = (COMMAND *)NULL;
         if (exit_immediately_on_error)
          {
            //printf("if (exit_immediately_on_error)\n");
            variable_context = 0; /* not in a function */
          }

           EOF_Reached = EOF;
         goto exec_done;

         case DISCARD:
         //printf("case DISCARD:\n");
	      /* Make sure the exit status is reset to a non-zero value, but
		 leave existing non-zero values (e.g., > 128 on signal)
		 alone. */
    if (last_command_exit_value == 0)
    {
      //printf("if (last_command_exit_value == 0)\n");
      last_command_exit_value = EXECUTION_FAILURE;
    }

    if (subshell_environment)
    {
      //printf("if (subshell_environment)\n");
      current_command = (COMMAND *)NULL;
      EOF_Reached = EOF;
      goto exec_done;
    }
	      /* Obstack free command elements, etc. */
    if (current_command)
    {
      //printf("if (current_command)\n");
      dispose_command (current_command);
      current_command = (COMMAND *)NULL;
    }
#if defined (HAVE_POSIX_SIGNALS)
    sigprocmask (SIG_SETMASK, &top_level_mask, (sigset_t *)NULL);
#endif
    break;

    default:
    command_error ("reader_loop", CMDERR_BADJUMP, code, 0);
  }
}

executing = 0;
if (temporary_env)
{
  //printf("if (temporary_env)\n");
	dispose_used_env_vars ();
}

#if (defined (ultrix) && defined (mips)) || defined (C_ALLOCA)
      /* Attempt to reclaim memory allocated with alloca (). */
(void) alloca (0);
#endif

if (read_command () == 0)
{
  //printf("read_command () == 0\n");
  if (interactive_shell == 0 && read_but_dont_execute)
  {
    //printf("if (interactive_shell == 0 && read_but_dont_execute)");
    last_command_exit_value = EXECUTION_SUCCESS;
    dispose_command (global_command);
    global_command = (COMMAND *)NULL;
  }
  else if (current_command = global_command)
  {
    //printf("else if (current_command:%d = global_command:%d)\n",current_command, global_command);
    global_command = (COMMAND *)NULL;
    current_command_number++;

    executing = 1;
    stdin_redir = 0;
    execute_command (current_command);

    exec_done:
    QUIT;

    if (current_command)
    {
      //printf("if (current_command)\n");
      dispose_command (current_command);
      current_command = (COMMAND *)NULL;
    }
  }
}
else
{
	       /* Parse error, maybe discard rest of stream if not interactive. */
  if (interactive == 0)
  {
    //printf("if (interactive == 0)\n");
    EOF_Reached = EOF;
  }
}

if (just_one_command)
{
 //printf("just_one_command\n");
 EOF_Reached = EOF;
}
//printf("EOF_Reached == 0   =======>   Exit\n");
}
indirection_level--;
  //printf("reader_loop  ------>  Exit\n");

return (last_command_exit_value);
}