Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
From: Ulrich Drepper <[EMAIL PROTECTED]> Date: 06 Nov 2000 10:50:37 -0800 > Arguably though the bug is in glibc, in that if it's using signals > behinds the scenes, it should have passed SA_RESTART to sigaction. Why are you talking such a nonsense? The claim was made that pthreads was using signals behind the scenes, so that programs which weren't expecting that system calls to get interrupted were getting interrupted. Hence, one could make the argument that if the pthreads code had used SA_RESTART to set up its signal handlers, then this situation wouldn't have come up. I haven't looked more deeply into this. As far as I'm concerned, threads === "more rope" and use of threads should be avoided whenever possible, even if Linux had a decent threads implementation - Ted - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
From: Ulrich Drepper [EMAIL PROTECTED] Date: 06 Nov 2000 10:50:37 -0800 Arguably though the bug is in glibc, in that if it's using signals behinds the scenes, it should have passed SA_RESTART to sigaction. Why are you talking such a nonsense? The claim was made that pthreads was using signals behind the scenes, so that programs which weren't expecting that system calls to get interrupted were getting interrupted. Hence, one could make the argument that if the pthreads code had used SA_RESTART to set up its signal handlers, then this situation wouldn't have come up. I haven't looked more deeply into this. As far as I'm concerned, threads === "more rope" and use of threads should be avoided whenever possible, even if Linux had a decent threads implementation - Ted - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Hello! > Glibc has to use signals because there *still* is not mechanism in the > kernel to allow synchronization. Could you tell why does it use SA_INTERRUPT on its internal signals? Alexey - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Ulrich Drepper <[EMAIL PROTECTED]> writes: > "Theodore Y. Ts'o" <[EMAIL PROTECTED]> writes: > > > Arguably though the bug is in glibc, in that if it's using signals > > behinds the scenes, it should have passed SA_RESTART to sigaction. > > Why are you talking such a nonsense? [Note to self: remove kitten from keyboard before writing mail.] Glibc has to use signals because there *still* is not mechanism in the kernel to allow synchronization. After how many years. I don't blame Linux. He has no interest in threads and therefore spends not much time thinking about it. But everybody who's complaining about things like this has to be willing to fix the real problems. Get your ass up and write a fast semaphore/mutex system. -- ---. ,-. 1325 Chesapeake Terrace Ulrich Drepper \,---' \ Sunnyvale, CA 94089 USA Red Hat `--' drepper at redhat.com ` - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
"Theodore Y. Ts'o" <[EMAIL PROTECTED]> writes: > Arguably though the bug is in glibc, in that if it's using signals > behinds the scenes, it should have passed SA_RESTART to sigaction. Why are you talking such a nonsense? > > However, from a portability point of view, you should *always* surround > certain system calls with while loops, since even if your program > doesn't use signals, if you run that program on a System-V derived Unix > system, and someone types ^Z at the wrong moment, you can also get an > EINTR. Similarly, you should always check the return value from write > and make sure all of what you asked to be written, was actually > written. > > What I normally do is have a full_write routine which looks something > like this: > > static errcode_t full_write(int fd, void *buf, int count) > { > char*cp = buf; > int left = count, c; > > while (left) { > c = write(fd, cp, left); > if (c < 0) { > if (errno == EINTR || errno == EAGAIN) > continue; > return errno; > } > left -= c; > cp += c; > } > return 0; > } > > It's like checking the return value from malloc(). Not everyone does > it, but even if it's not needed 99% of the time, it's a darned good idea > to do that. > > - Ted > - > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to [EMAIL PROTECTED] > Please read the FAQ at http://www.tux.org/lkml/ > > -- ---. ,-. 1325 Chesapeake Terrace Ulrich Drepper \,---' \ Sunnyvale, CA 94089 USA Red Hat `--' drepper at redhat.com ` - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
"Theodore Y. Ts'o" [EMAIL PROTECTED] writes: Arguably though the bug is in glibc, in that if it's using signals behinds the scenes, it should have passed SA_RESTART to sigaction. Why are you talking such a nonsense? However, from a portability point of view, you should *always* surround certain system calls with while loops, since even if your program doesn't use signals, if you run that program on a System-V derived Unix system, and someone types ^Z at the wrong moment, you can also get an EINTR. Similarly, you should always check the return value from write and make sure all of what you asked to be written, was actually written. What I normally do is have a full_write routine which looks something like this: static errcode_t full_write(int fd, void *buf, int count) { char*cp = buf; int left = count, c; while (left) { c = write(fd, cp, left); if (c 0) { if (errno == EINTR || errno == EAGAIN) continue; return errno; } left -= c; cp += c; } return 0; } It's like checking the return value from malloc(). Not everyone does it, but even if it's not needed 99% of the time, it's a darned good idea to do that. - Ted - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/ -- ---. ,-. 1325 Chesapeake Terrace Ulrich Drepper \,---' \ Sunnyvale, CA 94089 USA Red Hat `--' drepper at redhat.com ` - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Hello! Glibc has to use signals because there *still* is not mechanism in the kernel to allow synchronization. Could you tell why does it use SA_INTERRUPT on its internal signals? Alexey - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
I seem to recall when reading about sigaction in APUE, that while sigaction solves many of the races that can come up with various "signal" implementations, there were still some cases where there was no way to do what was desired without races. Is there ANY way (in theory, at least) to create a race-free signalling system? -- This message has been brought to you by the letter alpha and the number pi. David Feuer [EMAIL PROTECTED] - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
On Fri, 3 Nov 2000 [EMAIL PROTECTED] wrote: > I don't mean this to sound like a rant. It's just that I can't possibly > ascertain why someone in their right mind would want any behaviour > different than SA_RESTART. study apache 1.3's child_main code, you'll see an example of EINTR in use. it's used to get out of accept() -- most specifically when the child needs to die off (because the parent has determined that there's either too many children, or because a shutdown/restart is occuring). apache 1.3's BUFF code also uses EINTR for timeouts. i eliminated signals in the 2.0 design... so it doesn't use EINTR any more, but it restarts in userland because that's the most portable thing to do. On Fri, 3 Nov 2000 [EMAIL PROTECTED] wrote: > After reading about SA_RESTART, ok. However, couldn't those > applications that require it enable this behaviour explicitly? anyone sane writing modern applications will use sigaction(). signal() is legacy. -dean - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Followup to: <[EMAIL PROTECTED]> By author:[EMAIL PROTECTED] In newsgroup: linux.dev.kernel > > Hello! > > > > Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do > > > what BSD does: re-start the interrupted call? > > > > This is crap. Returning EINTR is necessary for many applications. > > Just reminder: this "crap" is default behaviour of Linux nowadays. 8)8) > signal() is crap... I personally think it was a major lose to have signal() change to BSD behaviour by default (an unexpected change for most applications!!) For sigaction() you must choose behaviour explicitly anyway, by either specifying or not specifying SA_RESTART. Applications should use sigaction(). Period. Full stop. signal() is so unpredictable these days as to be practically unusable. -hpa -- <[EMAIL PROTECTED]> at work, <[EMAIL PROTECTED]> in private! "Unix gives you enough rope to shoot yourself in the foot." http://www.zytor.com/~hpa/puzzle.txt - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
On Fri, 3 Nov 2000 [EMAIL PROTECTED] wrote: > Considering that the threading library for Linux uses signals to make it > work, would it be possible to change the Linux kernel to operate the way > BSD does--instead of returning EINTR, just restart the interrupted > primitive? > It's just how the default for signal() is set up by the 'C' runtime library. Instead of using signal, use sigaction(), set the SA_RESTART flag and you have BSD action. It is also possible to compile existing applications using -D_BSD_SIGNALS (this is from memory, it might not be exactly correct). New applications should not use signal(), then should use sigaction() which gives POSIX-defined fine control over the signal handler. Cheers, Dick Johnson Penguin : Linux version 2.2.17 on an i686 machine (801.18 BogoMips). "Memory is like gasoline. You use it up when you are running. Of course you get it all back when you reboot..."; Actual explanation obtained from the Micro$oft help desk. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Hello! > > Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do > > what BSD does: re-start the interrupted call? > > This is crap. Returning EINTR is necessary for many applications. Just reminder: this "crap" is default behaviour of Linux nowadays. 8)8) Alexey - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Ulrich Drepper wrote: > > [EMAIL PROTECTED] writes: > > > Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do > > what BSD does: re-start the interrupted call? > > This is crap. Returning EINTR is necessary for many applications. > > -- > ---. ,-. 1325 Chesapeake Terrace > Ulrich Drepper \,---' \ Sunnyvale, CA 94089 USA > Red Hat `--' drepper at redhat.com ` After reading about SA_RESTART, ok. However, couldn't those applications that require it enable this behaviour explicitly? The problem I'm having right now is with pthread_create() failing because deep somewhere in either the kernel or glibc, nanosleep() returns EINTR during said pthread_create() and pthread_create() fails. I've got a multithreaded program written using gcc (2.95.2) and glibc (2.1.3), and it's talking to a natively threaded Java program (tried both Sun & Blackdown ports, both 1.2.2 and 1.3) on a 2.2.17 kernel. The C program is listening for incoming socket connections, and the Java program is hammering on it with many parallel connect() calls. After a short, a bit random interval, pthread_create() will fail in either my program, or deep in the Java VM. I assume that the Java VM is using pthread_create(). I don't mean to sound like a psycho on this, but I can't see why SA_RESTART isn't the default behavior. Maybe I'm missing something somewhere. -- George T. Talbot - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
[EMAIL PROTECTED] writes: > Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do > what BSD does: re-start the interrupted call? This is crap. Returning EINTR is necessary for many applications. -- ---. ,-. 1325 Chesapeake Terrace Ulrich Drepper \,---' \ Sunnyvale, CA 94089 USA Red Hat `--' drepper at redhat.com ` - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Considering that the threading library for Linux uses signals to make it work, would it be possible to change the Linux kernel to operate the way BSD does--instead of returning EINTR, just restart the interrupted primitive? For example, if I'm using read(2) to read data from a file descriptor, and a signal happens, the signal handler runs, and read(2) returns EINTR after the system call finishes. Then I'm supposed to catch this and re-try the system call. I assume that this is true for _any_ system call which makes the process block, right? Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do what BSD does: re-start the interrupted call? Please? If this is something that would be acceptable for integration into a mainline kernel, I would do my best to help with a patch. If I'm wrong about this, please enlighten me. Also, please cc: me off the list, as I don't get the list directly. Thank you for your consideration. -- George T. Talbot - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Considering that the threading library for Linux uses signals to make it work, would it be possible to change the Linux kernel to operate the way BSD does--instead of returning EINTR, just restart the interrupted primitive? For example, if I'm using read(2) to read data from a file descriptor, and a signal happens, the signal handler runs, and read(2) returns EINTR after the system call finishes. Then I'm supposed to catch this and re-try the system call. I assume that this is true for _any_ system call which makes the process block, right? Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do what BSD does: re-start the interrupted call? Please? If this is something that would be acceptable for integration into a mainline kernel, I would do my best to help with a patch. If I'm wrong about this, please enlighten me. Also, please cc: me off the list, as I don't get the list directly. Thank you for your consideration. -- George T. Talbot george at moberg dot com - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
[EMAIL PROTECTED] writes: Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do what BSD does: re-start the interrupted call? This is crap. Returning EINTR is necessary for many applications. -- ---. ,-. 1325 Chesapeake Terrace Ulrich Drepper \,---' \ Sunnyvale, CA 94089 USA Red Hat `--' drepper at redhat.com ` - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Ulrich Drepper wrote: [EMAIL PROTECTED] writes: Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do what BSD does: re-start the interrupted call? This is crap. Returning EINTR is necessary for many applications. -- ---. ,-. 1325 Chesapeake Terrace Ulrich Drepper \,---' \ Sunnyvale, CA 94089 USA Red Hat `--' drepper at redhat.com ` After reading about SA_RESTART, ok. However, couldn't those applications that require it enable this behaviour explicitly? The problem I'm having right now is with pthread_create() failing because deep somewhere in either the kernel or glibc, nanosleep() returns EINTR during said pthread_create() and pthread_create() fails. I've got a multithreaded program written using gcc (2.95.2) and glibc (2.1.3), and it's talking to a natively threaded Java program (tried both Sun Blackdown ports, both 1.2.2 and 1.3) on a 2.2.17 kernel. The C program is listening for incoming socket connections, and the Java program is hammering on it with many parallel connect() calls. After a short, a bit random interval, pthread_create() will fail in either my program, or deep in the Java VM. I assume that the Java VM is using pthread_create(). I don't mean to sound like a psycho on this, but I can't see why SA_RESTART isn't the default behavior. Maybe I'm missing something somewhere. -- George T. Talbot george at moberg dot com - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Hello! Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do what BSD does: re-start the interrupted call? This is crap. Returning EINTR is necessary for many applications. Just reminder: this "crap" is default behaviour of Linux nowadays. 8)8) Alexey - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
On Fri, 3 Nov 2000 [EMAIL PROTECTED] wrote: Considering that the threading library for Linux uses signals to make it work, would it be possible to change the Linux kernel to operate the way BSD does--instead of returning EINTR, just restart the interrupted primitive? It's just how the default for signal() is set up by the 'C' runtime library. Instead of using signal, use sigaction(), set the SA_RESTART flag and you have BSD action. It is also possible to compile existing applications using -D_BSD_SIGNALS (this is from memory, it might not be exactly correct). New applications should not use signal(), then should use sigaction() which gives POSIX-defined fine control over the signal handler. Cheers, Dick Johnson Penguin : Linux version 2.2.17 on an i686 machine (801.18 BogoMips). "Memory is like gasoline. You use it up when you are running. Of course you get it all back when you reboot..."; Actual explanation obtained from the Micro$oft help desk. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
Followup to: [EMAIL PROTECTED] By author:[EMAIL PROTECTED] In newsgroup: linux.dev.kernel Hello! Can we _PLEASE_PLEASE_PLEASE_ not do this anymore and have the kernel do what BSD does: re-start the interrupted call? This is crap. Returning EINTR is necessary for many applications. Just reminder: this "crap" is default behaviour of Linux nowadays. 8)8) signal() is crap... I personally think it was a major lose to have signal() change to BSD behaviour by default (an unexpected change for most applications!!) For sigaction() you must choose behaviour explicitly anyway, by either specifying or not specifying SA_RESTART. Applications should use sigaction(). Period. Full stop. signal() is so unpredictable these days as to be practically unusable. -hpa -- [EMAIL PROTECTED] at work, [EMAIL PROTECTED] in private! "Unix gives you enough rope to shoot yourself in the foot." http://www.zytor.com/~hpa/puzzle.txt - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
On Fri, 3 Nov 2000 [EMAIL PROTECTED] wrote: I don't mean this to sound like a rant. It's just that I can't possibly ascertain why someone in their right mind would want any behaviour different than SA_RESTART. study apache 1.3's child_main code, you'll see an example of EINTR in use. it's used to get out of accept() -- most specifically when the child needs to die off (because the parent has determined that there's either too many children, or because a shutdown/restart is occuring). apache 1.3's BUFF code also uses EINTR for timeouts. i eliminated signals in the 2.0 design... so it doesn't use EINTR any more, but it restarts in userland because that's the most portable thing to do. On Fri, 3 Nov 2000 [EMAIL PROTECTED] wrote: After reading about SA_RESTART, ok. However, couldn't those applications that require it enable this behaviour explicitly? anyone sane writing modern applications will use sigaction(). signal() is legacy. -dean - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/
Re: Can EINTR be handled the way BSD handles it? -- a plea from a user-land programmer...
I seem to recall when reading about sigaction in APUE, that while sigaction solves many of the races that can come up with various "signal" implementations, there were still some cases where there was no way to do what was desired without races. Is there ANY way (in theory, at least) to create a race-free signalling system? -- This message has been brought to you by the letter alpha and the number pi. David Feuer [EMAIL PROTECTED] - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read the FAQ at http://www.tux.org/lkml/