[Freeciv-Dev] (PR#13461) Improve sanity of logging
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#13461) Improve sanity of logging |
From: |
"Per I. Mathisen" <per@xxxxxxxxxxx> |
Date: |
Tue, 12 Jul 2005 11:56:36 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13461 >
This ensures that filenames we give for logging will not be forgotten.
Using pointers to strings like it was done is dangerous since we should
not just assume that those strings will stay within scope and not fall off
the stack.
- Per
Index: utility/log.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/log.c,v
retrieving revision 1.47
diff -u -r1.47 log.c
--- utility/log.c 21 Mar 2005 23:01:12 -0000 1.47
+++ utility/log.c 12 Jul 2005 18:51:59 -0000
@@ -27,7 +27,7 @@
#include "log.h"
-static const char *log_filename;
+static char *log_filename = NULL;
static log_callback_fn log_callback;
int logd_init_counter = 1;
@@ -178,8 +178,12 @@
log_callback_fn callback)
{
fc_log_level = initial_level;
+ if (log_filename) {
+ free(log_filename);
+ log_filename = NULL;
+ }
if (filename && strlen(filename) > 0) {
- log_filename = filename;
+ log_filename = strdup(filename);
} else {
log_filename = NULL;
}
@@ -268,8 +272,8 @@
if (log_filename) {
if(!(fs=fopen(log_filename, "a"))) {
- fc_fprintf(stderr, _("Couldn't open logfile: %s for appending.\n"),
- log_filename);
+ fc_fprintf(stderr, _("Couldn't open logfile: %s for appending
\"%s\".\n"),
+ log_filename, message);
exit(EXIT_FAILURE);
}
} else {
Index: server/gamelog.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gamelog.c,v
retrieving revision 1.50
diff -u -r1.50 gamelog.c
--- server/gamelog.c 21 May 2005 19:40:25 -0000 1.50
+++ server/gamelog.c 12 Jul 2005 18:51:59 -0000
@@ -33,7 +33,7 @@
#include "stdinhand.h"
int gamelog_level; /* also accessed from stdinhand.c */
-static char *gamelog_filename;
+static char *gamelog_filename = NULL;
/* Stuff for gamelog_status() */
struct player_score_entry {
@@ -73,8 +73,12 @@
void gamelog_init(char *filename)
{
gamelog_level = GAMELOG_FULL;
+ if (gamelog_filename) {
+ free(gamelog_filename);
+ gamelog_filename = NULL;
+ }
if (filename && strlen(filename) > 0) {
- gamelog_filename = filename;
+ gamelog_filename = strdup(filename);
} else {
gamelog_filename = NULL;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13461) Improve sanity of logging,
Per I. Mathisen <=
|
|