git: 7d233b2220cd - main - libsys: fix sleep(3)/usleep(3) cancel behavior

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Fri, 23 Feb 2024 17:57:58 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=7d233b2220cd3d23c028bdac7eb3b6b7b2025125

commit 7d233b2220cd3d23c028bdac7eb3b6b7b2025125
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-02-23 14:53:10 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-02-23 17:39:44 +0000

    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
---
 lib/libc/gen/Makefile.inc         | 2 ++
 lib/{libsys => libc/gen}/sleep.c  | 2 +-
 lib/{libsys => libc/gen}/usleep.c | 3 ++-
 lib/libsys/Makefile.sys           | 2 +-
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 648ddc76e056..3a8b4e57420a 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -137,6 +137,7 @@ SRCS+= \
 	siglist.c \
 	signal.c \
 	sigsetops.c \
+	sleep.c \
 	srand48.c \
 	statvfs.c \
 	stringlist.c \
@@ -160,6 +161,7 @@ SRCS+= \
 	ulimit.c \
 	uname.c \
 	unvis-compat.c \
+	usleep.c \
 	utime.c \
 	utxdb.c \
 	valloc.c \
diff --git a/lib/libsys/sleep.c b/lib/libc/gen/sleep.c
similarity index 97%
rename from lib/libsys/sleep.c
rename to lib/libc/gen/sleep.c
index 7d0fa5332ecc..46a7dcc4dbca 100644
--- a/lib/libsys/sleep.c
+++ b/lib/libc/gen/sleep.c
@@ -56,7 +56,7 @@ __sleep(unsigned int seconds)
 	time_to_sleep.tv_sec = seconds;
 	time_to_sleep.tv_nsec = 0;
 	if (((int (*)(const struct timespec *, struct timespec *))
-	    __libsys_interposing[INTERPOS_nanosleep])(
+	    (*__libsys_interposing_slot(INTERPOS_nanosleep)))(
 	    &time_to_sleep, &time_remaining) != -1)
 		return (0);
 	if (errno != EINTR)
diff --git a/lib/libsys/usleep.c b/lib/libc/gen/usleep.c
similarity index 96%
rename from lib/libsys/usleep.c
rename to lib/libc/gen/usleep.c
index efd5ee0d1667..e312e55c6541 100644
--- a/lib/libsys/usleep.c
+++ b/lib/libc/gen/usleep.c
@@ -46,7 +46,8 @@ __usleep(useconds_t useconds)
 	time_to_sleep.tv_nsec = (useconds % 1000000) * 1000;
 	time_to_sleep.tv_sec = useconds / 1000000;
 	return (((int (*)(const struct timespec *, struct timespec *))
-	    __libsys_interposing[INTERPOS_nanosleep])(&time_to_sleep, NULL));
+	    (*__libsys_interposing_slot(INTERPOS_nanosleep)))(&time_to_sleep,
+	    NULL));
 }
 
 __weak_reference(__usleep, usleep);
diff --git a/lib/libsys/Makefile.sys b/lib/libsys/Makefile.sys
index e33a11bacb57..6b83e5812f76 100644
--- a/lib/libsys/Makefile.sys
+++ b/lib/libsys/Makefile.sys
@@ -40,7 +40,7 @@ SRCS+=	\
 SRCS+= getdents.c lstat.c mknod.c stat.c
 
 SRCS+=	creat.c
-SRCS+=	lockf.c sleep.c usleep.c wait.c wait3.c waitpid.c waitid.c
+SRCS+=	lockf.c wait.c wait3.c waitpid.c waitid.c
 SRCS+=	recv.c recvmmsg.c send.c sendmmsg.c
 
 NOASM+=  sched_getcpu.o