diff srogue/main.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
line wrap: on
line diff
--- a/srogue/main.c	Wed Apr 30 14:46:30 2014 -0700
+++ b/srogue/main.c	Fri May 02 15:06:23 2014 -0700
@@ -29,8 +29,6 @@
 #endif
 
 #ifdef BSD
-#define srand48(seed)	srandom(seed)
-#define lrand48()	random()
 #include <sys/time.h>
 #endif
 
@@ -57,13 +55,8 @@
 	if (homedir == NULL)
         	homedir = "";
 
-	playuid = getuid();
-
-	if (setuid(playuid) < 0) {
-		printf("Cannot change to effective uid: %d\n", playuid);
-		exit(1);
-	}
-	playgid = getgid();
+	playuid = md_getuid();
+	playgid = md_getgid();
 
 	/* check for print-score option */
 #ifdef SCOREFILE
@@ -121,6 +114,9 @@
 	}
 #endif
 
+	if (!use_savedir)
+		md_droppriv();
+
 	/* get home and options from environment */
 
 	if ((env = getenv("HOME")) != NULL)
@@ -177,7 +173,7 @@
 
 	fflush(stdout);
 	seed = dnum;
-	srand48(seed);			/* init rnd number gen */
+	srandom(seed);			/* init rnd number gen */
 
 	md_onsignal_exit();		/* just in case */
 
@@ -358,7 +354,7 @@
 	if (range == 0)
 		wh = 0;
 	else {
-		wh = lrand48() % range;
+		wh = random() % range;
 		wh &= 0x7FFFFFFF;
 	}
 	return wh;