Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 105410
b: refs/heads/master
c: a677a03
h: refs/heads/master
v: v3
  • Loading branch information
Ulrich Drepper authored and Linus Torvalds committed Jul 24, 2008
1 parent 837b7ec commit e899f0c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6e2c10a12a2170856f5582d62d583cbcd1cb5eaf
refs/heads/master: a677a039be7243357d93502bff2b40850c942e2d
7 changes: 7 additions & 0 deletions trunk/include/asm-mips/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ enum sock_type {
};

#define SOCK_MAX (SOCK_PACKET + 1)
/* Mask which covers at least up to SOCK_MASK-1. The
* * remaining bits are used as flags. */
#define SOCK_TYPE_MASK 0xf

/* Flags for socket, socketpair, paccept */
#define SOCK_CLOEXEC O_CLOEXEC
#define SOCK_NONBLOCK O_NONBLOCK

#define ARCH_HAS_SOCKET_TYPES 1

Expand Down
9 changes: 8 additions & 1 deletion trunk/include/linux/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <linux/wait.h>
#include <linux/socket.h>
#include <linux/fcntl.h> /* For O_CLOEXEC */
#include <asm/socket.h>

struct poll_table_struct;
Expand Down Expand Up @@ -94,6 +95,12 @@ enum sock_type {
};

#define SOCK_MAX (SOCK_PACKET + 1)
/* Mask which covers at least up to SOCK_MASK-1. The
* remaining bits are used as flags. */
#define SOCK_TYPE_MASK 0xf

/* Flags for socket, socketpair, paccept */
#define SOCK_CLOEXEC O_CLOEXEC

#endif /* ARCH_HAS_SOCKET_TYPES */

Expand Down Expand Up @@ -208,7 +215,7 @@ extern int sock_sendmsg(struct socket *sock, struct msghdr *msg,
size_t len);
extern int sock_recvmsg(struct socket *sock, struct msghdr *msg,
size_t size, int flags);
extern int sock_map_fd(struct socket *sock);
extern int sock_map_fd(struct socket *sock, int flags);
extern struct socket *sockfd_lookup(int fd, int *err);
#define sockfd_put(sock) fput(sock->file)
extern int net_ratelimit(void);
Expand Down
2 changes: 1 addition & 1 deletion trunk/net/9p/trans_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ static int p9_socket_open(struct p9_trans *trans, struct socket *csocket)
int fd, ret;

csocket->sk->sk_allocation = GFP_NOIO;
fd = sock_map_fd(csocket);
fd = sock_map_fd(csocket, 0);
if (fd < 0) {
P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to map fd\n");
return fd;
Expand Down
2 changes: 1 addition & 1 deletion trunk/net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -3910,7 +3910,7 @@ static int sctp_getsockopt_peeloff(struct sock *sk, int len, char __user *optval
goto out;

/* Map the socket to an unused fd that can be returned to the user. */
retval = sock_map_fd(newsock);
retval = sock_map_fd(newsock, 0);
if (retval < 0) {
sock_release(newsock);
goto out;
Expand Down
28 changes: 20 additions & 8 deletions trunk/net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ static struct dentry_operations sockfs_dentry_operations = {
* but we take care of internal coherence yet.
*/

static int sock_alloc_fd(struct file **filep)
static int sock_alloc_fd(struct file **filep, int flags)
{
int fd;

fd = get_unused_fd();
fd = get_unused_fd_flags(flags);
if (likely(fd >= 0)) {
struct file *file = get_empty_filp();

Expand Down Expand Up @@ -396,10 +396,10 @@ static int sock_attach_fd(struct socket *sock, struct file *file)
return 0;
}

int sock_map_fd(struct socket *sock)
int sock_map_fd(struct socket *sock, int flags)
{
struct file *newfile;
int fd = sock_alloc_fd(&newfile);
int fd = sock_alloc_fd(&newfile, flags);

if (likely(fd >= 0)) {
int err = sock_attach_fd(sock, newfile);
Expand Down Expand Up @@ -1218,12 +1218,18 @@ asmlinkage long sys_socket(int family, int type, int protocol)
{
int retval;
struct socket *sock;
int flags;

flags = type & ~SOCK_TYPE_MASK;
if (flags & ~SOCK_CLOEXEC)
return -EINVAL;
type &= SOCK_TYPE_MASK;

retval = sock_create(family, type, protocol, &sock);
if (retval < 0)
goto out;

retval = sock_map_fd(sock);
retval = sock_map_fd(sock, flags & O_CLOEXEC);
if (retval < 0)
goto out_release;

Expand All @@ -1246,6 +1252,12 @@ asmlinkage long sys_socketpair(int family, int type, int protocol,
struct socket *sock1, *sock2;
int fd1, fd2, err;
struct file *newfile1, *newfile2;
int flags;

flags = type & ~SOCK_TYPE_MASK;
if (flags & ~SOCK_CLOEXEC)
return -EINVAL;
type &= SOCK_TYPE_MASK;

/*
* Obtain the first socket and check if the underlying protocol
Expand All @@ -1264,13 +1276,13 @@ asmlinkage long sys_socketpair(int family, int type, int protocol,
if (err < 0)
goto out_release_both;

fd1 = sock_alloc_fd(&newfile1);
fd1 = sock_alloc_fd(&newfile1, flags & O_CLOEXEC);
if (unlikely(fd1 < 0)) {
err = fd1;
goto out_release_both;
}

fd2 = sock_alloc_fd(&newfile2);
fd2 = sock_alloc_fd(&newfile2, flags & O_CLOEXEC);
if (unlikely(fd2 < 0)) {
err = fd2;
put_filp(newfile1);
Expand Down Expand Up @@ -1426,7 +1438,7 @@ asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr,
*/
__module_get(newsock->ops->owner);

newfd = sock_alloc_fd(&newfile);
newfd = sock_alloc_fd(&newfile, 0);
if (unlikely(newfd < 0)) {
err = newfd;
sock_release(newsock);
Expand Down

0 comments on commit e899f0c

Please sign in to comment.