Skip to contentSkip to conversation

nanosleep interrupted by ignored signals

DISCUSSION Matt Mackall 3 participants 6 messages Nov 24, 2004 – Nov 30, 2004

lore
Share & tools
lore
#0 lore raw

Take the following trivial program:

#include <unistd.h>

int main(void)

{
	sleep(10);
	return 0;
}

Run it in an xterm. Note that resizing the xterm has no effect on the process. Now do the same with strace:

brk(0x80495bc) = 0x80495bc
brk(0x804a000) = 0x804a000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({10, 0}, 0xbffff548) = -1 EINTR (Interrupted system
call)
--- SIGWINCH (Window changed) ---
_exit(0) = ?

In short, nanosleep is getting interrupted by signals that are supposedly ignored when a process is being praced. This appears to be a long-standing bug.

It also appears to be a long-known bug. I found some old discussion of this problem here but no sign of any resolution:

http://www.ussg.iu.edu/hypermail/linux/kernel/0108.1/1448.html

What's the current thinking on this?

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#1 lore raw
Quoted 27 lines · Matt Mackall

Take the following trivial program:

#include <unistd.h>

int main(void)

{
	sleep(10);
	return 0;
}

Run it in an xterm. Note that resizing the xterm has no effect on the process. Now do the same with strace:

brk(0x80495bc) = 0x80495bc
brk(0x804a000) = 0x804a000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({10, 0}, 0xbffff548) = -1 EINTR (Interrupted system
call)
--- SIGWINCH (Window changed) ---
_exit(0) = ?

In short, nanosleep is getting interrupted by signals that are supposedly ignored when a process is being praced. This appears to be a long-standing bug.

Quoted 6 lines

It also appears to be a long-known bug. I found some old discussion of this problem here but no sign of any resolution:

http://www.ussg.iu.edu/hypermail/linux/kernel/0108.1/1448.html

What's the current thinking on this?

This should have been resolved with the 2.6 changes, in particular, the restart code. What kernel are you using?

Quoted 1 line
Signature · 2 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
#2 lore raw
Quoted 31 lines · George Anzinger
Quoted 30 lines · Matt Mackall

Take the following trivial program:

#include <unistd.h>

int main(void)

{
	sleep(10);
	return 0;
}

Run it in an xterm. Note that resizing the xterm has no effect on the process. Now do the same with strace:

brk(0x80495bc) = 0x80495bc
brk(0x804a000) = 0x804a000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({10, 0}, 0xbffff548) = -1 EINTR (Interrupted system
call)
--- SIGWINCH (Window changed) ---
_exit(0) = ?

In short, nanosleep is getting interrupted by signals that are supposedly ignored when a process is being praced. This appears to be a long-standing bug.

It also appears to be a long-known bug. I found some old discussion of this problem here but no sign of any resolution:

Quoted 6 lines
Quoted 3 lines

http://www.ussg.iu.edu/hypermail/linux/kernel/0108.1/1448.html

What's the current thinking on this?

This should have been resolved with the 2.6 changes, in particular, the restart code. What kernel are you using?

Indeed it is. Forgot I still had 2.4 on the box in question, didn't notice the restart bit when comparing the 2.6 code against the thread above. Mea culpa.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#3 lore raw
Quoted 34 lines · Matt Mackall
Quoted 33 lines · George Anzinger
Quoted 32 lines · Matt Mackall

Take the following trivial program:

#include <unistd.h>

int main(void)

{
	sleep(10);
	return 0;
}

Run it in an xterm. Note that resizing the xterm has no effect on the process. Now do the same with strace:

brk(0x80495bc) = 0x80495bc
brk(0x804a000) = 0x804a000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({10, 0}, 0xbffff548) = -1 EINTR (Interrupted system
call)
--- SIGWINCH (Window changed) ---
_exit(0) = ?

In short, nanosleep is getting interrupted by signals that are supposedly ignored when a process is being praced. This appears to be a long-standing bug.

It also appears to be a long-known bug. I found some old discussion of this problem here but no sign of any resolution:

http://www.ussg.iu.edu/hypermail/linux/kernel/0108.1/1448.html

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What's the current thinking on this?

This should have been resolved with the 2.6 changes, in particular, the restart code. What kernel are you using?

Indeed it is. Forgot I still had 2.4 on the box in question, didn't notice the restart bit when comparing the 2.6 code against the thread above. Mea culpa.

George,

Is it worth/necessary to fix this bug in v2.4 ?

Quoting yourself

"This is an issue for debugging also (same ptrace...). The fix is to fix nano_sleep to match the standard which says it should only return on a signal if the signal is delivered to the program (i.e. not on internal "do nothing" signals). Signal in the kernel returns 1 if it calls the task and 0 otherwise, thus nano sleep might be changed as follows: "

