static int vlc_nfs_mainloop(access_t *p_access, bool (*pf_until_cb)(access_t *)) { access_sys_t *p_sys = p_access->p_sys; assert(p_sys->p_nfs != NULL); return vlc_rpc_mainloop(p_access, nfs_get_rpc_context(p_sys->p_nfs), pf_until_cb); }
{ struct sync_cb_data *cb_data = private_data; cb_data->is_finished = 1; cb_data->status = status; if (status < 0) { nfs_set_error(nfs, "mount/mnt call failed with \"%s\"", (char *)data); return; } } int nfs_mount(struct nfs_context *nfs, const char *server, const char *export) { struct sync_cb_data cb_data; struct rpc_context *rpc = nfs_get_rpc_context(nfs); assert(rpc->magic == RPC_CONTEXT_MAGIC); cb_data.is_finished = 0; if (nfs_mount_async(nfs, server, export, mount_cb, &cb_data) != 0) { nfs_set_error(nfs, "nfs_mount_async failed"); return -1; } wait_for_nfs_reply(nfs, &cb_data); /* Dont want any more callbacks even if the socket is closed */ rpc->connect_cb = NULL;
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); }