PFS: UDS code cleanup:

- coalesce lots of duplicate code
- avoid using errno as much as possible
- fix bugs in some error handling cases
This commit is contained in:
David van Moolenbroek 2011-03-25 10:52:53 +00:00
parent 7a9e3651fd
commit 14e641cb8c
2 changed files with 128 additions and 610 deletions

View file

@ -190,8 +190,8 @@ PUBLIC int uds_open(message *dev_m_in, message *dev_m_out)
/* likely error: get_block() failed */ /* likely error: get_block() failed */
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT, uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, errno); (cp_grant_id_t) dev_m_in->IO_GRANT, rc);
return errno; return rc;
} }
/* Process the response */ /* Process the response */
@ -375,8 +375,7 @@ PRIVATE int uds_perform_read(int minor, endpoint_t m_source,
if (!(uds_fd_table[minor].mode & S_IRUSR)) { if (!(uds_fd_table[minor].mode & S_IRUSR)) {
/* socket is shutdown for reading */ /* socket is shutdown for reading */
errno = EPIPE; return EPIPE;
return -1;
} }
if (uds_fd_table[minor].size == 0) { if (uds_fd_table[minor].size == 0) {
@ -509,15 +508,13 @@ PRIVATE int uds_perform_write(int minor, endpoint_t m_source,
if (!(uds_fd_table[minor].mode & S_IWUSR)) { if (!(uds_fd_table[minor].mode & S_IWUSR)) {
/* socket is shutdown for writing */ /* socket is shutdown for writing */
errno = EPIPE; return EPIPE;
return -1;
} }
if (size > PIPE_BUF) { if (size > PIPE_BUF) {
/* message is too big to ever write to the PIPE */ /* message is too big to ever write to the PIPE */
errno = EMSGSIZE; return EMSGSIZE;
return -1;
} }
if (uds_fd_table[minor].type == SOCK_STREAM || if (uds_fd_table[minor].type == SOCK_STREAM ||
@ -530,12 +527,10 @@ PRIVATE int uds_perform_write(int minor, endpoint_t m_source,
if (uds_fd_table[minor].err == ECONNRESET) { if (uds_fd_table[minor].err == ECONNRESET) {
uds_fd_table[minor].err = 0; uds_fd_table[minor].err = 0;
errno = ECONNRESET; return ECONNRESET;
} else { } else {
errno = ENOTCONN; return ENOTCONN;
} }
return -1;
} else { } else {
peer = uds_fd_table[minor].peer; peer = uds_fd_table[minor].peer;
@ -562,8 +557,7 @@ PRIVATE int uds_perform_write(int minor, endpoint_t m_source,
} }
if (peer == -1) { if (peer == -1) {
errno = ENOENT; return ENOENT;
return -1;
} }
} }
@ -704,23 +698,12 @@ PUBLIC int uds_read(message *dev_m_in, message *dev_m_out)
bytes = uds_perform_read(minor, dev_m_in->m_source, bytes = uds_perform_read(minor, dev_m_in->m_source,
uds_fd_table[minor].io_gr_size, 0); uds_fd_table[minor].io_gr_size, 0);
if (bytes == -1) {
uds_set_reply(dev_m_out, TASK_REPLY,
uds_fd_table[minor].endpoint,
uds_fd_table[minor].io_gr,
errno);
return errno;
} else {
uds_set_reply(dev_m_out, TASK_REPLY, uds_set_reply(dev_m_out, TASK_REPLY,
uds_fd_table[minor].endpoint, uds_fd_table[minor].endpoint,
uds_fd_table[minor].io_gr, uds_fd_table[minor].io_gr,
bytes); bytes);
return bytes; return bytes;
}
} }
PUBLIC int uds_write(message *dev_m_in, message *dev_m_out) PUBLIC int uds_write(message *dev_m_in, message *dev_m_out)
@ -767,29 +750,17 @@ PUBLIC int uds_write(message *dev_m_in, message *dev_m_out)
bytes = uds_perform_write(minor, dev_m_in->m_source, bytes = uds_perform_write(minor, dev_m_in->m_source,
uds_fd_table[minor].io_gr_size, 0); uds_fd_table[minor].io_gr_size, 0);
if (bytes == -1) {
uds_set_reply(dev_m_out, TASK_REPLY,
uds_fd_table[minor].endpoint,
uds_fd_table[minor].io_gr,
errno);
return errno;
} else {
uds_set_reply(dev_m_out, TASK_REPLY, uds_set_reply(dev_m_out, TASK_REPLY,
uds_fd_table[minor].endpoint, uds_fd_table[minor].endpoint,
uds_fd_table[minor].io_gr, uds_fd_table[minor].io_gr,
bytes); bytes);
return bytes; return bytes;
}
} }
PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out) PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out)
{ {
int minor; int rc, minor;
#if DEBUG == 1 #if DEBUG == 1
static int call_count = 0; static int call_count = 0;
@ -828,103 +799,141 @@ PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out)
case NWIOSUDSCONN: case NWIOSUDSCONN:
/* connect to a listening socket -- connect() */ /* connect to a listening socket -- connect() */
return do_connect(dev_m_in, dev_m_out); rc = do_connect(dev_m_in, dev_m_out);
break;
case NWIOSUDSACCEPT: case NWIOSUDSACCEPT:
/* accept an incoming connection -- accept() */ /* accept an incoming connection -- accept() */
return do_accept(dev_m_in, dev_m_out); rc = do_accept(dev_m_in, dev_m_out);
break;
case NWIOSUDSBLOG: case NWIOSUDSBLOG:
/* set the backlog_size and put the socket into the /* set the backlog_size and put the socket into the
* listening state -- listen() * listening state -- listen()
*/ */
return do_listen(dev_m_in, dev_m_out); rc = do_listen(dev_m_in, dev_m_out);
break;
case NWIOSUDSTYPE: case NWIOSUDSTYPE:
/* set the type for this socket (i.e. /* set the type for this socket (i.e.
* SOCK_STREAM, SOCK_DGRAM, etc) -- socket() * SOCK_STREAM, SOCK_DGRAM, etc) -- socket()
*/ */
return do_socket(dev_m_in, dev_m_out); rc = do_socket(dev_m_in, dev_m_out);
break;
case NWIOSUDSADDR: case NWIOSUDSADDR:
/* set the address for this socket -- bind() */ /* set the address for this socket -- bind() */
return do_bind(dev_m_in, dev_m_out); rc = do_bind(dev_m_in, dev_m_out);
break;
case NWIOGUDSADDR: case NWIOGUDSADDR:
/* get the address for this socket -- getsockname() */ /* get the address for this socket -- getsockname() */
return do_getsockname(dev_m_in, dev_m_out); rc = do_getsockname(dev_m_in, dev_m_out);
break;
case NWIOGUDSPADDR: case NWIOGUDSPADDR:
/* get the address for the peer -- getpeername() */ /* get the address for the peer -- getpeername() */
return do_getpeername(dev_m_in, dev_m_out); rc = do_getpeername(dev_m_in, dev_m_out);
break;
case NWIOSUDSSHUT: case NWIOSUDSSHUT:
/* shutdown a socket for reading, writing, or /* shutdown a socket for reading, writing, or
* both -- shutdown() * both -- shutdown()
*/ */
return do_shutdown(dev_m_in, dev_m_out); rc = do_shutdown(dev_m_in, dev_m_out);
break;
case NWIOSUDSPAIR: case NWIOSUDSPAIR:
/* connect two sockets -- socketpair() */ /* connect two sockets -- socketpair() */
return do_socketpair(dev_m_in, dev_m_out); rc = do_socketpair(dev_m_in, dev_m_out);
break;
case NWIOGUDSSOTYPE: case NWIOGUDSSOTYPE:
/* get socket type -- getsockopt(SO_TYPE) */ /* get socket type -- getsockopt(SO_TYPE) */
return do_getsockopt_sotype(dev_m_in, dev_m_out); rc = do_getsockopt_sotype(dev_m_in, dev_m_out);
break;
case NWIOGUDSPEERCRED: case NWIOGUDSPEERCRED:
/* get peer endpoint -- getsockopt(SO_PEERCRED) */ /* get peer endpoint -- getsockopt(SO_PEERCRED) */
return do_getsockopt_peercred(dev_m_in, dev_m_out); rc = do_getsockopt_peercred(dev_m_in, dev_m_out);
break;
case NWIOSUDSTADDR: case NWIOSUDSTADDR:
/* set target address -- sendto() */ /* set target address -- sendto() */
return do_sendto(dev_m_in, dev_m_out); rc = do_sendto(dev_m_in, dev_m_out);
break;
case NWIOGUDSFADDR: case NWIOGUDSFADDR:
/* get from address -- recvfrom() */ /* get from address -- recvfrom() */
return do_recvfrom(dev_m_in, dev_m_out); rc = do_recvfrom(dev_m_in, dev_m_out);
break;
case NWIOGUDSSNDBUF: case NWIOGUDSSNDBUF:
/* get the send buffer size -- getsockopt(SO_SNDBUF) */ /* get the send buffer size -- getsockopt(SO_SNDBUF) */
return do_getsockopt_sndbuf(dev_m_in, dev_m_out); rc = do_getsockopt_sndbuf(dev_m_in, dev_m_out);
break;
case NWIOSUDSSNDBUF: case NWIOSUDSSNDBUF:
/* set the send buffer size -- setsockopt(SO_SNDBUF) */ /* set the send buffer size -- setsockopt(SO_SNDBUF) */
return do_setsockopt_sndbuf(dev_m_in, dev_m_out); rc = do_setsockopt_sndbuf(dev_m_in, dev_m_out);
break;
case NWIOGUDSRCVBUF: case NWIOGUDSRCVBUF:
/* get the send buffer size -- getsockopt(SO_SNDBUF) */ /* get the send buffer size -- getsockopt(SO_SNDBUF) */
return do_getsockopt_rcvbuf(dev_m_in, dev_m_out); rc = do_getsockopt_rcvbuf(dev_m_in, dev_m_out);
break;
case NWIOSUDSRCVBUF: case NWIOSUDSRCVBUF:
/* set the send buffer size -- setsockopt(SO_SNDBUF) */ /* set the send buffer size -- setsockopt(SO_SNDBUF) */
return do_setsockopt_rcvbuf(dev_m_in, dev_m_out); rc = do_setsockopt_rcvbuf(dev_m_in, dev_m_out);
break;
case NWIOSUDSCTRL: case NWIOSUDSCTRL:
/* set the control data -- sendmsg() */ /* set the control data -- sendmsg() */
return do_sendmsg(dev_m_in, dev_m_out); rc = do_sendmsg(dev_m_in, dev_m_out);
break;
case NWIOGUDSCTRL: case NWIOGUDSCTRL:
/* set the control data -- recvmsg() */ /* set the control data -- recvmsg() */
return do_recvmsg(dev_m_in, dev_m_out); rc = do_recvmsg(dev_m_in, dev_m_out);
break;
default: default:
@ -934,14 +943,17 @@ PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out)
* IOCTLs. Any not for us simply get a EBADIOCTL * IOCTLs. Any not for us simply get a EBADIOCTL
* response. * response.
*/ */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT,
EBADIOCTL);
return EBADIOCTL; rc = EBADIOCTL;
} }
if (rc != SUSPEND)
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, rc);
return rc;
} }
PUBLIC int uds_status(message *dev_m_in, message *dev_m_out) PUBLIC int uds_status(message *dev_m_in, message *dev_m_out)
@ -985,24 +997,14 @@ PUBLIC int uds_status(message *dev_m_in, message *dev_m_out)
uds_fd_table[i].io_gr_size, uds_fd_table[i].io_gr_size,
0); 0);
if (bytes == -1) { if (bytes == SUSPEND) {
uds_set_reply(dev_m_out,
DEV_REVIVE,
uds_fd_table[i].endpoint,
uds_fd_table[i].io_gr,
errno);
return errno;
} else if (bytes == SUSPEND) {
dev_m_out->m_type = dev_m_out->m_type =
DEV_NO_STATUS; DEV_NO_STATUS;
return OK; return OK;
} else { }
uds_fd_table[i].suspended = uds_fd_table[i].suspended =
UDS_NOT_SUSPENDED; UDS_NOT_SUSPENDED;
@ -1014,7 +1016,6 @@ PUBLIC int uds_status(message *dev_m_in, message *dev_m_out)
bytes); bytes);
return bytes; return bytes;
}
case UDS_SUSPENDED_WRITE: case UDS_SUSPENDED_WRITE:
@ -1023,24 +1024,14 @@ PUBLIC int uds_status(message *dev_m_in, message *dev_m_out)
uds_fd_table[i].io_gr_size, uds_fd_table[i].io_gr_size,
0); 0);
if (bytes == -1) { if (bytes == SUSPEND) {
uds_set_reply(dev_m_out,
DEV_REVIVE,
uds_fd_table[i].endpoint,
uds_fd_table[i].io_gr,
errno);
return errno;
} else if (bytes == SUSPEND) {
dev_m_out->m_type = dev_m_out->m_type =
DEV_NO_STATUS; DEV_NO_STATUS;
return OK; return OK;
} else { }
uds_fd_table[i].suspended = uds_fd_table[i].suspended =
UDS_NOT_SUSPENDED; UDS_NOT_SUSPENDED;
@ -1052,7 +1043,6 @@ PUBLIC int uds_status(message *dev_m_in, message *dev_m_out)
bytes); bytes);
return bytes; return bytes;
}
case UDS_SUSPENDED_CONNECT: case UDS_SUSPENDED_CONNECT:
case UDS_SUSPENDED_ACCEPT: case UDS_SUSPENDED_ACCEPT:

