/* likely error: get_block() failed */
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;
+ (cp_grant_id_t) dev_m_in->IO_GRANT, rc);
+ return rc;
}
/* Process the response */
if (!(uds_fd_table[minor].mode & S_IRUSR)) {
/* socket is shutdown for reading */
- errno = EPIPE;
- return -1;
+ return EPIPE;
}
if (uds_fd_table[minor].size == 0) {
if (!(uds_fd_table[minor].mode & S_IWUSR)) {
/* socket is shutdown for writing */
- errno = EPIPE;
- return -1;
+ return EPIPE;
}
if (size > PIPE_BUF) {
/* message is too big to ever write to the PIPE */
- errno = EMSGSIZE;
- return -1;
+ return EMSGSIZE;
}
if (uds_fd_table[minor].type == SOCK_STREAM ||
if (uds_fd_table[minor].err == ECONNRESET) {
uds_fd_table[minor].err = 0;
- errno = ECONNRESET;
+ return ECONNRESET;
} else {
- errno = ENOTCONN;
+ return ENOTCONN;
}
-
- return -1;
} else {
peer = uds_fd_table[minor].peer;
}
if (peer == -1) {
- errno = ENOENT;
- return -1;
+ return ENOENT;
}
}
bytes = uds_perform_read(minor, dev_m_in->m_source,
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);
+ uds_set_reply(dev_m_out, TASK_REPLY,
+ uds_fd_table[minor].endpoint,
+ uds_fd_table[minor].io_gr,
+ bytes);
- return errno;
- } else {
-
- uds_set_reply(dev_m_out, TASK_REPLY,
- uds_fd_table[minor].endpoint,
- uds_fd_table[minor].io_gr,
- bytes);
-
- return bytes;
- }
+ return bytes;
}
PUBLIC int uds_write(message *dev_m_in, message *dev_m_out)
bytes = uds_perform_write(minor, dev_m_in->m_source,
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);
+ uds_set_reply(dev_m_out, TASK_REPLY,
+ uds_fd_table[minor].endpoint,
+ uds_fd_table[minor].io_gr,
+ bytes);
- return errno;
-
- } else {
-
- uds_set_reply(dev_m_out, TASK_REPLY,
- uds_fd_table[minor].endpoint,
- uds_fd_table[minor].io_gr,
- bytes);
-
- return bytes;
- }
+ return bytes;
}
PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out)
{
- int minor;
+ int rc, minor;
#if DEBUG == 1
static int call_count = 0;
case NWIOSUDSCONN:
/* 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:
/* 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:
/* set the backlog_size and put the socket into the
* listening state -- listen()
*/
- return do_listen(dev_m_in, dev_m_out);
+ rc = do_listen(dev_m_in, dev_m_out);
+
+ break;
case NWIOSUDSTYPE:
/* set the type for this socket (i.e.
* 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:
/* 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:
/* 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:
/* 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:
/* shutdown a socket for reading, writing, or
* both -- shutdown()
*/
- return do_shutdown(dev_m_in, dev_m_out);
+ rc = do_shutdown(dev_m_in, dev_m_out);
+
+ break;
case NWIOSUDSPAIR:
/* 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:
/* 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:
/* 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:
/* 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:
/* 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:
/* 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:
/* 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:
/* 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:
/* 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:
/* 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:
/* 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:
* IOCTLs. Any not for us simply get a EBADIOCTL
* 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)
uds_fd_table[i].io_gr_size,
0);
- if (bytes == -1) {
-
- 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) {
+ if (bytes == SUSPEND) {
dev_m_out->m_type =
DEV_NO_STATUS;
return OK;
- } else {
+ }
- uds_fd_table[i].suspended =
- UDS_NOT_SUSPENDED;
+ uds_fd_table[i].suspended =
+ UDS_NOT_SUSPENDED;
- uds_set_reply(dev_m_out,
+ uds_set_reply(dev_m_out,
DEV_REVIVE,
uds_fd_table[i].endpoint,
uds_fd_table[i].io_gr,
bytes);
- return bytes;
- }
+ return bytes;
case UDS_SUSPENDED_WRITE:
uds_fd_table[i].io_gr_size,
0);
- if (bytes == -1) {
-
- 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) {
+ if (bytes == SUSPEND) {
dev_m_out->m_type =
DEV_NO_STATUS;
return OK;
- } else {
+ }
- uds_fd_table[i].suspended =
- UDS_NOT_SUSPENDED;
+ uds_fd_table[i].suspended =
+ UDS_NOT_SUSPENDED;
- uds_set_reply(dev_m_out,
+ uds_set_reply(dev_m_out,
DEV_REVIVE,
uds_fd_table[i].endpoint,
uds_fd_table[i].io_gr,
bytes);
- return bytes;
- }
+ return bytes;
case UDS_SUSPENDED_CONNECT:
case UDS_SUSPENDED_ACCEPT:
printf("(uds) sendrec error... req_nr: %d err: %d\n",
vfs_m.m_type, rc);
- return EIO;
+ return EIO;
}
#if DEBUG == 1
if (OK != rc) {
printf("(uds) sendrec error... req_nr: %d err: %d\n",
vfs_m.m_type, rc);
- return NULL;;
+ return NULL;
}
#if DEBUG == 1
if (OK != rc) {
printf("(uds) sendrec error... req_nr: %d err: %d\n",
vfs_m.m_type, rc);
- return EIO;
+ return EIO;
}
#if DEBUG == 1
if (OK != rc) {
printf("(uds) sendrec error... req_nr: %d err: %d\n",
vfs_m.m_type, rc);
- return EIO;
+ return EIO;
}
#if DEBUG == 1
if (OK != rc) {
printf("(uds) sendrec error... req_nr: %d err: %d\n",
vfs_m.m_type, rc);
- return EIO;
+ return EIO;
}
#if DEBUG == 1
if (OK != rc) {
printf("(uds) sendrec error... req_nr: %d err: %d\n",
vfs_m.m_type, rc);
- return EIO;
+ return EIO;
}
#if DEBUG == 1
uds_fd_table[minorx].type != uds_fd_table[minory].type) {
/* 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;
}
memcpy(&(uds_fd_table[minorx].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;
}
minor = uds_minor(dev_m_in);
if (uds_fd_table[minor].type != -1) {
-
/* 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;
}
D);
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;
}
}
if (rc == -1) {
-
/* there is no server listening on addr. Maybe someone
* 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;
}
*/
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;
}
printf("(uds) [%d] {do_accept} connection not performed\n",
minor);
#endif
- 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 rc;
}
uds_fd_table[minorparent].child = -1;
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;
}
/* only connection oriented sockets can connect */
if (uds_fd_table[minor].type != SOCK_STREAM &&
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;
}
if (uds_fd_table[minor].peer != -1) {
-
/* 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;
}
sizeof(struct sockaddr_un), D);
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;
}
rc = check_perms(minor, &addr);
if (rc != OK) {
-
/* 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;
}
/* wake the parent (server) */
uds_fd_table[i].ready_to_revive = 1;
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 {
#if DEBUG == 1
}
if (uds_fd_table[minor].peer == -1) {
-
/* could not find another open socket listening on the
* 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;
}
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;
}
uds_fd_table[minor].addr.sun_family != AF_UNIX) {
/* 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;
}
uds_fd_table[minor].type != SOCK_SEQPACKET) {
/* 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;
}
* don't allow the backlog to shrink
*/
rc = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT,
- (vir_bytes) 0, (vir_bytes) &backlog_size, sizeof(int),
- D);
+ (vir_bytes) 0, (vir_bytes) &backlog_size, sizeof(int), D);
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;
}
/* perform listen(2) */
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;
}
/* see if this socket already has a type */
if (uds_fd_table[minor].type != -1) {
-
/* 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;
}
if (rc != OK) {
/* 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;
}
case SOCK_SEQPACKET:
/* 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;
default:
/* set the type back to '-1' (no type set) */
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;
}
}
PUBLIC int do_bind(message *dev_m_in, message *dev_m_out)
{
- int minor, strlen;
+ int minor;
struct sockaddr_un addr;
int rc, i;
/* the type hasn't been set by do_socket() yet OR attempting
* 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;
}
D);
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;
}
if (addr.sun_family != AF_UNIX) {
/* 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;
}
if (addr.sun_path[0] == '\0') {
/* 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;
}
rc = check_perms(minor, &addr);
if (rc != OK) {
-
/* 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;
}
uds_fd_table[i].addr.sun_path, UNIX_PATH_MAX)) {
/* 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;
}
}
/* looks good, perform the bind() */
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;
}
(vir_bytes) 0, (vir_bytes) &(uds_fd_table[minor].addr),
sizeof(struct sockaddr_un), D);
- 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;
- }
-
- 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 rc ? EIO : OK;
}
PUBLIC int do_getpeername(message *dev_m_in, message *dev_m_out)
(vir_bytes) &(uds_fd_table[peer_minor].addr),
sizeof(struct sockaddr_un), D);
- 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;
- }
-
- 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 rc ? EIO : OK;
} else {
-
- int err;
-
if (uds_fd_table[minor].err == ECONNRESET) {
- err = ECONNRESET;
uds_fd_table[minor].err = 0;
+
+ return ECONNRESET;
} 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;
}
}
uds_fd_table[minor].type != SOCK_SEQPACKET) {
/* 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;
}
if (uds_fd_table[minor].peer == -1) {
-
- int err;
-
+ /* shutdown(2) is only valid for connected sockets */
if (uds_fd_table[minor].err == ECONNRESET) {
- err = ECONNRESET;
+ return ECONNRESET;
} else {
- err = ENOTCONN;
+ return ENOTCONN;
}
-
- /* shutdown(2) is only valid for connected 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, err);
-
- return err;
}
/* get the 'how' parameter from the process */
(vir_bytes) 0, (vir_bytes) &how, sizeof(int), D);
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;
}
break;
default:
-
/* 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;
}
-
- 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;
}
(vir_bytes) 0, (vir_bytes) &minorin, sizeof(dev_t), D);
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;
}
/* we won't allow you to magically connect your socket to
* 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;
}
/* the type hasn't been set yet. instead of returning an
* 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;
}
(vir_bytes) 0, (vir_bytes) &(uds_fd_table[minor].type),
sizeof(int), D);
- 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;
- }
-
- 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 rc ? EIO : OK;
}
PUBLIC int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out)
if (uds_fd_table[minor].peer == -1) {
- int err;
-
if (uds_fd_table[minor].err == ECONNRESET) {
- err = ECONNRESET;
uds_fd_table[minor].err = 0;
+
+ return ECONNRESET;
} 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;
/* obtain the peer's credentials */
rc = getnucred(uds_fd_table[peer_minor].owner, &cred);
if (rc == -1) {
-
/* 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;
}
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);
- 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;
- }
-
- 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 rc ? EIO : OK;
}
int do_getsockopt_sndbuf(message *dev_m_in, message *dev_m_out)
(vir_bytes) 0, (vir_bytes) &(sndbuf),
sizeof(size_t), D);
- 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;
- }
-
- 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 rc ? EIO : OK;
}
int do_setsockopt_sndbuf(message *dev_m_in, message *dev_m_out)
sizeof(size_t), D);
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;
}
if (sndbuf > PIPE_BUF) {
-
/* 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;
}
/* There is no way to reduce the send buffer, do we have to
* 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;
}
(vir_bytes) 0, (vir_bytes) &(rcvbuf),
sizeof(size_t), D);
- 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;
- }
-
- 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 rc ? EIO : OK;
}
int do_setsockopt_rcvbuf(message *dev_m_in, message *dev_m_out)
sizeof(size_t), D);
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;
}
if (rcvbuf > PIPE_BUF) {
-
/* 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;
}
/* There is no way to reduce the send buffer, do we have to
* 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;
}
minor = uds_minor(dev_m_in);
if (uds_fd_table[minor].type != SOCK_DGRAM) {
-
/* 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;
}
D);
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;
}
/* do some basic sanity checks on the address */
if (addr.sun_family != AF_UNIX || addr.sun_path[0] == '\0') {
-
/* 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;
}
rc = check_perms(minor, &addr);
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;
}
memcpy(&(uds_fd_table[minor].target), &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;
}
(vir_bytes) 0, (vir_bytes) &(uds_fd_table[minor].source),
sizeof(struct sockaddr_un), D);
- 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;
- }
-
- 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 rc ? EIO : OK;
}
int msg_control_read(struct msg_control *msg_ctrl, struct ancillary *data,
PRIVATE int recv_cred(int minor, struct ancillary *data,
struct msg_control *msg_ctrl)
{
- int rc, i;
struct msghdr msghdr;
struct cmsghdr *cmsg;
sizeof(struct msg_control), D);
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;
}
if (uds_fd_table[minor].target.sun_path[0] == '\0' ||
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;
}
}
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;
}
} else {
peer = uds_fd_table[minor].peer;
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;
}
}
rc = msg_control_read(&msg_ctrl, &uds_fd_table[peer].ancillary_data,
minor);
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;
}
- rc = 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;
+ return send_fds(minor, &uds_fd_table[peer].ancillary_data);
}
PUBLIC int do_recvmsg(message *dev_m_in, message *dev_m_out)
sizeof(struct msg_control), D);
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;
}
CMSG_LEN(sizeof(struct ucred));
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;
}
rc = recv_fds(minor, &uds_fd_table[minor].ancillary_data, &msg_ctrl);
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;
}
rc = recv_cred(minor, &uds_fd_table[minor].ancillary_data,
&msg_ctrl);
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;
}
}
(vir_bytes) 0, (vir_bytes) &msg_ctrl,
sizeof(struct msg_control), D);
- 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;
- }
-
- 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 rc ? EIO : OK;
}