]> git.zerfleddert.de Git - micropolis/blobdiff - src/sim/w_sound.c
prevent forking a huge number of player processes by limiting them to
[micropolis] / src / sim / w_sound.c
index a7dae7836d2d85030efd8d56d0cfd9ea5ee0df7b..7558e47013f447d4a4e522e2b512e595ca5300be 100644 (file)
@@ -271,9 +271,22 @@ ShutDownSound()
 MakeSound(char *channel, char *id)
 {
   char filename[256], player[256];
+  static struct timeval last = {0, 0};
+  struct timeval now;
+  unsigned int diff;
   int i;
   pid_t pid;
 
+  gettimeofday(&now, NULL);
+
+  diff = ((now.tv_sec - last.tv_sec) * 1000000) +
+    (now.tv_usec - last.tv_usec);
+  
+  if (diff < 100000)
+    return;
+
+  last = now;
+
   if (!UserSoundOn) return;
   if (!SoundInitialized) return;
 
@@ -292,6 +305,7 @@ MakeSound(char *channel, char *id)
   switch(pid) {
     case 0:
       execl(player, player, filename, NULL);
+      exit(1);
       break;
     case -1:
       perror("fork failed");
Impressum, Datenschutz