4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
29 * Execute one commandline
35 #include <fcntl.h> /* open() */
37 #include <mksh/dosys.h> /* doshell(), doexec() */
38 #include <mksh/misc.h> /* getmem() */
39 #include <sys/stat.h> /* open() */
40 #include <unistd.h> /* getpid() */
53 static int filter_file
;
54 static char *filter_file_name
;
57 * File table of contents
59 static void redirect_stderr(void);
62 * dosys(command, ignore_error, call_make, silent_error, target)
64 * Check if command string contains meta chars and dispatch to
65 * the proper routine for executing one command line.
68 * Indicates if the command execution failed
71 * command The command to run
72 * ignore_error Should make abort when an error is seen?
73 * call_make Did command reference $(MAKE) ?
74 * silent_error Should error messages be suppressed for pmake?
75 * target Target we are building
77 * Global variables used:
78 * do_not_exec_rule Is -n on?
79 * working_on_targets We started processing real targets
82 dosys(register Name command
, register Boolean ignore_error
, register Boolean call_make
, Boolean silent_error
, Boolean always_exec
, Name target
)
85 register int length
= command
->hash
.length
;
87 register wchar_t *p
= wcb
.get_string();
91 /* Strip spaces from head of command string */
92 while (iswspace(*p
)) {
95 if (*p
== (int) nul_char
) {
98 /* If we are faking it we just return */
99 if (do_not_exec_rule
&&
100 working_on_targets
&&
105 /* no_action_was_taken is used to print special message */
106 no_action_was_taken
= false;
108 /* Copy string to make it OK to write it. */
109 q
= ALLOC_WC(length
+ 1);
111 /* Write the state file iff this command uses make. */
112 if (call_make
&& command_changed
) {
113 write_state_file(0, false);
115 make_state
->stat
.time
= file_no_time
;
116 (void)exists(make_state
);
117 before
= make_state
->stat
.time
;
119 * Run command directly if it contains no shell meta chars,
120 * else run it using the shell.
122 if (await(ignore_error
,
127 doshell(q
, ignore_error
,
128 stdout_file
, stderr_file
, 0) :
129 doexec(q
, ignore_error
,
130 stdout_file
, stderr_file
,
137 result
= build_failed
;
141 if ((report_dependencies_level
== 0) &&
143 make_state
->stat
.time
= file_no_time
;
144 (void)exists(make_state
);
145 if (before
== make_state
->stat
.time
) {
148 makefile_type
= reading_statefile
;
149 if (read_trace_level
> 1) {
153 (void) read_simple_file(make_state
,
160 trace_reader
= false;