Print this page
make: unifdef for other OSes (undefined)
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
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 36 #if defined(TEAMWARE_MAKE_CMN) || defined(MAKETOOL) /* tolik */
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
37 37 # include <avo/util.h>
38 38 #endif
39 39
40 40 #include <mksh/dosys.h> /* redirect_io() */
41 41 #include <mksh/misc.h> /* retmem() */
42 42 #include <mksh/mksh.h>
43 43 #include <mksdmsi18n/mksdmsi18n.h>
44 44 #include <errno.h>
45 45 #include <signal.h>
46 46
47 -#ifdef HP_UX
48 - extern void (*sigset(int, void (*)(__harg)))(__harg);
49 -#endif
50 47
51 48 /*
52 49 * Workaround for NFS bug. Sometimes, when running 'chdir' on a remote
53 50 * dmake server, it fails with "Stale NFS file handle" error.
54 51 * The second attempt seems to work.
55 52 */
56 53 int
57 54 my_chdir(char * dir) {
58 55 int res = chdir(dir);
59 56 if (res != 0 && (errno == ESTALE || errno == EAGAIN)) {
60 57 /* Stale NFS file handle. Try again */
61 58 res = chdir(dir);
62 59 }
63 60 return res;
64 61 }
65 62
66 63
67 64 /*
68 65 * File table of contents
69 66 */
70 67 static void change_sunpro_dependencies_value(char *oldpath, char *newpath);
71 68 static void init_mksh_globals(char *shell);
72 69 static void set_env_vars(char *env_list[]);
73 70
74 71 #if defined(DISTRIBUTED) || defined(MAKETOOL) /* tolik */
75 72 /*
76 73 * Execute the command(s) of one Make or DMake rule
77 74 */
78 75 int
79 76 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)
80 77 {
81 78 Boolean always_exec_flag;
82 79 char *cmd;
83 80 Avo_DmakeCommand **cmd_list_p;
84 81 Name command;
85 82 Boolean do_not_exec_flag;
86 83 Boolean ignore_flag;
87 84 int length;
88 85 Boolean make_refd_flag;
89 86 Boolean meta_flag;
90 87 char pathname[MAXPATHLEN];
91 88 Doname result;
92 89 Boolean silent_flag;
93 90 wchar_t *tmp_wcs_buffer;
94 91
95 92 if ((childPid = fork()) < 0) { /* error */
96 93 ;
97 94 } else if (childPid > 0) { /* parent */
98 95 ;
99 96 } else { /* child, mksh */
100 97 (void) sigset(SIGCHLD, SIG_DFL);
101 98 enable_interrupt(handle_interrupt_mksh);
102 99 /* set environment variables */
103 100 set_env_vars(env_list);
104 101 /* redirect stdout and stderr to temp files */
105 102 dup2(1, 2); // Because fatal_mksh() prints error messages into
106 103 // stderr but dmake uses stderr for XDR communications
107 104 // and stdout for errors messages.
108 105 redirect_io(stdout_file, stderr_file);
109 106 /* try cd'ing to cwd */
110 107 if (my_chdir(cwd) != 0) {
111 108 /* try the netpath machine:pathname */
112 109 if (!avo_netpath_to_path(cnwd, pathname)) {
113 110 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 137, "`cd %s' failed, and conversion of %s to automounter pathname also failed: %s"), cwd, cnwd, strerror(errno));
114 111 } else if (my_chdir(pathname) != 0) {
115 112 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 138, "`cd %s' and `cd %s' both failed: %s"), cwd, pathname, strerror(errno));
116 113 }
117 114 /*
118 115 * change the value of SUNPRO_DEPENDENCIES
119 116 * to the new path.
120 117 */
121 118 change_sunpro_dependencies_value(cwd, pathname);
122 119 }
123 120 init_mksh_globals(shell);
124 121 for (cmd_list_p = cmd_list;
125 122 *cmd_list_p != (Avo_DmakeCommand *) NULL;
126 123 cmd_list_p++) {
127 124 if ((*cmd_list_p)->ignore()) {
128 125 ignore_flag = true;
129 126 } else {
130 127 ignore_flag = false;
131 128 }
132 129 if ((*cmd_list_p)->silent()) {
133 130 silent_flag = true;
134 131 } else {
135 132 silent_flag = false;
136 133 }
137 134 /*
138 135 if ((*cmd_list_p)->always_exec()) {
139 136 always_exec_flag = true;
140 137 } else {
141 138 always_exec_flag = false;
142 139 }
143 140 */
144 141 always_exec_flag = false;
145 142 if ((*cmd_list_p)->meta()) {
146 143 meta_flag = true;
147 144 } else {
148 145 meta_flag = false;
149 146 }
150 147 if ((*cmd_list_p)->make_refd()) {
151 148 make_refd_flag = true;
152 149 } else {
153 150 make_refd_flag = false;
154 151 }
155 152 if ((*cmd_list_p)->do_not_exec()) {
156 153 do_not_exec_flag = true;
157 154 } else {
158 155 do_not_exec_flag = false;
159 156 }
160 157 do_not_exec_rule = do_not_exec_flag;
161 158 cmd = (*cmd_list_p)->getCmd();
162 159 if ((length = strlen(cmd)) >= MAXPATHLEN) {
163 160 tmp_wcs_buffer = ALLOC_WC(length + 1);
164 161 (void) mbstowcs(tmp_wcs_buffer, cmd, length + 1);
165 162 command = GETNAME(tmp_wcs_buffer, FIND_LENGTH);
166 163 retmem(tmp_wcs_buffer);
167 164 } else {
168 165 MBSTOWCS(wcs_buffer, cmd);
169 166 command = GETNAME(wcs_buffer, FIND_LENGTH);
170 167 }
171 168 if ((command->hash.length > 0) &&
172 169 (!silent_flag || do_not_exec_flag)) {
173 170 (void) printf("%s\n", command->string_mb);
174 171 }
175 172 result = dosys_mksh(command,
176 173 ignore_flag,
177 174 make_refd_flag,
178 175 false, /* bugs #4085164 & #4990057 */
179 176 /* BOOLEAN(silent_flag && ignore_flag), */
180 177 always_exec_flag,
181 178 (Name) NULL,
182 179 false,
183 180 NULL,
184 181 NULL,
185 182 vroot_path,
186 183 nice_prio);
187 184 if (result == build_failed) {
188 185
189 186 #ifdef PRINT_EXIT_STATUS
190 187 warning_mksh(NOCATGETS("I'm in do_job(), and dosys_mksh() returned result of build_failed."));
191 188 #endif
192 189
193 190 if (silent_flag) {
194 191 (void) printf(catgets(libmksdmsi18n_catd, 1, 139, "The following command caused the error:\n%s\n"),
195 192 command->string_mb);
196 193 }
197 194 if (!ignore_flag && !ignore) {
198 195
199 196 #ifdef PRINT_EXIT_STATUS
200 197 warning_mksh(NOCATGETS("I'm in do_job(), and dosys_mksh() returned result of build_failed, exiting 1."));
201 198 #endif
202 199
203 200 exit(1);
204 201 }
205 202 }
206 203 }
207 204
208 205 #ifdef PRINT_EXIT_STATUS
209 206 warning_mksh(NOCATGETS("I'm in do_job(), exiting 0."));
210 207 #endif
211 208
212 209 exit(0);
213 210 }
214 211 return childPid;
215 212 }
216 213 #endif /* TEAMWARE_MAKE_CMN */
217 214
218 215 static void
219 216 set_env_vars(char *env_list[])
220 217 {
221 218 char **env_list_p;
222 219
223 220 for (env_list_p = env_list;
224 221 *env_list_p != (char *) NULL;
225 222 env_list_p++) {
226 223 putenv(*env_list_p);
227 224 }
228 225 }
229 226
230 227 static void
231 228 init_mksh_globals(char *shell)
232 229 {
233 230 /*
234 231 MBSTOWCS(wcs_buffer, NOCATGETS("SHELL"));
235 232 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
236 233 MBSTOWCS(wcs_buffer, shell);
237 234 (void) SETVAR(shell_name, GETNAME(wcs_buffer, FIND_LENGTH), false);
238 235 */
239 236 char * dmake_shell;
240 237 if ((dmake_shell = getenv(NOCATGETS("DMAKE_SHELL"))) == NULL) {
241 238 dmake_shell = shell;
242 239 }
243 240 MBSTOWCS(wcs_buffer, dmake_shell);
244 241 shell_name = GETNAME(wcs_buffer, FIND_LENGTH);
245 242 }
246 243
247 244 /*
248 245 * Change the pathname in the value of the SUNPRO_DEPENDENCIES env variable
249 246 * from oldpath to newpath.
250 247 */
251 248 static void
252 249 change_sunpro_dependencies_value(char *oldpath, char *newpath)
253 250 {
254 251 char buf[MAXPATHLEN];
255 252 static char *env;
256 253 int length;
257 254 int oldpathlen;
258 255 char *sp_dep_value;
259 256
260 257 /* check if SUNPRO_DEPENDENCIES is set in the environment */
261 258 if ((sp_dep_value = getenv(NOCATGETS("SUNPRO_DEPENDENCIES"))) != NULL) {
262 259 oldpathlen = strlen(oldpath);
263 260 /* check if oldpath is indeed in the value of SUNPRO_DEPENDENCIES */
264 261 if (strncmp(oldpath, sp_dep_value, oldpathlen) == 0) {
265 262 (void) sprintf(buf,
266 263 "%s%s",
267 264 newpath,
268 265 sp_dep_value + oldpathlen);
269 266 length = 2 +
270 267 strlen(NOCATGETS("SUNPRO_DEPENDENCIES")) +
271 268 strlen(buf);
272 269 env = getmem(length);
273 270 (void) sprintf(env,
274 271 "%s=%s",
275 272 NOCATGETS("SUNPRO_DEPENDENCIES"),
276 273 buf);
277 274 (void) putenv(env);
278 275 }
279 276 }
280 277 }
281 278
282 279
↓ open down ↓ |
223 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX