History log of /freebsd-current/lib/libc/gen/sleep.c
Revision Date Author Comments
# 7dd9070e 16-Apr-2024 Brooks Davis <brooks@FreeBSD.org>

libc: INTERPOS_SYS macro for interposed syscalls

This macro makes uses the __sys_<foo>_t typedefs from libsys.h to
greatly simplify calling functions in the interposing table.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D44389


# ef5fddd3 13-Mar-2024 Brooks Davis <brooks@FreeBSD.org>

libsys: make __libsys_interposing static

Access __libsys_interposing with __libc_interposing_slot() in all
cases to support a move of these wrappers back to libc.

Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D44239


# 7d233b22 23-Feb-2024 Konstantin Belousov <kib@FreeBSD.org>

libsys: fix sleep(3)/usleep(3) cancel behavior

Move functions back to libc/gen sources; they are only versioned from
libc and not libsys.
Access libsys interposing slots using __libsys_interposing_slot()
instead of direct __libsys_interposing array dereference, which cannot
work from libc.

Reported by: glebius
Reviewed by: brooks
Sponsored by: The FreeBSD Foundation
Differential revision: https://reviews.freebsd.org/D44042


# dc36d6f9 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

lib: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# c1920558 03-Jul-2018 John Baldwin <jhb@FreeBSD.org>

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


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

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.


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

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


# d5bf9eb5 20-Sep-2015 Craig Rodrigues <rodrigc@FreeBSD.org>

Remove names from some prototypes


# e0b54d01 19-Sep-2015 Craig Rodrigues <rodrigc@FreeBSD.org>

Add declarations to eliminate -Wmissing-prototypes warnings


# 397d851d 11-Jan-2015 Konstantin Belousov <kib@FreeBSD.org>

Reduce the size of the interposing table and amount of
cancellation-handling code in the libthr. Translate some syscalls
into their more generic counterpart, and remove translated syscalls
from the table.

List of the affected syscalls:
creat, open -> openat
raise -> thr_kill
sleep, usleep -> nanosleep
pause -> sigsuspend
wait, wait3, waitpid -> wait4

Suggested and reviewed by: jilles (previous version)
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 8495e8b1 03-Jan-2015 Konstantin Belousov <kib@FreeBSD.org>

Fix known issues which blow up the process after dlopen("libthr.so")
(or loading a dso linked to libthr.so into process which was not
linked against threading library).

- Remove libthr interposers of the libc functions, including
__error(). Instead, functions calls are indirected through the
interposing table, similar to how pthread stubs in libc are already
done. Libc by default points either to syscall trampolines or to
existing libc implementations. On libthr load, libthr rewrites the
pointers to the cancellable implementations already in libthr. The
interposition table is separate from pthreads stubs indirection
table to not pull pthreads stubs into static binaries.

- Postpone the malloc(3) internal mutexes initialization until libthr
is loaded. This avoids recursion between calloc(3) and static
pthread_mutex_t initialization.

- Reinstall signal handlers with wrapper on libthr load. The
_rtld_is_dlopened(3) is used to avoid useless calls to sigaction(2)
when libthr is statically referenced from the main binary.

In the process, fix openat(2), swapcontext(2) and setcontext(2)
interposing. The libc symbols were exported at different versions
than libthr interposers. Export both libc and libthr versions from
libc now, with default set to the higher version from libthr.

Remove unused and disconnected swapcontext(3) userspace implementation
from libc/gen.

No objections from: deischen
Tested by: pho, antoine (exp-run) (previous versions)
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 2c201a9a 05-Dec-2009 Ed Schouten <ed@FreeBSD.org>

Fix many "function declaration isn't a prototype" warnings in libc.

I've only fixed code that seems to be written by `us'. There are still
many warnings like this present in resolv/, rpc/, stdtime/ and yp/.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# c879ae35 08-Jan-2007 Warner Losh <imp@FreeBSD.org>

Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.


# ea8d448a 31-Jan-2002 David E. O'Brien <obrien@FreeBSD.org>

Fix SCM ID's.


# d201fe46 24-Jan-2001 Daniel Eischen <deischen@FreeBSD.org>

Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread
functions. If the threads library is linked in, the real
pthread functions will pulled in.

Use the following convention for system calls wrapped by the
threads library:
__sys_foo - actual system call
_foo - weak definition to __sys_foo
foo - weak definition to __sys_foo

