static void wait_for_reply(struct rpc_context *rpc, struct sync_cb_data *cb_data) { struct pollfd pfd; assert(rpc->magic == RPC_CONTEXT_MAGIC); while (!cb_data->is_finished) { pfd.fd = rpc_get_fd(rpc); pfd.events = rpc_which_events(rpc); if (poll(&pfd, 1, -1) < 0) { rpc_set_error(rpc, "Poll failed"); cb_data->status = -EIO; break; } if (rpc_service(rpc, pfd.revents) < 0) { rpc_set_error(rpc, "rpc_service failed"); cb_data->status = -EIO; break; } if (rpc_get_fd(rpc) == -1) { rpc_set_error(rpc, "Socket closed\n"); break; } } }
static int vlc_rpc_mainloop(access_t *p_access, struct rpc_context *p_rpc_ctx, bool (*pf_until_cb)(access_t *)) { access_sys_t *p_sys = p_access->p_sys; while (!p_sys->b_error && !pf_until_cb(p_access)) { struct pollfd p_fds[1]; int i_ret; p_fds[0].fd = rpc_get_fd(p_rpc_ctx); p_fds[0].events = rpc_which_events(p_rpc_ctx); if ((i_ret = vlc_poll_i11e(p_fds, 1, -1)) < 0) { if (errno == EINTR) msg_Warn(p_access, "vlc_poll_i11e interrupted"); else msg_Err(p_access, "vlc_poll_i11e failed"); p_sys->b_error = true; } else if (i_ret > 0 && p_fds[0].revents && rpc_service(p_rpc_ctx, p_fds[0].revents) < 0) { msg_Err(p_access, "nfs_service failed"); p_sys->b_error = true; } } return p_sys->b_error ? -1 : 0; }
static void wait_for_reply(struct rpc_context *rpc, struct sync_cb_data *cb_data) { struct pollfd pfd; for (;;) { if (cb_data->is_finished) { break; } pfd.fd = rpc_get_fd(rpc); pfd.events = rpc_which_events(rpc); if (poll(&pfd, 1, -1) < 0) { rpc_set_error(rpc, "Poll failed"); cb_data->status = -EIO; break; } if (rpc_service(rpc, pfd.revents) < 0) { rpc_set_error(rpc, "rpc_service failed"); cb_data->status = -EIO; break; } } }
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); }