Commit Graph

153 Commits

Author SHA1 Message Date
sjg 55b9a99afa wait[pid]() is called in several places.
If we encounter an error and run the .ERROR target, we may
reap a pid which jobs is waiting for.  Ensure that we
cleanup so that make isn't left waiting for an already
deceased child.
2010-08-07 06:44:08 +00:00
christos 703b8bafda PR/43643: David A. Holland: dash prefix broken with make -j
As the comment says in JobPrintJob set JOB_IGNERR with - commands. Fix
whitespace so that the output is consistent, although there are two separate
execution logic implementations (command.c, job.c)
2010-07-20 16:39:27 +00:00
sjg aa86bc2068 JobFinish: call PrintOnError if we detected an error we are not ignoring.
This gives the .ERROR target a chance to run at the first sign of trouble.
2010-06-17 03:36:05 +00:00
sjg 945e78bffe We have required sigaction() for quite a while.
Use bmake_signal() - a wrapper around sigaction()
rather than signal() to ensure that signals are handled
consistently.
2010-06-03 15:40:15 +00:00
sjg 24157036cd On darwin at least, vfork() fails in child of vfork().
It probably shouldn't work anyway, so avoid this.
We use the macro vFork() - a function seems to cause problems
and is unnecessary overhead.
2010-04-23 00:18:50 +00:00
sjg a71a4119cf Just because $TMPDIR is set does not mean it is valid.
Add a central function for creating temp files so we have one place to
audit.

Reviewed by: dh
2010-04-22 19:11:17 +00:00
sjg b6e2a6c85f Add:
.error "message"
.warning "message"
	based on FreeBSD implementation.
	add .info while were at it.

.ERROR:	a target to run on error.
	We pass the failing GNode to PrintOnError so it can set
	.ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
	As a means to control make's list of prefered makefile names.
	(Default: "makefile Makefile")

.MAKE.DEPENDFILE
	Names the file to read dependencies from
	(Default ".depend")

.MAKE.MODE
	Processed after all makefiles are read.
	Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.
2010-04-07 00:11:27 +00:00
sjg dd8e1ba252 JobExec: child of vfork must not empty the sigset_t that parent will
restore.  Use a separate mask.
2009-06-26 01:26:32 +00:00
apb af9429a671 Honour the TMPDIR environment variable instead of always using /tmp
as a place to store temporary files.
2009-04-11 09:41:18 +00:00
dsl 0cbb4ab551 Change 'ClientData' to 'void *' so that relevant parameters can
be made 'const void *'.
2009-01-23 21:26:30 +00:00
christos cd056136e4 if brk_string fail, so do we. 2008-12-19 22:03:41 +00:00
dsl 8a143811b9 Use NULL instead of -1 cast to the relavant type (usually via NIL).
This was a suggestion from christos - so blame him if there is a deep
reason for using -1 :-)
2008-12-13 15:19:29 +00:00
sjg 16d084a837 If Parse_Error is called after curFile is invalid, set it to a dummy
to avoid seg-fault.  Also the NULL filename will cause ParseVErrorInternal
to skip trying to report file and line number info.

If CondToken is called outside the context of a .if etc, variables in
the expression being parsed will already be expanded, so allow for
an unqouted number to jump us back into the compare logic.
This allows ${${SomeNumber:U42} > 0:?True:False} to work anywhere.

Job_Finish should process postCommands if it has commands or children.
2008-10-29 15:37:08 +00:00
joerg bd681a4d7e Don't use emalloc and friends directly, but call them consistently
bmake_malloc and friends. Implement them via macros for the native case
and provide fallback implementations otherwise. Avoid polluting the
namespace by not defining enomem globally. Don't bother to provide
strdup and strndup, they were only used for the estrdup and estrndup
comapt code.

This addresses the presence of emalloc in system libraries on A/UX and
resulted strange issues as reported by Timothy E. Larson.
2008-10-06 22:09:21 +00:00
christos a686e4e754 back all changes out until I fix it properly. 2008-02-15 21:29:50 +00:00
christos 4b3df4502b Improve dh's fix:
- make sure i is initialized
	- don't subtract 1 in comparison, add 1 to the other side
2008-02-15 20:08:11 +00:00
dholland a9c8da72a1 Avoid SIGSEGV caused by signed/unsigned mismatch. (hi xtos) 2008-02-15 08:55:31 +00:00
christos 2b28370627 - use pid_t/size_t as appropriate instead of int.
- use %ld to print pids.
- fix a bit of lint.
- WARNS=4
2008-02-14 22:11:20 +00:00
sjg 807aff24d0 Implement -dl (aka LOUD) to override '@' at the start of script lines.
Based on supplied patch.

