Commit Graph

18616 Commits

Author SHA1 Message Date
ache 67613cbbd8 a) Use strcoll() in opendir() and alphasort()
as POSIX 2008 requires. It also matches now how our 'ls' works for years.

b) Remove comment expressed 2 fears:
 1) One just simple describe how strcoll() works in _any_ context,
 not for directories only. Are we plan to remove strcoll() from everything
 just because it is little more complex than strcmp()? I doubt, and
 directories give nothing different here. Moreover, strcoll() used
 in 'ls' for years and nobody complaints yet.

 2) Plain wrong statement about undefined strcoll() behaviour. strcoll()
 always gives predictable results, falling back to strcmp() on any
 trouble, see strcoll(3).

No objections from -current list discussion.
2019-02-01 10:37:00 +01:00
das 2d3c2f4697 scandir(3) previously used st_size
to obtain an initial estimate of the array length needed to store all
the directory entries. Although BSD has historically guaranteed that
st_size is the size of the directory file, POSIX does not, and more to
the point, some recent filesystems such as ZFS use st_size to mean
something else.

The fix is to not stat the directory at all, set the initial
array size to 32 entries, and realloc it in powers of 2 if that
proves insufficient.

PR:	113668
2019-02-01 10:36:40 +01:00
obrien d785551a46 Remove __P and convert to ANSI prototypes.
* Fix SCM ID's.
2019-02-01 10:33:14 +01:00
jhb 0e7db0c356 Clean up the vcs ID strings
in libc's gen/ directory.

- Move CSRG IDs into __SCCSID().
- When a file has been copied, consistently use 'From: <tag>' for strings
  referencing the version of the source file copied from in the license
  block comment.
- Some of the 'From:' tags were using $FreeBSD$ that was being expanded on
  each checkout.  Fix those to hardcode the FreeBSD tag from the file that
  was copied at the time of the copy.
- When multiple strings are present list them in "chronological" order,
  so CSRG (__SCCSID) before FreeBSD (__FBSDID).  If a file came from
  OtherBSD and contains a CSRG ID from the OtherBSD file, use the order
  CSRG -> OtherBSD -> FreeBSD.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D15831
2019-02-01 10:32:24 +01:00
imp b46ef7699f Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2019-02-01 10:32:24 +01:00
Sebastian Huber 62fb0614c6 scandir: Update copyright notice from FreeBSD
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2019-02-01 10:32:24 +01:00
pfg 24629e9701 General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2019-02-01 10:32:24 +01:00
Corinna Vinschen 9a5abcc896 Cygwin: x86_64: pthreads: Install exception handler after switching stack
After creating a pthread, the stack gets moved to the desired memory
location.  While the 32 bit thread wrapper copies the exception handler
information to the new stack (so we have at least *some* exception
handler present), the x86_64 code didn't perform any exception handler
magic.  Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30 20:05:39 +01:00
Corinna Vinschen ba3e20894d Cygwin: document W10 1803 per-directory case-sensitivity behaviour
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30 16:16:25 +01:00
Corinna Vinschen ef8ce3077f Cygwin: fork: fix child process permissions, take 2
VirtualQueryEx, called by fixup_mmaps_after_fork, requires
PROCESS_QUERY_INFORMATION permissions per MSDN.  However, testing
shows that PROCESS_QUERY_LIMITED_INFORMATION is sufficient when
running the same code on Windows 8.1 or Windows 10.  Fix the code
to give the forked child always PROCESS_QUERY_INFORMATION perms
on Windows Vista/7 and respective server releases.

Revert now unneeded patch to check_token_membership as well.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30 12:18:03 +01:00
Corinna Vinschen a52396bd07 Cygwin: raise: change to call pthread_kill
POSIX requires that raise(3) is equivalent to

  pthread_kill(pthread_self(), sig);

in multi-threaded applications.  Our raise just called kill(sig).
Fix that.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-30 11:36:45 +01:00
Corinna Vinschen 4d738e0f62 Cygwin: execve: reduce parent handle to non-inheritable SYNCHRONIZE
Keeping an inheritable handle open results in that handle being
spilled over into grandchild processes, which is not desired.
Duplicate original parent handle into a non-inheritable one with
minimal SYNCHRONIZE permissions and close the original handle.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-29 20:37:00 +01:00
Corinna Vinschen 5a0f2c00aa Cygwin: fork/exec: fix child process permissions
- Exec'ed/spawned processes don't need PROCESS_DUP_HANDLE.  Remove that
  permission from the parent handle.

- PROCESS_QUERY_LIMITED_INFORMATION doesn't work for Windows 7 if the
  process is started as a service.  Add PROCESS_QUERY_INFORMATION for
  pre-Windows 8 in that case.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-29 17:59:23 +01:00
