OpenCoverage

command.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/command.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is command.def, from which is created command.c.-
2It implements the builtin "command" in Bash.-
3-
4Copyright (C) 1987-2015 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 command.c-
22-
23$BUILTIN command-
24$FUNCTION command_builtin-
25$SHORT_DOC command [-pVv] command [arg ...]-
26Execute a simple command or display information about commands.-
27-
28Runs COMMAND with ARGS suppressing shell function lookup, or display-
29information about the specified COMMANDs. Can be used to invoke commands-
30on disk when a function with the same name exists.-
31-
32Options:-
33 -p use a default value for PATH that is guaranteed to find all of-
34 the standard utilities-
35 -v print a description of COMMAND similar to the `type' builtin-
36 -V print a more verbose description of each COMMAND-
37-
38Exit Status:-
39Returns exit status of COMMAND, or failure if COMMAND is not found.-
40$END-
41-
42#include <config.h>-
43-
44#if defined (HAVE_UNISTD_H)-
45# ifdef _MINIX-
46# include <sys/types.h>-
47# endif-
48# include <unistd.h>-
49#endif-
50-
51#include "../bashansi.h"-
52-
53#include "../shell.h"-
54#include "../execute_cmd.h"-
55#include "../flags.h"-
56#include "bashgetopt.h"-
57#include "common.h"-
58-
59#if defined (_CS_PATH) && defined (HAVE_CONFSTR) && !HAVE_DECL_CONFSTR-
60extern size_t confstr __P((int, char *, size_t));-
61#endif-
62-
63/* Run the commands mentioned in LIST without paying attention to shell-
64 functions. */-
65int-
66command_builtin (list)-
67 WORD_LIST *list;-
68{-
69 int result, verbose, use_standard_path, opt;-
70 COMMAND *command;-
71-
72 verbose = use_standard_path = 0;-
73 reset_internal_getopt ();-
74 while ((opt = internal_getopt (list, "pvV")) != -1)
(opt = interna... "pvV")) != -1Description
TRUEevaluated 70 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 111 times by 1 test
Evaluated by:
  • Self test
70-111
75 {-
76 switch (opt)-
77 {-
78 case 'p':
executed 35 times by 1 test: case 'p':
Executed by:
  • Self test
35
79 use_standard_path = CDESC_STDPATH;-
80 break;
executed 35 times by 1 test: break;
Executed by:
  • Self test
35
81 case 'V':
executed 10 times by 1 test: case 'V':
Executed by:
  • Self test
10
82 verbose = CDESC_SHORTDESC|CDESC_ABSPATH; /* look in common.h for constants */-
83 break;
executed 10 times by 1 test: break;
Executed by:
  • Self test
10
84 case 'v':
executed 24 times by 1 test: case 'v':
Executed by:
  • Self test
24
85 verbose = CDESC_REUSABLE; /* ditto */-
86 break;
executed 24 times by 1 test: break;
Executed by:
  • Self test
24
87 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
88 default:
executed 1 time by 1 test: default:
Executed by:
  • Self test
1
89 builtin_usage ();-
90 return (EX_USAGE);
executed 1 time by 1 test: return (258);
Executed by:
  • Self test
1
91 }-
92 }-
93 list = loptend;-
94-
95 if (list == 0)
list == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
9-102
96 return (EXECUTION_SUCCESS);
executed 9 times by 1 test: return (0);
Executed by:
  • Self test
9
97-
98#if defined (RESTRICTED_SHELL)-
99 if (use_standard_path && restricted)
use_standard_pathDescription
TRUEevaluated 35 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 67 times by 1 test
Evaluated by:
  • Self test
restrictedDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 34 times by 1 test
Evaluated by:
  • Self test
1-67
100 {-
101 sh_restricted ("-p");-
102 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
103 }-
104#endif-
105-
106 if (verbose)
verboseDescription
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 67 times by 1 test
Evaluated by:
  • Self test
34-67
107 {-
108 int found, any_found;-
109-
110 for (any_found = 0; list; list = list->next)
listDescription
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 34 times by 1 test
Evaluated by:
  • Self test
34
111 {-
112 found = describe_command (list->word->word, verbose|use_standard_path);-
113-
114 if (found == 0 && verbose != CDESC_REUSABLE)
found == 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
verbose != 0x004Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
0-26
115 sh_notfound (list->word->word);
never executed: sh_notfound (list->word->word);
0
116-
117 any_found += found;-
118 }
executed 34 times by 1 test: end of block
Executed by:
  • Self test
34
119-
120 return (any_found ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
executed 34 times by 1 test: return (any_found ? 0 : 1);
Executed by:
  • Self test
34
121 }-
122-
123 begin_unwind_frame ("command_builtin");-
124-
125#define COMMAND_BUILTIN_FLAGS (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION | CMD_COMMAND_BUILTIN | (use_standard_path ? CMD_STDPATH : 0))-
126-
127 /* We don't want this to be reparsed (consider command echo 'foo &'), so-
128 just make a simple_command structure and call execute_command with it. */-
129 command = make_bare_simple_command ();-
130 command->value.Simple->words = (WORD_LIST *)copy_word_list (list);-
131 command->value.Simple->redirects = (REDIRECT *)NULL;-
132 command->flags |= COMMAND_BUILTIN_FLAGS;-
133 command->value.Simple->flags |= COMMAND_BUILTIN_FLAGS;-
134-
135 add_unwind_protect ((char *)dispose_command, command);-
136 result = execute_command (command);-
137-
138 run_unwind_frame ("command_builtin");-
139-
140 return (result);
executed 64 times by 1 test: return (result);
Executed by:
  • Self test
64
141}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2