Print this page
make: ship the Joyent patch to enable parallel make (originally from rm)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/lib/mksh/mksh.cc
+++ new/usr/src/cmd/make/lib/mksh/mksh.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
↓ open down ↓ |
25 lines elided |
↑ open up ↑ |
26 26
27 27 /*
28 28 * mksh.cc
29 29 *
30 30 * Execute the command(s) of one Make or DMake rule
31 31 */
32 32
33 33 /*
34 34 * Included files
35 35 */
36 -#if defined(TEAMWARE_MAKE_CMN) || defined(MAKETOOL) /* tolik */
37 -# include <avo/util.h>
38 -#endif
39 -
40 36 #include <mksh/dosys.h> /* redirect_io() */
41 37 #include <mksh/misc.h> /* retmem() */
42 38 #include <mksh/mksh.h>
43 39 #include <mksdmsi18n/mksdmsi18n.h>
44 40 #include <errno.h>
45 41 #include <signal.h>
46 42
47 43
48 44 /*
49 45 * Workaround for NFS bug. Sometimes, when running 'chdir' on a remote
50 46 * dmake server, it fails with "Stale NFS file handle" error.
51 47 * The second attempt seems to work.
52 48 */
53 49 int
54 50 my_chdir(char * dir) {
55 51 int res = chdir(dir);
56 52 if (res != 0 && (errno == ESTALE || errno == EAGAIN)) {
57 53 /* Stale NFS file handle. Try again */
58 54 res = chdir(dir);
59 55 }
60 56 return res;
61 57 }
62 58
63 59
64 60 /*
65 61 * File table of contents
66 62 */
67 63 static void change_sunpro_dependencies_value(char *oldpath, char *newpath);
68 64 static void init_mksh_globals(char *shell);
69 65 static void set_env_vars(char *env_list[]);
70 66
71 67 #if defined(DISTRIBUTED) || defined(MAKETOOL) /* tolik */
72 68 /*
73 69 * Execute the command(s) of one Make or DMake rule
74 70 */
75 71 int
76 72 do_job(Avo_DmakeCommand *cmd_list[], char *env_list[], char *stdout_file, char *stderr_file, char *cwd, char *cnwd, int ignore, int silent, pathpt vroot_path, char *shell, int nice_prio)
77 73 {
78 74 Boolean always_exec_flag;
79 75 char *cmd;
80 76 Avo_DmakeCommand **cmd_list_p;
81 77 Name command;
82 78 Boolean do_not_exec_flag;
83 79 Boolean ignore_flag;
84 80 int length;
85 81 Boolean make_refd_flag;
86 82 Boolean meta_flag;
87 83 char pathname[MAXPATHLEN];
88 84 Doname result;
89 85 Boolean silent_flag;
90 86 wchar_t *tmp_wcs_buffer;
91 87
92 88 if ((childPid = fork()) < 0) { /* error */
93 89 ;
94 90 } else if (childPid > 0) { /* parent */
95 91 ;
96 92 } else { /* child, mksh */
97 93 (void) sigset(SIGCHLD, SIG_DFL);
98 94 enable_interrupt(handle_interrupt_mksh);
99 95 /* set environment variables */
100 96 set_env_vars(env_list);
101 97 /* redirect stdout and stderr to temp files */
102 98 dup2(1, 2); // Because fatal_mksh() prints error messages into
103 99 // stderr but dmake uses stderr for XDR communications
104 100 // and stdout for errors messages.
105 101 redirect_io(stdout_file, stderr_file);
106 102 /* try cd'ing to cwd */
107 103 if (my_chdir(cwd) != 0) {
108 104 /* try the netpath machine:pathname */
109 105 if (!avo_netpath_to_path(cnwd, pathname)) {
110 106 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 137, "`cd %s' failed, and conversion of %s to automounter pathname also failed: %s"), cwd, cnwd, strerror(errno));
111 107 } else if (my_chdir(pathname) != 0) {
112 108 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 138, "`cd %s' and `cd %s' both failed: %s"), cwd, pathname, strerror(errno));
113 109 }
114 110 /*
115 111 * change the value of SUNPRO_DEPENDENCIES
116 112 * to the new path.
117 113 */
118 114 change_sunpro_dependencies_value(cwd, pathname);
119 115 }
120 116 init_mksh_globals(shell);
121 117 for (cmd_list_p = cmd_list;
122 118 *cmd_list_p != (Avo_DmakeCommand *) NULL;
123 119 cmd_list_p++) {
124 120 if ((*cmd_list_p)->ignore()) {
125 121 ignore_flag = true;
126 122 } else {
127 123 ignore_flag = false;
128 124 }
129 125 if ((*cmd_list_p)->silent()) {
130 126 silent_flag = true;
131 127 } else {
132 128 silent_flag = false;
133 129 }
134 130 /*
135 131 if ((*cmd_list_p)->always_exec()) {
136 132 always_exec_flag = true;
137 133 } else {
138 134 always_exec_flag = false;
139 135 }
140 136 */
141 137 always_exec_flag = false;
142 138 if ((*cmd_list_p)->meta()) {
143 139 meta_flag = true;
144 140 } else {
145 141 meta_flag = false;
146 142 }
147 143 if ((*cmd_list_p)->make_refd()) {
148 144 make_refd_flag = true;
149 145 } else {
150 146 make_refd_flag = false;
151 147 }
152 148 if ((*cmd_list_p)->do_not_exec()) {
153 149 do_not_exec_flag = true;
154 150 } else {
155 151 do_not_exec_flag = false;
156 152 }
157 153 do_not_exec_rule = do_not_exec_flag;
158 154 cmd = (*cmd_list_p)->getCmd();
159 155 if ((length = strlen(cmd)) >= MAXPATHLEN) {
160 156 tmp_wcs_buffer = ALLOC_WC(length + 1);
161 157 (void) mbstowcs(tmp_wcs_buffer, cmd, length + 1);
162 158 command = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
163 159 retmem(tmp_wcs_buffer);
164 160 } else {
165 161 MBSTOWCS(wcs_buffer, cmd);
166 162 command = GETNAME(wcs_buffer, FIND_LENGTH);
167 163 }
168 164 if ((command->hash.length > 0) &&
169 165 (!silent_flag || do_not_exec_flag)) {
170 166 (void) printf("%s\n", command->string_mb);
171 167 }
172 168 result = dosys_mksh(command,
173 169 ignore_flag,
174 170 make_refd_flag,
175 171 false, /* bugs #4085164 & #4990057 */
176 172 /* BOOLEAN(silent_flag && ignore_flag), */
177 173 always_exec_flag,
178 174 (Name) NULL,
179 175 false,
180 176 NULL,
181 177 NULL,
182 178 vroot_path,
183 179 nice_prio);
184 180 if (result == build_failed) {
185 181
186 182 #ifdef PRINT_EXIT_STATUS
187 183 warning_mksh(NOCATGETS("I'm in do_job(), and dosys_mksh() returned result of build_failed."));
188 184 #endif
189 185
190 186 if (silent_flag) {
191 187 (void) printf(catgets(libmksdmsi18n_catd, 1, 139, "The following command caused the error:\n%s\n"),
192 188 command->string_mb);
193 189 }
194 190 if (!ignore_flag && !ignore) {
195 191
196 192 #ifdef PRINT_EXIT_STATUS
197 193 warning_mksh(NOCATGETS("I'm in do_job(), and dosys_mksh() returned result of build_failed, exiting 1."));
198 194 #endif
199 195
200 196 exit(1);
201 197 }
202 198 }
203 199 }
204 200
205 201 #ifdef PRINT_EXIT_STATUS
206 202 warning_mksh(NOCATGETS("I'm in do_job(), exiting 0."));
207 203 #endif
208 204
209 205 exit(0);
210 206 }
211 207 return childPid;
212 208 }
213 209 #endif /* TEAMWARE_MAKE_CMN */
214 210
215 211 static void
216 212 set_env_vars(char *env_list[])
217 213 {
218 214 char **env_list_p;
219 215
220 216 for (env_list_p = env_list;
221 217 *env_list_p != (char *) NULL;
222 218 env_list_p++) {
223 219 putenv(*env_list_p);
224 220 }
225 221 }
226 222
227 223 static void
228 224 init_mksh_globals(char *shell)
229 225 {
230 226 /*
231 227 MBSTOWCS(wcs_buffer, NOCATGETS("SHELL"));
232 228 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
233 229 MBSTOWCS(wcs_buffer, shell);
234 230 (void) SETVAR(shell_name, GETNAME(wcs_buffer, FIND_LENGTH), false);
235 231 */
236 232 char * dmake_shell;
237 233 if ((dmake_shell = getenv(NOCATGETS("DMAKE_SHELL"))) == NULL) {
238 234 dmake_shell = shell;
239 235 }
240 236 MBSTOWCS(wcs_buffer, dmake_shell);
241 237 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
242 238 }
243 239
244 240 /*
245 241 * Change the pathname in the value of the SUNPRO_DEPENDENCIES env variable
246 242 * from oldpath to newpath.
247 243 */
248 244 static void
249 245 change_sunpro_dependencies_value(char *oldpath, char *newpath)
250 246 {
251 247 char buf[MAXPATHLEN];
252 248 static char *env;
253 249 int length;
254 250 int oldpathlen;
255 251 char *sp_dep_value;
256 252
257 253 /* check if SUNPRO_DEPENDENCIES is set in the environment */
258 254 if ((sp_dep_value = getenv(NOCATGETS("SUNPRO_DEPENDENCIES"))) != NULL) {
259 255 oldpathlen = strlen(oldpath);
260 256 /* check if oldpath is indeed in the value of SUNPRO_DEPENDENCIES */
261 257 if (strncmp(oldpath, sp_dep_value, oldpathlen) == 0) {
262 258 (void) sprintf(buf,
263 259 "%s%s",
264 260 newpath,
265 261 sp_dep_value + oldpathlen);
266 262 length = 2 +
267 263 strlen(NOCATGETS("SUNPRO_DEPENDENCIES")) +
268 264 strlen(buf);
269 265 env = getmem(length);
270 266 (void) sprintf(env,
271 267 "%s=%s",
272 268 NOCATGETS("SUNPRO_DEPENDENCIES"),
273 269 buf);
274 270 (void) putenv(env);
275 271 }
276 272 }
277 273 }
278 274
279 275
↓ open down ↓ |
230 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX