Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Force sys_close not to restart by returning ERESTART.



details:   https://anonhg.NetBSD.org/src/rev/2d655ee8b47e
branches:  trunk
changeset: 780746:2d655ee8b47e
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Aug 05 04:26:10 2012 +0000

description:
Force sys_close not to restart by returning ERESTART.

Print a diagnostic message if we ever get ERESTART out of fd_close
and convert it to EINTR instead.

Even if fd_close fails, it has already closed the file descriptor, so
restarting the system call is a mistake, with dangerous consequences
for multithreaded programs.

Should probably turn the message into a kassert eventually, and maybe
add one deeper in fd_close in order to more easily debug it before
all the data structures are destroyed.

diffstat:

 sys/kern/sys_descrip.c |  17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diffs (42 lines):

diff -r c3f25ff590e8 -r 2d655ee8b47e sys/kern/sys_descrip.c
--- a/sys/kern/sys_descrip.c    Sun Aug 05 04:24:13 2012 +0000
+++ b/sys/kern/sys_descrip.c    Sun Aug 05 04:26:10 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_descrip.c,v 1.26 2012/02/11 23:16:17 martin Exp $  */
+/*     $NetBSD: sys_descrip.c,v 1.27 2012/08/05 04:26:10 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.26 2012/02/11 23:16:17 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.27 2012/08/05 04:26:10 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -479,11 +479,22 @@
        /* {
                syscallarg(int) fd;
        } */
+       int error;
 
        if (fd_getfile(SCARG(uap, fd)) == NULL) {
                return EBADF;
        }
-       return fd_close(SCARG(uap, fd));
+
+       error = fd_close(SCARG(uap, fd));
+       if (error == ERESTART) {
+#ifdef DIAGNOSTIC
+               printf("pid %d: close returned ERESTART\n",
+                   (int)l->l_proc->p_pid);
+#endif
+               error = EINTR;
+       }
+
+       return error;
 }
 
 /*



Home | Main Index | Thread Index | Old Index