static void BkdoorChannelShutdown(RpcChannel *chan) { BackdoorChannel *bdoor = chan->_private; BkdoorChannelStop(chan); RpcOut_Destruct(bdoor->out); g_free(bdoor); chan->_private = NULL; }
static void RpcInShutdown(RpcChannel *chan) { BackdoorChannel *bdoor = chan->_private; RpcInStop(chan); if (bdoor->in != NULL) { RpcIn_Destruct(bdoor->in); } RpcOut_Destruct(bdoor->out); g_static_mutex_free(&bdoor->outLock); if (bdoor->mainCtx != NULL) { g_main_context_unref(bdoor->mainCtx); } g_free(bdoor); }
Bool RpcOut_SendOneRaw(void *request, // IN: RPCI command size_t reqLen, // IN: Size of request buffer char **reply, // OUT: Result size_t *repLen) // OUT: Length of the result { Bool status; RpcOut *out = NULL; char const *myReply; size_t myRepLen; status = FALSE; Debug("Rpci: Sending request='%s'\n", (char *)request); out = RpcOut_Construct(); if (out == NULL) { myReply = "RpcOut: Unable to create the RpcOut object"; myRepLen = strlen(myReply); goto sent; } else if (RpcOut_start(out) == FALSE) { myReply = "RpcOut: Unable to open the communication channel"; myRepLen = strlen(myReply); goto sent; } else if (RpcOut_send(out, request, reqLen, &myReply, &myRepLen) == FALSE) { /* We already have the description of the error */ goto sent; } status = TRUE; sent: Debug("Rpci: Sent request='%s', reply='%s', len=%"FMTSZ"u, status=%d\n", (char *)request, myReply, myRepLen, status); if (reply != NULL) { /* * If we got a non-NULL reply, make a copy of it, because the reply * we got back is inside the channel buffer, which will get destroyed * at the end of this function. */ if (myReply != NULL) { /* * We previously used strdup to duplicate myReply, but that * breaks if you are sending binary (not string) data over the * backdoor. Don't assume the data is a string. * * myRepLen is strlen(myReply), so we need an extra byte to * cover the NUL terminator. */ *reply = malloc(myRepLen + 1); if (*reply != NULL) { memcpy(*reply, myReply, myRepLen); /* * The message layer already writes a trailing NUL but we might * change that someday, so do it again here. */ (*reply)[myRepLen] = 0; } } else { /* * Our reply was NULL, so just pass the NULL back up to the caller. */ *reply = NULL; } /* * Only set the length if the caller wanted it and if we got a good * reply. */ if (repLen != NULL && *reply != NULL) { *repLen = myRepLen; } } if (out) { if (RpcOut_stop(out) == FALSE) { /* * We couldn't stop the channel. Free anything we allocated, give our * client a reply of NULL, and return FALSE. */ if (reply != NULL) { free(*reply); *reply = NULL; } Debug("Rpci: unable to close the communication channel\n"); status = FALSE; } RpcOut_Destruct(out); out = NULL; } return status; }