X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=builtins%2Fexit.def;h=ddaa5d315cd44f215a0b7e928f7f369ec9106a1a;hb=95732b497d12c98613bb3c5db16b61f377501a59;hp=ee02b38dd119510a4a369291942dc6eac59d999a;hpb=d166f048818e10cf3799aa24a174fb22835f1acc;p=platform%2Fupstream%2Fbash.git diff --git a/builtins/exit.def b/builtins/exit.def index ee02b38..ddaa5d3 100644 --- a/builtins/exit.def +++ b/builtins/exit.def @@ -1,13 +1,13 @@ This file is exit.def, from which is created exit.c. It implements the builtins "exit", and "logout" in Bash. -Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc. +Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. Bash is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 1, or (at your option) any later +Software Foundation; either version 2, or (at your option) any later version. Bash is distributed in the hope that it will be useful, but WITHOUT ANY @@ -17,7 +17,7 @@ for more details. You should have received a copy of the GNU General Public License along with Bash; see the file COPYING. If not, write to the Free Software -Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. $PRODUCES exit.c @@ -37,18 +37,21 @@ $END # include #endif +#include "../bashintl.h" + #include "../shell.h" #include "../jobs.h" #include "common.h" #include "builtext.h" /* for jobs_builtin */ -extern int interactive, login_shell; extern int last_command_exit_value; -extern Function *this_shell_builtin; -extern Function *last_shell_builtin; +extern int running_trap, trap_saved_exit_value; +extern int subshell_environment; +extern sh_builtin_func_t *this_shell_builtin; +extern sh_builtin_func_t *last_shell_builtin; -static int exit_or_logout (); +static int exit_or_logout __P((WORD_LIST *)); static int sourced_logout; int @@ -75,9 +78,9 @@ int logout_builtin (list) WORD_LIST *list; { - if (login_shell == 0 && interactive) + if (login_shell == 0 /* && interactive */) { - builtin_error ("not login shell: use `exit'"); + builtin_error (_("not login shell: use `exit'")); return (EXECUTION_FAILURE); } else @@ -102,10 +105,10 @@ exit_or_logout (list) if (!exit_immediate_okay) { register int i; - for (i = 0; i < job_slots; i++) + for (i = 0; i < js.j_jobslots; i++) if (jobs[i] && STOPPED (i)) { - fprintf (stderr, "There are stopped jobs.\n"); + fprintf (stderr, _("There are stopped jobs.\n")); /* This is NOT superfluous because EOF can get here without going through the command parser. Set both last and this @@ -119,20 +122,31 @@ exit_or_logout (list) /* Get return value if present. This means that you can type `logout 5' to a shell, and it returns 5. */ - exit_value = list ? get_numeric_arg (list, 1) : last_command_exit_value; + /* If we're running the exit trap (running_trap == 1, since running_trap + gets set to SIG+1), and we don't have a argument given to `exit' + (list == 0), use the exit status we saved before running the trap + commands (trap_saved_exit_value). */ + exit_value = (running_trap == 1 && list == 0) ? trap_saved_exit_value : get_exitstat (list); + + bash_logout (); + + last_command_exit_value = exit_value; + + /* Exit the program. */ + jump_to_top_level (EXITPROG); + /*NOTREACHED*/ +} + +void +bash_logout () +{ /* Run our `~/.bash_logout' file if it exists, and this is a login shell. */ - if (login_shell && sourced_logout++ == 0) + if (login_shell && sourced_logout++ == 0 && subshell_environment == 0) { maybe_execute_file ("~/.bash_logout", 1); #ifdef SYS_BASH_LOGOUT maybe_execute_file (SYS_BASH_LOGOUT, 1); #endif } - - last_command_exit_value = exit_value; - - /* Exit the program. */ - jump_to_top_level (EXITPROG); - /*NOTREACHED*/ }