Ticket #86: controlchan.diff

File controlchan.diff, 2.8 KB (added by eagle, 14 years ago)

Patch from September, 2006

  • controlchan

    old new  
    3939my $lastctl = 0;
    4040my $use_syslog = 0;
    4141my $debug = 0;
     42my $delayed = 1;
     43my $delay = 3;
     44my @actions = ();
    4245
    4346# setup logging ###########################################################
    4447# do not log to syslog if stderr is connected to a console
     
    5558}
    5659logmsg('starting');
    5760
     61sub delayedprocess {
     62    logmsg("Processing the queue (" . scalar(@actions) . " messages in queue)");
     63    my $t = 0;
     64    if(scalar(@actions) > 1) {
     65        $t = 1;
     66        system($inn::newsbin."/ctlinnd throttle 'controlchan processing'");
     67    }
     68    while(my $p = shift(@actions)) {
     69        my $subname = shift(@$p);
     70        my $token = shift(@$p);
     71        my $subfind = \&$subname;
     72        #my @p = ($subfind, \@progparams, $sender, $replyto, $sitepath,
     73        #         $action, $logname, $approved, \@headers, \@body);
     74        #logmsg("$subname, " . join(' ', @progparams)
     75        #    . " $sender $replyto $token, $sitepath, $action"
     76        #    . ($logname ? "=$logname" : '') .", $approved");
     77        logmsg("$subname, " . join(' ', @{$$p[0]})
     78             . " $$p[1] $$p[2] $$p[3] $token, $$p[4], $$p[6]"
     79             . ($$p[7] ? "=$$p[7]" : '') .", $$p[8]");
     80        &$subfind(@$p);
     81    }
     82    if($t) {
     83        system($inn::newsbin."/ctlinnd go 'controlchan processing'");
     84    }
     85}
     86
     87
     88if ($delayed) {
     89    $SIG{ALRM} = \&delayedprocess;
     90}
     91
    5892# load modules from the control directory #################################
    5993opendir(CTL, $inn::controlprogs)
    6094    or logdie("Cannot open $inn::controlprogs: $!", 'crit');
     
    156190    }
    157191
    158192    my $approved = $hdr{approved} ? 1 : 0;
    159     logmsg("$subname, " . join(' ', @progparams)
    160         . " $sender $replyto $token, $sitepath, $action"
    161         . ($logname ? "=$logname" : '') .", $approved");
    162193
    163     &$subfind(\@progparams, $sender, $replyto, $sitepath,
    164         $action, $logname, $approved, \@headers, \@body);
     194    if(!$delayed) {
     195        logmsg("$subname, " . join(' ', @progparams)
     196            . " $sender $replyto $token, $sitepath, $action"
     197            . ($logname ? "=$logname" : '') .", $approved");
     198        &$subfind(\@progparams, $sender, $replyto, $sitepath,
     199            $action, $logname, $approved, \@headers, \@body);
     200    } else {
     201        my @p = ($subname, $token, \@progparams, $sender, $replyto, $sitepath,
     202                 $action, $logname, $approved, \@headers, \@body);
     203        push(@actions, [ @p ]);
     204        if(scalar(@actions) > 50) {
     205            alarm 0;
     206            &delayedprocess;
     207        } else {
     208            logmsg("$subname, delayed for $delay seconds (" . scalar(@actions) . " messages in queue)");
     209            alarm $delay;
     210        }
     211    }
    165212}
    166213
    167214closelog() if $use_syslog;