Change all libc uses of system calls wrapped by the threads
library from foo to _foo. In order to define the prototypes
for _foo(), we introduce namespace.h and un-namespace.h
(suggested by bde). All files that need to reference these
system calls, should include namespace.h before any standard
includes, then include un-namespace.h after the standard
includes and before any local includes. <db.h> is an exception
and shouldn't be included in between namespace.h and
un-namespace.h namespace.h will define foo to _foo, and
un-namespace.h will undefine foo.

Try to eliminate some of the recursive calls to MT-safe
functions in libc/stdio in preparation for adding a mutex
to FILE. We have recursive mutexes, but would like to avoid
using them if possible.

Remove uneeded includes of <errno.h> from a few files.

Add $FreeBSD$ to a few files in order to pass commitprep.

Approved by: -arch


# b479399f 15-Mar-2000 Jason Evans <jasone@FreeBSD.org>

Take care to avoid having "strong" and "weak" symbols of the same name in
libc_r.


# 9233c4d9 27-Jan-2000 Jason Evans <jasone@FreeBSD.org>

Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),
just use _foo() <-- foo(). In the case of a libpthread that doesn't do
call conversion (such as linuxthreads and our upcoming libpthread), this
is adequate. In the case of libc_r, we still need three names, which are
now _thread_sys_foo() <-- _foo() <-- foo().

Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(),
nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo().

Remove all internal libc usage of: creat(), pause(), sleep(), system(),
tcdrain(), wait(), and waitpid().

Make thread cancellation fully POSIX-compliant.

Suggested by: deischen


# 92927338 12-Jan-2000 Jason Evans <jasone@FreeBSD.org>

Add three-tier symbol naming in support of POSIX thread cancellation
points. For library functions, the pattern is __sleep() <--
_libc_sleep() <-- sleep(). The arrows represent weak aliases. For
system calls, the pattern is _read() <-- _libc_read() <-- read().


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 7f41a65e 08-Sep-1998 Andrey A. Chernov <ache@FreeBSD.org>

restore rev 1.23 to give clear SIGALRM handling example, 68 years
are too long to affect real code


# 49d6409a 06-Sep-1998 Matthew Dillon <dillon@FreeBSD.org>

Reviewed by: Andrey A. Chernov <ache@nagual.pp.ru>, Doug Rabson <dfr@nlsystems.com>

Rewrote sleep() to remove int/long typing assumptions between the argument
to the function and the timespec structure.


# ae59c259 05-Sep-1998 John Birrell <jb@FreeBSD.org>

Use INT_MAX instead of LONG_MAX since the variable being compared
is an int, not a long.


# 8cfedef0 17-Oct-1997 Andrey A. Chernov <ache@FreeBSD.org>

Fix LONG_MAX overflowing
Return seconds if errno other than EINTR
Add $Id
Submitted by: bde with minor optimization by me


# 855a496c 16-Oct-1997 Andrey A. Chernov <ache@FreeBSD.org>

Copy time_to_sleep to time_remaining since it can be left
uninitialized if nanosleep returns early with agr error


# 49620c89 16-Oct-1997 Andrey A. Chernov <ache@FreeBSD.org>

Cleanup #includes


# 9f375c32 15-Oct-1997 Peter Wemm <peter@FreeBSD.org>

Give up on the "try and compensate for broken programs" cruft and revert
back to the original single nanosleep() implementation. This is POSIX and
Unix98 (aka single-unix spec v2) compliant behavior. If a program sets
alarm(2) or an interval timer (setitimer(2)) without a SIGALRM handler
being active, sleep(3) will no longer absorb it, and the program will get
what it asked for..... :-]

The original reason for this in the first place (apache) doesn't seem to
need it anymore, according to Andrey.

Reviewed by: ache, bde


# 3be4b5c3 13-Aug-1997 Andrey A. Chernov <ache@FreeBSD.org>

Back out itimerfix hack since nanosleep1 fixed now
Handle syscalls error return slightly better


# fc0cc5ad 12-Aug-1997 Andrey A. Chernov <ache@FreeBSD.org>

Rearrange itimerfix loop doing it inside SIGALRM handling section


# b39d66c0 12-Aug-1997 Andrey A. Chernov <ache@FreeBSD.org>

Solve itimerfix() problem completely by using loop in 100000000 secs chunks


