* gpg-agent.c (parse_rereadable_options): New arg REREAD. Allow

changing oLogFile.
(current_logfile): New.

* logging.c (log_set_file): Make sure the log stream will be
closed even if the stderr fileno will be assigned to a new socket.
This commit is contained in:
Werner Koch 2004-04-30 03:58:21 +00:00
parent 6d96ca16cf
commit 623fad67a5
4 changed files with 42 additions and 8 deletions

View File

@ -1,3 +1,9 @@
2004-04-30 Werner Koch <wk@gnupg.org>
* gpg-agent.c (parse_rereadable_options): New arg REREAD. Allow
changing oLogFile.
(current_logfile): New.
2004-04-26 Werner Koch <wk@gnupg.org> 2004-04-26 Werner Koch <wk@gnupg.org>
* call-scd.c (start_scd): Do not register an event signal if we * call-scd.c (start_scd): Do not register an event signal if we

View File

@ -155,6 +155,10 @@ static char *config_filename;
/* Helper to implement --debug-level */ /* Helper to implement --debug-level */
static const char *debug_level; static const char *debug_level;
/* Keep track of the current log file so that we can avoid updating
the log file afte a SIGHUP if id didn't changed. Malloced. */
static char *current_logfile;
/* Local prototypes. */ /* Local prototypes. */
static void create_directories (void); static void create_directories (void);
#ifdef USE_GNU_PTH #ifdef USE_GNU_PTH
@ -317,9 +321,10 @@ cleanup_sh (int sig)
/* Handle options which are allowed to be reset after program start. /* Handle options which are allowed to be reset after program start.
Return true when the current option in PARGS could be handled and Return true when the current option in PARGS could be handled and
false if not. As a special feature, passing a value of NULL for false if not. As a special feature, passing a value of NULL for
PARGS, resets the options to the default. */ PARGS, resets the options to the default. REREAD should be set
true if it is not the initial option parsing. */
static int static int
parse_rereadable_options (ARGPARSE_ARGS *pargs) parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
{ {
if (!pargs) if (!pargs)
{ /* reset mode */ { /* reset mode */
@ -343,6 +348,16 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs)
case oDebugAll: opt.debug = ~0; break; case oDebugAll: opt.debug = ~0; break;
case oDebugLevel: debug_level = pargs->r.ret_str; break; case oDebugLevel: debug_level = pargs->r.ret_str; break;
case oLogFile:
if (!current_logfile || !pargs->r.ret_str
|| strcmp (current_logfile, pargs->r.ret_str))
{
log_set_file (pargs->r.ret_str);
xfree (current_logfile);
current_logfile = xtrystrdup (pargs->r.ret_str);
}
break;
case oNoGrab: opt.no_grab = 1; break; case oNoGrab: opt.no_grab = 1; break;
case oPinentryProgram: opt.pinentry_program = pargs->r.ret_str; break; case oPinentryProgram: opt.pinentry_program = pargs->r.ret_str; break;
@ -424,7 +439,7 @@ main (int argc, char **argv )
may_coredump = disable_core_dumps (); may_coredump = disable_core_dumps ();
parse_rereadable_options (NULL); /* Reset them to default values. */ parse_rereadable_options (NULL, 0); /* Reset them to default values. */
shell = getenv ("SHELL"); shell = getenv ("SHELL");
if (shell && strlen (shell) >= 3 && !strcmp (shell+strlen (shell)-3, "csh") ) if (shell && strlen (shell) >= 3 && !strcmp (shell+strlen (shell)-3, "csh") )
@ -503,7 +518,7 @@ main (int argc, char **argv )
while (optfile_parse( configfp, configname, &configlineno, &pargs, opts) ) while (optfile_parse( configfp, configname, &configlineno, &pargs, opts) )
{ {
if (parse_rereadable_options (&pargs)) if (parse_rereadable_options (&pargs, 0))
continue; /* Already handled */ continue; /* Already handled */
switch (pargs.r_opt) switch (pargs.r_opt)
{ {
@ -626,7 +641,7 @@ main (int argc, char **argv )
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME,
GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME, GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME,
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME,
GC_OPT_FLAG_NONE ); GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME );
printf ("default-cache-ttl:%lu:%d:\n", printf ("default-cache-ttl:%lu:%d:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, DEFAULT_CACHE_TTL ); GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, DEFAULT_CACHE_TTL );
printf ("no-grab:%lu:\n", printf ("no-grab:%lu:\n",
@ -659,6 +674,7 @@ main (int argc, char **argv )
log_set_prefix (NULL, (JNLIB_LOG_WITH_PREFIX log_set_prefix (NULL, (JNLIB_LOG_WITH_PREFIX
|JNLIB_LOG_WITH_TIME |JNLIB_LOG_WITH_TIME
|JNLIB_LOG_WITH_PID)); |JNLIB_LOG_WITH_PID));
current_logfile = xstrdup (logfile);
} }
/* Make sure that we have a default ttyname. */ /* Make sure that we have a default ttyname. */
@ -957,7 +973,7 @@ reread_configuration (void)
return; return;
} }
parse_rereadable_options (NULL); /* Start from the default values. */ parse_rereadable_options (NULL, 1); /* Start from the default values. */
memset (&pargs, 0, sizeof pargs); memset (&pargs, 0, sizeof pargs);
dummy = 0; dummy = 0;
@ -968,7 +984,7 @@ reread_configuration (void)
if (pargs.r_opt < -1) if (pargs.r_opt < -1)
pargs.err = 1; /* Print a warning. */ pargs.err = 1; /* Print a warning. */
else /* Try to parse this option - ignore unchangeable ones. */ else /* Try to parse this option - ignore unchangeable ones. */
parse_rereadable_options (&pargs); parse_rereadable_options (&pargs, 1);
} }
fclose (fp); fclose (fp);
set_debug (); set_debug ();

View File

@ -1,3 +1,8 @@
2004-04-30 Werner Koch <wk@gnupg.org>
* logging.c (log_set_file): Make sure the log stream will be
closed even if the stderr fileno will be assigned to a new socket.
2004-04-16 Werner Koch <wk@gnupg.org> 2004-04-16 Werner Koch <wk@gnupg.org>
* logging.h (JNLIB_LOG_WITH_PREFIX): Add constants for the flag * logging.h (JNLIB_LOG_WITH_PREFIX): Add constants for the flag

View File

@ -211,7 +211,7 @@ fun_closer (void *cookie_arg)
/* Set the file to write log to. The sepcial names NULL and "_" may /* Set the file to write log to. The special names NULL and "-" may
be used to select stderr and names formatted like be used to select stderr and names formatted like
"socket:///home/foo/mylogs" may be used to write the logging to the "socket:///home/foo/mylogs" may be used to write the logging to the
socket "/home/foo/mylogs". If the connection to the socket fails socket "/home/foo/mylogs". If the connection to the socket fails
@ -258,6 +258,13 @@ log_set_file (const char *name)
/* We always need to print the prefix and the pid, so that the /* We always need to print the prefix and the pid, so that the
server reading the socket can do something meanigful. */ server reading the socket can do something meanigful. */
force_prefixes = 1; force_prefixes = 1;
/* On success close the old logstream right now, so that we are
really sure it has been closed. */
if (fp)
{
fclose (logstream);
logstream = NULL;
}
} }
else else
fp = (name && strcmp(name,"-"))? fopen (name, "a") : stderr; fp = (name && strcmp(name,"-"))? fopen (name, "a") : stderr;