Commit Graph

9760 Commits

Author SHA1 Message Date
Fabian Homborg
7c8b444927 Reduce default escape delay
300ms was waaay too long, and even 100ms wasn't necessary.

Emacs' evil mode uses 10ms (0.01s), so let's stay a tad higher in case
some terminals are slow.

If anyone really wants to be able to type alt+h with escape, let them
raise the timeout.

Fixes #3904.
2019-02-07 12:19:36 +01:00
Fabian Homborg
1a3471fa7d Revert "edit_command_buffer: Use variable-as-command"
This reverts commit 3c6844d4f4.

See #5625.
2019-02-07 09:47:24 +01:00
Fabian Homborg
8e60ebcd34 Revert "funced: Use variable-as-command"
This reverts commit 3253893923.

Fixes #5625.
2019-02-07 09:47:15 +01:00
Fabian Homborg
b03c62bd29 docs: Fix status is-command-substitution
The docs spoke of a short "is-command-sub" variant, which does not
exist.

Fixes #5624.

[ci skip]
2019-02-07 08:56:30 +01:00
Fabian Homborg
87e71bcde7 input: Remove useless .c_str
(Also removes some dead code)
2019-02-06 23:48:16 +01:00
Leonard Hecker
988283c717 Improved performance of the sorin theme
This improves performance of the sorin theme tremendously
for repositories with a large number of changes.
2019-02-06 12:29:52 +01:00
ridiculousfish
d4e3f49571 Correct the read_blocked comment 2019-02-05 23:21:47 -08:00
ridiculousfish
26ada583a0 Fix te_expr's flexible array member
te_expr has a flexible array member, but it's declared as size 1.
Stop declaring its size so UBSan stops complaining.

Noted in #2852
2019-02-05 23:03:59 -08:00
Brian Malehorn
6025c28efc Create function to retrieve tmpdir
`/tmp` isn't present / writeable on every system. Instead of always
using `/tmp`, try to use standard environment variables and
configuration to find a temporary directory.

Adapted from #3974, with updates based on those comments.

Closes #3845.
2019-02-05 22:18:51 -08:00
ridiculousfish
7f1dfb6284 Set CMAKE_ARCHIVE_OUTPUT_DIRECTORY
This allows Xcode archive builds to succeed.
2019-02-05 22:14:43 -08:00
ridiculousfish
23f8f1b6fb Remove some stale bits from make_pkg.sh 2019-02-05 22:14:43 -08:00
ridiculousfish
b952606430 Teach CMake Mac App build to dynamically derive the version
Populate CFBundleShortVersionString with the fish version from
git_version_gen.sh. Note this happens at build generation time, not at
build time.
2019-02-05 22:14:43 -08:00
ridiculousfish
0f5dc0b4e2 Add --stdout param to git_version_gen.sh
This causes git_version_gen.sh to print to stdout.
2019-02-05 22:14:43 -08:00
ridiculousfish
c869ab541d Remove some additional xcode references 2019-02-05 22:14:43 -08:00
ridiculousfish
807f79df03 Remove xcode instructions from README.md 2019-02-05 22:14:43 -08:00
ridiculousfish
9396f79e3e Remove xcode project
This removes the Xcode project and associated headers.
A better Xcode project can be generated via CMake:

    cmake -G Xcode /path/to/fish-shell/
2019-02-05 22:14:43 -08:00
ridiculousfish
ecb808fb39 Teach make_pkg.sh to build fish.app via cmake 2019-02-05 22:14:43 -08:00
ridiculousfish
e0396d8ef8 CMake support for building Mac app 2019-02-05 22:14:43 -08:00
ridiculousfish
eaefed434d make_pkg.sh to build with CMake instead of Xcode 2019-02-05 22:14:43 -08:00
ridiculousfish
2e542d7822 Initialize shutdown_fillthread_ to false
It was left uninitialized which was causing certain command substitutions
to exit too early.

Fixes #5616
2019-02-05 21:44:43 -08:00
David Adam
a042a4cb62 low level tests: set pwd from getcwd before starting
Fixes the tests in Debian pbuilder environments. Closes #5599.
2019-02-06 06:51:33 +08:00
Fabian Homborg
c7656e6622 Remove run_as_keepalive
Dead code, innit?
2019-02-04 17:11:34 +01:00
Fabian Homborg
ddfad001eb Remove unnecessary string copy
This called function_exists_no_autoload with a c_str().

