mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
symlink latest-log.txt on nix, copy to the real log file everywhere else
This commit is contained in:
parent
98cb238d36
commit
25525a6aae
3 changed files with 75 additions and 11 deletions
|
@ -127,6 +127,7 @@
|
||||||
|
|
||||||
#ifdef LOGMESSAGES
|
#ifdef LOGMESSAGES
|
||||||
extern FILE *logstream;
|
extern FILE *logstream;
|
||||||
|
extern char logfilename[1024];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#define DEVELOP // Disable this for release builds to remove excessive cheat commands and enable MD5 checking and stuff, all in one go. :3
|
//#define DEVELOP // Disable this for release builds to remove excessive cheat commands and enable MD5 checking and stuff, all in one go. :3
|
||||||
|
|
|
@ -23,10 +23,14 @@
|
||||||
#include "../m_misc.h"/* path shit */
|
#include "../m_misc.h"/* path shit */
|
||||||
#include "../i_system.h"
|
#include "../i_system.h"
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#if defined (__GNUC__) || defined (__unix__)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __unix__
|
||||||
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "time.h" // For log timestamps
|
#include "time.h" // For log timestamps
|
||||||
|
|
||||||
#ifdef HAVE_SDL
|
#ifdef HAVE_SDL
|
||||||
|
@ -48,6 +52,7 @@ extern int SDL_main(int argc, char *argv[]);
|
||||||
|
|
||||||
#ifdef LOGMESSAGES
|
#ifdef LOGMESSAGES
|
||||||
FILE *logstream = NULL;
|
FILE *logstream = NULL;
|
||||||
|
char logfilename[1024];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DOXYGEN
|
#ifndef DOXYGEN
|
||||||
|
@ -117,7 +122,6 @@ int main(int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
const char *logdir = NULL;
|
const char *logdir = NULL;
|
||||||
char logfile[MAX_WADPATH];
|
|
||||||
myargc = argc;
|
myargc = argc;
|
||||||
myargv = argv; /// \todo pull out path to exe from this string
|
myargv = argv; /// \todo pull out path to exe from this string
|
||||||
|
|
||||||
|
@ -157,7 +161,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (fileabs)
|
if (fileabs)
|
||||||
{
|
{
|
||||||
strftime(logfile, sizeof logfile, format, timeinfo);
|
strftime(logfilename, sizeof logfilename, format, timeinfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -168,32 +172,46 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
if (M_IsPathAbsolute(reldir))
|
if (M_IsPathAbsolute(reldir))
|
||||||
{
|
{
|
||||||
left = snprintf(logfile, sizeof logfile,
|
left = snprintf(logfilename, sizeof logfilename,
|
||||||
"%s"PATHSEP, reldir);
|
"%s"PATHSEP, reldir);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#ifdef DEFAULTDIR
|
#ifdef DEFAULTDIR
|
||||||
if (logdir)
|
if (logdir)
|
||||||
{
|
{
|
||||||
left = snprintf(logfile, sizeof logfile,
|
left = snprintf(logfilename, sizeof logfilename,
|
||||||
"%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir);
|
"%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif/*DEFAULTDIR*/
|
#endif/*DEFAULTDIR*/
|
||||||
{
|
{
|
||||||
left = snprintf(logfile, sizeof logfile,
|
left = snprintf(logfilename, sizeof logfilename,
|
||||||
"."PATHSEP"%s"PATHSEP, reldir);
|
"."PATHSEP"%s"PATHSEP, reldir);
|
||||||
}
|
}
|
||||||
#endif/*LOGMESSAGES*/
|
#endif/*LOGMESSAGES*/
|
||||||
|
|
||||||
strftime(&logfile[left], sizeof logfile - left, format, timeinfo);
|
strftime(&logfilename[left], sizeof logfilename - left,
|
||||||
|
format, timeinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
M_MkdirEachUntil(logfile,
|
M_MkdirEachUntil(logfilename,
|
||||||
M_PathParts(logdir) - 1,
|
M_PathParts(logdir) - 1,
|
||||||
M_PathParts(logfile) - 1, 0755);
|
M_PathParts(logfilename) - 1, 0755);
|
||||||
|
|
||||||
logstream = fopen(logfile, "wt");
|
#ifdef __unix__
|
||||||
|
logstream = fopen(logfilename, "w");
|
||||||
|
#ifdef DEFAULTDIR
|
||||||
|
if (symlink(logfilename,
|
||||||
|
va("%s/"DEFAULTDIR"/latest-log.txt", logdir)) == -1)
|
||||||
|
#else
|
||||||
|
if (symlink(logfilename, va("%s/latest-log.txt", logdir)) == -1)
|
||||||
|
#endif/*DEFAULTDIR*/
|
||||||
|
{
|
||||||
|
I_OutputMsg("Error symlinking latest-log.txt: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
#else/*__unix__*/
|
||||||
|
logstream = fopen("latest-log.txt", "wt+");
|
||||||
|
#endif/*__unix__*/
|
||||||
}
|
}
|
||||||
|
|
||||||
//I_OutputMsg("I_StartupSystem() ...\n");
|
//I_OutputMsg("I_StartupSystem() ...\n");
|
||||||
|
@ -222,7 +240,7 @@ int main(int argc, char **argv)
|
||||||
D_SRB2Main();
|
D_SRB2Main();
|
||||||
#ifdef LOGMESSAGES
|
#ifdef LOGMESSAGES
|
||||||
if (!M_CheckParm("-nolog"))
|
if (!M_CheckParm("-nolog"))
|
||||||
CONS_Printf("Logfile: %s\n", logfile);
|
CONS_Printf("Logfile: %s\n", logfilename);
|
||||||
#endif
|
#endif
|
||||||
CONS_Printf("Entering main game loop...\n");
|
CONS_Printf("Entering main game loop...\n");
|
||||||
// never return
|
// never return
|
||||||
|
|
|
@ -2377,6 +2377,48 @@ void I_RemoveExitFunc(void (*func)())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __unix__
|
||||||
|
static void Shittycopyerror(const char *name)
|
||||||
|
{
|
||||||
|
I_OutputMsg(
|
||||||
|
"Error copying log file: %s: %s\n",
|
||||||
|
name,
|
||||||
|
strerror(errno)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Shittylogcopy(void)
|
||||||
|
{
|
||||||
|
char buf[8192];
|
||||||
|
FILE *fp;
|
||||||
|
int n;
|
||||||
|
if (fseek(logstream, 0, SEEK_SET) == -1)
|
||||||
|
{
|
||||||
|
Shittycopyerror("fseek");
|
||||||
|
}
|
||||||
|
else if (( fp = fopen(logfilename, "wt") ))
|
||||||
|
{
|
||||||
|
while (( n = fread(buf, 1, sizeof buf, logstream) ))
|
||||||
|
{
|
||||||
|
if (fwrite(buf, 1, n, fp) < n)
|
||||||
|
{
|
||||||
|
Shittycopyerror("fwrite");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ferror(logstream))
|
||||||
|
{
|
||||||
|
Shittycopyerror("fread");
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Shittycopyerror(logfilename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif/*__unix__*/
|
||||||
|
|
||||||
//
|
//
|
||||||
// Closes down everything. This includes restoring the initial
|
// Closes down everything. This includes restoring the initial
|
||||||
// palette and video mode, and removing whatever mouse, keyboard, and
|
// palette and video mode, and removing whatever mouse, keyboard, and
|
||||||
|
@ -2395,6 +2437,9 @@ void I_ShutdownSystem(void)
|
||||||
if (logstream)
|
if (logstream)
|
||||||
{
|
{
|
||||||
I_OutputMsg("I_ShutdownSystem(): end of logstream.\n");
|
I_OutputMsg("I_ShutdownSystem(): end of logstream.\n");
|
||||||
|
#ifndef __unix__
|
||||||
|
Shittylogcopy();
|
||||||
|
#endif
|
||||||
fclose(logstream);
|
fclose(logstream);
|
||||||
logstream = NULL;
|
logstream = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue