gpgconf: Allow "all" for --launch, --kill, and --reload.

* tools/gpgconf-comp.c (gc_component_launch): Allow -1 for COMPONENT.
(gc_component_kill): Ditto.
(gc_component_reload): For robustness change the condition to < 0.
* tools/gpgconf.c (main) <aLaunch, aKill, aReload>: Support argument
"all".

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2017-01-18 10:01:55 +01:00
parent 701f54eccf
commit 2312248b2e
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 41 additions and 9 deletions

View File

@ -336,9 +336,10 @@ force an update of that file this command can be used:
@item --reload [@var{component}] @item --reload [@var{component}]
@opindex reload @opindex reload
Reload all or the given component. This is basically the same as sending Reload all or the given component. This is basically the same as
a SIGHUP to the component. Components which don't support reloading are sending a SIGHUP to the component. Components which don't support
ignored. reloading are ignored. Without @var{component} or by using "all" for
@var{component} all components which are daemons are reloaded.
@item --launch [@var{component}] @item --launch [@var{component}]
@opindex launch @opindex launch
@ -346,14 +347,16 @@ If the @var{component} is not already running, start it.
@command{component} must be a daemon. This is in general not required @command{component} must be a daemon. This is in general not required
because the system starts these daemons as needed. However, external because the system starts these daemons as needed. However, external
software making direct use of @command{gpg-agent} or @command{dirmngr} software making direct use of @command{gpg-agent} or @command{dirmngr}
may use this command to ensure that they are started. may use this command to ensure that they are started. Using "all" for
@var{component} launches all components which are daemons.
@item --kill [@var{component}] @item --kill [@var{component}]
@opindex kill @opindex kill
Kill the given component. Components which support killing are Kill the given component. Components which support killing are
@command{gpg-agent} and @command{scdaemon}. Components which don't @command{gpg-agent} and @command{scdaemon}. Components which don't
support reloading are ignored. Note that as of now reload and kill support reloading are ignored. Using "all" for @var{component} kills
have the same effect for @command{scdaemon}. all components running as daemons. Note that as of now reload and
kill have the same effect for @command{scdaemon}.
@item --create-socketdir @item --create-socketdir
@opindex create-socketdir @opindex create-socketdir

View File

@ -1263,6 +1263,14 @@ gc_component_launch (int component)
int i; int i;
pid_t pid; pid_t pid;
if (component < 0)
{
err = gc_component_launch (GC_COMPONENT_GPG_AGENT);
if (!err)
err = gc_component_launch (GC_COMPONENT_DIRMNGR);
return err;
}
if (!(component == GC_COMPONENT_GPG_AGENT if (!(component == GC_COMPONENT_GPG_AGENT
|| component == GC_COMPONENT_DIRMNGR)) || component == GC_COMPONENT_DIRMNGR))
{ {
@ -1304,7 +1312,16 @@ gc_component_kill (int component)
for (backend = 0; backend < GC_BACKEND_NR; backend++) for (backend = 0; backend < GC_BACKEND_NR; backend++)
runtime[backend] = 0; runtime[backend] = 0;
if (component >= 0) if (component < 0)
{
for (component = 0; component < GC_COMPONENT_NR; component++)
{
option = gc_component[component].options;
for (; option && option->name; option++)
runtime[option->backend] = 1;
}
}
else
{ {
assert (component < GC_COMPONENT_NR); assert (component < GC_COMPONENT_NR);
option = gc_component[component].options; option = gc_component[component].options;
@ -1333,7 +1350,7 @@ gc_component_reload (int component)
for (backend = 0; backend < GC_BACKEND_NR; backend++) for (backend = 0; backend < GC_BACKEND_NR; backend++)
runtime[backend] = 0; runtime[backend] = 0;
if (component == -1) if (component < 0)
{ {
for (component = 0; component < GC_COMPONENT_NR; component++) for (component = 0; component < GC_COMPONENT_NR; component++)
{ {

View File

@ -589,6 +589,18 @@ main (int argc, char **argv)
es_putc ('\n', es_stderr); es_putc ('\n', es_stderr);
exit (2); exit (2);
} }
else if (!strcmp (fname, "all"))
{
if (cmd == aLaunch)
{
if (gc_component_launch (-1))
exit (1);
}
else
{
gc_component_kill (-1);
}
}
else else
{ {
/* Launch/Kill a given component. */ /* Launch/Kill a given component. */
@ -617,7 +629,7 @@ main (int argc, char **argv)
break; break;
case aReload: case aReload:
if (!fname) if (!fname || !strcmp (fname, "all"))
{ {
/* Reload all. */ /* Reload all. */
gc_component_reload (-1); gc_component_reload (-1);