Wed Dec 15 10:04:49 2021 UTC ()
make: change return type of Compat_RunCommand from int to bool

The documentation was wrong before since status was not restricted to
only 0 or 1.

No functional change.


(rillig)
diff -r1.229 -r1.230 src/usr.bin/make/compat.c
diff -r1.440 -r1.441 src/usr.bin/make/job.c
diff -r1.219 -r1.220 src/usr.bin/make/nonints.h

cvs diff -r1.229 -r1.230 src/usr.bin/make/compat.c (expand / switch to unified diff)

--- src/usr.bin/make/compat.c 2021/11/28 23:12:51 1.229
+++ src/usr.bin/make/compat.c 2021/12/15 10:04:49 1.230
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: compat.c,v 1.229 2021/11/28 23:12:51 rillig Exp $ */ 1/* $NetBSD: compat.c,v 1.230 2021/12/15 10:04:49 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -86,27 +86,27 @@ @@ -86,27 +86,27 @@
86#include <sys/stat.h> 86#include <sys/stat.h>
87#include <sys/wait.h> 87#include <sys/wait.h>
88 88
89#include <errno.h> 89#include <errno.h>
90#include <signal.h> 90#include <signal.h>
91 91
92#include "make.h" 92#include "make.h"
93#include "dir.h" 93#include "dir.h"
94#include "job.h" 94#include "job.h"
95#include "metachar.h" 95#include "metachar.h"
96#include "pathnames.h" 96#include "pathnames.h"
97 97
98/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */ 98/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
99MAKE_RCSID("$NetBSD: compat.c,v 1.229 2021/11/28 23:12:51 rillig Exp $"); 99MAKE_RCSID("$NetBSD: compat.c,v 1.230 2021/12/15 10:04:49 rillig Exp $");
100 100
101static GNode *curTarg = NULL; 101static GNode *curTarg = NULL;
102static pid_t compatChild; 102static pid_t compatChild;
103static int compatSigno; 103static int compatSigno;
104 104
105/* 105/*
106 * CompatDeleteTarget -- delete the file of a failed, interrupted, or 106 * CompatDeleteTarget -- delete the file of a failed, interrupted, or
107 * otherwise duffed target if not inhibited by .PRECIOUS. 107 * otherwise duffed target if not inhibited by .PRECIOUS.
108 */ 108 */
109static void 109static void
110CompatDeleteTarget(GNode *gn) 110CompatDeleteTarget(GNode *gn)
111{ 111{
112 if (gn != NULL && !Targ_Precious(gn)) { 112 if (gn != NULL && !Targ_Precious(gn)) {
@@ -207,122 +207,122 @@ UseShell(const char *cmd MAKE_ATTR_UNUSE @@ -207,122 +207,122 @@ UseShell(const char *cmd MAKE_ATTR_UNUSE
207#endif 207#endif
208} 208}
209 209
210/* 210/*
211 * Execute the next command for a target. If the command returns an error, 211 * Execute the next command for a target. If the command returns an error,
212 * the node's made field is set to ERROR and creation stops. 212 * the node's made field is set to ERROR and creation stops.
213 * 213 *
214 * Input: 214 * Input:
215 * cmdp Command to execute 215 * cmdp Command to execute
216 * gn Node from which the command came 216 * gn Node from which the command came
217 * ln List node that contains the command 217 * ln List node that contains the command
218 * 218 *
219 * Results: 219 * Results:
220 * 0 if the command succeeded, 1 if an error occurred. 220 * true if the command succeeded.
221 */ 221 */
222int 222bool
223Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln) 223Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
224{ 224{
225 char *cmdStart; /* Start of expanded command */ 225 char *cmdStart; /* Start of expanded command */
226 char *bp; 226 char *bp;
227 bool silent; /* Don't print command */ 227 bool silent; /* Don't print command */
228 bool doIt; /* Execute even if -n */ 228 bool doIt; /* Execute even if -n */
229 volatile bool errCheck; /* Check errors */ 229 volatile bool errCheck; /* Check errors */
230 int reason; /* Reason for child's death */ 230 int reason; /* Reason for child's death */
231 int status; /* Description of child's death */ 231 int status; /* Description of child's death */
232 pid_t cpid; /* Child actually found */ 232 pid_t cpid; /* Child actually found */
233 pid_t retstat; /* Result of wait */ 233 pid_t retstat; /* Result of wait */
234 const char **volatile av; /* Argument vector for thing to exec */ 234 const char **volatile av; /* Argument vector for thing to exec */
235 char **volatile mav; /* Copy of the argument vector for freeing */ 235 char **volatile mav; /* Copy of the argument vector for freeing */
236 bool useShell; /* True if command should be executed 236 bool useShell; /* True if command should be executed
237 * using a shell */ 237 * using a shell */
238 const char *volatile cmd = cmdp; 238 const char *volatile cmd = cmdp;
239 239
240 silent = (gn->type & OP_SILENT) != OP_NONE; 240 silent = (gn->type & OP_SILENT) != OP_NONE;
241 errCheck = !(gn->type & OP_IGNORE); 241 errCheck = !(gn->type & OP_IGNORE);
242 doIt = false; 242 doIt = false;
243 243
244 (void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart); 244 (void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart);
245 /* TODO: handle errors */ 245 /* TODO: handle errors */
246 246
247 if (cmdStart[0] == '\0') { 247 if (cmdStart[0] == '\0') {
248 free(cmdStart); 248 free(cmdStart);
249 return 0; 249 return true;
250 } 250 }
251 cmd = cmdStart; 251 cmd = cmdStart;
252 LstNode_Set(ln, cmdStart); 252 LstNode_Set(ln, cmdStart);
253 253
254 if (gn->type & OP_SAVE_CMDS) { 254 if (gn->type & OP_SAVE_CMDS) {
255 GNode *endNode = Targ_GetEndNode(); 255 GNode *endNode = Targ_GetEndNode();
256 if (gn != endNode) { 256 if (gn != endNode) {
257 /* 257 /*
258 * Append the expanded command, to prevent the 258 * Append the expanded command, to prevent the
259 * local variables from being interpreted in the 259 * local variables from being interpreted in the
260 * scope of the .END node. 260 * scope of the .END node.
261 * 261 *
262 * A probably unintended side effect of this is that 262 * A probably unintended side effect of this is that
263 * the expanded command will be expanded again in the 263 * the expanded command will be expanded again in the
264 * .END node. Therefore, a literal '$' in these 264 * .END node. Therefore, a literal '$' in these
265 * commands must be written as '$$$$' instead of the 265 * commands must be written as '$$$$' instead of the
266 * usual '$$'. 266 * usual '$$'.
267 */ 267 */
268 Lst_Append(&endNode->commands, cmdStart); 268 Lst_Append(&endNode->commands, cmdStart);
269 return 0; 269 return true;
270 } 270 }
271 } 271 }
272 if (strcmp(cmdStart, "...") == 0) { 272 if (strcmp(cmdStart, "...") == 0) {
273 gn->type |= OP_SAVE_CMDS; 273 gn->type |= OP_SAVE_CMDS;
274 return 0; 274 return true;
275 } 275 }
276 276
277 for (;;) { 277 for (;;) {
278 if (*cmd == '@') 278 if (*cmd == '@')
279 silent = !DEBUG(LOUD); 279 silent = !DEBUG(LOUD);
280 else if (*cmd == '-') 280 else if (*cmd == '-')
281 errCheck = false; 281 errCheck = false;
282 else if (*cmd == '+') { 282 else if (*cmd == '+') {
283 doIt = true; 283 doIt = true;
284 if (shellName == NULL) /* we came here from jobs */ 284 if (shellName == NULL) /* we came here from jobs */
285 Shell_Init(); 285 Shell_Init();
286 } else 286 } else
287 break; 287 break;
288 cmd++; 288 cmd++;
289 } 289 }
290 290
291 while (ch_isspace(*cmd)) 291 while (ch_isspace(*cmd))
292 cmd++; 292 cmd++;
293 293
294 /* 294 /*
295 * If we did not end up with a command, just skip it. 295 * If we did not end up with a command, just skip it.
296 */ 296 */
297 if (cmd[0] == '\0') 297 if (cmd[0] == '\0')
298 return 0; 298 return true;
299 299
300 useShell = UseShell(cmd); 300 useShell = UseShell(cmd);
301 /* 301 /*
302 * Print the command before echoing if we're not supposed to be quiet 302 * Print the command before echoing if we're not supposed to be quiet
303 * for this one. We also print the command if -n given. 303 * for this one. We also print the command if -n given.
304 */ 304 */
305 if (!silent || !GNode_ShouldExecute(gn)) { 305 if (!silent || !GNode_ShouldExecute(gn)) {
306 printf("%s\n", cmd); 306 printf("%s\n", cmd);
307 fflush(stdout); 307 fflush(stdout);
308 } 308 }
309 309
310 /* 310 /*
311 * If we're not supposed to execute any commands, this is as far as 311 * If we're not supposed to execute any commands, this is as far as
312 * we go... 312 * we go...
313 */ 313 */
314 if (!doIt && !GNode_ShouldExecute(gn)) 314 if (!doIt && !GNode_ShouldExecute(gn))
315 return 0; 315 return true;
316 316
317 DEBUG1(JOB, "Execute: '%s'\n", cmd); 317 DEBUG1(JOB, "Execute: '%s'\n", cmd);
318 318
319 if (useShell) { 319 if (useShell) {
320 /* 320 /*
321 * We need to pass the command off to the shell, typically 321 * We need to pass the command off to the shell, typically
322 * because the command contains a "meta" character. 322 * because the command contains a "meta" character.
323 */ 323 */
324 static const char *shargv[5]; 324 static const char *shargv[5];
325 325
326 /* The following work for any of the builtin shell specs. */ 326 /* The following work for any of the builtin shell specs. */
327 int shargc = 0; 327 int shargc = 0;
328 shargv[shargc++] = shellPath; 328 shargv[shargc++] = shellPath;
@@ -444,37 +444,37 @@ Compat_RunCommand(const char *cmdp, GNod @@ -444,37 +444,37 @@ Compat_RunCommand(const char *cmdp, GNod
444 */ 444 */
445 printf(" (ignored)\n"); 445 printf(" (ignored)\n");
446 status = 0; 446 status = 0;
447 } 447 }
448 } 448 }
449 449
450 free(cmdStart); 450 free(cmdStart);
451 compatChild = 0; 451 compatChild = 0;
452 if (compatSigno != 0) { 452 if (compatSigno != 0) {
453 bmake_signal(compatSigno, SIG_DFL); 453 bmake_signal(compatSigno, SIG_DFL);
454 kill(myPid, compatSigno); 454 kill(myPid, compatSigno);
455 } 455 }
456 456
457 return status; 457 return status == 0;
458} 458}
459 459
460static void 460static void
461RunCommands(GNode *gn) 461RunCommands(GNode *gn)
462{ 462{
463 StringListNode *ln; 463 StringListNode *ln;
464 464
465 for (ln = gn->commands.first; ln != NULL; ln = ln->next) { 465 for (ln = gn->commands.first; ln != NULL; ln = ln->next) {
466 const char *cmd = ln->datum; 466 const char *cmd = ln->datum;
467 if (Compat_RunCommand(cmd, gn, ln) != 0) 467 if (!Compat_RunCommand(cmd, gn, ln))
468 break; 468 break;
469 } 469 }
470} 470}
471 471
472static void 472static void
473MakeNodes(GNodeList *gnodes, GNode *pgn) 473MakeNodes(GNodeList *gnodes, GNode *pgn)
474{ 474{
475 GNodeListNode *ln; 475 GNodeListNode *ln;
476 476
477 for (ln = gnodes->first; ln != NULL; ln = ln->next) { 477 for (ln = gnodes->first; ln != NULL; ln = ln->next) {
478 GNode *cohort = ln->datum; 478 GNode *cohort = ln->datum;
479 Compat_Make(cohort, pgn); 479 Compat_Make(cohort, pgn);
480 } 480 }

cvs diff -r1.440 -r1.441 src/usr.bin/make/job.c (expand / switch to unified diff)

--- src/usr.bin/make/job.c 2021/11/28 19:51:06 1.440
+++ src/usr.bin/make/job.c 2021/12/15 10:04:49 1.441
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: job.c,v 1.440 2021/11/28 19:51:06 rillig Exp $ */ 1/* $NetBSD: job.c,v 1.441 2021/12/15 10:04:49 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -132,27 +132,27 @@ @@ -132,27 +132,27 @@
132#ifndef USE_SELECT 132#ifndef USE_SELECT
133#include <poll.h> 133#include <poll.h>
134#endif 134#endif
135#include <signal.h> 135#include <signal.h>
136#include <utime.h> 136#include <utime.h>
137 137
138#include "make.h" 138#include "make.h"
139#include "dir.h" 139#include "dir.h"
140#include "job.h" 140#include "job.h"
141#include "pathnames.h" 141#include "pathnames.h"
142#include "trace.h" 142#include "trace.h"
143 143
144/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */ 144/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
145MAKE_RCSID("$NetBSD: job.c,v 1.440 2021/11/28 19:51:06 rillig Exp $"); 145MAKE_RCSID("$NetBSD: job.c,v 1.441 2021/12/15 10:04:49 rillig Exp $");
146 146
147/* 147/*
148 * A shell defines how the commands are run. All commands for a target are 148 * A shell defines how the commands are run. All commands for a target are
149 * written into a single file, which is then given to the shell to execute 149 * written into a single file, which is then given to the shell to execute
150 * the commands from it. The commands are written to the file using a few 150 * the commands from it. The commands are written to the file using a few
151 * templates for echo control and error control. 151 * templates for echo control and error control.
152 * 152 *
153 * The name of the shell is the basename for the predefined shells, such as 153 * The name of the shell is the basename for the predefined shells, such as
154 * "sh", "csh", "bash". For custom shells, it is the full pathname, and its 154 * "sh", "csh", "bash". For custom shells, it is the full pathname, and its
155 * basename is used to select the type of shell; the longest match wins. 155 * basename is used to select the type of shell; the longest match wins.
156 * So /usr/pkg/bin/bash has type sh, /usr/local/bin/tcsh has type csh. 156 * So /usr/pkg/bin/bash has type sh, /usr/local/bin/tcsh has type csh.
157 * 157 *
158 * The echoing of command lines is controlled using hasEchoCtl, echoOff, 158 * The echoing of command lines is controlled using hasEchoCtl, echoOff,
@@ -901,41 +901,41 @@ static void @@ -901,41 +901,41 @@ static void
901JobWriteCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd) 901JobWriteCommand(Job *job, ShellWriter *wr, StringListNode *ln, const char *ucmd)
902{ 902{
903 bool run; 903 bool run;
904 904
905 CommandFlags cmdFlags; 905 CommandFlags cmdFlags;
906 /* Template for writing a command to the shell file */ 906 /* Template for writing a command to the shell file */
907 const char *cmdTemplate; 907 const char *cmdTemplate;
908 char *xcmd; /* The expanded command */ 908 char *xcmd; /* The expanded command */
909 char *xcmdStart; 909 char *xcmdStart;
910 char *escCmd; /* xcmd escaped to be used in double quotes */ 910 char *escCmd; /* xcmd escaped to be used in double quotes */
911 911
912 run = GNode_ShouldExecute(job->node); 912 run = GNode_ShouldExecute(job->node);
913 913
914 Var_Subst(ucmd, job->node, VARE_WANTRES, &xcmd); 914 (void)Var_Subst(ucmd, job->node, VARE_WANTRES, &xcmd);
915 /* TODO: handle errors */ 915 /* TODO: handle errors */
916 xcmdStart = xcmd; 916 xcmdStart = xcmd;
917 917
918 cmdTemplate = "%s\n"; 918 cmdTemplate = "%s\n";
919 919
920 ParseCommandFlags(&xcmd, &cmdFlags); 920 ParseCommandFlags(&xcmd, &cmdFlags);
921 921
922 /* The '+' command flag overrides the -n or -N options. */ 922 /* The '+' command flag overrides the -n or -N options. */
923 if (cmdFlags.always && !run) { 923 if (cmdFlags.always && !run) {
924 /* 924 /*
925 * We're not actually executing anything... 925 * We're not actually executing anything...
926 * but this one needs to be - use compat mode just for it. 926 * but this one needs to be - use compat mode just for it.
927 */ 927 */
928 Compat_RunCommand(ucmd, job->node, ln); 928 (void)Compat_RunCommand(ucmd, job->node, ln);
929 free(xcmdStart); 929 free(xcmdStart);
930 return; 930 return;
931 } 931 }
932 932
933 /* 933 /*
934 * If the shell doesn't have error control, the alternate echoing 934 * If the shell doesn't have error control, the alternate echoing
935 * will be done (to avoid showing additional error checking code) 935 * will be done (to avoid showing additional error checking code)
936 * and this needs some characters escaped. 936 * and this needs some characters escaped.
937 */ 937 */
938 escCmd = shell->hasErrCtl ? NULL : EscapeShellDblQuot(xcmd); 938 escCmd = shell->hasErrCtl ? NULL : EscapeShellDblQuot(xcmd);
939 939
940 if (!cmdFlags.echo) { 940 if (!cmdFlags.echo) {
941 if (job->echo && run && shell->hasEchoCtl) { 941 if (job->echo && run && shell->hasEchoCtl) {

cvs diff -r1.219 -r1.220 src/usr.bin/make/Attic/nonints.h (expand / switch to unified diff)

--- src/usr.bin/make/Attic/nonints.h 2021/12/15 09:53:41 1.219
+++ src/usr.bin/make/Attic/nonints.h 2021/12/15 10:04:49 1.220
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nonints.h,v 1.219 2021/12/15 09:53:41 rillig Exp $ */ 1/* $NetBSD: nonints.h,v 1.220 2021/12/15 10:04:49 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -76,27 +76,27 @@ @@ -76,27 +76,27 @@
76void Arch_Init(void); 76void Arch_Init(void);
77void Arch_End(void); 77void Arch_End(void);
78 78
79bool Arch_ParseArchive(char **, GNodeList *, GNode *); 79bool Arch_ParseArchive(char **, GNodeList *, GNode *);
80void Arch_Touch(GNode *); 80void Arch_Touch(GNode *);
81void Arch_TouchLib(GNode *); 81void Arch_TouchLib(GNode *);
82void Arch_UpdateMTime(GNode *gn); 82void Arch_UpdateMTime(GNode *gn);
83void Arch_UpdateMemberMTime(GNode *gn); 83void Arch_UpdateMemberMTime(GNode *gn);
84void Arch_FindLib(GNode *, SearchPath *); 84void Arch_FindLib(GNode *, SearchPath *);
85bool Arch_LibOODate(GNode *) MAKE_ATTR_USE; 85bool Arch_LibOODate(GNode *) MAKE_ATTR_USE;
86bool Arch_IsLib(GNode *) MAKE_ATTR_USE; 86bool Arch_IsLib(GNode *) MAKE_ATTR_USE;
87 87
88/* compat.c */ 88/* compat.c */
89int Compat_RunCommand(const char *, GNode *, StringListNode *); 89bool Compat_RunCommand(const char *, GNode *, StringListNode *);
90void Compat_Run(GNodeList *); 90void Compat_Run(GNodeList *);
91void Compat_Make(GNode *, GNode *); 91void Compat_Make(GNode *, GNode *);
92 92
93/* cond.c */ 93/* cond.c */
94CondEvalResult Cond_EvalCondition(const char *, bool *) MAKE_ATTR_USE; 94CondEvalResult Cond_EvalCondition(const char *, bool *) MAKE_ATTR_USE;
95CondEvalResult Cond_EvalLine(const char *) MAKE_ATTR_USE; 95CondEvalResult Cond_EvalLine(const char *) MAKE_ATTR_USE;
96void Cond_restore_depth(unsigned int); 96void Cond_restore_depth(unsigned int);
97unsigned int Cond_save_depth(void) MAKE_ATTR_USE; 97unsigned int Cond_save_depth(void) MAKE_ATTR_USE;
98 98
99/* dir.c; see also dir.h */ 99/* dir.c; see also dir.h */
100 100
101MAKE_INLINE const char * MAKE_ATTR_USE 101MAKE_INLINE const char * MAKE_ATTR_USE
102str_basename(const char *pathname) 102str_basename(const char *pathname)