comparison srogue/save.c @ 120:d6b7c3fb37ea

srogue: add and use more md_* portable functions. Privileges and memory usage checks are now more portable.
author John "Elwin" Edwards
date Fri, 02 May 2014 15:06:23 -0700
parents 458df24e973d
children e6c8652473fe
comparison
equal deleted inserted replaced
119:458df24e973d 120:d6b7c3fb37ea
23 #include <sys/stat.h> 23 #include <sys/stat.h>
24 #include <signal.h> 24 #include <signal.h>
25 #include <errno.h> 25 #include <errno.h>
26 #include "rogue.h" 26 #include "rogue.h"
27 #include "rogue.ext" 27 #include "rogue.ext"
28
29 #ifdef BSD
30 #define srand48(seed) srandom(seed)
31 #endif
32 28
33 EXTCHAR version[]; 29 EXTCHAR version[];
34 EXTCHAR *ctime(); 30 EXTCHAR *ctime();
35 31
36 typedef struct stat STAT; 32 typedef struct stat STAT;
142 FILE *savef; 138 FILE *savef;
143 139
144 ignore(); 140 ignore();
145 if (!use_savedir) 141 if (!use_savedir)
146 { 142 {
147 setuid(playuid); 143 md_resetpriv();
148 setgid(playgid);
149 } 144 }
150 umask(022); 145 umask(022);
151 146
152 if (file_name[0] != '\0') { 147 if (file_name[0] != '\0') {
153 if ((savef = fopen(file_name,"w")) != NULL) 148 if ((savef = fopen(file_name,"w")) != NULL)
300 sleep(1); 295 sleep(1);
301 296
302 /* set id to unlink file */ 297 /* set id to unlink file */
303 if(pid == 0) 298 if(pid == 0)
304 { 299 {
305 setuid(playuid); 300 md_resetpriv();
306 setgid(playgid);
307 unlink(file); 301 unlink(file);
308 exit(0); 302 exit(0);
309 } 303 }
310 /* wait for unlink to finish */ 304 /* wait for unlink to finish */
311 else 305 else
348 environ = envp; 342 environ = envp;
349 343
350 strcpy(file_name, file); 344 strcpy(file_name, file);
351 setup(); 345 setup();
352 restscr(cw); 346 restscr(cw);
353 srand48(getpid()); 347 srandom(getpid());
354 playit(); 348 playit();
355 } 349 }