Пример #1
0
int dup2(int oldfd, int newfd)
{
	if (iscsi_fd_list[newfd].is_iscsi) {
		return real_dup2(oldfd, newfd);
	}

	close(newfd);

	if (iscsi_fd_list[oldfd].is_iscsi == 1) {
		int ret;
		if (iscsi_fd_list[oldfd].dup2fd >= 0) {
			return dup2(iscsi_fd_list[oldfd].dup2fd, newfd);
		}

		ret = real_dup2(oldfd, newfd);
		if (ret < 0) {
			return ret;
		}

		iscsi_fd_list[newfd].is_iscsi = 1;
		iscsi_fd_list[newfd].dup2fd   = oldfd;

		return newfd;
	}

	return real_dup2(oldfd, newfd);
}
Пример #2
0
void handle_uart_sock(void)
{
    int s;
    socklen_t t;
    struct sockaddr remote;

    t = sizeof(remote);

    _native_syscall_enter();
    if ((s = accept(_native_uart_sock, &remote, &t)) == -1) {
        err(EXIT_FAILURE, "handle_uart_sock: accept");
    }
    else {
        warnx("handle_uart_sock: successfully accepted socket");
    }

    if (real_dup2(s, STDOUT_FILENO) == -1) {
        err(EXIT_FAILURE, "handle_uart_sock: dup2()");
    }
    if (real_dup2(s, STDIN_FILENO) == -1) {
        err(EXIT_FAILURE, "handle_uart_sock: dup2()");
    }
    _native_syscall_leave();

    _native_uart_conn = s;
}
Пример #3
0
int dup2(int oldfd, int newfd)
{
    if (smbw_fd(newfd)) {
        close(newfd);
    }

    if (smbw_fd(oldfd)) {
        return smbw_dup2(oldfd, newfd);
    }

    return real_dup2(oldfd, newfd);
}
Пример #4
0
_PUBLIC_ int swrap_dup2(int oldd, int newd)
{
	struct socket_info *si_newd, *si_oldd;
	int fd;

	if (newd == oldd)
	    return newd;

	si_oldd = find_socket_info(oldd);
	si_newd = find_socket_info(newd);

	if (si_oldd == NULL && si_newd == NULL)
		return real_dup2(oldd, newd);

	fd = real_dup2(si_oldd->fd, newd);
	if (fd < 0)
		return fd;

	/* close new socket first */
	if (si_newd)
	       	swrap_close(newd);

	return dup_internal(si_oldd, fd);
}
Пример #5
0
void handle_uart_in(void)
{
    char buf[42];
    int nread;

    DEBUG("handle_uart_in\n");

    nread = _native_read(STDIN_FILENO, buf, sizeof(buf));
    if (nread == -1) {
        err(1, "handle_uart_in(): read()");
    }
    else if (nread == 0) {
        /* end of file / socket closed */
        if (_native_uart_conn != 0) {
            if (_native_null_out_file != -1) {
                if (real_dup2(_native_null_out_file, STDOUT_FILENO) == -1) {
                    err(EXIT_FAILURE, "handle_uart_in: dup2(STDOUT_FILENO)");
                }
            }
            if (real_dup2(_native_null_in_pipe[0], STDIN_FILENO) == -1) {
                err(EXIT_FAILURE, "handle_uart_in: dup2(STDIN_FILENO)");
            }
            _native_uart_conn = 0;
            warnx("closed stdio");
        }
        else {
            errx(EXIT_FAILURE, "handle_uart_in: unhandled situation!");
        }
    }
    for(int pos = 0; pos < nread; pos++) {
        uart0_handle_incoming(buf[pos]);
    }
    uart0_notify_thread();

    thread_yield();
}
Пример #6
0
int dup2(int fd, int fd2)
{
    // Call the close stub to avoid duplicating action logic.  This produces
    // different behavior in the case where fd is not active.
    close(fd2);
    fd_map_dump();

    wlog("dup2(%d, %d)", fd, fd2);
    int ret = real_dup2(fd, fd2);

    if (ret >= 0)
        fd_map_dup2(fd, fd2);

    fd_map_dump();

    return ret;
}
Пример #7
0
/* 
 * Copyright (c) 2008-2010 Wind River Systems; see
 * guts/COPYRIGHT for information.
 *
 * static int
 * wrap_dup2(int oldfd, int newfd) {
 *	int rc = -1;
 */
	int save_errno;

	/* close existing one first - this also causes the socket to the
	 * server to get moved around if someone tries to overwrite it. */
	pseudo_debug(PDBGF_CLIENT, "dup2: %d->%d\n", oldfd, newfd);
	pseudo_client_op(OP_CLOSE, 0, newfd, -1, 0, 0);
	rc = real_dup2(oldfd, newfd);
	save_errno = errno;
	pseudo_client_op(OP_DUP, 0, oldfd, newfd, 0, 0);
	errno = save_errno;

/*	return rc;
 * }
 */
Пример #8
0
int dup2(int oldfd, int newfd)
{
	close(newfd);

	if (nfs_fd_list[oldfd].is_nfs == 1) {
		struct nfs_context *nfs;
		struct nfs_url *url;
		struct nfsfh *fh = NULL;
		int ret, fd;

		LD_NFS_DPRINTF(9, "dup2(%s:%d, %d)", nfs_fd_list[oldfd].path,
			oldfd, newfd);
		nfs = nfs_init_context();
		if (nfs == NULL) {
			LD_NFS_DPRINTF(1, "Failed to create context");
			errno = ENOMEM;
			return -1;
		}

		url = nfs_parse_url_full(nfs, nfs_fd_list[oldfd].path);
		if (url == NULL) {
			LD_NFS_DPRINTF(1, "Failed to parse URL: %s\n",
				nfs_get_error(nfs));
			nfs_destroy_context(nfs);
			errno = EINVAL;
			return -1;
		}

		if (nfs_mount(nfs, url->server, url->path) != 0) {
			LD_NFS_DPRINTF(1, "Failed to mount nfs share : %s\n",
			       nfs_get_error(nfs));
			nfs_destroy_url(url);
			nfs_destroy_context(nfs);
			errno = EINVAL;
			return -1;
		}

		if ((ret = nfs_open(nfs, url->file, nfs_fd_list[oldfd].mode,
				&fh)) != 0) {
			LD_NFS_DPRINTF(1, "Failed to open nfs file : %s\n",
			       nfs_get_error(nfs));
			nfs_destroy_url(url);
			nfs_destroy_context(nfs);
			errno = -ret;
			return -1;
		}

		/* We could actually end on the right descriptor by chance */
		if (nfs_get_fd(nfs) != newfd) {
			if (real_dup2(nfs_get_fd(nfs), newfd) < 0) {
				LD_NFS_DPRINTF(1, "Failed to dup2 file : %d",
					errno);
				return -1;
			}

			close(rpc_get_fd(nfs_get_rpc_context(nfs)));
			rpc_set_fd(nfs_get_rpc_context(nfs), newfd);
		}

		fd = nfs_get_fd(nfs);
		if (fd >= NFS_MAX_FD) {
			LD_NFS_DPRINTF(1, "Too many files open");
			nfs_destroy_url(url);
			nfs_destroy_context(nfs);
			errno = ENFILE;
			return -1;
		}		

		nfs_fd_list[fd].is_nfs     = 1;
		nfs_fd_list[fd].nfs        = nfs;
		nfs_fd_list[fd].fh         = fh;
		nfs_fd_list[fd].path       = strdup(nfs_fd_list[oldfd].path);
		nfs_fd_list[fd].flags      = nfs_fd_list[oldfd].flags;
		nfs_fd_list[fd].mode       = nfs_fd_list[oldfd].mode;

		nfs_destroy_url(url);

		LD_NFS_DPRINTF(9, "dup2(%s) successful",
			nfs_fd_list[oldfd].path);
		return fd;
	}

	return real_dup2(oldfd, newfd);
}