Beispiel #1
0
PUBLIC int uds_write(message *dev_m_in, message *dev_m_out)
{
	int bytes;
	int minor;

#if DEBUG == 1
	static int call_count = 0;
	printf("(uds) [%d] uds_write() call_count=%d\n", uds_minor(dev_m_in),
							++call_count);
	printf("Endpoint: 0x%x | Position 0x%x\n", dev_m_in->USER_ENDPT, 
							dev_m_in->POSITION);
#endif

	minor = uds_minor(dev_m_in);

	if (uds_fd_table[minor].state != UDS_INUSE) {

		/* attempted to close a socket that hasn't been opened -- 
		 * something is very wrong :(
		 */
		uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->USER_ENDPT,
				(cp_grant_id_t) dev_m_in->IO_GRANT, EINVAL);

		return EINVAL;
	}

	/* track the system call we are performing in case it gets cancelled */
	uds_fd_table[minor].call_nr = dev_m_in->m_type;
	uds_fd_table[minor].ioctl = 0;
	uds_fd_table[minor].syscall_done = 0;

	/* Update the process endpoint. */
	uds_fd_table[minor].endpoint = dev_m_in->USER_ENDPT;

	/* setup select(2) framework */
	uds_fd_table[minor].selecting = 0;

	/* save I/O Grant info */
	uds_fd_table[minor].io_gr = (cp_grant_id_t) dev_m_in->IO_GRANT;
	uds_fd_table[minor].io_gr_size = dev_m_in->COUNT;

	bytes = uds_perform_write(minor, dev_m_in->m_source,
					uds_fd_table[minor].io_gr_size, 0);

	uds_set_reply(dev_m_out, TASK_REPLY, 
			uds_fd_table[minor].endpoint, 
			uds_fd_table[minor].io_gr,
			bytes);

	return bytes;
}
Beispiel #2
0
PUBLIC int uds_status(message *dev_m_in, message *dev_m_out)
{
	int i, bytes;

#if DEBUG == 1
	static int call_count = 0;
	printf("(uds) [%d] uds_status() call_count=%d\n", uds_minor(dev_m_in),
							++call_count);
	printf("Endpoint: 0x%x | Position 0x%x\n", dev_m_in->IO_ENDPT, dev_m_in->POSITION);
#endif

	for (i = 0; i < NR_FDS; i++) {

		if (uds_fd_table[i].status_updated == 1) {

			/* clear the status_updated flag */
			uds_fd_table[i].status_updated = 0;
			uds_fd_table[i].selecting = 0;

			/* prepare the response */
			dev_m_out->m_type = DEV_IO_READY;
			dev_m_out->DEV_MINOR = i;
			dev_m_out->DEV_SEL_OPS = uds_fd_table[i].sel_ops_out;

			return uds_fd_table[i].sel_ops_out;
		}

		if (uds_fd_table[i].ready_to_revive == 1) {

			/* clear the ready to revive flag */
			uds_fd_table[i].ready_to_revive = 0;

			switch (uds_fd_table[i].suspended) {

				case UDS_SUSPENDED_READ:

					bytes = uds_perform_read(i, 
						dev_m_in->m_source,
						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) {

						dev_m_out->m_type =
							DEV_NO_STATUS;

						return OK;

					} else  {

						uds_fd_table[i].suspended =
							UDS_NOT_SUSPENDED;

						uds_set_reply(dev_m_out,
						DEV_REVIVE, 
						uds_fd_table[i].endpoint,
						uds_fd_table[i].io_gr,
						bytes);

						return bytes;
					}

				case UDS_SUSPENDED_WRITE:

					bytes = uds_perform_write(i,
						dev_m_in->m_source, 
						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) {

						dev_m_out->m_type =
							DEV_NO_STATUS;

						return OK;

					} else  {

						uds_fd_table[i].suspended =
							UDS_NOT_SUSPENDED;

						uds_set_reply(dev_m_out, 
						DEV_REVIVE, 
						uds_fd_table[i].endpoint,
						uds_fd_table[i].io_gr,
						bytes);

						return bytes;
					}

				case UDS_SUSPENDED_CONNECT:
				case UDS_SUSPENDED_ACCEPT:

					/* In both cases, the process 
					 * that send the notify() 
					 * already performed the connection. 
					 * The only thing to do here is 
					 * unblock.
					 */

					uds_fd_table[i].suspended = 
							UDS_NOT_SUSPENDED;

					uds_set_reply(dev_m_out,
						DEV_REVIVE, 
						uds_fd_table[i].endpoint,
						uds_fd_table[i].io_gr,
						OK);

					return OK;

				default:
					continue;
			}

		}
	}

	dev_m_out->m_type = DEV_NO_STATUS;
	return OK;
}
Beispiel #3
0
PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out)
{
	int minor;

#if DEBUG == 1
	static int call_count = 0;
	printf("(uds) [%d] uds_ioctl() call_count=%d\n", uds_minor(dev_m_in),
							++call_count);
 	printf("Endpoint: 0x%x | Position 0x%x\n", dev_m_in->IO_ENDPT, 
							dev_m_in->POSITION);
#endif

	minor = uds_minor(dev_m_in);

	if (uds_fd_table[minor].state != UDS_INUSE) {

		/* attempted to close a socket that hasn't been opened --
		 * something is very wrong :(
		 */
		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;
	}

	/* track the system call we are performing in case it gets cancelled */
	uds_fd_table[minor].call_nr = dev_m_in->m_type;
	uds_fd_table[minor].ioctl = dev_m_in->COUNT;
	uds_fd_table[minor].syscall_done = 0;

	/* setup select(2) framework */
	uds_fd_table[minor].selecting = 0;

	/* update the owner endpoint - yes it's really stored in POSITION */
	uds_fd_table[minor].owner = dev_m_in->POSITION;

	switch (dev_m_in->COUNT) {	/* Handle the ioctl(2) command */

		case NWIOSUDSCONN:

			/* connect to a listening socket -- connect() */
			return do_connect(dev_m_in, dev_m_out);

		case NWIOSUDSACCEPT:

			/* accept an incoming connection -- accept() */
			return do_accept(dev_m_in, dev_m_out);

		case NWIOSUDSBLOG:

			/* set the backlog_size and put the socket into the
			 * listening state -- listen()
			 */
			return do_listen(dev_m_in, dev_m_out);

		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);

		case NWIOSUDSADDR:

			/* set the address for this socket -- bind() */
			return do_bind(dev_m_in, dev_m_out);

		case NWIOGUDSADDR:

			/* get the address for this socket -- getsockname() */
			return do_getsockname(dev_m_in, dev_m_out);

		case NWIOGUDSPADDR:

			/* get the address for the peer -- getpeername() */
			return do_getpeername(dev_m_in, dev_m_out);

		case NWIOSUDSSHUT:

			/* shutdown a socket for reading, writing, or 
			 * both -- shutdown()
			 */
			return do_shutdown(dev_m_in, dev_m_out);

		case NWIOSUDSPAIR:

			/* connect two sockets -- socketpair() */
			return do_socketpair(dev_m_in, dev_m_out);

		case NWIOGUDSSOTYPE:

			/* get socket type -- getsockopt(SO_TYPE) */
			return do_getsockopt_sotype(dev_m_in, dev_m_out);

		case NWIOGUDSPEERCRED:

			/* get peer endpoint -- getsockopt(SO_PEERCRED) */
			return do_getsockopt_peercred(dev_m_in, dev_m_out);

		case NWIOSUDSTADDR:

			/* set target address -- sendto() */
			return do_sendto(dev_m_in, dev_m_out);

		case NWIOGUDSFADDR:

			/* get from address -- recvfrom() */
			return do_recvfrom(dev_m_in, dev_m_out);

		case NWIOGUDSSNDBUF:

			/* get the send buffer size -- getsockopt(SO_SNDBUF) */
			return do_getsockopt_sndbuf(dev_m_in, dev_m_out);

		case NWIOSUDSSNDBUF:

			/* set the send buffer size -- setsockopt(SO_SNDBUF) */
			return do_setsockopt_sndbuf(dev_m_in, dev_m_out);

		case NWIOGUDSRCVBUF:

			/* get the send buffer size -- getsockopt(SO_SNDBUF) */
			return do_getsockopt_rcvbuf(dev_m_in, dev_m_out);

		case NWIOSUDSRCVBUF:

			/* set the send buffer size -- setsockopt(SO_SNDBUF) */
			return do_setsockopt_rcvbuf(dev_m_in, dev_m_out);

		case NWIOSUDSCTRL:

			/* set the control data -- sendmsg() */
			return do_sendmsg(dev_m_in, dev_m_out);

		case NWIOGUDSCTRL:

			/* set the control data -- recvmsg() */
			return do_recvmsg(dev_m_in, dev_m_out);

		default:

			/* the IOCTL command is not valid for /dev/uds --
			 * this happens a lot and is normal. a lot of 
			 * libc functions determine the socket type with 
			 * 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;
	}
}
Beispiel #4
0
PUBLIC int uds_open(message *dev_m_in, message *dev_m_out)
{
	message fs_m_in, fs_m_out;
	struct ucred ucred;
	int rc, i;
	int minor;

#if DEBUG == 1
	static int call_count = 0;
	printf("(uds) [%d] uds_open() call_count=%d\n", uds_minor(dev_m_in),
							++call_count);
	printf("Endpoint: 0x%x\n", dev_m_in->IO_ENDPT);
#endif

	/*
	 * Find a slot in the descriptor table for the new descriptor.
	 * The index of the descriptor in the table will be returned.
	 * Subsequent calls to read/write/close/ioctl/etc will use this
	 * minor number. The minor number must be different from the
	 * the /dev/uds device's minor number (currently 0).
	 */

	minor = -1; /* to trap error */

	for (i = 1; i < NR_FDS; i++) {
		if (uds_fd_table[i].state == UDS_FREE) {
			minor = i;
			break;
		}
	}

	if (minor == -1) {

		/* descriptor table full */
		uds_set_reply(dev_m_out, TASK_REPLY, dev_m_in->IO_ENDPT,
				(cp_grant_id_t) dev_m_in->IO_GRANT, ENFILE);
		return ENFILE;
	}

	/*
	 * We found a slot in uds_fd_table, now initialize the descriptor
	 */

	/* mark this one as 'in use' so that it doesn't get assigned to
	 * another socket
	 */
	uds_fd_table[minor].state = UDS_INUSE;

	/* track the system call we are performing in case it gets cancelled */
	uds_fd_table[minor].call_nr = dev_m_in->m_type;
	uds_fd_table[minor].ioctl = 0;
	uds_fd_table[minor].syscall_done = 0;

	/* set the socket owner */
	uds_fd_table[minor].owner = dev_m_in->IO_ENDPT;
	uds_fd_table[minor].endpoint = dev_m_in->IO_ENDPT;

	/* setup select(2) framework */
	uds_fd_table[minor].selecting = 0;
	uds_fd_table[minor].select_proc = 0;
	uds_fd_table[minor].sel_ops_in = 0;
	uds_fd_table[minor].sel_ops_out = 0;
	uds_fd_table[minor].status_updated = 0;

	/* initialize the data pointer (pos) to the start of the PIPE */
	uds_fd_table[minor].pos = 0;

	/* the PIPE is initially empty */
	uds_fd_table[minor].size = 0;

	/* the default for a new socket is to allow reading and writing.
	 * shutdown(2) will remove one or both flags.
	 */
	uds_fd_table[minor].mode = S_IRUSR|S_IWUSR;

	/* In libc socket(2) sets this to the actual value later with the
	 * NWIOSUDSTYPE ioctl().
	 */
	uds_fd_table[minor].type = -1;

	/* Clear the backlog by setting each entry to -1 */
	for (i = 0; i < UDS_SOMAXCONN; i++) {
		/* initially no connections are pending */
		uds_fd_table[minor].backlog[i] = -1;
	}

	memset(&uds_fd_table[minor].ancillary_data, '\0', sizeof(struct 
								ancillary));
	for (i = 0; i < OPEN_MAX; i++) {
		uds_fd_table[minor].ancillary_data.fds[i] = -1;
	}

	/* default the size to UDS_SOMAXCONN */
	uds_fd_table[minor].backlog_size = UDS_SOMAXCONN;

	/* the socket isn't listening for incoming connections until
	 * listen(2) is called
	 */
	uds_fd_table[minor].listening = 0;

	/* initially the socket is not connected to a peer */
	uds_fd_table[minor].peer = -1;

	/* there isn't a child waiting to be accept(2)'d */
	uds_fd_table[minor].child = -1;

	/* initially the socket is not bound or listening on an address */
	memset(&(uds_fd_table[minor].addr), '\0', sizeof(struct sockaddr_un));
	memset(&(uds_fd_table[minor].source), '\0', sizeof(struct sockaddr_un));
	memset(&(uds_fd_table[minor].target), '\0', sizeof(struct sockaddr_un));

	/* Initially the socket isn't suspended. */
	uds_fd_table[minor].suspended = UDS_NOT_SUSPENDED;

	/* and the socket doesn't have an I/O grant initially */
	uds_fd_table[minor].io_gr = (cp_grant_id_t) 0;

	/* since there is no I/O grant it effectively has no size either */
	uds_fd_table[minor].io_gr_size = 0;

	/* The process isn't suspended so we don't flag it as revivable */
	uds_fd_table[minor].ready_to_revive = 0;

	/* get the effective user id and effective group id from the endpoint */
	/* this is needed in the REQ_NEWNODE request to PFS. */
	rc = getnucred(uds_fd_table[minor].endpoint, &ucred);
	if (rc == -1) {
		/* roll back the changes we made to the descriptor */
		memset(&(uds_fd_table[minor]), '\0', sizeof(uds_fd_t));

		/* likely error: invalid endpoint / proc doesn't exist */
		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;
	}

	/* Prepare Request to the FS side of PFS */

	fs_m_in.m_type = REQ_NEWNODE;
	fs_m_in.REQ_MODE = I_NAMED_PIPE;
	fs_m_in.REQ_DEV = NO_DEV;
	fs_m_in.REQ_UID = ucred.uid;
	fs_m_in.REQ_GID = ucred.gid;

	/* Request a new inode on the pipe file system */

	rc = fs_newnode(&fs_m_in, &fs_m_out);
	if (rc != OK) {
		/* roll back the changes we made to the descriptor */
		memset(&(uds_fd_table[minor]), '\0', sizeof(uds_fd_t));

		/* 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;
	}

	/* Process the response */

	uds_fd_table[minor].inode_nr = fs_m_out.RES_INODE_NR;

	/* prepare the reply */

	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, minor);
	return minor;
}
Beispiel #5
0
PUBLIC int uds_select(message *dev_m_in, message *dev_m_out)
{
	int i, bytes;
	int minor;

#if DEBUG == 1
	static int call_count = 0;
	printf("(uds) [%d] uds_select() call_count=%d\n", uds_minor(dev_m_in),
							++call_count);
	printf("Endpoint: 0x%x\n", dev_m_in->IO_ENDPT);
#endif

	minor = uds_minor(dev_m_in);

	if (uds_fd_table[minor].state != UDS_INUSE) {

		/* attempted to close a socket that hasn't been opened -- 
		 * something is very wrong :(
		 */
		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;
	}

	/* setup select(2) framework */
	uds_fd_table[minor].selecting = 1;
	uds_fd_table[minor].select_proc = dev_m_in->m_source;

	/* track the system call we are performing in case it gets cancelled */
	uds_fd_table[minor].call_nr = dev_m_in->m_type;
	uds_fd_table[minor].ioctl = 0;
	uds_fd_table[minor].syscall_done = 0;

	/* Can't update the process endpoint here, no info.  */

	uds_fd_table[minor].sel_ops_in = dev_m_in->IO_ENDPT;
	uds_fd_table[minor].sel_ops_out = 0;

	/* check if there is data available to read */
	bytes = uds_perform_read(minor, dev_m_in->m_source, 1, 1);
	if (bytes > 0) {

		/* there is data in the pipe for us to read */
		uds_fd_table[minor].sel_ops_out |= SEL_RD;

	} else if (uds_fd_table[minor].listening == 1) {

		/* check for pending connections */
		for (i = 0; i < uds_fd_table[minor].backlog_size; i++) {
			if (uds_fd_table[minor].backlog[i] != -1) {
				uds_fd_table[minor].sel_ops_out |= SEL_RD;
				break;
			}
		}
	}

	/* check if we can write without blocking */
	bytes = uds_perform_write(minor, dev_m_in->m_source, PIPE_BUF, 1);
	if (bytes > 0) {
		uds_fd_table[minor].sel_ops_out |= SEL_WR;
	}

	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, 
			uds_fd_table[minor].sel_ops_out);

	return uds_fd_table[minor].sel_ops_out;
}
Beispiel #6
0
PUBLIC int uds_close(message *dev_m_in, message *dev_m_out)
{
	int minor;
	message fs_m_in, fs_m_out;
	int rc;

#if DEBUG == 1
	static int call_count = 0;
	printf("(uds) [%d] uds_close() call_count=%d\n", uds_minor(dev_m_in),
							++call_count);
	printf("Endpoint: 0x%x\n", dev_m_in->IO_ENDPT);
#endif

	minor = uds_minor(dev_m_in);

	if (uds_fd_table[minor].state != UDS_INUSE) {
		/* attempted to close a socket that hasn't been opened -- 
		 * something is very wrong :(
		 */
		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;
	}

	/* no need to track the syscall in case of cancellation. close() is
	 * atomic and can't be cancelled. no need to update the endpoint here,
	 * we won't be needing it to kill the socket
	 */

	/* if the socket is connected, disconnect it */
	if (uds_fd_table[minor].peer != -1) {

		/* set peer of this peer to -1 */
		uds_fd_table[uds_fd_table[minor].peer].peer = -1;

		/* error to pass to peer */
		uds_fd_table[uds_fd_table[minor].peer].err = ECONNRESET;

		/* if peer was blocked on I/O revive peer */
		if (uds_fd_table[uds_fd_table[minor].peer].suspended) {

			int peer = uds_fd_table[minor].peer;

			uds_fd_table[peer].ready_to_revive = 1;
			notify(dev_m_in->m_source);
		}
	}

	if (uds_fd_table[minor].ancillary_data.nfiledes > 0) {
		clear_fds(minor, &(uds_fd_table[minor].ancillary_data));
	}

	/* Prepare Request to the FS side of PFS */

	fs_m_in.m_type = REQ_PUTNODE;
	fs_m_in.REQ_INODE_NR = uds_fd_table[minor].inode_nr;
	fs_m_in.REQ_COUNT = 1;

	/* set the socket back to its original UDS_FREE state */
	memset(&(uds_fd_table[minor]), '\0', sizeof(uds_fd_t));

	/* Request the removal of the inode from the pipe file system */

	rc = fs_putnode(&fs_m_in, &fs_m_out);
	if (rc != OK) {
		perror("fs_putnode");
		/* likely error: get_block() failed */
		return rc;
	}

	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;
}
Beispiel #7
0
PUBLIC int uds_cancel(message *dev_m_in, message *dev_m_out)
{
	int i, j;
	int minor;

#if DEBUG == 1
	static int call_count = 0;
	printf("(uds) [%d] uds_cancel() call_count=%d\n", uds_minor(dev_m_in),
							++call_count);
	printf("Endpoint: 0x%x\n", dev_m_in->IO_ENDPT);
#endif

	minor = uds_minor(dev_m_in);

	if (uds_fd_table[minor].state != UDS_INUSE) {

		/* attempted to close a socket that hasn't been opened --
		 * something is very wrong :(
		 */
		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;
	}

	/* Update the process endpoint. */
	uds_fd_table[minor].endpoint = dev_m_in->IO_ENDPT;

	/* setup select(2) framework */
	uds_fd_table[minor].selecting = 0;

	/* the system call was cancelled, so if the socket was suspended
	 * (which is likely the case), then it is not suspended anymore.
	 */
	uds_fd_table[minor].suspended = UDS_NOT_SUSPENDED;

	/* If there is a system call and it isn't complete, roll back */
	if (uds_fd_table[minor].call_nr && !uds_fd_table[minor].syscall_done) {


		if  (uds_fd_table[minor].call_nr == DEV_IOCTL_S) {

			switch (uds_fd_table[minor].ioctl) {

				case NWIOSUDSACCEPT:	/* accept() */

					/* partial accept() only changes 
					 * uds_fd_table[minorparent].child
					 */

					for (i = 0; i < NR_FDS; i++) {
						if (uds_fd_table[i].child ==
							minor) {
							
						uds_fd_table[i].child = -1;

						}
					}

					break;

				case NWIOSUDSCONN:	/* connect() */

					/* partial connect() sets addr 
					 * and adds minor to server backlog
					 */

					for (i = 0; i < NR_FDS; i++) {

						/* find a socket that is in
						 * use.
						 */
						if (uds_fd_table[i].state ==
							UDS_INUSE) {

							/* see if minor is in
							 * the backlog 
							 */
			for (j = 0; j < uds_fd_table[i].backlog_size; j++) {

				if (uds_fd_table[i].backlog[j] == minor) {

					/* remove from backlog */
					uds_fd_table[i].backlog[j] = -1;
				}
			}

						}
					}

					/* clear the address */
					memset(&(uds_fd_table[minor].addr),
						'\0',
						sizeof(struct sockaddr_un));

					break;

				case NWIOSUDSTADDR:	/* sendto() */
				case NWIOSUDSADDR:	/* bind() */
				case NWIOGUDSADDR:	/* getsockname() */
				case NWIOGUDSPADDR:	/* getpeername() */
				case NWIOSUDSTYPE:	/* socket() */
				case NWIOSUDSBLOG:	/* listen() */
				case NWIOSUDSSHUT:	/* shutdown() */
				case NWIOSUDSPAIR:	/* socketpair() */
				case NWIOGUDSSOTYPE:	/* SO_TYPE */
				case NWIOGUDSPEERCRED:	/* SO_PEERCRED */
				default:
					/* these are atomic, never suspend,
					 * and can't be cancelled once called
					 */
					break;
			}

		}

		/* DEV_READ_S or DEV_WRITE_S don't need to do anything 
		 * when cancelled. DEV_OPEN, DEV_REOPEN, DEV_SELECT, 
		 * DEV_CLOSE are atomic, never suspend, and can't 
		 * be cancelled once called.
		 */

		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, EINTR);

	return EINTR;
}
Beispiel #8
0
int uds_unsuspend(endpoint_t m_source, int minor)
{
	int r = OK, bytes;
	message m_out;
	uds_fd_t *fdp;

	fdp = &uds_fd_table[minor];

	if (fdp->status_updated == 1) {

		/* clear the status_updated flag */
		fdp->status_updated = 0;
		fdp->selecting = 0;

		/* prepare the response */
		uds_sel_reply(&m_out, DEV_SEL_REPL2, minor, fdp->sel_ops_out);
	} else if (fdp->ready_to_revive == 1) {

		/* clear the ready to revive flag */
		fdp->ready_to_revive = 0;

		switch (fdp->suspended) {

			case UDS_SUSPENDED_READ:

				bytes = uds_perform_read(minor, m_source,
							 fdp->io_gr_size, 0);

				if (bytes == SUSPEND) {
					r = SUSPEND;
					break;
				}

				fdp->suspended = UDS_NOT_SUSPENDED;

				uds_set_reply(&m_out, DEV_REVIVE, fdp->endpoint,
					      fdp->io_gr, bytes);

				break;

			case UDS_SUSPENDED_WRITE:

				bytes = uds_perform_write(minor, m_source,
							  fdp->io_gr_size, 0);

				if (bytes == SUSPEND) {
					r = SUSPEND;
					break;
				}

				fdp->suspended = UDS_NOT_SUSPENDED;

				uds_set_reply(&m_out, DEV_REVIVE, fdp->endpoint,
					      fdp->io_gr, bytes);

				break;

			case UDS_SUSPENDED_CONNECT:
			case UDS_SUSPENDED_ACCEPT:

				/* In both cases, the process
				 * that send the notify()
				 * already performed the connection.
				 * The only thing to do here is
				 * unblock.
				 */

				fdp->suspended = UDS_NOT_SUSPENDED;

				uds_set_reply(&m_out, DEV_REVIVE, fdp->endpoint,
					      fdp->io_gr, OK);

				break;

			default:
				return(OK);
		}

	}

	if (r == OK) reply(m_source, &m_out);
	return(r);
}