Only that takes a wcstring, so the constructor gets called which
copies that.
2019-02-04 17:10:53 +01:00
Fabian Homborg
eb8a93f499 lint.fish: Modernize a bit
Use argparse, variable-as-command, skip missingInclude.
2019-02-04 16:58:38 +01:00
Fabian Homborg
9f469e576b tinyexpr: Prevent possible division by zero
This is possibly not actually undefined behavior because IEEE754
defines _more_ of division-by-zero, but let's be careful.

Fixes #2852.
2019-02-04 16:32:53 +01:00
David Adam
c9e529951b Documentation for while: note updated exit status
From updates in #4982.

(cherry picked from commit 4cc168ae11)
2019-02-04 22:39:01 +08:00
David Adam
4cc168ae11 Documentation for while: note updated exit status
From updates in #4982.
2019-02-04 22:26:59 +08:00
ridiculousfish
d3fa58d621 Cleanup common.h
Remove a bunch of headers, simplify lots of code, migrate it into .cpp files.

Debug build time improves by ~3 seconds on my Mac.
2019-02-03 18:22:38 -08:00
ridiculousfish
6f682c8405 Fill io_buffer via background thread
This is a large change to how io_buffers are filled. The essential problem
comes about with code like (example):

    echo ( /bin/pwd )

The output of /bin/pwd must go to fish, not the tty. To arrange for this,
fish does the following:

1. Invoke pipe() to create a pipe.
2. Add an io_bufferfill_t redirection that owns the write end of the pipe.
3. After fork (or equiv), call dup2() to replace pwd's stdout with this  pipe.

Now when /bin/pwd writes, it will send output to the read end of the pipe.
But who reads it?

Prior to this fix, fish would do the following in a loop:

1. select() on the pipe with a 10 msec timeout
2. waitpid(WNOHANG) on the pwd proc

This polling is ugly and confusing and is what is replaced here.

With this new change, fish now reads from the pipe via a background thread:

1. Spawn a background pthread, which select()s on the pipe's read end with
a long (100 msec) timeout.
2. In the foreground, waitpid() (allowing hanging) on the pwd proc.

The big win here is a major simplification of job_t::continue_job() since
it no longer has to worry about filling buffers. This will make things
easier for concurrent execution.

It may not be obvious why the background thread still needs a poll (100 msec).
The answer is for cases where the write end of the fd escapes, in particular
background processes invoked inside command substitutions. psub is perhaps
the only important case of this (other shells typically just hang here).
2019-02-03 01:58:49 -08:00
ridiculousfish
ec29a5b913 Introduce make_pthread
This allows creating a pthread directly, which can be joined.
iothread_spawn wraps this.
2019-02-03 01:58:49 -08:00
ridiculousfish
178b72b2fd io_buffer_t becomes io_bufferfill_t
This makes some significant architectual improvements to io_pipe_t and
io_buffer_t.

Prior to this fix, io_buffer_t subclassed io_pipe_t. io_buffer_t is now
replaced with a class io_bufferfill_t, which does not subclass pipe.

io_pipe_t no longer remembers both fds. Instead it has an autoclose_fd_t,
so that the file descriptor ownership is clear.
2019-02-03 01:58:49 -08:00
ridiculousfish
084ff64f4f Allow posix_spawn more often
Now that we no longer open files after fork, we can correctly report errors
for failed file opens. So allow posix_spawn even if there's redirections.
2019-02-03 01:58:49 -08:00
ridiculousfish
2742267b9e Use dup2_list_t in posix_spawn
This simplifies the posix_spawn path and unifies it with the fork execution
path.
2019-02-03 01:58:49 -08:00
ridiculousfish
d62576ce22 Adopt dup2_list_t in fork execution path
This switches IO redirections after fork() to use the dup2_list_t,
instead of io_chain_t. This results in simpler code with much simpler
error handling.
2019-02-03 01:58:49 -08:00
ridiculousfish
6c22c8893b Switch from tee to cat in psub --fifo
Prior to this fix, we would write to a fifo via cat >$filename & .
However in some cases (and soon in all cases) we open the file before
the fork, not after. This results in a deadlock because the file open
cannot succeed until a write begins.

Switch to using tee to write to the file. Because tee opens the file itself,
fish is no longer responsible and the deadlock is resolved.
2019-02-03 01:58:49 -08:00
ridiculousfish
dbe906b79e Introduce dup2_list_t
This represents a "resolved" io_chain_t, where all of the different io_data_t
types have been reduced to a sequence of dup2() and close(). This will
eliminate a lot of the logic duplication around posix_spawn vs fork, and pave
the way for in-process redirections.
2019-02-03 01:58:49 -08:00
ridiculousfish
e3dcb01e67 Fix travis via a user-declared ctor 2019-02-02 19:13:09 -08:00
ridiculousfish
22d05dc18b Try once more to fix the Travis build 2019-02-02 17:45:21 -08:00
ridiculousfish
6ba0d4c88a Revert io_bufferfill_t stack
This reverts commit 88dc484858 onwards.
2019-02-02 17:53:40 -08:00
ridiculousfish
f4e1d7c97e Satisfy the compiler harder 2019-02-02 17:38:12 -08:00
Fabian Homborg
38b4d47560 Initialize empty_ios emptier
This placates the compiler.

