summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2004-04-30 05:58:21 +0200
committerWerner Koch <wk@gnupg.org>2004-04-30 05:58:21 +0200
commit623fad67a576532a82c065e98b955da43266dcf4 (patch)
tree258194bab553543438ba52c5c46febce1c2dfe5a
parent(check_and_store): Do not update the stats for hidden (diff)
downloadgnupg2-623fad67a576532a82c065e98b955da43266dcf4.tar.xz
gnupg2-623fad67a576532a82c065e98b955da43266dcf4.zip
* 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.
-rw-r--r--agent/ChangeLog6
-rw-r--r--agent/gpg-agent.c30
-rw-r--r--jnlib/ChangeLog5
-rw-r--r--jnlib/logging.c9
4 files changed, 42 insertions, 8 deletions
diff --git a/agent/ChangeLog b/agent/ChangeLog
index 10674ad18..a76199961 100644
--- a/agent/ChangeLog
+++ b/agent/ChangeLog
@@ -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>
* call-scd.c (start_scd): Do not register an event signal if we
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index 9b8678823..3bf62c26f 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -155,6 +155,10 @@ static char *config_filename;
/* Helper to implement --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. */
static void create_directories (void);
#ifdef USE_GNU_PTH
@@ -317,9 +321,10 @@ cleanup_sh (int sig)
/* Handle options which are allowed to be reset after program start.
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
- 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
-parse_rereadable_options (ARGPARSE_ARGS *pargs)
+parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread)
{
if (!pargs)
{ /* reset mode */
@@ -343,6 +348,16 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs)
case oDebugAll: opt.debug = ~0; 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 oPinentryProgram: opt.pinentry_program = pargs->r.ret_str; break;
@@ -424,7 +439,7 @@ main (int argc, char **argv )
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");
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) )
{
- if (parse_rereadable_options (&pargs))
+ if (parse_rereadable_options (&pargs, 0))
continue; /* Already handled */
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_DEFAULT|GC_OPT_FLAG_RUNTIME,
- GC_OPT_FLAG_NONE );
+ GC_OPT_FLAG_NONE|GC_OPT_FLAG_RUNTIME );
printf ("default-cache-ttl:%lu:%d:\n",
GC_OPT_FLAG_DEFAULT|GC_OPT_FLAG_RUNTIME, DEFAULT_CACHE_TTL );
printf ("no-grab:%lu:\n",
@@ -659,6 +674,7 @@ main (int argc, char **argv )
log_set_prefix (NULL, (JNLIB_LOG_WITH_PREFIX
|JNLIB_LOG_WITH_TIME
|JNLIB_LOG_WITH_PID));
+ current_logfile = xstrdup (logfile);
}
/* Make sure that we have a default ttyname. */
@@ -957,7 +973,7 @@ reread_configuration (void)
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);
dummy = 0;
@@ -968,7 +984,7 @@ reread_configuration (void)
if (pargs.r_opt < -1)
pargs.err = 1; /* Print a warning. */
else /* Try to parse this option - ignore unchangeable ones. */
- parse_rereadable_options (&pargs);
+ parse_rereadable_options (&pargs, 1);
}
fclose (fp);
set_debug ();
diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog
index 99c9177b5..1527fb773 100644
--- a/jnlib/ChangeLog
+++ b/jnlib/ChangeLog
@@ -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>
* logging.h (JNLIB_LOG_WITH_PREFIX): Add constants for the flag
diff --git a/jnlib/logging.c b/jnlib/logging.c
index fdf2d7fcb..7397ddd30 100644
--- a/jnlib/logging.c
+++ b/jnlib/logging.c
@@ -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
"socket:///home/foo/mylogs" may be used to write the logging to the
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
server reading the socket can do something meanigful. */
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
fp = (name && strcmp(name,"-"))? fopen (name, "a") : stderr;