]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Shm.pl
* Replaced chanServ_ops in infobot.config with chansetable +chanServCheck
[infobot.git] / src / Shm.pl
index 170811b7d3ed85897b1e3c8a53c219fda316be24..0484ff2e2c34e2f2a2021443bf4d2a6e8e3f714e 100644 (file)
@@ -9,6 +9,8 @@
 
 use POSIX qw(_exit);
 
+my %shm_keys;
+
 sub openSHM {
     my $IPC_PRIVATE = 0;
     my $size = 2000;
@@ -20,6 +22,10 @@ sub openSHM {
 
     if (defined( $_ = shmget($IPC_PRIVATE, $size, 0777) )) {
        &status("Created shared memory (shm) key: [$_]");
+       $shm_keys{$_} = {time     => time,
+                        accessed => 0,
+                        key      => $_,
+                       };
        return $_;
     } else {
        &ERROR("openSHM: failed.");
@@ -52,8 +58,12 @@ sub shmRead {
        return $retval;
     } else {
        &ERROR("shmRead: failed: $!");
+       if (exists $shm_keys{$_}) {
+             closeSHM($key);
+       }
        ### TODO: if this fails, never try again.
-       &openSHM();
+       # What use is opening a SHM segment if we're not going to read it?
+       # &openSHM();
        return '';
     }
 }
@@ -65,6 +75,8 @@ sub shmWrite {
 
     return if (&IsParam('noSHM'));
 
+    $shm_keys{$keys}{accessed} = 1;
+
     if (length($str) > $size) {
        &status("ERROR: length(str) (..)>$size...");
        return;
@@ -229,7 +241,7 @@ sub shmFlush {
     return if ($$ != $::bot_pid); # fork protection.
 
     if (@_) {
-       &ScheduleThis(15, 'shmFlush');
+       &ScheduleThis(15*60, 'shmFlush'); # 15 minutes
        return if ($_[0] eq '2');
     }
 
@@ -276,3 +288,5 @@ sub shmFlush {
 }
 
 1;
+
+# vim:ts=4:sw=4:expandtab:tw=80