# 8d7bf613 12-Aug-1997 Andrey A. Chernov <ache@FreeBSD.org>

Back out my installation of SIGALRM handler even if it is blocked
and return to previous Peter's variant.
POSIX says that this place is implementation defined and old variant allows
application block SIGALRM and sleep and not be killed by external SIGALRMs.
BTW, GNU sleep f.e. sleeps forever in blocked SIGALRM :-)


# d23cc31d 12-Aug-1997 Andrey A. Chernov <ache@FreeBSD.org>

Make itimerfix hack better: return the time we can't sleep at once


# ac77b481 09-Aug-1997 Joerg Wunsch <joerg@FreeBSD.org>

Hack^H^H^H^Hworkaround for itimerfix(9) gratuitously limiting the
acceptable range for tv_sec to the magic number 100000000 (which at
least ought to be declared in a header file, and explained in the
non-existing man page, as well as in the existing man pages for
nanosleep(2) & Co.).

PR: bin/4259


# 925d069a 18-Jul-1997 Peter Wemm <peter@FreeBSD.org>

Make sleep() and usleep() "eat" any stray SIGALRM signals during the
lifetime of the call, just like the old implementation did. Previously,
we were only eating them if the application did not call sleep()/usleep()
with SIGALRM masked.

Submitted by: ache


# be159dca 02-Jun-1997 Peter Wemm <peter@FreeBSD.org>

Re-activate the nanosleep style using code, but with the signal handling
semantics of the old sleep for compatability with a few decades of expected
side effects. Apache breaks if we just use nanosleep() for some reason,
here we use a new signanosleep() syscall which is kinda like a hybrid of
sigsuspend and nanosleep..

Reviewed by: ache (and tested on his apache that was failing when
sleep used plain nanosleep)


# 0913e7ce 01-Jun-1997 Peter Wemm <peter@FreeBSD.org>

Update the sleep(3)/usleep(3) code to use signanosleep(2) if compiled with
-DUSE_NANOSLEEP. Also, seperate the code for _THREAD_SAFE so that it uses
the simpler threaded nanosleep() call in libc_r.. We don't go to the same
extremes for emulating traditional sleep semantics (ie: eating any SIGALRM
that might happen) which things like apache seem to depend on.


# 304e0890 18-May-1997 Peter Wemm <peter@FreeBSD.org>

Update the nanosleep versions to set a SIGALRM handler while sleeping.
This appears to appease Apache, although depending on having sleep(3)
changing the SIGALRM handler is a bit bogus.


# 7bf1f2c9 17-May-1997 Peter Wemm <peter@FreeBSD.org>

round-up non-zero nanoseconds in #ifdef'ed code.


# fa0f6323 17-May-1997 Peter Wemm <peter@FreeBSD.org>

Allow conditional use (add -DUSE_NANOSLEEP) to CFLAGS of nanosleep() for
the backend of sleep(3) and usleep(3). It's off by default until the
problem is fixed.


# e3c1328e 17-May-1997 Andrey A. Chernov <ache@FreeBSD.org>

Temporarily restore old (itimer) sleep variant because new one
(nanosleep) breaks Apache httpd badly: his childs died quickly after
number of requests (SIGPIPE). To reproduce this bug start
gdb /usr/local/sbin/httpd
run -X

and make some bunch of concurent requests (load the server pages
from 3 different places f.e.)
After short time httpd dies via SIGPIPE. It never dies with old sleep.c

In real life it looks like lots of broken images on the pages or missing
pages. Lynx says about Network read error, etc.
It seems something wrong in nanosleep signal handling.


# 511d7b9c 12-May-1997 Peter Wemm <peter@FreeBSD.org>

Use nanosleep() in all cases, not just in the reentrant libc (_THREAD_SAFE)
version.


# 34eeb764 20-Sep-1996 Nate Williams <nate@FreeBSD.org>

ts_sec -> tv_sec
ts_nsec -> tv_nsec


# f70177e7 21-Jan-1996 Julian Elischer <julian@FreeBSD.org>

Reviewed by: julian and (hsu?)
Submitted by: John Birrel(L?)

changes for threadsafe operations


# 8b102407 22-Oct-1995 Poul-Henning Kamp <phk@FreeBSD.org>

Minor cleanup, mostly unused vars and missing #includes.


# 58f0484f 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Lib Sources