View file

@ -109,7 +109,7 @@ PRIVATE filp_id_t verify_fd(endpoint_t ep, int fd)
if (OK != rc) { if (OK != rc) {
printf("(uds) sendrec error... req_nr: %d err: %d\n", printf("(uds) sendrec error... req_nr: %d err: %d\n",
vfs_m.m_type, rc); vfs_m.m_type, rc);
return NULL;; return NULL;
} }
#if DEBUG == 1 #if DEBUG == 1
@ -256,9 +256,6 @@ PUBLIC int perform_connection(message *dev_m_in, message *dev_m_out,
uds_fd_table[minorx].type != uds_fd_table[minory].type) { uds_fd_table[minorx].type != uds_fd_table[minory].type) {
/* sockets are not in a valid state */ /* sockets are not in a valid state */
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
@ -270,9 +267,6 @@ PUBLIC int perform_connection(message *dev_m_in, message *dev_m_out,
memcpy(&(uds_fd_table[minorx].addr), addr, sizeof(struct sockaddr_un)); memcpy(&(uds_fd_table[minorx].addr), addr, sizeof(struct sockaddr_un));
memcpy(&(uds_fd_table[minory].addr), addr, sizeof(struct sockaddr_un)); memcpy(&(uds_fd_table[minory].addr), addr, sizeof(struct sockaddr_un));
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK; return OK;
} }
@ -303,13 +297,7 @@ PUBLIC int do_accept(message *dev_m_in, message *dev_m_out)
minor = uds_minor(dev_m_in); minor = uds_minor(dev_m_in);
if (uds_fd_table[minor].type != -1) { if (uds_fd_table[minor].type != -1) {
/* this IOCTL must be called on a 'fresh' socket */ /* this IOCTL must be called on a 'fresh' socket */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
@ -319,12 +307,6 @@ PUBLIC int do_accept(message *dev_m_in, message *dev_m_out)
D); D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
@ -345,16 +327,9 @@ PUBLIC int do_accept(message *dev_m_in, message *dev_m_out)
} }
if (rc == -1) { if (rc == -1) {
/* there is no server listening on addr. Maybe someone /* there is no server listening on addr. Maybe someone
* screwed up the ioctl()? * screwed up the ioctl()?
*/ */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
@ -390,9 +365,6 @@ PUBLIC int do_accept(message *dev_m_in, message *dev_m_out)
*/ */
uds_fd_table[minor].suspended = UDS_SUSPENDED_ACCEPT; uds_fd_table[minor].suspended = UDS_SUSPENDED_ACCEPT;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, SUSPEND);
return SUSPEND; return SUSPEND;
} }
@ -407,10 +379,7 @@ PUBLIC int do_accept(message *dev_m_in, message *dev_m_out)
printf("(uds) [%d] {do_accept} connection not performed\n", printf("(uds) [%d] {do_accept} connection not performed\n",
minor); minor);
#endif #endif
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT, return rc;
(cp_grant_id_t) dev_m_in->IO_GRANT, errno);
return errno;
} }
uds_fd_table[minorparent].child = -1; uds_fd_table[minorparent].child = -1;
@ -425,11 +394,6 @@ PUBLIC int do_accept(message *dev_m_in, message *dev_m_out)
notify(dev_m_in->m_source); notify(dev_m_in->m_source);
} }
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK; return OK;
} }
@ -450,23 +414,11 @@ PUBLIC int do_connect(message *dev_m_in, message *dev_m_out)
/* only connection oriented sockets can connect */ /* only connection oriented sockets can connect */
if (uds_fd_table[minor].type != SOCK_STREAM && if (uds_fd_table[minor].type != SOCK_STREAM &&
uds_fd_table[minor].type != SOCK_SEQPACKET) { uds_fd_table[minor].type != SOCK_SEQPACKET) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
if (uds_fd_table[minor].peer != -1) { if (uds_fd_table[minor].peer != -1) {
/* socket is already connected */ /* socket is already connected */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EISCONN);
return EISCONN; return EISCONN;
} }
@ -475,24 +427,12 @@ PUBLIC int do_connect(message *dev_m_in, message *dev_m_out)
sizeof(struct sockaddr_un), D); sizeof(struct sockaddr_un), D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
rc = check_perms(minor, &addr); rc = check_perms(minor, &addr);
if (rc != OK) { if (rc != OK) {
/* permission denied, socket file doesn't exist, etc. */ /* permission denied, socket file doesn't exist, etc. */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, rc);
return rc; return rc;
} }
@ -527,26 +467,9 @@ PUBLIC int do_connect(message *dev_m_in, message *dev_m_out)
/* wake the parent (server) */ /* wake the parent (server) */
uds_fd_table[i].ready_to_revive = 1; uds_fd_table[i].ready_to_revive = 1;
notify(dev_m_in->m_source); notify(dev_m_in->m_source);
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT,
OK);
return OK;
} else {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT,
rc);
return rc; return rc;
}
} else { } else {
@ -617,15 +540,9 @@ PUBLIC int do_connect(message *dev_m_in, message *dev_m_out)
} }
if (uds_fd_table[minor].peer == -1) { if (uds_fd_table[minor].peer == -1) {
/* could not find another open socket listening on the /* could not find another open socket listening on the
* specified address with room in the backlog * specified address with room in the backlog
*/ */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, ECONNREFUSED);
return ECONNREFUSED; return ECONNREFUSED;
} }
@ -638,9 +555,6 @@ PUBLIC int do_connect(message *dev_m_in, message *dev_m_out)
uds_fd_table[minor].suspended = UDS_SUSPENDED_CONNECT; uds_fd_table[minor].suspended = UDS_SUSPENDED_CONNECT;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, SUSPEND);
return SUSPEND; return SUSPEND;
} }
@ -663,9 +577,6 @@ PUBLIC int do_listen(message *dev_m_in, message *dev_m_out)
uds_fd_table[minor].addr.sun_family != AF_UNIX) { uds_fd_table[minor].addr.sun_family != AF_UNIX) {
/* probably trying to call listen() before bind() */ /* probably trying to call listen() before bind() */
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
@ -676,11 +587,6 @@ PUBLIC int do_listen(message *dev_m_in, message *dev_m_out)
uds_fd_table[minor].type != SOCK_SEQPACKET) { uds_fd_table[minor].type != SOCK_SEQPACKET) {
/* probably trying to call listen() with a SOCK_DGRAM */ /* probably trying to call listen() with a SOCK_DGRAM */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EOPNOTSUPP);
return EOPNOTSUPP; return EOPNOTSUPP;
} }
@ -690,16 +596,9 @@ PUBLIC int do_listen(message *dev_m_in, message *dev_m_out)
* don't allow the backlog to shrink * don't allow the backlog to shrink
*/ */
rc = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT, rc = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT,
(vir_bytes) 0, (vir_bytes) &backlog_size, sizeof(int), (vir_bytes) 0, (vir_bytes) &backlog_size, sizeof(int), D);
D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
@ -736,11 +635,6 @@ PUBLIC int do_listen(message *dev_m_in, message *dev_m_out)
/* perform listen(2) */ /* perform listen(2) */
uds_fd_table[minor].listening = 1; uds_fd_table[minor].listening = 1;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK; return OK;
} }
@ -759,13 +653,7 @@ PUBLIC int do_socket(message *dev_m_in, message *dev_m_out)
/* see if this socket already has a type */ /* see if this socket already has a type */
if (uds_fd_table[minor].type != -1) { if (uds_fd_table[minor].type != -1) {
/* socket type can only be set once */ /* socket type can only be set once */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
@ -777,11 +665,6 @@ PUBLIC int do_socket(message *dev_m_in, message *dev_m_out)
if (rc != OK) { if (rc != OK) {
/* something went wrong and we couldn't get the type */ /* something went wrong and we couldn't get the type */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
@ -792,13 +675,6 @@ PUBLIC int do_socket(message *dev_m_in, message *dev_m_out)
case SOCK_SEQPACKET: case SOCK_SEQPACKET:
/* the type is one of the 3 valid socket types */ /* the type is one of the 3 valid socket types */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT,
OK);
return OK; return OK;
default: default:
@ -810,20 +686,13 @@ PUBLIC int do_socket(message *dev_m_in, message *dev_m_out)
/* set the type back to '-1' (no type set) */ /* set the type back to '-1' (no type set) */
uds_fd_table[minor].type = -1; uds_fd_table[minor].type = -1;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT,
EINVAL);
return EINVAL; return EINVAL;
} }
} }
PUBLIC int do_bind(message *dev_m_in, message *dev_m_out) PUBLIC int do_bind(message *dev_m_in, message *dev_m_out)
{ {
int minor, strlen; int minor;
struct sockaddr_un addr; struct sockaddr_un addr;
int rc, i; int rc, i;
@ -842,11 +711,6 @@ PUBLIC int do_bind(message *dev_m_in, message *dev_m_out)
/* the type hasn't been set by do_socket() yet OR attempting /* the type hasn't been set by do_socket() yet OR attempting
* to re-bind() a non-SOCK_DGRAM socket * to re-bind() a non-SOCK_DGRAM socket
*/ */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
@ -855,12 +719,6 @@ PUBLIC int do_bind(message *dev_m_in, message *dev_m_out)
D); D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
@ -868,35 +726,18 @@ PUBLIC int do_bind(message *dev_m_in, message *dev_m_out)
if (addr.sun_family != AF_UNIX) { if (addr.sun_family != AF_UNIX) {
/* bad family */ /* bad family */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT,
EAFNOSUPPORT);
return EAFNOSUPPORT; return EAFNOSUPPORT;
} }
if (addr.sun_path[0] == '\0') { if (addr.sun_path[0] == '\0') {
/* bad address */ /* bad address */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, ENOENT);
return ENOENT; return ENOENT;
} }
rc = check_perms(minor, &addr); rc = check_perms(minor, &addr);
if (rc != OK) { if (rc != OK) {
/* permission denied, socket file doesn't exist, etc. */ /* permission denied, socket file doesn't exist, etc. */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, rc);
return rc; return rc;
} }
@ -907,13 +748,6 @@ PUBLIC int do_bind(message *dev_m_in, message *dev_m_out)
uds_fd_table[i].addr.sun_path, UNIX_PATH_MAX)) { uds_fd_table[i].addr.sun_path, UNIX_PATH_MAX)) {
/* another socket is bound to this sun_path */ /* another socket is bound to this sun_path */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT,
EADDRINUSE);
return EADDRINUSE; return EADDRINUSE;
} }
} }
@ -921,11 +755,6 @@ PUBLIC int do_bind(message *dev_m_in, message *dev_m_out)
/* looks good, perform the bind() */ /* looks good, perform the bind() */
memcpy(&(uds_fd_table[minor].addr), &addr, sizeof(struct sockaddr_un)); memcpy(&(uds_fd_table[minor].addr), &addr, sizeof(struct sockaddr_un));
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK; return OK;
} }
@ -952,22 +781,7 @@ PUBLIC int do_getsockname(message *dev_m_in, message *dev_m_out)
(vir_bytes) 0, (vir_bytes) &(uds_fd_table[minor].addr), (vir_bytes) 0, (vir_bytes) &(uds_fd_table[minor].addr),
sizeof(struct sockaddr_un), D); sizeof(struct sockaddr_un), D);
if (rc != OK) { return rc ? EIO : OK;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO;
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK;
} }
PUBLIC int do_getpeername(message *dev_m_in, message *dev_m_out) PUBLIC int do_getpeername(message *dev_m_in, message *dev_m_out)
@ -995,40 +809,15 @@ PUBLIC int do_getpeername(message *dev_m_in, message *dev_m_out)
(vir_bytes) &(uds_fd_table[peer_minor].addr), (vir_bytes) &(uds_fd_table[peer_minor].addr),
sizeof(struct sockaddr_un), D); sizeof(struct sockaddr_un), D);
if (rc != OK) { return rc ? EIO : OK;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO;
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK;
} else { } else {
int err;
if (uds_fd_table[minor].err == ECONNRESET) { if (uds_fd_table[minor].err == ECONNRESET) {
err = ECONNRESET;
uds_fd_table[minor].err = 0; uds_fd_table[minor].err = 0;
return ECONNRESET;
} else { } else {
err = ENOTCONN; return ENOTCONN;
} }
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, err);
return err;
} }
} }
@ -1049,31 +838,16 @@ PUBLIC int do_shutdown(message *dev_m_in, message *dev_m_out)
uds_fd_table[minor].type != SOCK_SEQPACKET) { uds_fd_table[minor].type != SOCK_SEQPACKET) {
/* socket must be a connection oriented socket */ /* socket must be a connection oriented socket */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
if (uds_fd_table[minor].peer == -1) { if (uds_fd_table[minor].peer == -1) {
int err;
if (uds_fd_table[minor].err == ECONNRESET) {
err = ECONNRESET;
} else {
err = ENOTCONN;
}
/* shutdown(2) is only valid for connected sockets */ /* shutdown(2) is only valid for connected sockets */
uds_fd_table[minor].syscall_done = 1; if (uds_fd_table[minor].err == ECONNRESET) {
return ECONNRESET;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT, } else {
(cp_grant_id_t) dev_m_in->IO_GRANT, err); return ENOTCONN;
}
return err;
} }
/* get the 'how' parameter from the process */ /* get the 'how' parameter from the process */
@ -1081,12 +855,6 @@ PUBLIC int do_shutdown(message *dev_m_in, message *dev_m_out)
(vir_bytes) 0, (vir_bytes) &how, sizeof(int), D); (vir_bytes) 0, (vir_bytes) &how, sizeof(int), D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
@ -1109,23 +877,10 @@ PUBLIC int do_shutdown(message *dev_m_in, message *dev_m_out)
break; break;
default: default:
/* the 'how' parameter is invalid */ /* the 'how' parameter is invalid */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK; return OK;
} }
@ -1150,12 +905,6 @@ PUBLIC int do_socketpair(message *dev_m_in, message *dev_m_out)
(vir_bytes) 0, (vir_bytes) &minorin, sizeof(dev_t), D); (vir_bytes) 0, (vir_bytes) &minorin, sizeof(dev_t), D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minorx].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
@ -1171,11 +920,6 @@ PUBLIC int do_socketpair(message *dev_m_in, message *dev_m_out)
/* we won't allow you to magically connect your socket to /* we won't allow you to magically connect your socket to
* someone elses socket * someone elses socket
*/ */
uds_fd_table[minorx].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EPERM);
return EPERM; return EPERM;
} }
@ -1205,11 +949,6 @@ PUBLIC int do_getsockopt_sotype(message *dev_m_in, message *dev_m_out)
/* the type hasn't been set yet. instead of returning an /* the type hasn't been set yet. instead of returning an
* invalid type, we fail with EINVAL * invalid type, we fail with EINVAL
*/ */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
@ -1217,22 +956,7 @@ PUBLIC int do_getsockopt_sotype(message *dev_m_in, message *dev_m_out)
(vir_bytes) 0, (vir_bytes) &(uds_fd_table[minor].type), (vir_bytes) 0, (vir_bytes) &(uds_fd_table[minor].type),
sizeof(int), D); sizeof(int), D);
if (rc != OK) { return rc ? EIO : OK;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO;
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK;
} }
PUBLIC int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out) PUBLIC int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out)
@ -1252,21 +976,13 @@ PUBLIC int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out)
if (uds_fd_table[minor].peer == -1) { if (uds_fd_table[minor].peer == -1) {
int err;
if (uds_fd_table[minor].err == ECONNRESET) { if (uds_fd_table[minor].err == ECONNRESET) {
err = ECONNRESET;
uds_fd_table[minor].err = 0; uds_fd_table[minor].err = 0;
return ECONNRESET;
} else { } else {
err = ENOTCONN; return ENOTCONN;
} }
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, err);
return err;
} }
peer_minor = uds_fd_table[minor].peer; peer_minor = uds_fd_table[minor].peer;
@ -1274,35 +990,14 @@ PUBLIC int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out)
/* obtain the peer's credentials */ /* obtain the peer's credentials */
rc = getnucred(uds_fd_table[peer_minor].owner, &cred); rc = getnucred(uds_fd_table[peer_minor].owner, &cred);
if (rc == -1) { if (rc == -1) {
/* likely error: invalid endpoint / proc doesn't exist */ /* likely error: invalid endpoint / proc doesn't exist */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, errno);
return errno; return errno;
} }
rc = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT, rc = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT,
(vir_bytes) 0, (vir_bytes) &cred, sizeof(struct ucred), D); (vir_bytes) 0, (vir_bytes) &cred, sizeof(struct ucred), D);
if (rc != OK) { return rc ? EIO : OK;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO;
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK;
} }
int do_getsockopt_sndbuf(message *dev_m_in, message *dev_m_out) int do_getsockopt_sndbuf(message *dev_m_in, message *dev_m_out)
@ -1323,22 +1018,7 @@ int do_getsockopt_sndbuf(message *dev_m_in, message *dev_m_out)
(vir_bytes) 0, (vir_bytes) &(sndbuf), (vir_bytes) 0, (vir_bytes) &(sndbuf),
sizeof(size_t), D); sizeof(size_t), D);
if (rc != OK) { return rc ? EIO : OK;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO;
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK;
} }
int do_setsockopt_sndbuf(message *dev_m_in, message *dev_m_out) int do_setsockopt_sndbuf(message *dev_m_in, message *dev_m_out)
@ -1361,35 +1041,17 @@ int do_setsockopt_sndbuf(message *dev_m_in, message *dev_m_out)
sizeof(size_t), D); sizeof(size_t), D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
if (sndbuf > PIPE_BUF) { if (sndbuf > PIPE_BUF) {
/* The send buffer is limited to 32K at the moment. */ /* The send buffer is limited to 32K at the moment. */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, ENOSYS);
return ENOSYS; return ENOSYS;
} }
/* There is no way to reduce the send buffer, do we have to /* There is no way to reduce the send buffer, do we have to
* let this call fail for smaller buffers? * let this call fail for smaller buffers?
*/ */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK; return OK;
} }
@ -1411,22 +1073,7 @@ int do_getsockopt_rcvbuf(message *dev_m_in, message *dev_m_out)
(vir_bytes) 0, (vir_bytes) &(rcvbuf), (vir_bytes) 0, (vir_bytes) &(rcvbuf),
sizeof(size_t), D); sizeof(size_t), D);
if (rc != OK) { return rc ? EIO : OK;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO;
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK;
} }
int do_setsockopt_rcvbuf(message *dev_m_in, message *dev_m_out) int do_setsockopt_rcvbuf(message *dev_m_in, message *dev_m_out)
@ -1449,35 +1096,17 @@ int do_setsockopt_rcvbuf(message *dev_m_in, message *dev_m_out)
sizeof(size_t), D); sizeof(size_t), D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
if (rcvbuf > PIPE_BUF) { if (rcvbuf > PIPE_BUF) {
/* The send buffer is limited to 32K at the moment. */ /* The send buffer is limited to 32K at the moment. */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, ENOSYS);
return ENOSYS; return ENOSYS;
} }
/* There is no way to reduce the send buffer, do we have to /* There is no way to reduce the send buffer, do we have to
* let this call fail for smaller buffers? * let this call fail for smaller buffers?
*/ */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK; return OK;
} }
@ -1497,13 +1126,7 @@ PUBLIC int do_sendto(message *dev_m_in, message *dev_m_out)
minor = uds_minor(dev_m_in); minor = uds_minor(dev_m_in);
if (uds_fd_table[minor].type != SOCK_DGRAM) { if (uds_fd_table[minor].type != SOCK_DGRAM) {
/* This IOCTL is only for SOCK_DGRAM sockets */ /* This IOCTL is only for SOCK_DGRAM sockets */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
@ -1512,46 +1135,23 @@ PUBLIC int do_sendto(message *dev_m_in, message *dev_m_out)
D); D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
/* do some basic sanity checks on the address */ /* do some basic sanity checks on the address */
if (addr.sun_family != AF_UNIX || addr.sun_path[0] == '\0') { if (addr.sun_family != AF_UNIX || addr.sun_path[0] == '\0') {
/* bad address */ /* bad address */
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);
return EINVAL; return EINVAL;
} }
rc = check_perms(minor, &addr); rc = check_perms(minor, &addr);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, rc);
return rc; return rc;
} }
memcpy(&(uds_fd_table[minor].target), &addr, memcpy(&(uds_fd_table[minor].target), &addr,
sizeof(struct sockaddr_un)); sizeof(struct sockaddr_un));
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK; return OK;
} }
@ -1572,22 +1172,7 @@ PUBLIC int do_recvfrom(message *dev_m_in, message *dev_m_out)
(vir_bytes) 0, (vir_bytes) &(uds_fd_table[minor].source), (vir_bytes) 0, (vir_bytes) &(uds_fd_table[minor].source),
sizeof(struct sockaddr_un), D); sizeof(struct sockaddr_un), D);
if (rc != OK) { return rc ? EIO : OK;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO;
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK;
} }
int msg_control_read(struct msg_control *msg_ctrl, struct ancillary *data, int msg_control_read(struct msg_control *msg_ctrl, struct ancillary *data,
@ -1771,7 +1356,6 @@ PRIVATE int recv_fds(int minor, struct ancillary *data,
PRIVATE int recv_cred(int minor, struct ancillary *data, PRIVATE int recv_cred(int minor, struct ancillary *data,
struct msg_control *msg_ctrl) struct msg_control *msg_ctrl)
{ {
int rc, i;
struct msghdr msghdr; struct msghdr msghdr;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
@ -1817,9 +1401,6 @@ PUBLIC int do_sendmsg(message *dev_m_in, message *dev_m_out)
sizeof(struct msg_control), D); sizeof(struct msg_control), D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
@ -1829,11 +1410,6 @@ PUBLIC int do_sendmsg(message *dev_m_in, message *dev_m_out)
if (uds_fd_table[minor].target.sun_path[0] == '\0' || if (uds_fd_table[minor].target.sun_path[0] == '\0' ||
uds_fd_table[minor].target.sun_family != AF_UNIX) { uds_fd_table[minor].target.sun_family != AF_UNIX) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT,
EDESTADDRREQ);
return EDESTADDRREQ; return EDESTADDRREQ;
} }
@ -1853,19 +1429,11 @@ PUBLIC int do_sendmsg(message *dev_m_in, message *dev_m_out)
} }
if (peer == -1) { if (peer == -1) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, ENOENT);
return ENOENT; return ENOENT;
} }
} else { } else {
peer = uds_fd_table[minor].peer; peer = uds_fd_table[minor].peer;
if (peer == -1) { if (peer == -1) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, ENOTCONN);
return ENOTCONN; return ENOTCONN;
} }
} }
@ -1881,24 +1449,10 @@ PUBLIC int do_sendmsg(message *dev_m_in, message *dev_m_out)
rc = msg_control_read(&msg_ctrl, &uds_fd_table[peer].ancillary_data, rc = msg_control_read(&msg_ctrl, &uds_fd_table[peer].ancillary_data,
minor); minor);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, rc);
return rc; return rc;
} }
rc = send_fds(minor, &uds_fd_table[peer].ancillary_data); return send_fds(minor, &uds_fd_table[peer].ancillary_data);
if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, rc);
return rc;
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK;
} }
PUBLIC int do_recvmsg(message *dev_m_in, message *dev_m_out) PUBLIC int do_recvmsg(message *dev_m_in, message *dev_m_out)
@ -1936,10 +1490,6 @@ PUBLIC int do_recvmsg(message *dev_m_in, message *dev_m_out)
sizeof(struct msg_control), D); sizeof(struct msg_control), D);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO; return EIO;
} }
@ -1955,18 +1505,11 @@ PUBLIC int do_recvmsg(message *dev_m_in, message *dev_m_out)
CMSG_LEN(sizeof(struct ucred)); CMSG_LEN(sizeof(struct ucred));
if (controllen_needed > controllen_avail) { if (controllen_needed > controllen_avail) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EOVERFLOW);
return EOVERFLOW; return EOVERFLOW;
} }
rc = recv_fds(minor, &uds_fd_table[minor].ancillary_data, &msg_ctrl); rc = recv_fds(minor, &uds_fd_table[minor].ancillary_data, &msg_ctrl);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, rc);
return rc; return rc;
} }
@ -1974,10 +1517,6 @@ PUBLIC int do_recvmsg(message *dev_m_in, message *dev_m_out)
rc = recv_cred(minor, &uds_fd_table[minor].ancillary_data, rc = recv_cred(minor, &uds_fd_table[minor].ancillary_data,
&msg_ctrl); &msg_ctrl);
if (rc != OK) { if (rc != OK) {
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY,
dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, rc);
return rc; return rc;
} }
} }
@ -1987,16 +1526,5 @@ PUBLIC int do_recvmsg(message *dev_m_in, message *dev_m_out)
(vir_bytes) 0, (vir_bytes) &msg_ctrl, (vir_bytes) 0, (vir_bytes) &msg_ctrl,
sizeof(struct msg_control), D); sizeof(struct msg_control), D);
if (rc != OK) { return rc ? EIO : OK;
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, EIO);
return EIO;
}
uds_fd_table[minor].syscall_done = 1;
uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
(cp_grant_id_t) dev_m_in->IO_GRANT, OK);
return OK;
} }