srogue: add support for SAVEDIR

This commit is contained in:
John "Elwin" Edwards 2010-11-25 17:28:29 +00:00
parent ce4b930551
commit 20d469d64f
5 changed files with 91 additions and 22 deletions

View file

@ -136,8 +136,11 @@ dosave()
FILE *savef;
ignore();
setuid(playuid);
setgid(playgid);
if (!use_savedir)
{
setuid(playuid);
setgid(playgid);
}
umask(022);
if (file_name[0] != '\0') {
@ -209,8 +212,12 @@ char *file, **envp;
int slines, scols;
if ((inf = open(file, O_RDONLY)) < 0) {
printf("Cannot read save game %s\n",file);
return FALSE;
if (use_savedir && errno == ENOENT)
return TRUE;
else {
printf("Cannot read save game %s\n",file);
return FALSE;
}
}
encread(buf, strlen(version) + 1, inf);
@ -297,23 +304,36 @@ char *file, **envp;
{
#ifndef __DJGPP__
endwin();
while((pid = fork()) < 0)
sleep(1);
/* set id to unlink file */
if(pid == 0)
if (!use_savedir)
{
setuid(playuid);
setgid(playgid);
unlink(file);
exit(0);
while((pid = fork()) < 0)
sleep(1);
/* set id to unlink file */
if(pid == 0)
{
setuid(playuid);
setgid(playgid);
unlink(file);
exit(0);
}
/* wait for unlink to finish */
else
{
while(wait(&ret_status) != pid)
continue;
if (ret_status < 0)
{
printf("Cannot unlink file\n");
return FALSE;
}
}
}
/* wait for unlink to finish */
else
{
while(wait(&ret_status) != pid)
continue;
if (ret_status < 0)
/* Don't drop privileges, they're needed
* for the unlink. */
if (unlink(file) < 0)
{
printf("Cannot unlink file\n");
return FALSE;