PERFORCE change 101046 for review
John Baldwin
jhb at FreeBSD.org
Sat Jul 8 19:22:55 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=101046
Change 101046 by jhb at jhb_mutex on 2006/07/08 19:21:50
- Even though it's trivial, add a kern_close() and use it in various
places instead of a struct close_args + close().
- Note a case in the svr4 streams gunk where we can leak the accept fd.
- Add a kern_close() to accept() to close the fd if the copyout's
fault.
Affected files ...
.. //depot/projects/smpng/sys/compat/linux/linux_socket.c#31 edit
.. //depot/projects/smpng/sys/compat/svr4/svr4_stream.c#34 edit
.. //depot/projects/smpng/sys/fs/portalfs/portal_vnops.c#23 edit
.. //depot/projects/smpng/sys/i386/ibcs2/ibcs2_other.c#9 edit
.. //depot/projects/smpng/sys/kern/kern_descrip.c#93 edit
.. //depot/projects/smpng/sys/kern/uipc_syscalls.c#86 edit
.. //depot/projects/smpng/sys/sys/syscallsubr.h#45 edit
Differences ...
==== //depot/projects/smpng/sys/compat/linux/linux_socket.c#31 (text+ko) ====
@@ -705,9 +705,6 @@
struct sockaddr * __restrict name;
socklen_t * __restrict anamelen;
} */ bsd_args;
- struct close_args /* {
- int fd;
- } */ c_args;
int error, fd;
if ((error = copyin(args, &linux_args, sizeof(linux_args))))
@@ -724,8 +721,7 @@
if (linux_args.addr) {
error = linux_sa_put(PTRIN(linux_args.addr));
if (error) {
- c_args.fd = td->td_retval[0];
- (void)close(td, &c_args);
+ (void)kern_close(td, td->td_retval[0]);
return (error);
}
}
==== //depot/projects/smpng/sys/compat/svr4/svr4_stream.c#34 (text+ko) ====
@@ -1035,7 +1035,6 @@
struct svr4_strm *st = svr4_stream_get(fp);
struct svr4_strfdinsert fdi;
struct dup2_args d2p;
- struct close_args clp;
if (st == NULL) {
DPRINTF(("fdinsert: bad file type\n"));
@@ -1061,9 +1060,7 @@
return error;
}
- clp.fd = st->s_afd;
-
- if ((error = close(td, &clp)) != 0) {
+ if ((error = kern_close(td, st->s_afd)) != 0) {
DPRINTF(("fdinsert: close(%d) failed %d\n",
st->s_afd, error));
return error;
@@ -1919,6 +1916,7 @@
return EINVAL;
}
+ /* XXX: We leak the accept fd if we get an error here. */
if (uap->ctl) {
if (ctl.len > sizeof(sc))
ctl.len = sizeof(sc);
==== //depot/projects/smpng/sys/fs/portalfs/portal_vnops.c#23 (text+ko) ====
@@ -52,6 +52,7 @@
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/stat.h>
+#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
#include <sys/systm.h>
#include <sys/un.h>
@@ -77,10 +78,8 @@
int fd;
{
int error;
- struct close_args ua;
- ua.fd = fd;
- error = close(td, &ua);
+ error = kern_close(td, fd);
/*
* We should never get an error, and there isn't anything
* we could do if we got one, so just print a message.
==== //depot/projects/smpng/sys/i386/ibcs2/ibcs2_other.c#9 (text+ko) ====
@@ -109,9 +109,7 @@
error = kern_connect(td, fd, (struct sockaddr *)&sun);
if (error) {
- struct close_args cl;
- cl.fd = fd;
- close(td, &cl);
+ kern_close(td, fd);
return error;
}
td->td_retval[0] = fd;
==== //depot/projects/smpng/sys/kern/kern_descrip.c#93 (text+ko) ====
@@ -973,12 +973,20 @@
struct thread *td;
struct close_args *uap;
{
+
+ return (kern_close(td, uap->fd));
+}
+
+int
+kern_close(td, fd)
+ struct thread *td;
+ int fd;
+{
struct filedesc *fdp;
struct file *fp;
- int fd, error;
+ int error;
int holdleaders;
- fd = uap->fd;
error = 0;
holdleaders = 0;
fdp = td->td_proc->p_fd;
==== //depot/projects/smpng/sys/kern/uipc_syscalls.c#86 (text+ko) ====
@@ -313,11 +313,12 @@
* return a namelen of zero for older code which might
* ignore the return value from accept.
*/
- if (error && name == NULL) {
+ if (error) {
(void) copyout(&namelen,
uap->anamelen, sizeof(*uap->anamelen));
return (error);
}
+
if (error == 0 && name != NULL) {
#ifdef COMPAT_OLDSOCK
if (compat)
@@ -329,6 +330,8 @@
if (error == 0)
error = copyout(&namelen, uap->anamelen,
sizeof(namelen));
+ if (error)
+ kern_close(td, td->td_retval[0]);
free(name, M_SONAME);
return (error);
}
==== //depot/projects/smpng/sys/sys/syscallsubr.h#45 (text+ko) ====
@@ -70,6 +70,7 @@
struct timespec *ats);
int kern_clock_settime(struct thread *td, clockid_t clock_id,
struct timespec *ats);
+int kern_close(struct thread *td, int fd);
int kern_connect(struct thread *td, int fd, struct sockaddr *sa);
int kern_eaccess(struct thread *td, char *path, enum uio_seg pathseg,
int flags);
More information about the p4-projects
mailing list