fix mandatory client logfile
The logfile can't be created before the commandline arguments are parsed, because before that, the home directory is unknown. This patch logs into a memory buffer which is then copied to the logfile as soon as the logfile is created after processing the commandline arguments. The memory buffer is created during the initialisation of global variables, and destroyed after the logfile is created.
This commit is contained in:
@@ -95,6 +95,7 @@ COMMANDN(toggleconsole, toggleconsole, "");
|
||||
void renderconsole() { con.render(); }
|
||||
|
||||
stream *clientlogfile = NULL;
|
||||
vector<char> *bootclientlog = new vector<char>;
|
||||
int clientloglinesremaining = INT_MAX;
|
||||
|
||||
void clientlogf(const char *s, ...)
|
||||
@@ -113,6 +114,7 @@ void clientlogf(const char *s, ...)
|
||||
clientlogfile->printf("%s%s\n", ts, l);
|
||||
if(--clientloglinesremaining <= 0) DELETEP(clientlogfile);
|
||||
}
|
||||
else if(bootclientlog) cvecprintf(*bootclientlog, "%s%s\n", ts, l);
|
||||
l = p + 1;
|
||||
}
|
||||
while(p);
|
||||
|
||||
+9
-4
@@ -992,7 +992,6 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
|
||||
|
||||
void initclientlog() // rotate old logfiles and create new one
|
||||
{
|
||||
extern stream *clientlogfile;
|
||||
const int MAXROT = 5; // keep five old logfiles
|
||||
string fname1, fname2 = "";
|
||||
const char *basename = findfile("clientlog", "w");
|
||||
@@ -1003,9 +1002,13 @@ void initclientlog() // rotate old logfiles and create new one
|
||||
else remove(fname1);
|
||||
copystring(fname2, fname1);
|
||||
}
|
||||
clientlogfile = openfile(fname2, "w");
|
||||
if(clientlogfile) clientlogfile->printf("######## start logging: %s\n", timestring(true));
|
||||
clientlogfile = openfile("clientlog.txt", "w");
|
||||
if(clientlogfile)
|
||||
{
|
||||
if(bootclientlog && bootclientlog->length()) clientlogfile->write(bootclientlog->getbuf(), bootclientlog->length());
|
||||
}
|
||||
else conoutf("could not create logfile \"%s\"", fname2);
|
||||
DELETEP(bootclientlog);
|
||||
}
|
||||
|
||||
VARP(compatibilitymode, 0, 1, 1); // FIXME : find a better place to put this ?
|
||||
@@ -1030,7 +1033,7 @@ int main(int argc, char **argv)
|
||||
string servername, password;
|
||||
int serverport;
|
||||
|
||||
initclientlog();
|
||||
if(bootclientlog) cvecprintf(*bootclientlog, "######## start logging: %s\n", timestring(true));
|
||||
|
||||
const char *initmap = rndmapname();
|
||||
|
||||
@@ -1041,6 +1044,7 @@ int main(int argc, char **argv)
|
||||
initing = INIT_RESET;
|
||||
for(int i = 1; i<argc; i++)
|
||||
{
|
||||
clientlogf("parsing commandline argument %d: \"%s\"", i, argv[i]);
|
||||
// server: ufimNFTLAckyxpDWrXBKIoOnPMVC
|
||||
if(!scl.checkarg(argv[i]))
|
||||
{
|
||||
@@ -1105,6 +1109,7 @@ int main(int argc, char **argv)
|
||||
else conoutf("\f3unknown commandline argument: %c", argv[i][0]);
|
||||
}
|
||||
}
|
||||
initclientlog();
|
||||
if(quitdirectly) return EXIT_SUCCESS;
|
||||
|
||||
i18nmanager i18n("AC", path("packages/locale", true));
|
||||
|
||||
@@ -52,6 +52,9 @@ struct authkey // for AUTH
|
||||
};
|
||||
|
||||
// console
|
||||
extern stream *clientlogfile;
|
||||
extern vector<char> *bootclientlog;
|
||||
|
||||
extern void keypress(int code, bool isdown, int cooked, SDLMod mod = KMOD_NONE);
|
||||
extern int rendercommand(int x, int y, int w);
|
||||
extern void renderconsole();
|
||||
|
||||
@@ -403,6 +403,14 @@ char *concatformatstring(char *d, const char *s, ...)
|
||||
return concatstring(d, temp);
|
||||
}
|
||||
|
||||
int cvecprintf(vector<char> &v, const char *s, ...)
|
||||
{
|
||||
defvformatstring(temp, s, s);
|
||||
int len = strlen(temp);
|
||||
if(len) v.put(temp, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
const char *hiddenpwd(const char *pwd, int showchars)
|
||||
{
|
||||
static int sc = 3;
|
||||
|
||||
@@ -968,6 +968,7 @@ extern const char *iptoa(const enet_uint32 ip);
|
||||
extern const char *iprtoa(const struct iprange &ipr);
|
||||
extern int cmpiprange(const struct iprange *a, const struct iprange *b);
|
||||
extern int cmpipmatch(const struct iprange *a, const struct iprange *b);
|
||||
extern int cvecprintf(vector<char> &v, const char *s, ...);
|
||||
extern const char *hiddenpwd(const char *pwd, int showchars = 0);
|
||||
|
||||
#if defined(WIN32) && !defined(_DEBUG) && !defined(__GNUC__)
|
||||
|
||||
Reference in New Issue
Block a user