Corinna Vinschen c86b2f549b Cygwin: Makefile.in: Improve dependency for version info
The version info only depends on the object files.  This results
in the version info not being rebuild immediately if a source
file is changed.  Rather, the version info is only rebuilt on the
next make run.

Fix that by making the version info build rule dependent on the
source files.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-29 17:55:37 +01:00
Corinna Vinschen e148aa62a7 Cygwin: procfd: improve debug output
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-28 10:24:39 +01:00
Corinna Vinschen 2741dd0550 Cygwin: seteuid: disable unused funcs and lsaauth subdir
If S4U proves to be usable alone, remove this code entirely.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-28 10:24:18 +01:00
Corinna Vinschen 3b21333172 Cygwin: spawn: revert incorrect restriction of permissions
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-27 22:42:41 +01:00
Corinna Vinschen 69cc7a0686 Cygwin: fork: restrict parent handle perms and drop handle after use
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-27 13:15:31 +01:00
Corinna Vinschen 0fb497165f Cygwin: seteuid: use Kerberos/MsV1_0 S4U authentication by default
- This simple and official method replaces cyglsa and "create token"
  methods.  No network share access, same as before.

- lsaauth and create_token are disabled now.  If problems crop up,
  they can be easily reactivated.  If no problems crop up, they
  can be removed in a while, together with the lsaauth subdir.

- Bump Cygwin version to 3.0.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 19:41:03 +01:00
Corinna Vinschen 84230b71c6 Cygwin: uname: Raise size of utsname fields and revamp uname(2) output
New format:

  sysname:      CYGWIN_NT-${osversion}-${os_build_number}[-WOW64]
  nodename:     `gethostname`
  release:      ${cygwin_version}-${API minor}.${arch}[.snap]
  version:      YYYY-MM-DD HH:MM UTC
  machine:      ${arch}
_GNU_SOURCE:
  domainname:   `getdomainname`
!_GNU_SOURCE:
  __domainname: `getdomainname`

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 18:37:25 +01:00
Corinna Vinschen 6ffcc50f19 Cygwin: netdb.h: fix __GNU_VISIBLE tests
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 18:34:03 +01:00
Corinna Vinschen 0e3fd33321 Cygwin: create_token: Return NULL, not INVALID_HANDLE_VALUE
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 12:42:38 +01:00
Corinna Vinschen 3a1ed0ef70 Cygwin: syscalls.cc: fix formatting
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 12:42:38 +01:00
Corinna Vinschen c524a915a5 Cygwin: lsaauth: Drop outdated test for loading Secur32.dll
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-26 12:42:37 +01:00
Corinna Vinschen 02373d8bec Cygwin: seteuid: work with password-less user switch as well
The previous patch failed with password-less auth because in
that case the return code from get_server_groups wasn't tested.
Fix that.  Also make sure that get_server_groups does not
check if the account is disabled or locked out when just fetching
the group list for initgroups or getgrouplist.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 21:20:09 +01:00
Corinna Vinschen 2c12a2c32a Cygwin: seteuid: refuse changing uid to disabled or locked out user
So far seteuid could change uid to any existing account, given
sufficient permissions of the caller.  This is kind of bad since
it disallows admins to refuse login to disabled or locked out
accounts.