#4 lore raw
Quoted 51 lines · Marcelo Tosatti
Quoted 36 lines · Matt Mackall
Quoted 34 lines · George Anzinger
Quoted 32 lines · Matt Mackall

Take the following trivial program:

#include <unistd.h>

int main(void)

{
	sleep(10);
	return 0;
}

Run it in an xterm. Note that resizing the xterm has no effect on the process. Now do the same with strace:

brk(0x80495bc) = 0x80495bc
brk(0x804a000) = 0x804a000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({10, 0}, 0xbffff548) = -1 EINTR (Interrupted system
call)
--- SIGWINCH (Window changed) ---
_exit(0) = ?

In short, nanosleep is getting interrupted by signals that are supposedly ignored when a process is being praced. This appears to be a long-standing bug.

It also appears to be a long-known bug. I found some old discussion of this problem here but no sign of any resolution:

http://www.ussg.iu.edu/hypermail/linux/kernel/0108.1/1448.html

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

What's the current thinking on this?

This should have been resolved with the 2.6 changes, in particular, the restart code. What kernel are you using?

Indeed it is. Forgot I still had 2.4 on the box in question, didn't notice the restart bit when comparing the 2.6 code against the thread above. Mea culpa.

George,

Is it worth/necessary to fix this bug in v2.4 ?

Quoted 8 lines

Quoting yourself

"This is an issue for debugging also (same ptrace...). The fix is to fix nano_sleep to match the standard which says it should only return on a signal if the signal is delivered to the program (i.e. not on internal "do nothing" signals). Signal in the kernel returns 1 if it calls the task and 0 otherwise, thus nano sleep might be changed as follows: "

Hmm, wise fellow, that :) We (MontaVista) have back ported this fix to our kernels as part of the HRT patch, and, in fact, it is in the latest (albeit somewhat out of date) HRT patch on sourceforge. The main issue is that it requires changes in arch level code and so requires a cooperative effort (in that most folks only have one or two archs to check it out on).

My take on this is that this has been in the kernel since nanosleep() was put in and so, for a mature kernel, it is not really important to change it. Now if you want to back port POSIX clocks and timers (i.e. clock_nanosleep()) I would argue that you should back port this change as part of that effort.

Signature · 2 lines
George Anzinger   [email protected]
High-res-timers:  http://sourceforge.net/projects/high-res-timers/
#5 lore raw
Quoted 68 lines · George Anzinger
Quoted 53 lines · Marcelo Tosatti
Quoted 37 lines · Matt Mackall
Quoted 35 lines · George Anzinger
Quoted 33 lines · Matt Mackall

Take the following trivial program:

#include <unistd.h>

int main(void)

{
	sleep(10);
	return 0;
}

Run it in an xterm. Note that resizing the xterm has no effect on the process. Now do the same with strace:

brk(0x80495bc) = 0x80495bc
brk(0x804a000) = 0x804a000
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({10, 0}, 0xbffff548) = -1 EINTR (Interrupted system
call)
--- SIGWINCH (Window changed) ---
_exit(0) = ?

In short, nanosleep is getting interrupted by signals that are supposedly ignored when a process is being praced. This appears to be a long-standing bug.

It also appears to be a long-known bug. I found some old discussion of this
problem here but no sign of any resolution:

http://www.ussg.iu.edu/hypermail/linux/kernel/0108.1/1448.html

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What's the current thinking on this?

This should have been resolved with the 2.6 changes, in particular, the restart code. What kernel are you using?

Indeed it is. Forgot I still had 2.4 on the box in question, didn't notice the restart bit when comparing the 2.6 code against the thread above. Mea culpa.

George,

Is it worth/necessary to fix this bug in v2.4 ?

Quoted 8 lines

Quoting yourself

"This is an issue for debugging also (same ptrace...). The fix is to fix nano_sleep to match the standard which says it should only return on a signal if the signal is delivered to the program (i.e. not on internal "do nothing" signals). Signal in the kernel returns 1 if it calls the task and 0 otherwise, thus nano sleep might be changed as follows: "

Hmm, wise fellow, that :) We (MontaVista) have back ported this fix to our kernels as part of the HRT patch, and, in fact, it is in the latest (albeit somewhat out of date) HRT patch on sourceforge. The main issue is that it requires changes in arch level code and so requires a cooperative effort (in that most folks only have one or two archs to check it out on).

Quoted 5 lines

My take on this is that this has been in the kernel since nanosleep() was put in and so, for a mature kernel, it is not really important to change it. Now if you want to back port POSIX clocks and timers (i.e. clock_nanosleep()) I would argue that you should back port this change as part of that effort.

Not really a good idea IMO - lets live with the bug. If it was easy to fix it, then it would be interesting, but since it is not...

Thanks for your input.