As reported in fish-shell/fish-shell#5180, when the USER environment
variable is not set and fish is started, `get_runtime_path()` returns a
blank string. At some point in the past, this was called after
`setup_user()` in env.cpp, but this is no longer the case.
This commit removes the reliance on the $USER environment variable
entirely, and instead uses `getpwuid(geteuid()).pw_name` to retrieve the
current username.
Closes#5180.
Prior to this fix, the fish universal variables file claimed that
changes to it would be overwritten. This no longer true and has not
been true for a long time. Remove that warning.
This switches the universal variables file from a machine-specific
name to the fixed '.config/fish/fish_universal_variables'. The old file
name is migrated if necessary.
Fixes#1912
The value is not electrified or tied and is read-only. It isn't cached
in the get_hostname_identifier() function as the ENV_GLOBAL $hostname
will cache it for its duration.
The behavior of `gethostname` in case of an insufficient buffer is
library and version dependent. Work around this by using a big enough
buffer then truncating the output to our desired max length.
Took care of remaining issues preventing fish from building on Solaris.
Mainly caused by some assumptions that certain defines are POSIX when
they are not (`NAME_MAX`).
Moved `NAME_MAX` defines to common.h - for some reason, it was being
defined in a cpp file (`env_universal_common.cpp`) even though it is used
in multiple source files.
Now compiles on Solaris 11 with GNU Make. Still some warnings because
fish was written with GNU getopt in mind and the Solaris version doesn't
use `const char *` but rather just `char *` for getopt values, but it
builds nevertheless.
Assuming this closes#3340
This eliminates the "missing" notion of env_var_t. Instead
env_get returns a maybe_t<env_var_t>, which forces callers to
handle the possibility that the variable is missing.
This commit backs out certain optimizations around setting environment
variables, and replaces them with move semantics. env_set accepts a
list, by value, permitting callers to use std::move to transfer
ownership.
Make setting fish vars more efficient by avoiding creating a
wcstring_list_t for the case where we're setting one value. For the case
where we're passing a list of values swap it with the list in the var
rather than copying it. This makes the benchmark in #4200 approximately
6% faster.
commit 50f414a45d58fcab664ff662dd27befcfa0fdd95
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date: Sat Aug 19 13:43:35 2017 -0500
Converted file_id_t set to unordered_set with custom hash
commit 83ef2dd7cc1bc3e4fdf0b2d3546d6811326cc3c9
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date: Sat Aug 19 13:43:14 2017 -0500
Converted remaining set<wcstring> to unordered_set<wcstring>
commit 053da88f933f27505b3cf4810402e2a2be070203
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date: Sat Aug 19 13:29:21 2017 -0500
Switched function sets to unordered_set
commit d469742a14ac99599022a9258cda8255178826b5
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date: Sat Aug 19 13:21:32 2017 -0500
Converted list of modified variables to an unordered set
commit 5c06f866beeafb23878b1a932c7cd2558412c283
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date: Sat Aug 19 13:15:20 2017 -0500
Convert const_string_set_t to std::unordered_set
As it is a readonly-list of raw character pointer strings (not
wcstring), this necessitated the addition of a hashing function since
the C++ standard library does not come with a char pointer hash
function.
To that end, a zlib-licensed [0] port of the excellent, lightweight
XXHash family of 32- and 64-bit hashing algorithms in the form of a C++
header-only include library has been included. XXHash32/64 is pretty
much universally the fastest hashing library for general purpose
applications, and has been thoroughly vetted and is used in countless
open source projects. The single-header version of this library makes it
a lot simpler to include in the fish project, and the license
compatibility with fish' GPLv2 and the zero-lib nature should make it an
easy decision.
std::unordered_set brings a massive speedup as compared to the default
std::set, and the further use of the fast XXHash library to provide the
string hashing should make all forms of string lookups in fish
significantly faster (to a user-noticeable extent).
0: http://create.stephan-brumme.com/about.html
commit 30d7710be8f0c23a4d42f7e713fcb7850f99036e
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date: Sat Aug 19 12:29:39 2017 -0500
Using std::unordered_set for completions backing store
While the completions shown to the user are sorted, their storage in
memory does not need to be since they are re-sorted before they are
shown in completions.cpp.
commit 695e83331d7a60ba188e57f6ea0d9b6da54860c6
Author: Mahmoud Al-Qudsi <mqudsi@neosmart.net>
Date: Sat Aug 19 12:06:53 2017 -0500
Updated is_loading to use unordered_set
No longer using RAII wrappers around pthread_mutex_t and pthread_cond_t
in favor of the C++11 std::mutex, std::recursive_mutex, and
std::condition_variable data types.
Internally fish should store vars as a vector of elements. The current
flat string representation is a holdover from when the code was written
in C.
Fixes#4200
Newer versions of GCC and Clang are not satisfied by a cast to void,
this fix is adapted from glibc's solution.
New wrapper function ignore_result should be used when a function with
explicit _unused_attribute_ wrapper is called whose result will not be
handled.
Make the `env_var_t::missing_var()` object a singleton rather than a
dynamically constructed object. This requires some discipline in its use
since C++ doesn't directly support immutable objects. But it is slightly
more efficient and helps identify code that incorrectly mutates `env_var_t`
objects that should not be modified.
This silences warnings from the compiler about ignoring return value of
‘ssize_t write(int, const void*, size_t)’, declared with attribute
warn_unused_result [-Wunused-result].
Fish 2.6.0 introduced a regression that keeps setting
`fish_escape_delay_ms` as a uvar from working. This also fixes a related
problem: callbacks generated from the initial loading of universal vars
were not being acted on.
Fixes#4196
Commit f10e4f8 causes some old compilers to complain about implicit
return from non-void function. A false positive error but make the
compiler happy so it stops complaining.
This is the first step in addressing issue #3965. It renames some of the
functions involved in validating variable and function names to clarify
their purpose. It also augments the documentation to make the rules for
such identifiers clearly documented.
A call to default_vars_path() takes the environment variable
lock while the uvars lock is held. Ensure that doesn't happen by
deferring the uvars lock to later in the function.
I recently upgraded the software on my macOS server and was dismayed to
see that cppcheck reported a huge number of format string errors due to
mismatches between the format string and its arguments from calls to
`assert()`. It turns out they are due to the macOS header using `%lu`
for the line number which is obviously wrong since it is using the C
preprocessor `__LINE__` symbol which evaluates to a signed int.
I also noticed that the macOS implementation writes to stdout, rather
than stderr. It also uses `printf()` which can be a problem on some
platforms if the stream is already in wide mode which is the normal case
for fish.
So implement our own `assert()` implementation. This also eliminates
double-negative warnings that we get from some of our calls to
`assert()` on some platforms by oclint.
Also reimplement the `DIE()` macro in terms of our internal
implementation.
Rewrite `assert(0 && msg)` statements to `DIE(msg)` for clarity and to
eliminate oclint warnings about constant expressions.
Fixes#3276, albeit not in the fashion I originally envisioned.
I'm starting to wonder if IWYU is worth the effort. Nonetheless, this
makes it lint clean on macOS and reduces the number of warnings on
FreeBSD and Linux.
mkostemp is not available on some older versions of macOS. In order
for our built binaries to run on them, mkostemp must be weak-linked.
On other systems, we use the autoconf check.
Introduce a function fish_mkstemp_cloexec which uses mkostemp if
it was detected and is available at runtime, else falls back to
mkstemp. This isolates some logic that is currently duplicated in
two places.
See #3138 for more on weak linking.
On some platforms, notably GNU libc, you cannot mix narrow and wide
stdio functions on a stream like stdout or stderr. Doing so will drop
the output of one or the other. This change makes all output to the
stderr stream consistently use the wide forms.
This change also converts some fprintf(stderr,...) calls to debug()
calls where appropriate.
Fixes#3692
I noticed that universal variable tests were failing on Cygwin and
Dragonfly BSD. The failures were because we are attempting to verify the
correct behavior of mechanisms that are known to be broken on those
platforms. There are still uvar test failures on those platforms with
this change but they are due to actual problems rather than bugs in the
tests.
Fixes#3587
If acquiring a lock on the history or uvar file takes more than 250 ms
disable locking of the file. On systems with broken remote file system
locking it can cause tens of seconds delay after running each command
which can make the shell borderline unusable.
This also changes history file locking to use flock() rather than
fcntl() to be consistent with uvar file locking. It also implements the
250 ms time limit before giving up on locking.
Fixes#685
This change increases the amount of useful information when fish is
unable to create or use its config or data directory. We now make it
clear when neither var is set or one is set to an unusable location.
Fixes#3545
Builtin commands that validate var names should use a consistent
mechanism. I noticed that builtin_read() had it's own custom code that
differed slightly from wcsvarname().
Fixes#3569
This fixes some of the IWYU and cppcheck lint warnings. And only on
macOS (formerly OS X). Fixing these types of warnings on a broader set
of platforms should be done but this is a baby step to making `make
lint-all` have few, if any, warnings. This reduces the number of lines
in the `make lint-all` output on macOS by over 500 lines.
Commit acfd3801 included a legitimate bug fix and a second change that
didn't correct an actual bug but made the code more fragile. Revert the
second part of that commit (while also suppressing the uninitialized
variable compiler warning that caused the ill-advised change).
Just use static_cast directly instead of inscrutible "shortcut"
macro.
It was not always used and doesn't seem to do much besides scramble
things up; encountering CAST_INIT() in the code seems likely to lead
to head scratching due to the transformation taking place.
It was added to save folks typing the type twice, now with 100
columns available, let's roll that convenience macro back.
sockaddr_dl:
Perform reinterpret_cast<sockaddr_dl> conversion. The cast affected
alignment and looks fishy to a compiler (but it's fine). Ditch
C-style cast and communicate we're doing that on purpose.
* if (result == ULLONG_MAX) is always false, likely a typo as
result is unsigned long, and the comment says ULONG_MAX.
* use off_t instead of size_t for file size where it can mismatch
st_size's type in stat.h
This only eliminates errors reported by `make lint`. It shouldn't cause any
functional changes.
This change does remove several functions that are unused. It also removes the
`desc_arr` variable which is both unused and out of date with reality.
Remove the "make iwyu" build target. Move the functionality into the
recently introduced lint.fish script. Fix a lot, but not all, of the
include-what-you-use errors. Specifically, it fixes all of the IWYU errors
on my OS X server but only removes some of them on my Ubuntu 14.04 server.
Fixes#2957
This is a quick and dirty conversion of the atypical, and undocumented,
logging done by env_universal_common.cpp to the usual `debug()` pattern. I
didn't want to drop the messages because they could be useful when
debugging future issues. So I simply converted them to the lowest debug
level using the normal debug() function.
Fixes#2887
The u_int typedef fails to compile on all platforms (e.g. Windows). It
is part of the code imported from tmux.
Update it to the SUS-standard uid_t.
Closes#2821.
Address the feedback from the prior commit:
- Change the sense of return value testing to match more common
comparison idiom
- Test result of fchmod as well as fchown
- Change sense of return value testing around wrename as well
- Include errno where possible in error message
The function fchown is annotated with warn_unused_result. As
formerly used in the code, it would emit a compiler warning
```warning: ignoring return value of ‘fchown’, declared with
attribute warn_unused_result [-Wunused-result]```
This commit notes the return value and emits appropriate error/logging
messages if the call fails, creating more traceable results and
satisfying the compiler.
Previously, when decoding UTF-8, we would first run through the
array to compute the correct size, then allocate a buffer of that size,
then run through the array again to fill the buffer, and then copy it
into a std::wstring. With this fix we can copy it into the string
directly, reducing allocations and only requiring a single pass.
We identify when the universal variable file has changed out from under us by
comparing a bunch of fields from its stat: inode, device, size, high-precision
timestamp, generation. Linux aggressively reuses inodes, and the size may be
the same by coincidence (which is the case in the tests). Also, Linux
officially has nanosecond precision, but in practice it seems to only uses
millisecond precision for storing mtimes. Thus if there are three or more
updates within a millisecond, every field we check may be the same, and we are
vulnerable to the ABA problem. I believe this explains the occasional test
failures.
The solution is to manually set the nanosecond field of the mtime timestamp to
something unlikely to be duplicated, like a random number, or better yet, the
current time (with nanosecond precision). This is more in the spirit of the
timestamp, and it means we're around a million times less likely to collide.
This seems to fix the tests.
Cygwin FIFOs do not support more than one reader, so avoid them on this
platform. An autoconf feature test would be helpful but is tricky to
write.
Closes#2152.
This change moves source files into a src/ directory,
and puts object files into an obj/ directory. The Makefile
and xcode project are updated accordingly.
Fixes#1866