Commit Graph

1690 Commits

Author SHA1 Message Date
Aaron Gyes
57d6124e6e builtin_test: don't exit 1 for eval errors, add tests for big args
Return STATUS_INVALID_ARGS when failing due to evaluation errors,
so we can tell the difference between an error and falseness.

Add a test for the ERANGE error
2018-12-16 14:51:26 -08:00
Aaron Gyes
cf2b40040a STATUS_INVALID_ARGS = 2
The rest of the high-numbered exit codes are not values used by scripts
or builtins, they are internal to fish and come out of
the parser for example.

Prior to adding STATUS_INVALID_ARGS, builtins were usually exiting 2
if they had a special exit status for the situation of bad arguments.

Set it to 2.
2018-12-16 14:51:18 -08:00
Aaron Gyes
b404b9392c builtin_test.cpp: split a long line, add braces 2018-12-16 14:51:10 -08:00
Aaron Gyes
1f871c4d0c builtin_test.cpp: check for ERANGE and special fish_wcstoll errno
We were not parsing an in-range number when we claimed we were,
and were thus failing to error with invalid numbers and returned
a wrong test result. Fixed #5414

Also, provide the detail we can for the other error cases.
2018-12-16 14:51:02 -08:00
Fabian Homborg
ffab420e43 Add fallback wcstod_l for musl
Just sets locale to "C" (because that's the only one we need), does
wcstod and resets the locale.

No idea why uselocale(loc) failed for me, but it did.

Fixes #5407.
2018-12-12 15:12:12 +01:00
Aaron Gyes
0b45b474f3 Update bugreport()
I left this out of the last commit accidentally.
2018-12-11 02:50:03 -08:00
Fabian Homborg
88f7d50633 Acquire terminal even if our pgroup is 0
`tcsetpgrp` still works.

[ci skip]

(This isn't tested)
2018-12-08 16:21:52 +01:00
Fabian Homborg
0a0060481f Guard against pgid == 0
This happens in firejail, and it means that we can't use it as an
argument to most pgid-taking functions.

E.g. `wait(0)` means to wait for the _current_ process group,
`tcsetpgrp(0)` doesn't work etc.

So we just stop doing this stuff and hope it works.

Fixes #5295.
2018-12-08 16:21:52 +01:00
ridiculousfish
df4a41ff81 Fix a crash with -d5 and block processes 2018-12-02 14:53:26 -08:00
Fabian Homborg
366c21ca47 parser_keywords: Pre-create "begin" and "else" wcstrings
Otherwise this creates two wcstrings every call.

C++ is silly.
2018-12-01 23:03:41 +01:00
ridiculousfish
5012fb0e36 Add 'round' function to builtin math 2018-12-01 13:25:00 -08:00
Aaron Gyes
fe67cc4f6e Revert "Show how fish was executed, using argv[0] for program_name"
This reverts commit 1cb8b2a87b.

argv[0] has the full path in it for a user when he executes it
out of $PATH. This is really annoying in the title which uses $_.
2018-11-28 06:08:24 -08:00
Aaron Gyes
dd582abcc5 Revert "argv: don't reassign parameters"
This reverts commit ba455c81b4.
2018-11-28 06:07:58 -08:00
Fabian Homborg
d91b48b866 screen: Avoid crash if clr_eol is undefined
This crashes if the terminfo entry does not have the el capability.
Which is unusual but happens with the (outdated) "terminology" entry.

Fixes #5371.
2018-11-28 13:37:40 +01:00
Fabian Homborg
047fcb3224 proc: Don't hardcode clr_eol
Also check if that is actually defined, not the cur_term proxy.

In #5371, we figured out that there are terminfo entries without this
capability, so this would do a NULL-dereference.
2018-11-28 13:37:40 +01:00
Fabian Homborg
a730f9fc90 history: Move profiler message to debug level 5
This message would print when the prompt had just been printed, and
nobody really needs this currently.
2018-11-28 13:37:40 +01:00
Aaron Gyes
ba455c81b4 argv: don't reassign parameters
OCLINT was ignoring this, but we can just not do the bad thing.
Declare argc and argv const. These are in the stack, they can
be modified, but we won't.

Fix a typo
2018-11-27 13:27:21 -08:00
Aaron Gyes
1cb8b2a87b Show how fish was executed, using argv[0] for program_name
... rather than hard code it to "fish". This affects
what is found in $_ and improves the errors:

For example, if fish was ran with ./fish, instead of
something like:

  fish: Expected 3 surprises, only got 2 surprises

we'll see:

 ./fish: Expected 3 surprises, only got 2 surprises

like most other shell utilities. It's just a tiny bit
of detail that can avoid confusion.
2018-11-27 11:57:09 -08:00
Fabian Homborg
a1c481c06a source: Actually check if stdin is a tty, not just redirected
This broke fishtape, which did

    somestuff | fish -c "source"

Because `source` didn't have a redirection, it refused to read from
stdin.

So, to keep the common issue of `source (command that does not print)`
from seeminly stopping fish, we instead actually check if stdin is a terminal.
2018-11-26 23:48:19 +01:00
Aaron Gyes
9e7034c903 fish.cpp: Dirs relative to CMAKE_SOURCE_DIR, don't assume 'fish'
This was causing problems if "fish" wasn't in exec_path, like
if the binary had been renamed.

I also noticed that even with 'fish' not renamed, only paths.data
was made relative to my source tree. paths.sysconf, paths.doc, and
paths.bin were all relative to /usr/local.
2018-11-25 14:37:12 -08:00
Fabian Homborg
7e854e072a reader: Deduplicate some movements
This had a bunch of "do_{backward,forward}" movements that differed
only in one argument.

Just keep them together, so it's less code, and less needs to be
changed.
2018-11-25 18:57:35 +01:00
David Adam
2dab869b41 Restore legacy CMD_DURATION and FISH_VERSION variables
Work on #4154.

Effectively reverts fb8ae04f80.

Discussed extensively in
https://github.com/fish-shell/fish-shell/pull/5320
2018-11-24 12:37:26 +08:00
ridiculousfish
d6a5792ce2 Allow nested square brackets again
Code like echo $list[$var[1]] was producing an error because of
nested square brackets. Allow these brackets again.

Fixes #5362
2018-11-22 17:57:27 -08:00
Fabian Homborg
c729a97c43 builtin_read: Remove --all-lines
This was unused and needed to be warned about in the docs. Remove it
so nobody stumbles over it.

Fixes #5332.
2018-11-20 16:56:52 +01:00
Fabian Homborg
7367e545f2 Revert "wrealpath: Fail for file/something"
Apparently macOS realpath is broken.

This reverts commit ca1c499069.
2018-11-19 09:12:26 +01:00
Mahmoud Al-Qudsi
3d557518d5 Replace 0/1 with true/false in calls to job_reap 2018-11-18 17:40:18 -06:00
Mahmoud Al-Qudsi
d0085cae3c Fix zombie job on failed redirection in exec_job
Closes #5346.
2018-11-18 17:40:18 -06:00
ridiculousfish
a8ce7bad7b Always pass in the working directory in path_get_cdpath
If the user is in a directory which has been unlinked, it is possible
for the path .. to not exist, relative to the working directory.
Always pass in the working directory (potentially virtual) to
path_get_cdpath; this ensures we check absolute paths and are immune
from issues if the working directory has been unlinked.

Also introduce a new function path_normalize_for_cd which normalizes the
"join point" of a path and a working directory. This allows us to 'cd' out of
a non-existent directory, but not cd into such a directory.

Fixes #5341
2018-11-18 14:36:42 -08:00
Mahmoud Al-Qudsi
8730b482a7 Prevent zombie processes after disowned child procs exit
Closes #5346.
2018-11-18 15:27:58 -06:00
Fabian Homborg
58b29fb5d1 Revert "Remove unnecessary "string_set_contains" function"
I have no idea why this worked or passed the tests?

This reverts commit 1836e704c4.

Fixes #5349.
2018-11-18 22:25:17 +01:00
Aaron Gyes
4221d6c3e6 Realpath styling tweaks.
Add braces I forgot, improve comments, make line spacing more
consistent around if blocks.
2018-11-18 12:29:35 -08:00
Fabian Homborg
442eb028c1 wrealpath: Simplify
- Reuse the buffer
- Don't duplicate the code for no "/"
2018-11-18 20:30:26 +01:00
Fabian Homborg
ca1c499069 wrealpath: Fail for file/something
This incorrectly allowed "file/something" if file existed (as a file), because it
checked "afile".

Fixes #5352.
2018-11-18 20:30:21 +01:00
Aaron Gyes
b00b1af152 Improve realpath error reporting, fix a crasher
realpath() will return NULL and sets errno if it fails.
We asserted that realpath(".") does not fail. We also didn't really
check that it was successful. Made sure we'll get a perror telling
us about what went wrong if something like this happens again.

Updated tests and added test case

Fixes #5351
2018-11-18 09:35:58 -08:00
Mahmoud Al-Qudsi
31d17f4559 Rename string escape --style=pcre2 to string escape --style=regex 2018-11-16 20:22:06 -06:00
Mahmoud Al-Qudsi
e160cde606 Implement PCRE2 escaping
Closes #5309.
2018-11-15 12:00:56 -06:00
Fabian Homborg
1fffdbce79 Fix status current-command
As it turns out, this just always printed "fish".

The solution here is a bit hacky as we go via the $_ variable.

Fixes #5339.
2018-11-14 12:15:40 +01:00
Fabian Homborg
278cbc5ff1 env_universal_common: Constref env_var_t as well 2018-11-14 12:15:40 +01:00
Fabian Homborg
534f694cee parse_execution: Check array index before using it 2018-11-14 12:15:40 +01:00
Mahmoud Al-Qudsi
6dafcc4960 Partially revert 55b3c45 to create pgrp when launched with invalid pgrp
If fish detects that it was started with a pgrp of 0 (which appears to
oddly be the case when run under firejail), create new process group for
fish and give it control of the terminal.

This selectively reverts 55b3c45 in cases where an invalid pgrp is
detected. Note that this is known to cause problems in other cases, such
as #3805 and Microsoft/WSL#1653, although the former may have been
ameliorated or even addressed by the recent job control overhaul, so
that's why we are careful to only assign fish to its own pgroup if an
invalid pgroup was detected and not as the normal case.
2018-11-13 15:00:52 +01:00
ridiculousfish
121991b98c Revert "Convert job list to a dequeue"
This reverts commit 54050bd4c5.

Type job_list_t was changed from a list to a deque in
commit 54050bd4c5.

In process_clean_after_marking(), we remove jobs while iterating.
dequeues do not support that. Make it a list again.
2018-11-11 16:57:30 -08:00
ridiculousfish
6f46eaaeeb Revert "Fix a stale comment"
This reverts commit efa9553dc1.

The comment was not stale.
2018-11-11 16:56:49 -08:00
ridiculousfish
efa9553dc1 Fix a stale comment 2018-11-11 16:08:45 -08:00
ridiculousfish
aa6be9bee4 Pass the original string into wildcard's decsription function
wildcard_complete was invoking the description function with some fragment
of the wildcard string. Instead pass in the original string.

Fixes #5327
2018-11-11 14:15:45 -08:00
Fabian Homborg
77229effb5 expand: Fix get_home_directory_name
This fixes the `~floam/` case, where the out_tail_idx pointer needs to
point to the "/", not the last letter.

The `~/` and `~floam` cases still work.

Unfortunately, I'm unsure of how to test this.

Fixes #5325.
2018-11-08 10:07:45 +01:00
Fabian Homborg
460bc00698 Fix string escape var and url styles
Turns out I broke these in my zeal to remove wcs2string.

This reverts commit 583d771b10.

Fixes #5322.
2018-11-07 12:48:11 +01:00
ridiculousfish
bfd50863b8 Correct fish_wcstod and fix Linux build failure
Limit the fish_wcstod fast path to ASCII digits only, to fix the problem
observed in the discussion for a700acadfa
where LANG=de_DE.UTF-8 would cause `test` to interpret commas instead of
periods inside floating point values.
2018-11-06 23:17:41 -08:00
ridiculousfish
a700acadfa Implement fish_wcstod and adopt it in builtin_test
wcstod_l is enormously slow on the Mac. This makes arithmetic comparisons
using builtin_test about 250% as fast on macOS.
2018-11-04 20:28:10 -08:00
Fabian Homborg
a7ec158373 env: Use preexisting_flags to determine pathiness
We've already checked if the variable exists above, and we've already
gotten the preexisting_flags, so we can just use them.

Saves a lookup.
2018-11-04 17:05:22 +01:00
ridiculousfish
73537fc7c3 Remove NESTED and WAIT_BY_PROCESS
Now jobs are aware of their parent jobs, and can interrogate those jobs,
to determine if every job in the chain is fully constructed.
Remove flags and the static stacks that manipulated them.
2018-11-04 01:52:17 -08:00