The compiler is pleased.
2019-02-03 00:14:03 +01:00
ridiculousfish
9a4153f5e2 Fill io_buffer via background thread
This is a large change to how io_buffers are filled. The essential problem
comes about with code like (example):

    echo ( /bin/pwd )

The output of /bin/pwd must go to fish, not the tty. To arrange for this,
fish does the following:

1. Invoke pipe() to create a pipe.
2. Add an io_bufferfill_t redirection that owns the write end of the pipe.
3. After fork (or equiv), call dup2() to replace pwd's stdout with this  pipe.

Now when /bin/pwd writes, it will send output to the read end of the pipe.
But who reads it?

Prior to this fix, fish would do the following in a loop:

1. select() on the pipe with a 10 msec timeout
2. waitpid(WNOHANG) on the pwd proc

This polling is ugly and confusing and is what is replaced here.

With this new change, fish now reads from the pipe via a background thread:

1. Spawn a background pthread, which select()s on the pipe's read end with
a long (100 msec) timeout.
2. In the foreground, waitpid() (allowing hanging) on the pwd proc.

The big win here is a major simplification of job_t::continue_job() since
it no longer has to worry about filling buffers. This will make things
easier for concurrent execution.

It may not be obvious why the background thread still needs a poll (100 msec).
The answer is for cases where the write end of the fd escapes, in particular
background processes invoked inside command substitutions. psub is perhaps
the only important case of this (other shells typically just hang here).
2019-02-02 14:21:46 -08:00
ridiculousfish
6e0dd06f43 Introduce make_pthread
This allows creating a pthread directly, which can be joined.
iothread_spawn wraps this.
2019-02-02 14:21:46 -08:00
ridiculousfish
78bbcef356 io_buffer_t becomes io_bufferfill_t
This makes some significant architectual improvements to io_pipe_t and
io_buffer_t.

Prior to this fix, io_buffer_t subclassed io_pipe_t. io_buffer_t is now
replaced with a class io_bufferfill_t, which does not subclass pipe.

io_pipe_t no longer remembers both fds. Instead it has an autoclose_fd_t,
so that the file descriptor ownership is clear.
2019-02-02 14:21:46 -08:00
ridiculousfish
7c256e7e51 Allow posix_spawn more often
Now that we no longer open files after fork, we can correctly report errors
for failed file opens. So allow posix_spawn even if there's redirections.
2019-02-02 14:21:46 -08:00
ridiculousfish
4c0b6a6add Use dup2_list_t in posix_spawn
This simplifies the posix_spawn path and unifies it with the fork execution
path.
2019-02-02 14:21:46 -08:00
ridiculousfish
d895075d9b Adopt dup2_list_t in fork execution path
This switches IO redirections after fork() to use the dup2_list_t,
instead of io_chain_t. This results in simpler code with much simpler
error handling.
2019-02-02 14:21:46 -08:00
ridiculousfish
b956f13880 Switch from tee to cat in psub --fifo
Prior to this fix, we would write to a fifo via cat >$filename & .
However in some cases (and soon in all cases) we open the file before
the fork, not after. This results in a deadlock because the file open
cannot succeed until a write begins.

Switch to using tee to write to the file. Because tee opens the file itself,
fish is no longer responsible and the deadlock is resolved.
2019-02-02 14:21:46 -08:00
ridiculousfish
88dc484858 Introduce dup2_list_t
This represents a "resolved" io_chain_t, where all of the different io_data_t
types have been reduced to a sequence of dup2() and close(). This will
eliminate a lot of the logic duplication around posix_spawn vs fork, and pave
the way for in-process redirections.
2019-02-02 14:21:46 -08:00
Mahmoud Al-Qudsi
4dfaa33d95 Switch to wait_by_process when waitpid without WNOHANG returns nothing
By exclusively waiting by pgrp, we can fail to reap processes that
change their own pgrp then either crash or close their fds. If we wind
up in a situation where `waitpid(2)` returns 0 or ECHLD even though we
did not specify `WNOHANG` but we still have unreaped child processes,
wait on them by pid.

Closes #5596.
2019-02-02 16:06:29 -06:00