Пример #1
0
/* part of report class dtor */
static void Report(struct NaClApp *nap)
{
  GString *report = g_string_sized_new(BIG_ENOUGH_STRING);
  char *eol = hide_report ? "; " : "\n";

  /* report validator state and user return code */
  g_string_append_printf(report, "%s%d%s", REPORT_VALIDATOR, validation_state, eol);
  g_string_append_printf(report, "%s%d%s", REPORT_RETCODE, user_code, eol);

  /* add memory digest to cumulative digests if asked */
  if(nap != NULL && nap->manifest != NULL)
    if(nap->manifest->mem_tag != NULL)
      ReportTag(STDRAM, GetMemoryDigest(nap));

  /* report tags digests and remove ending " " if exist */
  g_string_append_printf(report, "%s", REPORT_ETAG);
  g_string_append_printf(report, "%s", digests->len == 0
      ? TAG_ENGINE_DISABLED : digests->str);
  g_string_truncate(report, report->len - 1);

  /* report accounting and session message */
  g_string_append_printf(report, "%s%s%s%s", eol, REPORT_ACCOUNTING, GetAccountingInfo(), eol);
  g_string_append_printf(report, "%s%s%s", REPORT_STATE, zvm_state, eol);

  /* output report */
  if(hide_report)
    ZLOGS(LOG_ERROR, "%s", report->str);
  else
    ZLOGIF(write(STDOUT_FILENO, report->str, report->len) != report->len,
        "report write error %d: %s", errno, strerror(errno));

  g_string_free(report, TRUE);
  g_string_free(digests, TRUE);
}
Пример #2
0
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;
}