1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

dirmngr: Add command "GETINFO stats".

* dirmngr/server.c (cmd_getinfo): New sub-command "stats".
(dirmngr_status_helpf): Allow for a CTRL of NULL.
* dirmngr/certcache.c (cert_cache_print_stats): Add arg ctrl and use
dirmngr_status_helpf.  Adjust all callers.
* dirmngr/domaininfo.c (domaininfo_print_stats): Ditto.

* sm/certchain.c (ask_marktrusted): Flush stdout before printing the
fingerprint.
This commit is contained in:
Werner Koch 2023-03-10 10:52:43 +01:00
parent be77a7ab8a
commit 56ca164684
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
8 changed files with 59 additions and 35 deletions

View File

@ -768,7 +768,7 @@ cert_cache_init (strlist_t hkp_cacerts)
initialization_done = 1;
release_cache_lock ();
cert_cache_print_stats ();
cert_cache_print_stats (NULL);
}
/* Deinitialize the certificate cache. With FULL set to true even the
@ -811,7 +811,7 @@ cert_cache_deinit (int full)
/* Print some statistics to the log file. */
void
cert_cache_print_stats (void)
cert_cache_print_stats (ctrl_t ctrl)
{
cert_item_t ci;
int idx;
@ -848,11 +848,14 @@ cert_cache_print_stats (void)
release_cache_lock ();
log_info (_("permanently loaded certificates: %u\n"),
dirmngr_status_helpf (ctrl,
_("permanently loaded certificates: %u\n"),
n_permanent);
log_info (_(" runtime cached certificates: %u\n"),
dirmngr_status_helpf (ctrl,
_(" runtime cached certificates: %u\n"),
n_nonperm);
log_info (_(" trusted certificates: %u (%u,%u,%u,%u)\n"),
dirmngr_status_helpf (ctrl,
_(" trusted certificates: %u (%u,%u,%u,%u)\n"),
n_trusted,
n_trustclass_system,
n_trustclass_config,

View File

@ -37,7 +37,7 @@ void cert_cache_init (strlist_t hkp_cacerts);
void cert_cache_deinit (int full);
/* Print some statistics to the log file. */
void cert_cache_print_stats (void);
void cert_cache_print_stats (ctrl_t ctrl);
/* Return true if any cert of a class in MASK is permanently loaded. */
int cert_cache_any_in_class (unsigned int mask);

View File

@ -2031,8 +2031,9 @@ handle_signal (int signo)
break;
case SIGUSR1:
cert_cache_print_stats ();
domaininfo_print_stats ();
/* See also cmd_getinfo:"stats". */
cert_cache_print_stats (NULL);
domaininfo_print_stats (NULL);
break;
case SIGUSR2:

View File

@ -266,7 +266,7 @@ gpg_error_t dirmngr_load_swdb (ctrl_t ctrl, int force);
/*-- domaininfo.c --*/
void domaininfo_print_stats (void);
void domaininfo_print_stats (ctrl_t ctrl);
int domaininfo_is_wkd_not_supported (const char *domain);
void domaininfo_set_no_name (const char *domain);
void domaininfo_set_wkd_supported (const char *domain);

View File

@ -81,7 +81,7 @@ hash_domain (const char *domain)
void
domaininfo_print_stats (void)
domaininfo_print_stats (ctrl_t ctrl)
{
int bidx;
domaininfo_t di;
@ -112,7 +112,8 @@ domaininfo_print_stats (void)
if (minlen == -1 || len < minlen)
minlen = len;
}
log_info ("domaininfo: items=%d chainlen=%d..%d nn=%d nf=%d ns=%d s=%d\n",
dirmngr_status_helpf
(ctrl, "domaininfo: items=%d chainlen=%d..%d nn=%d nf=%d ns=%d s=%d\n",
count,
minlen > 0? minlen : 0,
maxlen,

View File

@ -2788,13 +2788,14 @@ static const char hlp_getinfo[] =
"Multi purpose command to return certain information. \n"
"Supported values of WHAT are:\n"
"\n"
"version - Return the version of the program.\n"
"pid - Return the process id of the server.\n"
"version - Return the version of the program\n"
"pid - Return the process id of the server\n"
"tor - Return OK if running in Tor mode\n"
"dnsinfo - Return info about the DNS resolver\n"
"socket_name - Return the name of the socket.\n"
"session_id - Return the current session_id.\n"
"socket_name - Return the name of the socket\n"
"session_id - Return the current session_id\n"
"workqueue - Inspect the work queue\n"
"stats - Print stats\n"
"getenv NAME - Return value of envvar NAME\n";
static gpg_error_t
cmd_getinfo (assuan_context_t ctx, char *line)
@ -2863,6 +2864,12 @@ cmd_getinfo (assuan_context_t ctx, char *line)
workqueue_dump_queue (ctrl);
err = 0;
}
else if (!strcmp (line, "stats"))
{
cert_cache_print_stats (ctrl);
domaininfo_print_stats (ctrl);
err = 0;
}
else if (!strncmp (line, "getenv", 6)
&& (line[6] == ' ' || line[6] == '\t' || !line[6]))
{
@ -3221,7 +3228,8 @@ dirmngr_status_help (ctrl_t ctrl, const char *text)
/* Print a help status line using a printf like format. The function
* splits text at LFs. */
* splits text at LFs. With CTRL beeing NULL, the function behaves
* like log_info. */
gpg_error_t
dirmngr_status_helpf (ctrl_t ctrl, const char *format, ...)
{
@ -3230,12 +3238,20 @@ dirmngr_status_helpf (ctrl_t ctrl, const char *format, ...)
char *buf;
va_start (arg_ptr, format);
if (ctrl)
{
buf = es_vbsprintf (format, arg_ptr);
err = buf? 0 : gpg_error_from_syserror ();
va_end (arg_ptr);
if (!err)
err = dirmngr_status_help (ctrl, buf);
es_free (buf);
}
else
{
log_logv (GPGRT_LOGLVL_INFO, format, arg_ptr);
err = 0;
}
va_end (arg_ptr);
return err;
}

View File

@ -59,7 +59,7 @@ workqueue_dump_queue (ctrl_t ctrl)
wqitem_t item;
unsigned int count;
/* Temporarily detach the entiere workqueue so that other threads don't
/* Temporarily detach the entire workqueue so that other threads don't
* get into our way. */
saved_workqueue = workqueue;
workqueue = NULL;
@ -74,8 +74,8 @@ workqueue_dump_queue (ctrl_t ctrl)
item->func? item->func (NULL, NULL): "nop",
item->args, strlen (item->args) > 100? "[...]":"");
/* Restore then workqueue. Actually we append the saved queue do a
* possibly updated workqueue. */
/* Restore the workqueue. Actually we append the saved queue to
* handle a possibly updated workqueue. */
if (!(item=workqueue))
workqueue = saved_workqueue;
else

View File

@ -122,6 +122,7 @@ do_list (int is_error, int listmode, estream_t fp, const char *format, ...)
}
else
{
es_fflush (es_stdout);
log_logv (is_error? GPGRT_LOGLVL_ERROR: GPGRT_LOGLVL_INFO,
format, arg_ptr);
log_printf ("\n");
@ -1480,6 +1481,7 @@ ask_marktrusted (ctrl_t ctrl, ksba_cert_t cert, int listmode)
int success = 0;
fpr = gpgsm_get_fingerprint_string (cert, GCRY_MD_SHA1);
es_fflush (es_stdout);
log_info (_("fingerprint=%s\n"), fpr? fpr : "?");
xfree (fpr);
@ -2277,6 +2279,7 @@ gpgsm_basic_cert_check (ctrl_t ctrl, ksba_cert_t cert)
{
if (!opt.quiet)
{
es_fflush (es_stdout);
log_info ("issuer certificate (#/");
gpgsm_dump_string (issuer);
log_printf (") not found\n");