Exemplo n.º 1
0
void _LOG(log_t* log, int scopeFlags, const char* fmt, ...) {
  char buf[512];
  bool want_tfd_write;
  bool want_log_write;
  bool want_amfd_write;
  int len = 0;

  va_list ap;
  va_start(ap, fmt);

  // where is the information going to go?
  want_tfd_write = log && log->tfd >= 0;
  want_log_write = IS_AT_FAULT(scopeFlags) && (!log || !log->quiet);
  want_amfd_write = IS_AT_FAULT(scopeFlags) && !IS_SENSITIVE(scopeFlags) && log && log->amfd >= 0;

  // if we're going to need the literal string, generate it once here
  if (want_tfd_write || want_amfd_write) {
    vsnprintf(buf, sizeof(buf), fmt, ap);
    len = strlen(buf);
  }

  if (want_tfd_write) {
    write(log->tfd, buf, len);
  }

  if (want_log_write) {
    // whatever goes to logcat also goes to the Activity Manager
    __android_log_vprint(ANDROID_LOG_INFO, "DEBUG", fmt, ap);
    if (want_amfd_write && len > 0) {
      int written = write_to_am(log->amfd, buf, len);
      if (written <= 0) {
        // timeout or other failure on write; stop informing the activity manager
        log->amfd = -1;
      }
    }
  }
  va_end(ap);
}
Exemplo n.º 2
0
Arquivo: dump.c Projeto: kdave/neomutt
/**
 * dump_config - Write all the config to a file
 * @param cs    ConfigSet to dump
 * @param style Output style, e.g. #CS_DUMP_STYLE_MUTT
 * @param flags Flags, see #ConfigDumpFlags
 * @param fp    File to write config to
 */
bool dump_config(struct ConfigSet *cs, enum CsDumpStyle style,
                 ConfigDumpFlags flags, FILE *fp)
{
  if (!cs)
    return false;

  struct HashElem *he = NULL;

  struct HashElem **list = get_elem_list(cs);
  if (!list)
    return false; /* LCOV_EXCL_LINE */

  bool result = true;

  struct Buffer *value = mutt_buffer_alloc(256);
  struct Buffer *initial = mutt_buffer_alloc(256);
  struct Buffer *tmp = mutt_buffer_alloc(256);

  for (size_t i = 0; list[i]; i++)
  {
    mutt_buffer_reset(value);
    mutt_buffer_reset(initial);
    he = list[i];
    const int type = DTYPE(he->type);

    if ((type == DT_SYNONYM) && !(flags & CS_DUMP_SHOW_SYNONYMS))
      continue;

    // if ((type == DT_DISABLED) && !(flags & CS_DUMP_SHOW_DISABLED))
    //   continue;

    if (type != DT_SYNONYM)
    {
      /* If necessary, get the current value */
      if ((flags & CS_DUMP_ONLY_CHANGED) || !(flags & CS_DUMP_HIDE_VALUE) ||
          (flags & CS_DUMP_SHOW_DEFAULTS))
      {
        int rc = cs_he_string_get(cs, he, value);
        if (CSR_RESULT(rc) != CSR_SUCCESS)
        {
          result = false; /* LCOV_EXCL_LINE */
          break;          /* LCOV_EXCL_LINE */
        }

        const struct ConfigDef *cdef = he->data;
        if (IS_SENSITIVE(*cdef) && (flags & CS_DUMP_HIDE_SENSITIVE) &&
            !mutt_buffer_is_empty(value))
        {
          mutt_buffer_reset(value);
          mutt_buffer_addstr(value, "***");
        }

        if ((type == DT_PATH) && (value->data[0] == '/'))
          mutt_pretty_mailbox(value->data, value->dsize);

        if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) &&
            (type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING))
        {
          mutt_buffer_reset(tmp);
          pretty_var(value->data, tmp);
          mutt_buffer_strcpy(value, tmp->data);
        }
      }

      /* If necessary, get the default value */
      if (flags & (CS_DUMP_ONLY_CHANGED | CS_DUMP_SHOW_DEFAULTS))
      {
        int rc = cs_he_initial_get(cs, he, initial);
        if (CSR_RESULT(rc) != CSR_SUCCESS)
        {
          result = false; /* LCOV_EXCL_LINE */
          break;          /* LCOV_EXCL_LINE */
        }

        if ((type == DT_PATH) && !(he->type & DT_MAILBOX))
          mutt_pretty_mailbox(initial->data, initial->dsize);

        if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) &&
            (type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING))
        {
          mutt_buffer_reset(tmp);
          pretty_var(initial->data, tmp);
          mutt_buffer_strcpy(initial, tmp->data);
        }
      }
    }

    if (style == CS_DUMP_STYLE_MUTT)
      dump_config_mutt(cs, he, value, initial, flags, fp);
    else
      dump_config_neo(cs, he, value, initial, flags, fp);
  }

  FREE(&list);
  mutt_buffer_free(&value);
  mutt_buffer_free(&initial);
  mutt_buffer_free(&tmp);

  return result;
}