mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
gpgconf: Add command --launch.
* tools/gpgconf.c: Add command --launch. * tools/gpgconf-comp.c (gc_component_launch): New. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
36dfc37e43
commit
b4cf4686f7
@ -305,6 +305,14 @@ Reload all or the given component. This is basically the same as sending
|
|||||||
a SIGHUP to the component. Components which don't support reloading are
|
a SIGHUP to the component. Components which don't support reloading are
|
||||||
ignored.
|
ignored.
|
||||||
|
|
||||||
|
@item --launch [@var{component}]
|
||||||
|
@opindex launch
|
||||||
|
If the @var{component} is not already running, start it.
|
||||||
|
@command{component} must be a daemon. This is in general not required
|
||||||
|
because the system starts these daemons as needed. However, external
|
||||||
|
software making direct use of @command{gpg-agent} or @command{dirmngr}
|
||||||
|
may use this command to ensure that they are started.
|
||||||
|
|
||||||
@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
|
||||||
|
@ -1108,6 +1108,44 @@ scdaemon_runtime_change (int killflag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Launch the gpg-agent or the dirmngr if not already running. */
|
||||||
|
void
|
||||||
|
gc_component_launch (int component)
|
||||||
|
{
|
||||||
|
gpg_error_t err;
|
||||||
|
const char *pgmname;
|
||||||
|
const char *argv[3];
|
||||||
|
int i;
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
if (!(component == GC_COMPONENT_GPG_AGENT
|
||||||
|
|| component == GC_COMPONENT_DIRMNGR))
|
||||||
|
{
|
||||||
|
es_fputs (_("Component not suitable for launching"), es_stderr);
|
||||||
|
es_putc ('\n', es_stderr);
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pgmname = gnupg_module_name (GNUPG_MODULE_NAME_CONNECT_AGENT);
|
||||||
|
i = 0;
|
||||||
|
if (component == GC_COMPONENT_DIRMNGR)
|
||||||
|
argv[i++] = "--dirmngr";
|
||||||
|
argv[i++] = "NOP";
|
||||||
|
argv[i] = NULL;
|
||||||
|
|
||||||
|
err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid);
|
||||||
|
if (!err)
|
||||||
|
err = gnupg_wait_process (pgmname, pid, 1, NULL);
|
||||||
|
if (err)
|
||||||
|
gc_error (0, 0, "error running '%s%s%s': %s",
|
||||||
|
pgmname,
|
||||||
|
component == GC_COMPONENT_DIRMNGR? " --dirmngr":"",
|
||||||
|
" NOP",
|
||||||
|
gpg_strerror (err));
|
||||||
|
gnupg_release_process (pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Unconditionally restart COMPONENT. */
|
/* Unconditionally restart COMPONENT. */
|
||||||
void
|
void
|
||||||
gc_component_kill (int component)
|
gc_component_kill (int component)
|
||||||
|
@ -51,6 +51,7 @@ enum cmd_and_opt_values
|
|||||||
aListConfig,
|
aListConfig,
|
||||||
aCheckConfig,
|
aCheckConfig,
|
||||||
aListDirs,
|
aListDirs,
|
||||||
|
aLaunch,
|
||||||
aKill,
|
aKill,
|
||||||
aReload
|
aReload
|
||||||
};
|
};
|
||||||
@ -75,6 +76,7 @@ static ARGPARSE_OPTS opts[] =
|
|||||||
{ aCheckConfig, "check-config", 256,
|
{ aCheckConfig, "check-config", 256,
|
||||||
N_("check global configuration file") },
|
N_("check global configuration file") },
|
||||||
{ aReload, "reload", 256, N_("reload all or a given component")},
|
{ aReload, "reload", 256, N_("reload all or a given component")},
|
||||||
|
{ aLaunch, "launch", 256, N_("launch a given component")},
|
||||||
{ aKill, "kill", 256, N_("kill a given component")},
|
{ aKill, "kill", 256, N_("kill a given component")},
|
||||||
|
|
||||||
{ 301, NULL, 0, N_("@\nOptions:\n ") },
|
{ 301, NULL, 0, N_("@\nOptions:\n ") },
|
||||||
@ -184,6 +186,7 @@ main (int argc, char **argv)
|
|||||||
case aListConfig:
|
case aListConfig:
|
||||||
case aCheckConfig:
|
case aCheckConfig:
|
||||||
case aReload:
|
case aReload:
|
||||||
|
case aLaunch:
|
||||||
case aKill:
|
case aKill:
|
||||||
cmd = pargs.r_opt;
|
cmd = pargs.r_opt;
|
||||||
break;
|
break;
|
||||||
@ -255,6 +258,7 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case aLaunch:
|
||||||
case aKill:
|
case aKill:
|
||||||
if (!fname)
|
if (!fname)
|
||||||
{
|
{
|
||||||
@ -266,7 +270,7 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Kill a given component. */
|
/* Launch/Kill a given component. */
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
idx = gc_component_find (fname);
|
idx = gc_component_find (fname);
|
||||||
@ -276,10 +280,10 @@ main (int argc, char **argv)
|
|||||||
es_putc ('\n', es_stderr);
|
es_putc ('\n', es_stderr);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
else if (cmd == aLaunch)
|
||||||
|
gc_component_launch (idx);
|
||||||
else
|
else
|
||||||
{
|
gc_component_kill (idx);
|
||||||
gc_component_kill (idx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -44,6 +44,9 @@ char *gc_percent_escape (const char *src);
|
|||||||
|
|
||||||
void gc_error (int status, int errnum, const char *fmt, ...);
|
void gc_error (int status, int errnum, const char *fmt, ...);
|
||||||
|
|
||||||
|
/* Launch given component. */
|
||||||
|
void gc_component_launch (int component);
|
||||||
|
|
||||||
/* Kill given component. */
|
/* Kill given component. */
|
||||||
void gc_component_kill (int component);
|
void gc_component_kill (int component);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user