Add check for the account's UF_ACCOUNTDISABLE or UF_LOCKOUT flags
and don't let the user in, if one of the flags is set.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 16:24:35 +01:00
Corinna Vinschen 2166f7dc0d Cygwin: net: unify gethostname/getdomainname
Use info from same source (GetNetworkParams).
Also move getdomainname near gethostname in source.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 14:22:24 +01:00
Corinna Vinschen c6171b9fde Cygwin: gethostname: fix fetching hostname from non-winsock function
If gethostname() fails we call GetComputerNameEx with
ComputerNameDnsFullyQualified.  This is wrong, gethostname should return
the hostname only, not the FQDN.  Fix this by calling GetComputerNameEx
with ComputerNameDnsHostname.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 14:04:42 +01:00
Corinna Vinschen 04e3dc1128 Cygwin: version: Use UTC timestamp as build time
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-24 11:39:43 +01:00
Corinna Vinschen b79b0c2bae Cygwin: cygthread: set thread name before calling thread func
When reusing a cygthread, the stub method fails to set the thread name
to the new name.  The name is only set when actually creating the
thread.  Fix that by moving the SetThreadName call right in front of the
thread function call.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-23 21:45:59 +01:00
Jozef Lawrynowicz b644774b8f Use nanf() instead of nan() in single-precision float libm math functions
This patch reduces code size for a few single-precision float math
functions, by using nanf() instead of nan() where required.
2019-01-23 10:46:30 +01:00
Jozef Lawrynowicz d451d9ec78 Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functions
This patch replaces instances of "(float).*HUGE_VAL" with a direct usage of
HUGE_VALF, which is also defined in math.h.
2019-01-23 10:46:30 +01:00
Jozef Lawrynowicz 7db203304e Remove HUGE_VAL definition from libm math functions
This patch removes the definitions of HUGE_VAL from some of the float math
functions. HUGE_VAL is defined in newlib/libc/include/math.h, so it is not
necessary to have a further definition in the math functions.
2019-01-23 10:46:30 +01:00
Jozef Lawrynowicz b14a879d85 Remove matherr, and SVID and X/Open math library configurations
Default math library configuration is now IEEE
2019-01-23 10:46:24 +01:00
Corinna Vinschen 1f10a00ba7 Cygwin: posix timers: fix overrun count always being 1 too big
Combine with a bit of cleanup:
- Drop overrun_event_running in favor of overrun_count being -1.
- Fix include guard in posix_timer.h.
- Drop ununsed function timespec_to_us.
- Don't use Interlocked functions without need.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 18:20:18 +01:00
Corinna Vinschen de0ec284a3 Cygwin: posix timers: fix error handling in public API
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 16:38:21 +01:00
Corinna Vinschen 83c51fffe6 Cygwin: posix timers: allocate timer_tracker on system heap.
Allocating on the cygheap would copy information of the tracker into
the child process.  A forked child knows the timer id and could simply
still access the (free'd but still valid) timer_tracker on the heap,
which is dangerous and very certainly doesn't reflect POSIX semantics.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 16:38:14 +01:00
Corinna Vinschen 6c44af8179 Cygwin: timerfd: Add support for CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:46:17 +01:00
Corinna Vinschen 013e2bd9ec Cygwin: posix timers: Add support for CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:45:58 +01:00
Corinna Vinschen 1daece5861 Cygwin: clocks: Add CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM clocks
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:42:07 +01:00
Corinna Vinschen 13ea67a3c6 time.h: Add CLOCK_REALTIME_ALARM/CLOCK_BOOTTIME_ALARM
Slightly reshuffle and add comment

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:39:39 +01:00
Corinna Vinschen 229ea3f23c Cygwin: posix timers: reimplement using OS timer
- Rename files timer.* to posix_timer.*.
- Reimplement using an OS timer rather than a handcrafted wait loop.
- Use a Slim R/W Lock for synchronization.
- Drop timer chaining.  It doesn't server a purpose since all timers
  are local only.
- Rename ttstart to itimer_tracker to better reflect its purpose.
  It's not the anchor for a timer chain anymore anyway.
- Drop fixup_timers_after_fork.  Everything is process-local, nothing
  gets inherited.
- Rename timer_tracker::disarm_event to disarm_overrun_event for
  better readability.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:23:05 +01:00
Corinna Vinschen 4c50dc94c3 Cygwin: timerfd: another overrun computation fix and drop useless variable
- When correcting the next expiration timestamp, the number of
  expirations gets computed correctly, just the expiration timestamp
  itself is then only incremented by a single interval, rather than
  the just computed expired intervals.  Fix that.

- drop the local clock variable in timerfd_tracker::create.  It doesn't
  serve any purpose.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-22 15:06:51 +01:00
Corinna Vinschen a75bd958b4 Cygwin: timerfd: reset expiry counter in settime
As on Linux, reset the expiry counter when the timer gets rearmed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 22:54:26 +01:00
Corinna Vinschen 5b23a8e831 Cygwin: timerfd: fix gettime
- split into to __try/__except blocks to make sure
  leave_critical_section is always called when required.

- Actually fill time_spec in settime so it_interval is returned
  correctly.

- Return all 0 if timer is disarmed.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 22:52:39 +01:00
Corinna Vinschen 289b7c09c8 Cygwin: timerfd: move ioctl error handling into timerfd_tracker
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 12:41:00 +01:00
Corinna Vinschen 528f4d4938 Cygwin: timerfd: rename overrun_count to expiration_count
The value returned by reading from a timerfd is not an overrun
count in the same sense as for posix timers, it's an expiry counter.
Reflect that in the name.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 12:26:51 +01:00
Corinna Vinschen ea99e9fdda Cygwin: timerfd: fix overrun computation
- Drop erroneous initial computation of overrun count in settime
  for absolute non-realtime clocks.  It's repeated in thread_func
  and thus counted twice.

- Fix overrun computation for timestamp offsets being a multiple of
  the timer interval.  The timestamp has to be corrected after the
  first offset, otherwise the correction loop counts the intervals
  again.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 11:14:16 +01:00
Corinna Vinschen 6ed50a68a1 Cygwin: timerfd: settime: fix computing DueTime on non-realtime clocks
Non-CLOCK_REALTIME counters always use a relative DueTime in NtSetTimer.
However, relative DueTime has to be negative, but the code

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 10:05:16 +01:00
Corinna Vinschen a3268ac392 Cygwin: timerfd: Handle gettime error in settime
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2019-01-21 00:14:51 +01:00