void ReportTag(char *name, void *tag) { char digest[TAG_DIGEST_SIZE + 1]; assert(name != NULL); if(tag == NULL) return; TagDigest(tag, digest); g_string_append_printf(digests, "%s %s ", name, digest); }
int ProxyReport(struct NaClApp *nap) { char report[BIG_ENOUGH_STRING]; char etag[TAG_DIGEST_SIZE] = TAG_ENGINE_DISABLED; int length; int i; assert(nap != NULL); assert(nap->system_manifest != NULL); /* tag user memory / channels if session successful */ if(TagEngineEnabled()) { if(CHANNELS_ETAG_ENABLED) ChannelsDigest(nap); if(MEMORY_ETAG_ENABLED) EtagMemoryChunk(nap); TagDigest(nap->user_tag, etag); TagDtor(nap->user_tag); } /* for debugging purposes it is useful to see more advanced information */ #ifdef DEBUG length = g_snprintf(report, BIG_ENOUGH_STRING, "validator state = %d\nuser return code = %d\netag = %s\naccounting = %s\n" "exit state = %s\n", nap->validation_state, nap->system_manifest->user_ret_code, etag, GetAccountingInfo(), GetExitState()); #else /* .. but for production zvm will switch to more brief output */ length = g_snprintf(report, BIG_ENOUGH_STRING, "%d\n%d\n%s\n%s\n%s\n", nap->validation_state, nap->system_manifest->user_ret_code, etag, GetAccountingInfo(), GetExitState()); #endif /* give the report to proxy */ i = write(STDOUT_FILENO, report, length); /* log the report */ length = g_snprintf(report, BIG_ENOUGH_STRING, "validator state = %d, user return code = %d, etag = %s, accounting = %s, " "exit state = %s", nap->validation_state, nap->system_manifest->user_ret_code, etag, GetAccountingInfo(), GetExitState()); ZLOGS(LOG_DEBUG, "%s", report); return i == length ? 0 : -1; }
int PrefetchChannelDtor(struct ChannelDesc *channel) { char url[BIG_ENOUGH_STRING]; /* debug purposes only */ assert(channel != NULL); assert(channel->socket != NULL); /* log parameters and channel internals */ MakeURL(url, BIG_ENOUGH_STRING, channel, GetChannelConnectionInfo(channel)); ZLOGS(LOG_DEBUG, "%s has url %s", channel->alias, url); /* close "PUT" channel */ if(channel->limits[PutsLimit] && channel->limits[PutSizeLimit]) { int size = CHANNELS_ETAG_ENABLED ? TAG_DIGEST_SIZE - 1 : 0; /* prepare digest */ if(TagEngineEnabled()) { TagDigest(channel->tag, channel->digest); TagDtor(channel->tag); } /* send eof */ channel->eof = 1; SendMessage(channel, channel->digest, size); ZLOGS(LOG_DEBUG, "%s closed with tag %s, putsize %ld", channel->alias, channel->digest, channel->counters[PutSizeLimit]); } /* close "GET" channel */ if(channel->limits[GetsLimit] && channel->limits[GetSizeLimit]) { /* wind the channel to the end */ while(channel->eof == 0) { char buf[NET_BUFFER_SIZE]; int32_t size = FetchMessage(channel, buf, NET_BUFFER_SIZE); ++channel->counters[GetsLimit]; channel->counters[GetSizeLimit] += size; /* update tag if enabled */ if(TagEngineEnabled()) TagUpdate(channel->tag, buf, size); } /* test integrity (if etag enabled) */ if(TagEngineEnabled()) { /* prepare digest */ TagDigest(channel->tag, channel->digest); TagDtor(channel->tag); /* raise the error if the data corrupted */ if(memcmp(channel->control, channel->digest, TAG_DIGEST_SIZE) != 0) { ZLOG(LOG_ERROR, "%s corrupted, control: %s, local: %s", channel->alias, channel->control, channel->digest); SetExitState("data corrupted"); SetExitCode(EPIPE); } ZLOGS(LOG_DEBUG, "%s closed with tag %s, getsize %ld", channel->alias, channel->digest, channel->counters[GetSizeLimit]); } zmq_msg_close(&channel->msg); zmq_close(channel->socket); } /* will destroy context and netlist after all network channels closed */ NetDtor(); return 0; }