OpenCoverage

exit.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/exit.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is exit.def, from which is created exit.c.-
2It implements the builtins "exit", and "logout" in Bash.-
3-
4Copyright (C) 1987-2009 Free Software Foundation, Inc.-
5-
6This file is part of GNU Bash, the Bourne Again SHell.-
7-
8Bash is free software: you can redistribute it and/or modify-
9it under the terms of the GNU General Public License as published by-
10the Free Software Foundation, either version 3 of the License, or-
11(at your option) any later version.-
12-
13Bash is distributed in the hope that it will be useful,-
14but WITHOUT ANY WARRANTY; without even the implied warranty of-
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16GNU General Public License for more details.-
17-
18You should have received a copy of the GNU General Public License-
19along with Bash. If not, see <http://www.gnu.org/licenses/>.-
20-
21$PRODUCES exit.c-
22-
23$BUILTIN exit-
24$FUNCTION exit_builtin-
25$SHORT_DOC exit [n]-
26Exit the shell.-
27-
28Exits the shell with a status of N. If N is omitted, the exit status-
29is that of the last command executed.-
30$END-
31-
32#include <config.h>-
33-
34#include "../bashtypes.h"-
35#include <stdio.h>-
36-
37#if defined (HAVE_UNISTD_H)-
38# include <unistd.h>-
39#endif-
40-
41#include "../bashintl.h"-
42-
43#include "../shell.h"-
44#include "../execute_cmd.h"-
45#include "../jobs.h"-
46#include "../trap.h"-
47-
48#include "common.h"-
49#include "builtext.h" /* for jobs_builtin */-
50-
51extern int check_jobs_at_exit;-
52-
53static int exit_or_logout __P((WORD_LIST *));-
54static int sourced_logout;-
55-
56int-
57exit_builtin (list)-
58 WORD_LIST *list;-
59{-
60 CHECK_HELPOPT (list);
never executed: __result = (((const unsigned char *) (const char *) ( ((list)->word->word) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "--help" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: return (258);
(list)Description
TRUEevaluated 71 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
(list)->wordDescription
TRUEevaluated 71 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(((list)->word... ("--help")[0]Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 70 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-71
61-
62 if (interactive)
interactiveDescription
TRUEnever evaluated
FALSEevaluated 80 times by 1 test
Evaluated by:
  • Self test
0-80
63 {-
64 fprintf (stderr, login_shell ? _("logout\n") : "exit\n");-
65 fflush (stderr);-
66 }
never executed: end of block
0
67-
68 return (exit_or_logout (list));
executed 80 times by 1 test: return (exit_or_logout (list));
Executed by:
  • Self test
80
69}-
70-
71$BUILTIN logout-
72$FUNCTION logout_builtin-
73$SHORT_DOC logout [n]-
74Exit a login shell.-
75-
76Exits a login shell with exit status N. Returns an error if not executed-
77in a login shell.-
78$END-
79-
80/* How to logout. */-
81int-
82logout_builtin (list)-
83 WORD_LIST *list;-
84{-
85 CHECK_HELPOPT (list);
never executed: __result = (((const unsigned char *) (const char *) ( ((list)->word->word) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "--help" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: return (258);
(list)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
(list)->wordDescription
TRUEnever evaluated
FALSEnever evaluated
(((list)->word... ("--help")[0]Description
TRUEnever evaluated
FALSEnever evaluated
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-5
86-
87 if (login_shell == 0 /* && interactive */)
login_shell == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
88 {-
89 builtin_error (_("not login shell: use `exit'"));-
90 return (EXECUTION_FAILURE);
executed 5 times by 1 test: return (1);
Executed by:
  • Self test
5
91 }-
92 else-
93 return (exit_or_logout (list));
never executed: return (exit_or_logout (list));
0
94}-
95-
96static int-
97exit_or_logout (list)-
98 WORD_LIST *list;-
99{-
100 int exit_value;-
101-
102#if defined (JOB_CONTROL)-
103 int exit_immediate_okay, stopmsg;-
104-
105 exit_immediate_okay = (interactive == 0 ||
interactive == 0Description
TRUEevaluated 80 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-80
106 last_shell_builtin == exit_builtin ||
last_shell_bui...= exit_builtinDescription
TRUEnever evaluated
FALSEnever evaluated
0
107 last_shell_builtin == logout_builtin ||
last_shell_bui...logout_builtinDescription
TRUEnever evaluated
FALSEnever evaluated
0
108 last_shell_builtin == jobs_builtin);
last_shell_bui...= jobs_builtinDescription
TRUEnever evaluated
FALSEnever evaluated
0
109-
110 /* Check for stopped jobs if the user wants to. */-
111 if (exit_immediate_okay == 0)
exit_immediate_okay == 0Description
TRUEnever evaluated
FALSEevaluated 80 times by 1 test
Evaluated by:
  • Self test
0-80
112 {-
113 register int i;-
114 for (i = stopmsg = 0; i < js.j_jobslots; i++)
i < js.j_jobslotsDescription
TRUEnever evaluated
FALSEnever evaluated
0
115 if (jobs[i] && STOPPED (i))
jobs[i]Description
TRUEnever evaluated
FALSEnever evaluated
(jobs[(i)]->state == JSTOPPED)Description
TRUEnever evaluated
FALSEnever evaluated
0
116 stopmsg = JSTOPPED;
never executed: stopmsg = JSTOPPED;
0
117 else if (check_jobs_at_exit && stopmsg == 0 && jobs[i] && RUNNING (i))
check_jobs_at_exitDescription
TRUEnever evaluated
FALSEnever evaluated
stopmsg == 0Description
TRUEnever evaluated
FALSEnever evaluated
jobs[i]Description
TRUEnever evaluated
FALSEnever evaluated
(jobs[(i)]->state == JRUNNING)Description
TRUEnever evaluated
FALSEnever evaluated
0
118 stopmsg = JRUNNING;
never executed: stopmsg = JRUNNING;
0
119-
120 if (stopmsg == JSTOPPED)
stopmsg == JSTOPPEDDescription
TRUEnever evaluated
FALSEnever evaluated
0
121 fprintf (stderr, _("There are stopped jobs.\n"));
never executed: fprintf ( stderr , dcgettext (((void *)0), "There are stopped jobs.\n" , 5) );
0
122 else if (stopmsg == JRUNNING)
stopmsg == JRUNNINGDescription
TRUEnever evaluated
FALSEnever evaluated
0
123 fprintf (stderr, _("There are running jobs.\n"));
never executed: fprintf ( stderr , dcgettext (((void *)0), "There are running jobs.\n" , 5) );
0
124-
125 if (stopmsg && check_jobs_at_exit)
stopmsgDescription
TRUEnever evaluated
FALSEnever evaluated
check_jobs_at_exitDescription
TRUEnever evaluated
FALSEnever evaluated
0
126 list_all_jobs (JLIST_STANDARD);
never executed: list_all_jobs (0);
0
127-
128 if (stopmsg)
stopmsgDescription
TRUEnever evaluated
FALSEnever evaluated
0
129 {-
130 /* This is NOT superfluous because EOF can get here without-
131 going through the command parser. Set both last and this-
132 so that either `exit', `logout', or ^D will work to exit-
133 immediately if nothing intervenes. */-
134 this_shell_builtin = last_shell_builtin = exit_builtin;-
135 return (EXECUTION_FAILURE);
never executed: return (1);
0
136 }-
137 }
never executed: end of block
0
138#endif /* JOB_CONTROL */-
139-
140 /* Get return value if present. This means that you can type-
141 `logout 5' to a shell, and it returns 5. */-
142-
143 /* If we're running the exit trap (running_trap == 1, since running_trap-
144 gets set to SIG+1), and we don't have a argument given to `exit'-
145 (list == 0), use the exit status we saved before running the trap-
146 commands (trap_saved_exit_value). */-
147 exit_value = (running_trap == 1 && list == 0) ? trap_saved_exit_value : get_exitstat (list);
running_trap == 1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 78 times by 1 test
Evaluated by:
  • Self test
list == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-78
148-
149 bash_logout ();-
150-
151 last_command_exit_value = exit_value;-
152-
153 /* Exit the program. */-
154 jump_to_top_level (EXITPROG);-
155 /*NOTREACHED*/-
156}
never executed: end of block
0
157-
158void-
159bash_logout ()-
160{-
161 /* Run our `~/.bash_logout' file if it exists, and this is a login shell. */-
162 if (login_shell && sourced_logout++ == 0 && subshell_environment == 0)
login_shellDescription
TRUEnever evaluated
FALSEevaluated 80 times by 1 test
Evaluated by:
  • Self test
sourced_logout++ == 0Description
TRUEnever evaluated
FALSEnever evaluated
subshell_environment == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-80
163 {-
164 maybe_execute_file ("~/.bash_logout", 1);-
165#ifdef SYS_BASH_LOGOUT-
166 maybe_execute_file (SYS_BASH_LOGOUT, 1);-
167#endif-
168 }
never executed: end of block
0
169}
executed 80 times by 1 test: end of block
Executed by:
  • Self test
80
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2