Commit Graph

7346 Commits

Author SHA1 Message Date
Kurtis Rader
29f933adfc Merge branch 'master' into major 2017-08-09 12:26:24 -07:00
Kurtis Rader
11f5bbf83d remove completions for . and source
These completions never actually worked and always fell back to the
builtin path completion. But a recent fix means that these now keep the
fallback from happening resulting in no completions for these commands.
2017-08-09 11:15:20 -07:00
David Adam
5e4d046492 docs: tidy language in set notes 2017-08-09 23:25:00 +08:00
David Adam
5d2a806ac6 set: update language of warning message 2017-08-09 14:23:00 +08:00
Kurtis Rader
3a506543b6 Merge branch 'master' into major 2017-08-07 18:52:00 -07:00
Radek SPRTA
74cac0f86f completions for snap command 2017-08-07 18:47:37 -07:00
Kurtis Rader
55bef3cd2e remove deprecated . (dot) command
Fixes #4294
2017-08-07 18:31:20 -07:00
Mahmoud Al-Qudsi
0ebff8c516 Addresses #4292 by removing custom completions for source builtin
The source builtin should use the default path completion and isn't
restricted to *.fish files by wrapping ..fish
2017-08-07 17:49:28 -07:00
Kurtis Rader
1e67baf00e Merge branch 'master' into major 2017-08-07 17:49:02 -07:00
Alexey Alekhin
326f2affa4 Fixed functions -D/--details completion 2017-08-07 17:43:05 -07:00
Kurtis Rader
9d5a6c57a8 Merge branch 'master' into major 2017-08-06 20:53:51 -07:00
Elliott Beach
9fa0edcbc9 document bind behavior when mixing command types
Fixes 3683
2017-08-06 20:49:30 -07:00
Kurtis Rader
fb7645659f Merge branch 'master' into major 2017-08-06 20:22:31 -07:00
Kurtis Rader
4f5bd08b20 improve set -U warning
Doing `set -U var` when a global named `var` exists can result in
confusing behavior. Try to limit the confusion by improving the warning
we write. Also, only write the warning if interactive.

Fixes #4267
2017-08-06 19:57:25 -07:00
Kurtis Rader
975a5bfbde make style-all time again
Recent changes have introduced some style deviations so clean them up.
2017-08-06 16:05:51 -07:00
Kurtis Rader
acdb81bbca lint and style cleanups 2017-08-06 15:47:01 -07:00
Kurtis Rader
083224d1c0 fixes to job control changes
The job control changes need a couple of fixes for compatibility with
changes I merged while @mqudsi was workin on his change.
2017-08-06 15:25:42 -07:00
Kurtis Rader
52d739c746 Revert "Revert "finish cleanup of signal blocking code""
This reverts commit 35ee28ff24.

Reapply the signal blocking cleanup change on top of the job control
changes made by @mqudsi.
2017-08-06 14:46:12 -07:00
Mahmoud Al-Qudsi
0594735714 Deduplication between INTERNAL_FUNCTION and INTERNAL_BLOCK_NODE 2017-08-06 14:41:27 -07:00
Mahmoud Al-Qudsi
4dfb334db8 Corrected job_type for external command in debug log 2017-08-06 14:41:27 -07:00
Mahmoud Al-Qudsi
384879704a Unified all child/parent forking code in exec_job 2017-08-06 14:41:27 -07:00
Mahmoud Al-Qudsi
4a1de248bc Split internal_exec to its own function 2017-08-06 14:41:27 -07:00
Mahmoud Al-Qudsi
711c81b8c8 Raised debug level for "Retrying setpgid" message 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
87db424e45 Removed unused <mutex> header include 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
7e23965250 Cleaned up terminal_give_to_job() code flow and comments
No longer using a lambda for pgroupTerminated, using a boolean flag
instead. The new code structure should be much more self-documenting.
2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
dabe718c52 Removed unused job_t * parameter from setup_child_process 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
628db65504 OS X EINVAL compatibility for waitpid
The return value on OS X is more along the lines of the documented
waitpid behavior; EINVAL is returned if the group no longer exists.
2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
8e63386203 Removed old/unneeded variants of block_child 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
16d2f4faff Added important comment about blocked_pid 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
15da6f0203 Minor refactoring 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
a0efae5f08 Logging updates 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
5db8065f15 unblock_previous on exec_job finish 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
c3d756b5df blocking only if pipes_to_next_command breaks things like read.expect test 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
b27217e106 terminal_give_to_job() was bypassing the cont branch
If tcgetpgrp for STDIN was already a match, the `cont` branch was
skipped. This wais making the history.expect test fail.
2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
f7b051905e Split child_set_group from setup_child_process
setup_child_process blocks in the case of IO_FILE, meaning it can't
be called before child processes SIGSTOP.
2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
8537cc982e Fixed no-op loop hang 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
d6c4e66484 Retry setpgid in setup_child_process on EPERM 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
1ae0272c4e Improved comments 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
30aa8b3663 No need to unblock last process since it will no longer be SIGSTOP'd 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
abf6874a2d Be more judicious about when SIGSTOP is performed 2017-08-06 14:40:18 -07:00
Mahmoud Al-Qudsi
99c6f65fee Better set_child_group logic for multi-process jobs 2017-08-06 14:40:17 -07:00
Mahmoud Al-Qudsi
8f2ef082be Clarified job_continue logging 2017-08-06 14:40:17 -07:00
Mahmoud Al-Qudsi
bdcd451030 Handling EPERM in terminal_give_to_job() 2017-08-06 14:40:17 -07:00
Mahmoud Al-Qudsi
8b8a21dcad Fixed exec failure regression
The process_t pointer sent to setup_child_process can actually be 0
without it being failure, as that is what fish sends when `exec` is run
(in the case of INTERNAL_EXEC).

