NetBSD Problem Report #57052
From kre@munnari.OZ.AU Mon Oct 10 05:52:07 2022
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id D9F621A923C
for <gnats-bugs@gnats.NetBSD.org>; Mon, 10 Oct 2022 05:52:06 +0000 (UTC)
Message-Id: <202210100551.29A5pqDX004090@jacaranda.noi.kre.to>
Date: Mon, 10 Oct 2022 12:51:52 +0700 (+07)
From: kre@munnari.OZ.AU
Reply-To:
To: gnats-bugs@NetBSD.org
Subject: clock_nanosleep() returns(0) immediately after a SIGTSTP/SIGCONT
X-Send-Pr-Version: 3.95
>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
>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:/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:
?
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2022
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.