summaryrefslogtreecommitdiff
path: root/src/posixos.c
Commit message (Collapse)AuthorAgeFilesLines
* Use MK_OS_OS2 macro instead of __EMX__Paul Smith2023-01-161-1/+1
| | | | | * src/makeint.h: Set MK_OS_OS2 to 1 if __EMX__ is set. * src/*: Convert #if refs to __EMX__, to use MK_OS_OS2.
* Allow jobserver style to be forced to "pipe"Paul Smith2023-02-191-2/+2
| | | | | | | | | | | | | | Some systems that support mkfifo() don't support the usage that GNU make wants. Provide a way to force using "pipe" jobserver mode even when mkfifo() is available. * src/makeint.h (MK_OS_HURD): Define if we're on Hurd. (JOBSERVER_USE_FIFO): Define if we have mkfifo() and we're NOT on Hurd. * src/main.c (main): Test JOBSERVER_USE_FIFO not HAVE_MKFIFO. * src/posixos.c (jobserver_setup): Ditto. * maintMakefile: Create a config check test for forcing "pipe" mode. * tests/run_make_tests.pl: Show discovered FEATURES in verbose mode.
* Update support for OS/2Paul Smith2023-01-081-0/+3
| | | | | | | | | | | | | | | | | | Patches provided by KO Myung-Hun <komh78@gmail.com> * NEWS: Add a note. * AUTHORS: Add a new author. * README.OS2: Updates to build instructions. * src/dir.c (dir_contents_file_exists_p): Use a stack copy when modifying a const string. * src/job.c (construct_command_argv_internal): Ditto. Reuse variables rather than re-defining them. (exec_command): Cast a const string (we don't change it anyway). * src/getopt.c (_getopt_initialize): Reference unused variables. (_getopt_internal): Add block braces to quiet the compiler. * src/main.c (main): Cast argument to child_execute_job(). * src/posixos.c (set_blocking): Reference unused variables. * src/remake.c (f_mtime): Delete useless code.
* [SV 62654] Support GNU Make on z/OSPaul Smith2023-01-081-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Original patches provided by Igor Todorovski <itodorov@ca.ibm.com> Reworked by Paul Smith <psmith@gnu.org>. Thanks to IBM for providing a test system. * NEWS: Announce support. * AUTHORS: Ditto. * README.zOS: Provide details on building GNU Make on z/OS. * build.sh (get_mk_var): z/OS sh has a strange bug which causes it to generate extra lines of output: rework the function to print output as we compute it instead of collecting it into a variable, which works around this bug. * src/makeint.h: Declare MK_OS_ZOS if we're building for z/OS. * src/arscan.c: Don't include <ar.h> on z/OS. * src/job.c: We can't change environ in ASCII mode on z/OS. * src/main.c: Ditto. Also we can't use pselect() on z/OS. * src/posixos.c: pselect() seems to hang on z/OS: don't use it. * tests/run_make_tests.pl: Handle different exit codes on z/OS. * tests/test_driver.pl: Preserve some special z/OS env.vars. Add special checks to output comparisons when on z/OS. * tests/scripts/features/archives: Don't validate names. Don't try to compile empty files as IBM compilers complain. * tests/scripts/features/shell_assignment: Fix octal value of #. * tests/scripts/features/temp_stdin: Don't print "term". * tests/scripts/functions/shell: Handle shell exit codes. * tests/scripts/targets/ONESHELL: Ditto. * tests/scripts/targets/POSIX: sh -x prints differently. * tests/scripts/variables/SHELL: Ditto.
* Update the copyright year on all filesPaul Smith2023-01-011-1/+1
|
* [SV 63333] Be more lenient when failing to create temporary filesDmitry Goncharov2022-11-131-2/+5
| | | | | | | | | | | | | | | | | | | | | | If make cannot create a temporary lock file for output sync, continue without output sync enabled rather than dying. However, if make cannot store a makefile from stdin to a temporary file that is still a fatal error. * misc.c (get_tmppath): Keep running on failure to generate a temporary file name. (get_tmpfd): Keep running on failure to get a temporary file. (get_tmpfile): Keep running on failure to open a temporary file. Ensure memory is freed if we return an error. * posixos.c (os_anontmp): Keep running on failure to open an anonymous temporary file. * output.c (setup_tmpfile): Print an error on failure to create an output sync lock file. * main.c (main): Die on failure to store makefile from stdin to a temporary file. * tests/scripts/features/output-sync: Add tests. * tests/scripts/features/temp_stdin: Ditto.
* Keep going if we can't connect to the jobserverPaul Smith2022-11-131-9/+14
| | | | | | | | * src/posixos.c (jobserver_parse_auth): Don't invoke fatal() if we can't connect to an existing jobserver: just keep going without it. * src/w32/w32os.c (jobserver_parse_auth): Ditto. * tests/scripts/features/jobserver: Add a test for invalid FIFO auth files.
* Fix issues found by ASAN and CoverityPaul Smith2022-10-311-0/+1
| | | | | | | | | | | | | | | * tests/test_driver.pl: Preserve the LSAN_OPTIONS variable. * tests/scripts/targets/ONESHELL: Don't set a local variable. * tests/scripts/functions/let: Test empty let variable. * src/posixos.c (osync_parse_mutex): Free existing osync_tmpfile. * src/misc.c (get_tmpfd): Set umask() before invoking mkstemp(). * src/ar.c (ar_parse_name): Check invalid name (shouldn't happen). * src/function.c (define_new_function): Free previous function entry when replacing it with a new one. * src/job.c (child_execute_job): Initialize pid for safety. (construct_command_argv_internal): In oneshell mode ensure that the returned argv has the right format (0th element is a pointer to the entire buffer).
* * src/posixos.c (os_anontmp): [SV 63287] Only fail O_TMPFILE oncePaul Smith2022-10-291-5/+11
| | | | Reported by Dmitry Goncharov <dgoncharov@users.sf.net>.
* * src/posixos.c (os_anontmp): If O_TMPFILE fails try dup() method.Dmitry Goncharov2022-10-231-8/+13
|
* [SV 63248] Ignore SIGPIPEDmitry Goncharov2022-10-221-0/+1
| | | | | | | | | | | | | Don't terminate when make's output is redirected to a pipe and the reader exits early; e.g.: $ echo 'all:; sleep 2' | make -f- -j2 -O |: This lets us unlink temporary files, and tell the user that make was not able to write its output. Reported by Frank Heckenbach <f.heckenbach@fh-soft.de>. * src/main.c (main): Ignore SIGPIPE. * src/posixos.c (osync_clear): Fix a memory leak.
* Update URLs to use https rather than httpPaul Smith2022-10-181-1/+1
| | | | | * (all): Change http:// to https:// * README.W32: Remove invalid link to mingw.org.
* Rework temp file handling to avoid GNU libc warningsPaul Smith2022-10-181-6/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Original patch provided by Paul Eggert <eggert@cs.ucla.edu>. GNU libc will generate a link-time warning if we use mktemp() even though we are using it safely (we only use it with mkfifo()). Avoid this and clean up some handling. First, check all calls related to temporary files and exit with a fatal error and a useful message if we can't obtain them. In some situations it might be possible to continue with reduced capability but it's not worth the effort. On POSIX systems we can create anonymous temp files using O_TMPFILE if it's supported, else if we're using the default location and we have dup(2), we can use standard tmpfile() and get an FD from it. If we need a named temp file and FILE* and we have mkstemp() we can use that, else if we have fdopen() we can get a temp FD and open it. If none of those are available all we can do is generate a temp name then open it with fopen() which is not secure. * src/makeint.h (get_tmpdir): Declare it for use elsewhere. * src/misc.c (get_tmpdir): Make it public not static. (get_tmptemplate): Simplify the implementation. (get_tmppath): Only define this if we have to have it to avoid warnings from GNU libc. (get_tmpfd): Generate fatal errors on error. (get_tmpfile): Ditto. Open files in "wb+" mode to match tmpfile(). Require a filename pointer (all callers want it). * src/os.h (os_anontmp): Implement for posixos.c as well. * src/posix.c (jobserver_setup): Don't use mktemp to avoid GNU libc errors. Instead construct the FIFO name based on the PID. (osync_setup): get_tmpfd() can't fail so don't check it. (os_anontmp): If the system supports O_TMPFILE use it. If not, and we want to create the temporary file in the default directory, we can use tmpfile() then use dup() to copy the file descriptor. * src/main.c (main): get_tmpfile() can't fail. * src/vmsjobs.c (child_execute_job): get_tmpfile() can't fail.
* * src/posixos.c (job_root): Remember root jobserver instancesPaul Smith2022-10-151-10/+30
| | | | | | | | (jobserver_setup): Set job_root to true. (jobserver_clear): if we're the root instance and we're using a FIFO, unlink it. If we're not in a signal handler, free memory. (jobserver_acquire_all): Call jobserver_clear(). (sync_root): Rename from sync_parent for consistency.
* * src/main.c (main): Add debug output for jobserver and osync.Paul Smith2022-10-021-7/+0
| | | | | * src/posixos.c (jobserver_setup): Remove redundant debug output. (jobserver_parse_auth): Ditto.
* [SV 63111] Ensure output-sync is cleaned on re-exec and recursionAndreas Schwab2022-10-021-2/+7
| | | | | | | | | | | | Now that output-sync is using a separate file as a mutex rather than stdout, ensure the new file descriptor is closed before re-exec and not inherited by children. * src/main.c (main): Call osync_clear() before re-exec. * src/posixos.c (osync_setup): Reset output-sync handle inheritance. (osync_parse_mutex): Ditto. Copyright-paperwork-exempt: yes
* * src/posixos.c (osync_clear): Don't close invalid FDs.Paul Smith2022-09-251-1/+1
|
* Ensure debug output ends in newlinePaul Smith2022-09-081-6/+4
| | | | | | * src/load.c (load_object): Debug output strings must include \n. * src/variable.c (target_environment): Ditto. * src/posixos.c: Remove extra newlines.
* Rework output sync to lock a temp file on POSIXPaul Smith2022-08-301-4/+170
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some POSIX systems do not allow locks to be taken on non-files, such as pipes. This is a problem since very often make is invoked with its stdout redirected to a pipe. Also, if stdout is redirected to a file that already has a lock on it for some other reason (perhaps a shared file such as /dev/null) it can cause a hang. This means our previous method of locking stdout, although it had some nice advantages, is not portable enough. Instead, use a temporary file and take the lock on that. We pass the name of the file to child make processes. On Windows we continue to use a shared mutex for output sync. Remove POSIX emulation functions like fcntl from Windows; instead follow the lead of the jobserver and create an interface in os.h for output sync, and move the OS-specific content to posixos.c and w32os.c. * NEWS: Add a note. * src/makeint.h (ALL_SET): Check that all bits are set. * src/os.h: Add bits for checking the state of stdin/stdout/stderr. Add prototypes for OS-specific output sync methods. * src/posixos.c (check_io_state): Determine the status of stdin, stdout, stderr an return a suite of bits describing them. (osync_enabled): If the global variable holding the FD of the lock file (osync_handle) is valid return true. (osync_setup): Create a temporary file and remember its name in a global variable (osync_tmpfile), and set osync_handle. (osync_get_mutex): If output sync is enabled, return the filename of the lock file prefixed with "fnm:" to denote a filename. (osync_parse_mutex): If the provided filename has the wrong format disable output sync. Else open the lock file and set osync_handle. (osync_clear): Close osync_handle. If we're the parent make, then also unlink the temporary file. (osync_acquire): Take a lock on the osync_handle descriptor. (osync_release): Release the lock on the osync_handle descriptor. (fd_set_append): Add APPEND mode to a file descriptor. * src/w32/w32os.c: Perform the same actions as posixos.c, copying the details from src/w32/compat/posixfcn.c. Use a mutex rather than locking a temporary file. * src/output.h: Remove all the OS-specific content. * src/output.c: Remove all the OS-specific content. (set_append_mode): Remove and replace with fd_set_append(). (sync_init): Remove and replace with check_io_state(). (acquire_semaphore): Remove and replace with osync_acquire(). (release_semaphore): Remove and replace with osync_release(). (setup_tmpfile): If the IO state is not obtained, get it. If stdout and/or stderr are valid, set up a tempfile to capture them. (output_init): Set io_state if not set already, and check it when deciding whether to close stdout on exit. * src/main.c (main): If we're syncing, set up the mutex using the new osync_setup() / osync_parse_mutex() methods. (prepare_mutex_handl_string): Replace with osync_parse_mutex(). (die): Call osync_clear(). * src/w32/compat/posixfcn.c: Remove implementations of fcntl(), record_sync_mutex(), create_mutex(), and same_stream().
* [SV 62908] Don't free fifo_name twice during error handlingDmitry Goncharov2022-08-221-0/+1
| | | | | * src/posixos.c (jobserver_setup): Set fifo_name to NULL after free. * tests/scripts/features/jobserver: Add tests.
* Support implementing the jobserver using named pipesPaul Smith2022-08-021-37/+155
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using anonymous pipes for jobserver support has some advantages: for example there is nothing on disk that needs to be cleaned up. However it has many obscure problems, related to the fact that in order for it to work we need to ensure these resources are properly passed through to child processes that want to use the jobserver. At the same time we don't want to pass the pipe to process which DON'T know about the jobserver. Other processes can open file descriptors which we then think are our jobserver, but aren't. And, we open the pipe file descriptors in blocking mode which doesn't work for all users. See issues such as SV 57178, SV 57242, and SV 62397 To avoid these issues, use named pipes (on systems where they are available) instead of anonoymous pipes. This simplifies many things: we never need to pass open file descriptors to our children; they can open the jobserver named pipe. We don't need to worry about recursive vs. non-recursive children. Users don't have to "pass through" the resources if they are invoking sub-makes. Each child can open its own file descriptor and set blocking as needed. The downside is the named pipe exists on disk and so must be cleaned up when the "top-level" make instance exits. In order to allow make to continue to be used in build systems where older versions of GNU make, or other tools that want to use the jobserver, but don't understand named pipes, introduce a new option --jobserver-style that allows the user to choose anonymous pipes. * NEWS: Announce the change and the --jobserver-style option. * doc/make.1: Add --jobserver-style documentation. * doc/make.texi (Special Variables): Add missing items to .FEATURES. (Options Summary): Add --jobserver-style. (POSIX Jobserver): Named pipes, changes to --jobserver-auth, and the --jobserver-style option. (Windows Jobserver): Document --jobserver-style for Windows. * configure.ac: Check for mkfifo. * src/config.h-vms.template: Undefined HAVE_MKFIFO. * src/config.h.W32.template: Ditto. * src/main.c: Add jobserver-style as a new command line option. (main): Add jobserver-fifo to .FEATURES if supported. Pass the style option to jobserver_setup(). * src/os.h (jobserver_setup): Accept a style string option. * src/posixos.c (enum js_type): Enumeration of the jobserver style. (js_type): Which style we are currently using. (fifo_name): The path to the named pipe (if in use). (jobserver_setup): If no style is given, or "fifo" is given, set up a named pipe: get a temporary file and use mkfifo() on it, then open it for reading and writing. If something fails fall back to anonymous pipes. (jobserver_parse_auth): Parse jobserver-auth to determine the style. If we are using a named pipe, open it. If we're using anonymous pipes ensure they're valid as before. (jobserver_get_invalid_auth): Don't invalidate the jobserver when using named pipes. (jobserver_clear): Clean up memory used for named pipes. (jobserver_acquire_all): Unlink the named pipe when done. * src/w32/w32os.c (jobserver_setup): Check the style argument. * tests/scripts/features/jobserver: Use --jobserver-style to test the anonymous pipe behavior, and also test named pipe/semaphore behavior. Check invalid jobserver-style options. * tests/scripts/functions/shell: Use --jobserver-style to test the anonymous pipe behavior, and also test named pipe/semaphore behavior.
* Disable the jobserver in non-recursive childrenPaul Smith2022-07-301-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Savannah issues such as SV 57242 and SV 62397 show how passing references to closed file descriptors via the --jobserver-auth option in MAKEFLAGS can lead to problematic outcomes. When computing the child environment for a non-recursive shell, add an extra option to MAKEFLAGS to disable the file descriptors for the jobserver. Unfortunately this doesn't modify the value of the make variable MAKEFLAGS, it only modifies the value of the sub-shell environment variable MAKEFLAGS. This can lead to confusion if the user is not considering the distinction. * src/makeint.h: Publish the jobserver-auth value. Add a global definition of the name of the command line option. * src/os.h (jobserver_get_invalid_auth): New function to return a string invalidating the jobserver-auth option. * src/w32/w32os.c (jobserver_get_invaid_auth): Implement it. On Windows we use a semaphore so there's no need to invalidate. * src/posixos.c (jobserver_parse_auth): If we parse the invalid auth string, don't set up the jobserver. (jobserver_get_invalid_auth): Return an invalid option. * src/variable.h (target_environment): Specify if the target environment is for a recursive shell or non-recursive shell. * src/variable.c (target_environment): Move checking for MAKELEVEL into the loop rather than doing it at the end. Along with this, check for MAKEFLAGS and MFLAGS, and update them based on whether we're invoking a recursive or non-recursive child, and also on whether it's necessary to invalidate the jobserver. * src/function.c (func_shell_base): Shell functions can never be recursive to pass 0 to target_environment(). * src/job.c (start_job_command): Specify whether the child is recursive when calling target_environment(). * src/main.c: Export jobserver_auth. sync_mutex doesn't need to be exported. Use the global definition for the option name. * tests/scripts/variables/MAKEFLAGS: Add tests for $MAKEFLAGS.
* Run autoupdate and clean up autoconf usagePaul Smith2022-07-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | We can assume that the return type of a signal handler is void. We can assume that, if sys/time.h exists, it can be included with time.h. * bootstrap: Get the latest version * configure.ac: Require a newer version of autoconf. Remove unnecessary AC_PROG_CC_C99 (already have AC_PROC_CC). Remove unnecessary AC_AIX, AC_ISC_POSIX, AC_MINIX. Remove unnecessary AC_HEADER_STDC, AC_HEADER_TIME, AC_TYPE_SIGNAL. Use strerror to search for the cposix library. * src/commands.c (fatal_error_signal): Assume return type is void. * src/commands.h: Ditto. * src/job.c: Ditto. * src/job.h: Ditto. * src/main.c: Ditto. * src/makeint.h: Ditto. Don't bother with TIME_WITH_SYS_TIME. * src/remote-cstms.c: Check HAVE_SYS_TIME_H. * src/config.ami.template: Remove RETSIGTYPE. * src/config.h-vms.template: Ditto. * src/config.h.W32.template: Ditto. Remove TIME_WITH_SYS_TIME.
* * <all>: Update copyright notices.Paul Smith2022-02-101-1/+1
|
* [SV 58232] Disable inheritance of jobserver FDs for recursive makeKevin Buettner2020-05-021-0/+5
| | | | | | | | | | | | | | | | | A parent make will invoke a sub-make with close-on-exec disabled for the jobserver pipe FDs. Force close-on-exec to be to be enabled in the sub-make so the pipe is not always passed to child jobs. I have a test case which, when invoked with a suitable -j switch, will hang if the recipe inherits the jobserver pipe. This test case was inspired by a real world case in which testing GDB on Fedora would hang due to some poorly written test GDB cases having been passed the jobserver file descriptors. * src/posixos.c (jobserver_parse_auth): Call fd_noinherit() for jobserver pipe descriptors. Copyright-paperwork-exempt: yes
* Update copyright statements for 2020Paul Smith2020-01-031-1/+1
|
* Update copyright statements for 2019Paul Smith2019-05-191-1/+1
|
* * src/read.c(unescape_char): Use C comments not C++ comments.Paul Smith2018-08-021-1/+1
| | | | | * src/posixos.c(set_blocking): Ditto. * src/w32/subproc/sub_proc.c(process_init): Ditto
* * all: Update Copyright statements for 2018Paul Smith2018-07-011-1/+1
|
* Rework directory structure to use GNU-recommended "src" directory.Paul Smith2017-11-191-0/+512
Move the source code (other than glob) into the "src" subdirectory. Update all scripting and recommendations to support this change. * *.c, *.h, w32/*: Move to src/ * configure.ac, Makefile.am, maintMakefile: Locate new source files. * Basic.mk.template, mk/*: Update for new source file locations. * NEWS, README.DOS.template: Update for new locations. * build.template, build_w32.bat, builddos.bat: Ditto. * po/POTFILES.in: Ditto * tests/run_make_tests.pl, tests/scripts/features/load*: Ditto. * make.1: Move to doc. * mk/VMS.mk: Add support for building on VMS (hopefully). * makefile.vms, prepare_w32.bat: Remove. * SCOPTIONS: Update to define HAVE_CONFIG_H