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; initialization_done = 1;
release_cache_lock (); release_cache_lock ();
cert_cache_print_stats (); cert_cache_print_stats (NULL);
} }
/* Deinitialize the certificate cache. With FULL set to true even the /* 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. */ /* Print some statistics to the log file. */
void void
cert_cache_print_stats (void) cert_cache_print_stats (ctrl_t ctrl)
{ {
cert_item_t ci; cert_item_t ci;
int idx; int idx;
@ -848,11 +848,14 @@ cert_cache_print_stats (void)
release_cache_lock (); release_cache_lock ();
log_info (_("permanently loaded certificates: %u\n"), dirmngr_status_helpf (ctrl,
_("permanently loaded certificates: %u\n"),
n_permanent); n_permanent);
log_info (_(" runtime cached certificates: %u\n"), dirmngr_status_helpf (ctrl,
_(" runtime cached certificates: %u\n"),
n_nonperm); 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_trusted,
n_trustclass_system, n_trustclass_system,
n_trustclass_config, n_trustclass_config,

View File

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

View File

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

View File

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

View File

@ -81,7 +81,7 @@ hash_domain (const char *domain)
void void
domaininfo_print_stats (void) domaininfo_print_stats (ctrl_t ctrl)
{ {
int bidx; int bidx;
domaininfo_t di; domaininfo_t di;
@ -112,7 +112,8 @@ domaininfo_print_stats (void)
if (minlen == -1 || len < minlen) if (minlen == -1 || len < minlen)
minlen = len; 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, count,
minlen > 0? minlen : 0, minlen > 0? minlen : 0,
maxlen, maxlen,

View File

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

View File

@ -59,7 +59,7 @@ workqueue_dump_queue (ctrl_t ctrl)
wqitem_t item; wqitem_t item;
unsigned int count; 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. */ * get into our way. */
saved_workqueue = workqueue; saved_workqueue = workqueue;
workqueue = NULL; workqueue = NULL;
@ -74,8 +74,8 @@ workqueue_dump_queue (ctrl_t ctrl)
item->func? item->func (NULL, NULL): "nop", item->func? item->func (NULL, NULL): "nop",
item->args, strlen (item->args) > 100? "[...]":""); item->args, strlen (item->args) > 100? "[...]":"");
/* Restore then workqueue. Actually we append the saved queue do a /* Restore the workqueue. Actually we append the saved queue to
* possibly updated workqueue. */ * handle a possibly updated workqueue. */
if (!(item=workqueue)) if (!(item=workqueue))
workqueue = saved_workqueue; workqueue = saved_workqueue;
else else

View File

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