PR: 37202
2008-01-19 06:52:13 +00:00
dsl 2cdb58761e If make can't find a rule to create a file it needs to satisfy a rule
that came from .depend then just output a message and contine.
2007-12-21 20:32:24 +00:00
apb d15c1edea0 Make it easier for the build environment (such as a configure script)
to override the default shell:

* Rename _BASENAME_DEFSHELL to DEFSHELL_CUSTOM, because it's no longer
  always a basename, it might be a full path;
* Rename DEFSHELL to DEFSHELL_INDEX, because it's actually an index into
  an array;
* Provide symbolic names for the possible values if DEFSHELL_INDEX;
* Document how the build environment may set DEFSHELL_INDEX or
  DEFSHELL_CUSTOM to choose the default shell;
* Move the fallback definition of DEFSHELL_INDEX from config.h to job.c,
  because it's used only in job.c.

Discussed with sjg.
2007-10-14 20:22:53 +00:00
apb ec2d191f5e Revert to revision 1.128. Now that the Var* functions no longer try to
write into const strings, it's safe to pass a truly constant string to
Var_Subst.
2007-10-13 20:01:33 +00:00
dsl 5651920158 The 'job_prefix' string can be static but not const 'hi xtos'. 2007-10-13 08:58:48 +00:00
christos 31bed26f71 improve on previous 2007-10-12 23:07:04 +00:00
dsl bb4beef604 Var_Subst() seems to write into its input string! So we do need a copy. 2007-10-12 22:49:36 +00:00
dsl 215593ad6c Remove tmp[] buffer and strncpy() call. 2007-10-12 21:47:25 +00:00
sjg 1050c04a22 If _BASENAME_DEFSHELL is defined, it might be a full path,
in which case we should not prepend _PATH_DEFSHELLDIR.
2007-10-11 21:19:28 +00:00
sjg f28827375c Add the ability to .export variables to the environment. 2007-10-05 15:27:45 +00:00
sjg 216e9ba475 Add the ability to tweak the token output before targets in job mode.
Eg.
.MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
would produce
---make[1234] target ---
2007-10-01 22:14:09 +00:00
dsl 16c8499ed2 Since 'ClientData' is 'void *', nuke almost all the (ClientData) casts. 2006-10-27 21:00:18 +00:00
dsl 0195907f3d Output all debug trace output through 'debug_file' defaulting to 'stdout'.
(Almost all the debug output went there, but some went to stderr.)
Split the parsing of -d (debug flags) out into its own routine.
Allow the output filename to be changed by specifying -dF<file> to create
a log file, or -dF+<file> to append to it. <file> may be stdout or stderr.
Also change so that -d-<flags> acts on <flags> locally but doesn't copy
them to MAKEFLAGS so they aren't inherited by child makes.
I'm not 100% happy with the command line syntax for the above, so they are
currently undocumented.
2006-10-15 08:38:21 +00:00
dsl 505a3bb2b7 There is no need to resize the pollfd array, it can only ever have 2+maxJobs
entries, so allocate at startup.
Use an 'int jobPipe[2]' within the job structure, and create pipes directly
into it.  Common up the code that creates all the pipes - making them all
non-block on the read side in the process.
Call Job_CatchChildren() directly from Job_CatchOutput() so that it only
gets called when a child actually exits.
NB: Something causes a 'pregnant pause' if (for example) you call 'nbmake obj'
in src/tools.  Introduced between netbsd 3 and 4.
2006-10-11 07:01:44 +00:00
apb cd195008c6 Allow make(1) to be built with something other than "sh" as the
shell.  To use this, build with -D_PATH_DEFSHELLDIR=\"/path/to/dir\"
-D_BASENAME_DEFSHELL=\"shell\".

* Change the order of entries in shells[].  Now DEFSHELL defaults to 0,
  and shells[0] describes the default shell.  This will be "sh" in the
  usual case.

* If _BASENAME_DEFSHELL is defined, insert an additional entry above
  "sh" in the shells[] array, making this new entry shells[0].  The
  new entry is assumed to refer to an sh-compatible shell with a
  non-standard name.  (Tested using _PATH_DEFSHELLDIR="/usr/pkg/bin" and
  _BASENAME_DEFSHELL="bash".)

* In the shells[] entry for "sh", test defined(MAKE_NATIVE) &&
  defined(__NetBSD__) to decide whether we can use the "q" flag.

