NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/57052: clock_nanosleep() returns(0) immediately after a SIGTSTP/SIGCONT
>Number: 57052
>Category: kern
>Synopsis: clock_nanosleep() returns(0) immediately after a SIGTSTP/SIGCONT
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Oct 10 05:55:00 +0000 2022
>Originator: kre%munnari.OZ.AU@localhost
>Release: NetBSD 9.99.100
>Organization:
>Environment:
System: NetBSD jacaranda.noi.kre.to 9.99.100 NetBSD 9.99.100 (JACARANDA:1.1-20220925) #26: Mon Sep 26 01:36:09 +07 2022 kre%jacaranda.noi.kre.to@localhost:/usr/obj/testing/kernels/amd64/JACARANDA amd64
Architecture: x86_64
Machine: amd64
>Description:
clock_nanosleep() is specified as returning only when the
specified time is reached, or when a signal which is caught
or terminates the process occurs.
If while running in clock_nanosleep() the process is suspended
(using SIGTSTP, this doesn't seem to happen with SIGSTOP, though
that may depend upon the shell being used, which is weird)
and then resumed (with SIGCONT) the clock_nanosleep() call
returns (and returns 0 not EINTR - which should indicate that
the time requested has elapsed).
>How-To-Repeat:
Pick a shell, any shell that supports job control
(I have used sh csh ksh bash yash dash and zsh to tty this).
Run:
/bin/sleep 1000 # don't panic, this won't take that long
^Z # or whatever your TSTP generating char is
fg
and notice that the sleep command is finished. Unless you're a
very slow typist (or were interrupted) notice that far less than
1000 seconds has elapsed. If you want to make that more obvious,
use bg instead of fg so you will get the shell's "background job
done" message (which might need an extra \n after the fg command).
Eg:
$ date; /bin/sleep 1000
Mon Oct 10 12:32:38 +07 2022
^Z[1] + Suspended /bin/sleep 1000
$ fg; date
/bin/sleep 1000
Mon Oct 10 12:32:41 +07 2022
$
/bin/sleep uses clock_nanosleep() as...
for (;;) {
int e;
if ((e = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
&endtime, NULL)) == 0) {
printf("Done\n"); /*XXX*/
return EXIT_SUCCESS;
}
where endtime is the time that the sleep should end (when there
is no SIGTSTP sleep sleeps for the correct time, so one can
assume that endtime is calculated correctly). The XXX'd printf
I added to confirm that the sys call is returning 0 (that output
isn't shown above, it would have been had I run /tmp/sleep but
then you wouldn't be able to easily duplicate my results).
sleep does not catch SIGTSTP (or SIGCONT) - only SIGINFO
(that's what that for(;;) loop is about, if a SIGINFO arrives
sleep reports how much longer until it will finish, then
redoes the clock_nanosleep() - that part works fine) and
SIGALRM (which seems to be a historic relic from when
sleep used the alarm() sys call inform it when the time
was up) - nothing should normally be sending SIGALRM here.
>Fix:
?
Home |
Main Index |
Thread Index |
Old Index