/* Close only marks the link as available */ int minipc_close(struct minipc_ch *ch) { struct mpc_link *link = mpc_get_link(ch); CHECK_LINK(link); link->magic = 0; /* available */ return 0; }
/* From: minipc-server.c (mostly: mpc_handle_client) */ int minipc_server_action(struct minipc_ch *ch, int timeoutms) { struct mpc_link *link = mpc_get_link(ch); struct mpc_req_packet *p_in; struct mpc_rep_packet *p_out; struct mpc_shmem *shm = link->memaddr; const struct minipc_pd *pd; struct mpc_flist *flist; int i; CHECK_LINK(link); /* keep track of the request in an otherwise unused field */ if (shm->nrequest == link->pid) return 0; link->pid = shm->nrequest; p_in = &shm->request; p_out = &shm->reply; /* use p_in->name to look for the function */ for (flist = link->flist; flist; flist = flist->next) if (!(strcmp(p_in->name, flist->pd->name))) break; if (!flist) { p_out->type = MINIPC_ARG_ENCODE(MINIPC_ATYPE_ERROR, int); *(int *)(&p_out->val) = EOPNOTSUPP; goto send_reply; }
/* Return the current fdset associated to the service */ int minipc_server_get_fdset(struct minipc_ch *ch, fd_set *setptr) { struct mpc_link *link = mpc_get_link(ch); CHECK_LINK(link); *setptr = link->fdset; return 0; }
int minipc_set_logfile(struct minipc_ch *ch, FILE *logf) { struct mpc_link *link = mpc_get_link(ch); CHECK_LINK(link); link->logf = logf; return 0; }
/* From: minipc-server.c -- but no log and relies on fake calloc above */ int minipc_export(struct minipc_ch *ch, const struct minipc_pd *pd) { struct mpc_link *link = mpc_get_link(ch); struct mpc_flist *flist; CHECK_LINK(link); flist = calloc(1, sizeof(*flist)); if (!flist) return -1; flist->pd = pd; flist->next = link->flist; link->flist = flist; return 0; }
/* From: minipc-server.c -- but no log file */ int minipc_unexport(struct minipc_ch *ch, const struct minipc_pd *pd) { struct mpc_link *link = mpc_get_link(ch); struct mpc_flist *flist; CHECK_LINK(link); /* We must find the flist that points to pd */ for (flist = link->flist; flist; flist = flist->next) if (flist->pd == pd) break; if (!flist) { errno = EINVAL; return -1; } flist = container_of(&pd, struct mpc_flist, pd); mpc_free_flist(link, flist); return 0; }
/* * The following ones add to the export list and remove from it */ int minipc_export(struct minipc_ch *ch, const struct minipc_pd *pd) { struct mpc_link *link = mpc_get_link(ch); struct mpc_flist *flist; CHECK_LINK(link); flist = calloc(1, sizeof(*flist)); if (!flist) return -1; flist->pd = pd; flist->next = link->flist; link->flist = flist; if (link->logf) fprintf(link->logf, "%s: exported %p (%s) with pd %p --" " retval %08x, args %08x...\n", __func__, flist, pd->name, pd, pd->retval, pd->args[0]); return 0; }
int minipc_close(struct minipc_ch *ch) { struct mpc_link *link = mpc_get_link(ch); struct mpc_link **nextp; CHECK_LINK(link); /* Look for link in our list */ for (nextp = &__mpc_base; (*nextp); nextp = &(*nextp)->nextl) if (*nextp == link) break; if (!*nextp) { errno = ENOENT; return -1; } (*nextp) = link->nextl; if (link->logf) { fprintf(link->logf, "%s: found link %p (fd %i)\n", __func__, link, link->ch.fd); } close(ch->fd); if (link->pid) kill(link->pid, SIGINT); if (link->flags & MPC_FLAG_SHMEM) shmdt(link->memaddr); if (link->flags & MPC_FLAG_DEVMEM) munmap(link->memaddr, link->memsize); /* Release allocated functions */ while (link->flist) mpc_free_flist(link, link->flist); free(link); return 0; }