OK sjg, christos
2006-10-09 20:44:35 +00:00
dsl 01a426f62c Rip out the code for the undocumented -P (don't use pipes for command
output) option.  I'm sure it is baggage from the past.
2006-10-09 14:36:41 +00:00
dsl 4a7a153be0 Rip out the code for not 'USE_PGRP', I can't imagine it being useful!
My guess is that it is compat code for before the pgrp stuff was added.
2006-10-09 13:49:59 +00:00
dsl 9f624ea07b Instead of trying to report all the 'job suspended' and 'job resumed'
messages whan make itself is suspended (ie by ^Z) before make actually
suspends, supress the messages during this sequence.
This means we don't care that they would be output after the suspend
and we can stop attempting to reap child status from withing the signal
handler (which doesn't work for recursive parallel makes).
The code simplification means that we can remove much of the code that
blocked signals - since the signal handlers (expect that for ^C and friends)
now do almost no work.
2006-10-09 13:40:11 +00:00
dsl a178085551 Reap any dead children that we have at startup.
If there are any undead ones set a flag so we don't report the 'Child (pid)
not in table' message when they die - it is impossible to (portably) find
the childrens pids.
This happens when make is run as 'make -f- ... <<EOF' and the shell uses
a child of (what will be) make to write the data into a pipe.
2006-09-29 19:38:48 +00:00
dsl 56564e27f6 Complete revamp of the way make handles job control signals.
- Send each type of signal to its own handler.
- Only call JobFinish when a process exits, in particular don't 'fake up'
  'exitstatus' for jobs being continued, nor call it for suspends.
- When a job is stopped, use an entire variable to remember the fact, so
  we know we need to send a SIGCONT.  Don't change any other state.
- In order to report '*** [job3] Suspended' before we suspend ourselves we
  have to call waitpid() from the signal handler - where we don't want to
  process job termination events. Save the exit status and process later.
The code now handles:
- jobs that suspend themselves
- jobs exiting while suspended
- jobs that don't actually suspend at all
Hoewever it still does printfs() from the signal handler, and I haven't yet
stopped it thrashing the signal mask.
2006-09-23 20:51:28 +00:00
dsl 7adfa633e3 Fix build on 64 bit systems.
Remove now-unecessary temporary local.
2006-09-22 21:55:52 +00:00
dsl 11d35f72b2 Replace the two lists 'job_list' (previously 'jobs') and 'stoppedJobs'
with a table that is malloced with 'maxJobs' entries.
Add a 'job_state' field to the Job type that exactly follows which of
the old lists the job was on (or not).
Change all the code that scanned the lists to scan the array.
No logic changes in this commit.
(Soon we'll no longer need to lock out signals for the changes to job
statuses that are done from signal handlers now that there is no linked list.)
2006-09-22 19:07:09 +00:00
dsl edb0aa98de Rename the variable 'jobs' to 'job_list' in preparation for making it an array. 2006-09-21 19:56:05 +00:00
rillig a3ea8b9d59 Fixed the bug reported in PR 33866, which is that the :Q operator does not
handle newlines correctly. Ok'ed by christos.
2006-06-29 22:01:17 +00:00
dsl 33369a0245 There is no need to count jobs and job tokens.
If we don't create the job pipe, use the '-j n' option to limit the number
of tokens we will remove from the pipe.
2006-03-31 21:05:34 +00:00
dsl 5f31eae781 nJobs and jobTokensRunning are both counting the same thing.
Kill nJobs and just use the count of tokens in use.
Don't eat job tokens when we are ignoring errors.
2006-03-15 20:33:19 +00:00
dsl f26d89e3d9 JOB_FIRST is always set (since we only execute the shell once for every
target). Nuke it.
2006-03-13 20:35:09 +00:00
dsl b85c051fa8 Remove the 'never non-NULL' 'previous' argument to JobStart.
Looks like it was intended as a minor (and pointless) optimisation to
remove a free() malloc() pair.
Make he comment about the stoppedJobs list more correct.
2006-03-12 20:14:56 +00:00
dsl a484dfd693 It isn't possibly to execute any part of job.c that references compatMake
when it is 'true'.  So delete the unexecutable code.
2006-03-12 19:14:51 +00:00
dsl c9b3912b1e Remove most of the code seemed to be there to support 'remote jobs'.
It isn't clear that it ever worked, if it did it has almost certainly
bitrotted in the last 12 years.  I'm not even sure all the required
components were present.
I suspect it was written to attempt to use a 'farm' of diskless sun3s.
In any case the apparant random assignment fo jobs to other systems doesn't
actually seem like a good idea!
Things like 'distcc' han be used to help slow systems run native builds.
Removing this code also simplifies make, and should let me speed up some of
its processing - without worrying about bitrotting it further.
2006-03-11 17:18:00 +00:00
dsl 5e60bf00ce Avoid calling JobRestartJobs() from the SIGCONT signal handler, instead
push a byte through the (now badly named) exit_pipe and call JobRestartJobs()
from the main code path when poll() wakes up.
Part of a plan to remove JobSigLock() and the zillions of system calls
it does.
2006-03-08 22:11:48 +00:00
dsl e99202b6cf Actually SIG_DFL the correct signal (not SIGINT every time) just prior to
exec'ing a program in the child.
2006-02-11 20:58:53 +00:00