diff options
author | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2011-12-03 12:38:31 +0000 |
---|---|---|
committer | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2011-12-03 12:38:31 +0000 |
commit | 81b1a587746eace9605fc22c53206a649ac474f9 (patch) | |
tree | 1b0c127a2c44227ae1e5883bb27919104693d618 /sys | |
parent | 4bfcceb4971aaa6faec629589fb94c0264bffdeb (diff) |
add support for MSG_NOSIGNAL.
linux bits compiled on i386 by sebastia@, mikeb@ ok
Diffstat (limited to 'sys')
-rw-r--r-- | sys/compat/linux/linux_socket.c | 39 | ||||
-rw-r--r-- | sys/compat/linux/linux_socket.h | 16 | ||||
-rw-r--r-- | sys/kern/uipc_syscalls.c | 4 | ||||
-rw-r--r-- | sys/sys/socket.h | 3 |
4 files changed, 50 insertions, 12 deletions
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index b711c934f6e..21598960a36 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: linux_socket.c,v 1.42 2011/09/19 22:37:03 pirofti Exp $ */ +/* $OpenBSD: linux_socket.c,v 1.43 2011/12/03 12:38:30 fgsch Exp $ */ /* $NetBSD: linux_socket.c,v 1.14 1996/04/05 00:01:50 christos Exp $ */ /* @@ -83,6 +83,8 @@ static int linux_to_bsd_domain (int); static int bsd_to_linux_domain(int); +static int linux_to_bsd_msg_flags(int); + int linux_socket(struct proc *, void *, register_t *); int linux_bind(struct proc *, void *, register_t *); int linux_connect(struct proc *, void *, register_t *); @@ -201,6 +203,29 @@ bsd_to_linux_domain(bdom) return bsd_to_linux_domain_[bdom]; } +/* + * Convert between Linux and BSD MSG_XXX flags + */ +static int +linux_to_bsd_msg_flags(int lflags) +{ + int flags = 0; + + if (lflags & LINUX_MSG_OOB) + flags |= MSG_OOB; + if (lflags & LINUX_MSG_PEEK) + flags |= MSG_PEEK; + if (lflags & LINUX_MSG_DONTROUTE) + flags |= MSG_DONTROUTE; + if (lflags & LINUX_MSG_DONTWAIT) + flags |= MSG_DONTWAIT; + if (lflags & LINUX_MSG_WAITALL) + flags |= MSG_WAITALL; + if (lflags & LINUX_MSG_NOSIGNAL) + flags |= MSG_NOSIGNAL; + return (flags); +} + int linux_socket(p, v, retval) struct proc *p; @@ -568,7 +593,7 @@ linux_send(p, v, retval) SCARG(&bsa, s) = lsa.s; SCARG(&bsa, buf) = lsa.msg; SCARG(&bsa, len) = lsa.len; - SCARG(&bsa, flags) = lsa.flags; + SCARG(&bsa, flags) = linux_to_bsd_msg_flags(lsa.flags); return compat_sys_send(p, &bsa, retval); } @@ -623,7 +648,7 @@ linux_recv(p, v, retval) SCARG(&bra, s) = lra.s; SCARG(&bra, buf) = lra.msg; SCARG(&bra, len) = lra.len; - SCARG(&bra, flags) = lra.flags; + SCARG(&bra, flags) = linux_to_bsd_msg_flags(lra.flags); return compat_sys_recv(p, &bra, retval); } @@ -766,7 +791,7 @@ linux_sendto(p, v, retval) SCARG(&bsa, s) = lsa.s; SCARG(&bsa, buf) = lsa.msg; SCARG(&bsa, len) = lsa.len; - SCARG(&bsa, flags) = lsa.flags; + SCARG(&bsa, flags) = linux_to_bsd_msg_flags(lsa.flags); tolen = lsa.tolen; if (lsa.to) { struct sockaddr *sa; @@ -807,7 +832,7 @@ linux_recvfrom(p, v, retval) SCARG(&bra, s) = lra.s; SCARG(&bra, buf) = lra.buf; SCARG(&bra, len) = lra.len; - SCARG(&bra, flags) = lra.flags; + SCARG(&bra, flags) = linux_to_bsd_msg_flags(lra.flags); SCARG(&bra, from) = (struct sockaddr *) lra.from; SCARG(&bra, fromlenaddr) = lra.fromlen; @@ -1126,7 +1151,7 @@ linux_recvmsg(p, v, retval) SCARG(&bla, s) = lla.s; SCARG(&bla, msg) = (struct msghdr *)lla.msg; - SCARG(&bla, flags) = lla.flags; + SCARG(&bla, flags) = linux_to_bsd_msg_flags(lla.flags); error = sys_recvmsg(p, &bla, retval); if (error) @@ -1186,7 +1211,7 @@ linux_sendmsg(p, v, retval) SCARG(&bla, s) = lla.s; SCARG(&bla, msg) = lla.msg; - SCARG(&bla, flags) = lla.flags; + SCARG(&bla, flags) = linux_to_bsd_msg_flags(lla.flags); error = copyin(lla.msg->msg_control, &control, sizeof(caddr_t)); if (error) diff --git a/sys/compat/linux/linux_socket.h b/sys/compat/linux/linux_socket.h index 3f304c72d2c..1d22cec0299 100644 --- a/sys/compat/linux/linux_socket.h +++ b/sys/compat/linux/linux_socket.h @@ -1,4 +1,4 @@ -/* $OpenBSD: linux_socket.h,v 1.8 2011/04/05 22:54:31 pirofti Exp $ */ +/* $OpenBSD: linux_socket.h,v 1.9 2011/12/03 12:38:30 fgsch Exp $ */ /* $NetBSD: linux_socket.h,v 1.3 1995/05/28 10:16:34 mycroft Exp $ */ /* @@ -102,12 +102,24 @@ #define LINUX_IP_DROP_MEMBERSHIP 36 /* - * Options vor [gs]etsockopt(2), TCP level. + * Options for [gs]etsockopt(2), TCP level. */ #define LINUX_TCP_NODELAY 1 #define LINUX_TCP_MAXSEG 2 +/* + * Flags for recv(2) and send(2) family functions. + * The first 3 match MSG_XXX. + */ + +#define LINUX_MSG_OOB 1 +#define LINUX_MSG_PEEK 2 +#define LINUX_MSG_DONTROUTE 4 +#define LINUX_MSG_DONTWAIT 0x40 +#define LINUX_MSG_WAITALL 0x100 +#define LINUX_MSG_NOSIGNAL 0x4000 + struct linux_sockaddr { unsigned short sa_family; char sa_data[14]; diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 1423aae00ad..ebd25d673a4 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_syscalls.c,v 1.83 2011/10/23 15:11:14 deraadt Exp $ */ +/* $OpenBSD: uipc_syscalls.c,v 1.84 2011/12/03 12:38:30 fgsch Exp $ */ /* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */ /* @@ -526,7 +526,7 @@ sendit(struct proc *p, int s, struct msghdr *mp, int flags, register_t *retsize) if (auio.uio_resid != len && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; - if (error == EPIPE) + if (error == EPIPE && (flags & MSG_NOSIGNAL) == 0) ptsignal(p, SIGPIPE, STHREAD); } if (error == 0) { diff --git a/sys/sys/socket.h b/sys/sys/socket.h index 19c8c0b7de3..0446c0cb9e9 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socket.h,v 1.77 2011/09/08 03:40:32 guenther Exp $ */ +/* $OpenBSD: socket.h,v 1.78 2011/12/03 12:38:30 fgsch Exp $ */ /* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */ /* @@ -412,6 +412,7 @@ struct msghdr { #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ #define MSG_BCAST 0x100 /* this message rec'd as broadcast */ #define MSG_MCAST 0x200 /* this message rec'd as multicast */ +#define MSG_NOSIGNAL 0x400 /* do not send SIGPIPE */ /* * Header for ancillary data objects in msg_control buffer. |