public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Manual should discourage mixing TEMP_FAILURE_RETRY and close
@ 2013-12-03 18:05 Mark Mentovai
  2013-12-04  0:16 ` Ondřej Bílka
  0 siblings, 1 reply; 21+ messages in thread
From: Mark Mentovai @ 2013-12-03 18:05 UTC (permalink / raw)
  To: libc-alpha

When the close system call is interrupted by a signal, the state of its
file descriptor argument is not specified[1]. On Linux, a close that
fails with EINTR must not be restarted because the file descriptor is
guaranteed to have been closed at that point[2]. Note that the kernel
itself never restarts a close when SA_RESTART is set or when no
user-space signal handler is present[3].

Because glibc is widely used on Linux, its documentation should state
affirmatively that the TEMP_FAILURE_RETRY, which restarts interrupted
system calls that fail with EINTR, is not to be used with close on
Linux. Examples in glibc documentation should avoid recommending
wrapping close with TEMP_FAILURE_RETRY.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
[2] http://lkml.org/lkml/2005/9/10/129
[3] http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=ee731f4f7880b09ca147008ab46ad4e5f72cb8b

2013-12-03  Mark Mentovai  <mark@chromium.org>

	* manual/llio.texi (Opening and Closing Files): Document that
	TEMP_FAILURE_RETRY should not be used with close on Linux.
	(Duplicating Descriptors): Don't wrap close in TEMP_FAILURE_RETRY
	in example code.

---
 manual/llio.texi | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/manual/llio.texi b/manual/llio.texi
index b6c9260..f04a2cf 100644
--- a/manual/llio.texi
+++ b/manual/llio.texi
@@ -253,11 +253,9 @@ The @var{filedes} argument is not a valid file descriptor.
 @item EINTR
 The @code{close} call was interrupted by a signal.
 @xref{Interrupted Primitives}.
-Here is an example of how to handle @code{EINTR} properly:
-
-@smallexample
-TEMP_FAILURE_RETRY (close (desc));
-@end smallexample
+On Linux, @code{close} will have closed its file descriptor argument even when
+reporting @code{EINTR}.  It is not safe to retry calling @code{close} in this
+case, as would be done when wrapped in the @code{TEMP_FAILURE_RETRY} macro.
 
 @item ENOSPC
 @itemx EIO
@@ -2765,7 +2763,7 @@ if (pid == 0)
     @dots{}
     file = TEMP_FAILURE_RETRY (open (filename, O_RDONLY));
     dup2 (file, STDIN_FILENO);
-    TEMP_FAILURE_RETRY (close (file));
+    close (file);
     execv (program, NULL);
   @}
 @end smallexample
-- 
1.8.3.4

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2016-12-07 12:37 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-03 18:05 [PATCH] Manual should discourage mixing TEMP_FAILURE_RETRY and close Mark Mentovai
2013-12-04  0:16 ` Ondřej Bílka
2013-12-04  0:38   ` Rich Felker
2013-12-05 17:35   ` Mark Mentovai
2016-12-05 14:49   ` Michael Kerrisk
2016-12-05 16:11     ` Rich Felker
2016-12-05 16:18       ` Michael Kerrisk
2016-12-05 16:23         ` Rich Felker
2016-12-05 16:27           ` Michael Kerrisk
2016-12-05 16:34             ` Rich Felker
2016-12-05 16:41               ` Michael Kerrisk (man-pages)
2016-12-05 16:50                 ` Rich Felker
2016-12-06  9:57                   ` Michael Kerrisk (man-pages)
2016-12-06 15:52                     ` Rich Felker
2016-12-06 22:43                       ` Zack Weinberg
2016-12-06 23:58                         ` Rich Felker
2016-12-07 12:16                           ` Michael Kerrisk (man-pages)
2016-12-07 12:37                         ` Michael Kerrisk (man-pages)
2016-12-05 16:32           ` Paul Eggert
2016-12-05 16:39             ` Rich Felker
2016-12-05 17:17               ` Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).