This was causing exec to fail.
2017-08-06 14:40:17 -07:00
Mahmoud Al-Qudsi
9f2addcf27 Set child process group in case of posix_spawn 2017-08-06 14:40:17 -07:00
Mahmoud Al-Qudsi
25afc9b377 Changed how process groups are assigned to child processes
There is no more race condition between parent and child with
regards to setting the process groups. Each child sets it for themselves
and then blocks indefinitely until the parent does what it needs to for
them (having waited for them to set their process groups). They are not
SIGCONT'd until the next process in the chain (if any) starts so that
that process can join their process group and open the pipes.
2017-08-06 14:40:17 -07:00
Mahmoud Al-Qudsi
c81cf56c0b Don't indiscriminately unblock previous cmd for internal builtin/functions
In the last commit, we introduced an indiscriminate if !EXTERNAL check
that unblocks a previously SIGSTOP'd command (if any) to allow the main
loop in exec_job to read from it without deadlocking (since builtins and
functions read directly from input as an optimization, sometimes).

Now only unblocking where a fork will not happen to ensure that if a
builtin ends up forking, that fork'd process is guaranteed to be able to
join the previous process' process group and access its output pipes.
2017-08-06 14:40:17 -07:00
Mahmoud Al-Qudsi
0e9177b590 Don't attempt to unconditionally tcsetpgrp
Setting the process group in a fork/exec scenario is a well-documented
race condition in pretty much any job control mechanism [0] [1]. The
Wikipedia article contradicts the glibc article and suggests that the
best approach is for the parent to wait for the child to become the
process group leader, while the glibc article suggests that both should
make it so (which is what fish did previously). However, I'm running
into cases where tcsetpgrp is causing an EPERM error, which it isn't
documented to do except if the session id for the calling process
differs from that of the target process group (which is never the case
in fish since they are all part of the same session), which should cause
a _different_ error (SIGTTOU to be sent to all members of the calling
process' group).

In all cases, this is easily remedied by checking if the process group
in question is already in control of the terimnal. There's still the
off-chance that in the time between we check that and the time that the
command completes that situation may have changed, but the parent
process is supposed to ignore the result of this call if it errors out.

[0]: https://en.wikipedia.org/wiki/Process_group
[1]: https://www.gnu.org/software/libc/manual/html_node/Launching-Jobs.html
2017-08-06 14:40:17 -07:00
Mahmoud Al-Qudsi
87394a9e0b Fixed race condition in new job control synchronization
We were having child processes SIGSTOP themselves immediately after
setting their process group and before launching their intended targets,
but they were not necessarily stopped by the time the next command was
being executed (so the opposite of the original race condition where
they might have finished executing by the time the next command came
around), and as a result when we sent them SIGCONT, that could never
reach. Now using waitpid to synchronize the SIGSTOP/SIGCONT between the
two.

If we had a good, unnamed inter-process event/semaphore, we could use
that to have a child process conditionally stop itself if the next
command in the job chain hadn't yet been started / setup, but this is
probably a lot more straightforward and less-confusing, which isn't a
bad thing.

Additionally, there was a bug caused by the fact that the main exec_job
loop actually blocks to read from previous commands in the job if the
current command is a built-in that doesn't need to fork.

With this waitpid code, I was able to finally add the SIGSTOP code to
all the fork'd processes in the main exec_job loop without introducing
deadlocks; it turns out that they should be treated just like the main
EXTERNAL fork, but they tend to execute faster causing the same deadlock
described above to occur more readily.

The only thing I'm not sure about is whether we should execute
unblock_pid undconditionally for all !EXTERNAL commands. It makes more
sense to *only* do that if a blocking read were about to be done in the
main loop, otherwise the original race condition could still appear
(though it is probably mitigated by whatever duration the SIGSTOP lasted
for, even if it is SIGCONT'd before the next command tries to join the
process group).
2017-08-06 14:40:17 -07:00
Mahmoud Al-Qudsi
dfac81803b Improved blocked prcoess comments, clarified job vs command chain 2017-08-06 14:40:17 -07:00