Oliver Kurth [Fri, 15 Sep 2017 18:23:15 +0000 (11:23 -0700)]
Hgfs FUSE client: fix broken attribute caching on writes
The FUSE write implementation incorrectly invalidated the cache of file
attributes. The return code for the write operation checked for only invalidating
attribute cache if the result was zero. However, this result is negative for
an error (in which case the cached attributes should not be invalidated) and anything
else is the number of bytes written.
The fix for the broken attribute caching on writes is made to check the result
for greater than zero so any success. If no bytes were actually written we take
the conservative approach of still invalidating the cache as so all the files
attributes for that file will be reset in the FUSE client. This should be rare
at best.
Oliver Kurth [Fri, 15 Sep 2017 18:23:15 +0000 (11:23 -0700)]
Set up pid/socket directory earlier
/var/run/vmware is used for both the sockets and the
pid file. In fresh open-vm-tools scenarios, it tends
not to exist when we need it for the pid file. Refactor
the code and make sure it exists soon enough to be used
for the pid file.
Oliver Kurth [Fri, 15 Sep 2017 18:23:10 +0000 (11:23 -0700)]
make System_GetTimeMonotonic() really monotonic
Solaris has an issue where times() can return a lower value than it
returned earlier, making it non-monotonic. This change works
around this by saving the last returned value and returning that
if the times() function return a lower value.
Oliver Kurth [Fri, 15 Sep 2017 18:23:10 +0000 (11:23 -0700)]
Properly configure xmlsec1 for CentOS
Some distros build xmlsec1 with dynamic crypto, so do things slightly
differently.
Also work around an issue with the way Redhat & SuSE package xmlsec1.
They built it with -DXMLSEC_NO_SIZE_T, but that flag isn't properly
exposed by xmlsec1-config. This results in a bunch of xmlsec1 data
structures (anything with an xmlSecSize in it) being different between
the lib and our code, and it tends not to work when our code references
fields in the data structure. This change always sets -DXMLSEC_NO_SIZE_T.
Oliver Kurth [Fri, 15 Sep 2017 18:23:10 +0000 (11:23 -0700)]
Backout asyncSocket change to not exit recv loop early when SSL_Pending is zero
Change being reverted:
After reading some bytes with SSL_Read() and firing any
callbacks, we would make a call to SSL_Pending() and, if that
returned zero, we would break out of the read loop and return.
We would only make a second call to SSL_Read() if Pending()
returned a non-zero value.
There are several problems with this.
Firstly, having bytes buffered up within SSL is a reason to
continue performing SSL_read()s, but not having bytes buffered
is not a reason to stop.
If the socket does not have SSL enabled, for instance,
Pending() always returned zero, so non-SSL sockets would never
actually loop here and every read would bounce back through
Poll.
Even in the case where SSL is enabled, this function returns
only the number of bytes buffered inside the SSL context and
provides no information about whether the socket itself has
bytes available for immediate read.
So, again, if SSL_Pending() is non-zero, we want to keep on
reading data with SSL_Read(), and if it is zero, we *still*
want to keep on reading data the socket itself may have more
data immediately available.
Oliver Kurth [Fri, 15 Sep 2017 18:23:10 +0000 (11:23 -0700)]
Use /etc as default dir for pam instead of sysconfdir
sysconfdir evaluates to $(prefix)/etc by default, which evaluates
to /usr/local/etc by default. This is (almost?) never a correct path
for pam config files except for FreeBSD, so set the default to /etc,
with the exception of FreeBSD.
Oliver Kurth [Fri, 15 Sep 2017 18:23:10 +0000 (11:23 -0700)]
Additional AsyncSocket API clean-up.
- Convert void-returning asyncsocket entrypoints to have an integer
return type, returning ASOCKERR_*/
- Do not exit recv loop early when SSL_Pending is zero; the socket
itself may have more data immediately available.
- Allow a small number of recursives uses of the send callback.
Common header file change; not applicable to open-vm-tools.
Oliver Kurth [Fri, 15 Sep 2017 18:23:09 +0000 (11:23 -0700)]
Hgfs Linux Kernel Client: Fix RHEL 7 system backports
RHEL 7.3 introduced some backport changes for the Linux kernel
which broke some of the assumptions about wait_on_bit function
arguments. This fixes the test of wait_on_bit compile which
accidentally tests the function in kernel 3.17.0 which will
always fail instead of intentionally failing with the pragma.
Oliver Kurth [Fri, 15 Sep 2017 18:23:09 +0000 (11:23 -0700)]
Improve network recovery for Linux Virtual Desktop Infrastructure.
Client needs to react to an unexpected disconnect and reconnect with a saved session id and path.
Common header file change; not applicable to open-vm-tools.
Oliver Kurth [Fri, 15 Sep 2017 18:23:09 +0000 (11:23 -0700)]
Hostinfo_SystemTimerNS
On Apple, switch from using floating-point to fixed-point
for nanosecond time conversions on iOS. (Note: x86 is 1:1
so never used floating point). Fixed point is easily faster,
plus uses a 128-bit multiply that avoids overflow. Added
some comments to point out "interesting" cases that show
why we do not use Apple's documented method.
Oliver Kurth [Fri, 15 Sep 2017 18:23:09 +0000 (11:23 -0700)]
Fix localization code
The code that loads a message catalog attempted to handle
continuation lines. However, it ended up dropping anything
it decided wasn't a continuation line.
The end result is that any message catalog that had
multiple valid entries without any empty lines
between them would lose valid data.
Oliver Kurth [Fri, 15 Sep 2017 18:23:08 +0000 (11:23 -0700)]
Hostinfo_SystemTimerNS: Inlining
Now that we require glibc-2.5+, we can
also require the glibc-2.4 clock_gettime() call
be implemented. CLOCK_MONOTONIC is required for
all clock_gettime() implementations (per POSIX),
so the implementation here just became Really Easy.
This is intended as a code simplification / standardization;
there is no expected performance impact.
Oliver Kurth [Fri, 15 Sep 2017 18:23:08 +0000 (11:23 -0700)]
Hostinfo_SystemTimerNS: Inlining
Now that we require glibc-2.5+, we can
also require the glibc-2.4 clock_gettime() call
be implemented. CLOCK_MONOTONIC is required for
all clock_gettime() implementations (per POSIX),
so the implementation here just became Really Easy.
This is intended as a code simplification / standardization;
there is no expected performance impact.
Oliver Kurth [Fri, 15 Sep 2017 18:23:08 +0000 (11:23 -0700)]
Hostinfo_SystemTimerNS: Update Tools build files
The tools build files need some light touch-ups to
make librt.so mandatory (Linux and Solaris only).
- configure.ac: Linux already required librt, add
a Solaris requirement
- vmtoolslib.make: add a Solaris requirement
Oliver Kurth [Fri, 15 Sep 2017 18:23:08 +0000 (11:23 -0700)]
Update glib and pcre for FreeBSD and Solaris
Update glib, pcre, and additional libraries they require
for FreeBSD and Solaris.
With this change, a release note will be needed to advise
users to add the following lines to /etc/libmap.conf before
installing vmtools on FreeBSD 6.x:
The presence of these lines will cause the run-time linker to use
libthr.so.2 whenever it encounter a dependency on libpthread.so.2
in an executable whose path starts with /usr/local/lib/vmware-tools.
The reason for the release note is as follows. FreeBSD provides
a threads library called libthr.so.2. In FreeBSD 6.x, this library
is separate from and incompatible with libpthread.so.2. In FreeBSD
7 or later, libpthread.so.2 is a symlink to libthr.so.2.
vmtoolslib is linked against libthr.so.2, while libgthread-2.0.so.0
and libglib-2.0.so.0 are linked against libpthread.so.2. On FreeBSD
7 or later, this works fine since libpthread.so.2 is a symlink to
libthr.so.2, as noted above. However, on FreeBSD 6.x, vmtoolsd
core dumps because libthr.so.2 and libpthread.so.2 are separate
libraries, hence both are loaded and their incomatibility results
in a core dump.
Adding the above lines in /etc/libmap.conf will keep libpthread.so.2
from being loaded, thereby allowing vmtoolsd to run.
Oliver Kurth [Fri, 15 Sep 2017 18:23:08 +0000 (11:23 -0700)]
More AsyncSocket changes. In AsyncTCPSocketBlockingWork(), do not block
necessary. Reverse the order of the read/write and poll/select opterations.
This reduces latency when the socket is ready for the I/O operation.
This low latency option is "off" be default.
Changes to common header files; not directly applicable to open-vm-tools.
Oliver Kurth [Fri, 15 Sep 2017 18:23:07 +0000 (11:23 -0700)]
Update VGAuth source for compilation with OpenSSL 1.0.x or 1.1.0
OpenSSL 1.1.0 is about to released. With that release comes a number
of changes that include making several types opaque. Along with this,
new or renamed setter/getter functions appear. The API changes and
the impact on open-source products is discussed at:
https://wiki.openssl.org/index.php/1.1_API_Changes. Updated man pages
are available at: https://www.openssl.org/docs/manmaster/
The impact to open-vm-tools is that the message digest type MD_CTX
has become opague. Local (stack) MD_CTX objects are not supported.
The required change is to dynamically allocate MD_CTX objects as needed
using the 1.1.0 API xxx_new() and xxx_free() or the pre-1.1.0 functions
xxx_create() and xxx_destroy().
Oliver Kurth [Fri, 15 Sep 2017 18:23:07 +0000 (11:23 -0700)]
Add string concatenation function to DynBuf
The DynBuf code operates on both strings and non-strings. To add a
string at the end of a DynBuf is easy: DynBuf_AppendString() appends
a copy of the input string, including its NULL-termination. Sometimes
strings are repeatedly concatenated, such that a version of this
function without NULL-termination is needed.
This change implements DynBuf_ConcatString() which explicitly does not
copy the NULL at the end of a string.
Oliver Kurth [Fri, 15 Sep 2017 18:23:07 +0000 (11:23 -0700)]
POSIX FileIOErrno2Result should not log when it is called
POSIX FileIOErrno2Result logs when an errno doesn't map well. This can
cause callers to have unexpected logging. In fact, the Log Facility
got caught by this. Log write errors generated more logs!
This has, at times, lead to spew in the logs. Logging could occur on
each I/O failure!
If an error needs to be logged, the caller should check the error
status and react accordingly. They can use Err_Errno to get the
native error in a platform independent way.
Remove the logging in FileIOErrno2Result; Add logging for open
failures that are from "unusual" errors; remove logging from I/O
errors.
Oliver Kurth [Fri, 15 Sep 2017 18:23:06 +0000 (11:23 -0700)]
VThreadBase signal counting: remove malloc
This is the easy first half of rewriting VThreadBase to not malloc
within signal handlers. The second half is still under construction.
The core problem is that malloc() inside a signal handler can
deadlock; consider especially the case of malloc() detecting
heap corruption -> SEGV -> signal handler -> malloc() and
self-deadlocking. Thus, the overall plan is to stop malloc()ing
and instead use TLS variables ... as the new comment points out,
we can now count on good TLS behavior since Linux and Windows
minimum OS versions bumped.
In the signal handler case this is easy: if __thread is available
we can just use that as a counter. Life is a little more tricky
without __thread (see: macOS and Android), where we need to use
pthread_{get,set}specific() calls. Use a constructor/destructor
to manage the TLS keys, which is a strategy dependent on the
TLS destructor being NULL. (Specifically, on library unload
the destructor function can remove the TLS key but cannot fire
the TLS destructor on all threads, which would leak).
One small note, the use of an atomic is not needed here because
only the current thread can set the value and, if interrupted by
a signal, the stack preserves the correct value.
Two other minor things deserve mention: first, remove the TID
parameter from VThreadBase_SetIsInSignal(); it was only used for
self. Second, re-ordered setting is-in-signal and the first
VThread_CurID() in the signal handler; this means the VThread_CurID()
implementation can check whether we are in a signal handler, a
feature that will matter in a future change.
Net result: the signal counting part can now run without any memory
allocations whatsoever. Memory allocation is thus needed only for
the thread ID and name. Stay tuned for TID/name in a future change.
Oliver Kurth [Fri, 15 Sep 2017 18:23:06 +0000 (11:23 -0700)]
Minor dead code removal
Hostinfo_GetPCFrequency: function has no callsites. And
now that Windows Hostinfo_SystemTimerNS is Really Fast(tm),
amortizing ticks-to-nanosecond conversions doesn't make sense.
Util_TokenHasInteractPriv: has only one callsite, used in
a log message. Delete.