srogue: open the score and log files when the program starts.

Super-Rogue can now use the same privilege-dropping scheme as the other
games.
This commit is contained in:
John "Elwin" Edwards 2015-08-01 15:12:11 -04:00
parent 2d3d25c5e9
commit bc5b26fece
3 changed files with 28 additions and 7 deletions

View file

@ -47,6 +47,9 @@ static char *rip[] = {
#define RIP_LINES (sizeof rip / (sizeof (char *)))
extern int scorefd;
extern FILE *logfile;
char *killname();
void writelog(int amount, int aflag, char monst);
@ -140,7 +143,7 @@ int amount, aflag;
/*
* Open file and read list
*/
if ((fd = open(scorefile, O_RDWR | O_CREAT, 0666)) < 0)
if ((fd = scorefd) < 0)
return;
outf = (FILE *) fdopen(fd, "w");
for (scp = top_ten; scp <= &top_ten[9]; scp++) {
@ -221,11 +224,12 @@ void writelog(int amount, int aflag, char monst)
{
char logmessage[220], ltemp[80], mlev[40];
char *killer;
FILE *logfi;
if (waswizard)
return;
#ifdef LOGFILE
if (logfile == NULL)
return;
sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami,
him->s_lvl);
if (amulet)
@ -247,11 +251,8 @@ void writelog(int amount, int aflag, char monst)
else
return;
strcat(logmessage, ltemp);
logfi = fopen(LOGFILE, "a");
if (logfi == NULL)
return;
fprintf(logfi, "%s", logmessage);
fclose(logfi);
fprintf(logfile, "%s", logmessage);
fclose(logfile);
#endif
return;
}