ref updates: ignore non-update updates
[girocco.git] / taskd / taskd.pl
blob400f8af19a8e76ee0f5b85d442567f0cf854b784
1 #!/usr/bin/perl
3 # taskd - Clone repositories on request
5 # taskd is Girocco mirroring servant; it processes requests for clones
6 # of given URLs received over its socket.
8 # When a request is received, new process is spawned that sets up
9 # the repository and reports further progress
10 # to .clonelog within the repository. In case the clone fails,
11 # .clone_failed is touched and .clone_in_progress is removed.
13 # Clone protocol:
14 # Alice sets up repository and touches .cloning
15 # Alice opens connection to Bob
16 # Alice sends project name through the connection
17 # Bob opens the repository and sends error code if there is a problem
18 # Bob closes connection
19 # Alice polls .clonelog in case of success.
20 # If Alice reads "@OVER@" from .clonelog, it stops polling.
22 # Ref-change protocol:
23 # Alice opens connection to Bob
24 # Alice sends ref-change command for each changed ref
25 # Alice closes connection
26 # Bob sends out notifications
28 # Initially based on perlipc example.
30 use 5.008; # we need safe signals
31 use strict;
32 use warnings;
34 use Getopt::Long;
35 use Pod::Usage;
36 use Socket;
37 use Errno;
38 use Fcntl;
39 use POSIX ":sys_wait_h";
40 use File::Basename;
42 use lib dirname($0);
43 use Girocco::Config;
44 use Girocco::Notify;
45 use Girocco::Project;
46 use Girocco::User;
47 use Girocco::Util qw(noFatalsToBrowser get_git);
48 BEGIN {noFatalsToBrowser}
50 # Throttle Classes Defaults
51 # Note that any same-named classes in @Girocco::Config::throttle_classes
52 # will override (completely replacing the entire hash) these ones.
53 my @throttle_defaults = (
55 name => "ref-change",
56 maxproc => 0,
57 maxjobs => 1,
58 interval => 1
61 name => "clone",
62 maxproc => 0,
63 maxjobs => 2,
64 interval => 5
67 name => "snapshot",
68 #maxproc => max(5, cpucount + maxjobs), # this is the default
69 #maxjobs => max(1, int(cpucount / 4)) , # this is the default
70 interval => 5
74 # Options
75 my $quiet;
76 my $progress;
77 my $syslog;
78 my $stderr;
79 my $inetd;
80 my $idle_timeout;
81 my $abbrev = 8;
82 my $showff = 1;
83 my $statusintv = 60;
84 my $idleintv = 3600;
85 my $maxspawn = 8;
87 $| = 1;
89 my $progname = basename($0);
90 my $children = 0;
91 my $idlestart = time;
92 my $idlestatus = 0;
94 sub cpucount {
95 use Girocco::Util "online_cpus";
96 our $online_cpus_result;
97 $online_cpus_result = online_cpus unless $online_cpus_result;
98 return $online_cpus_result;
101 sub logmsg {
102 my $hdr = "[@{[scalar localtime]}] $progname $$: ";
103 if (tied *STDOUT) {
104 $OStream::only = 2; # STDERR only
105 print "$hdr@_\n";
106 $OStream::only = 1; # syslog only
107 print "@_\n";
108 $OStream::only = 0; # back to default
109 } else {
110 print "$hdr@_\n";
114 sub statmsg {
115 return unless $progress;
116 my $hdr = "[@{[scalar localtime]}] $progname $$: ";
117 if (tied *STDERR) {
118 $OStream::only = 2; # STDERR only
119 print STDERR "$hdr@_\n";
120 $OStream::only = 1; # syslog only
121 print STDERR "@_\n";
122 $OStream::only = 0; # back to default
123 } else {
124 print STDERR "$hdr@_\n";
128 sub duration {
129 my $secs = shift;
130 return $secs unless defined($secs) && $secs >= 0;
131 $secs = int($secs);
132 my $ans = ($secs % 60) . 's';
133 return $ans if $secs < 60;
134 $secs = int($secs / 60);
135 $ans = ($secs % 60) . 'm' . $ans;
136 return $ans if $secs < 60;
137 $secs = int($secs / 60);
138 $ans = ($secs % 24) . 'h' . $ans;
139 return $ans if $secs < 24;
140 $secs = int($secs / 24);
141 return $secs . 'd' . $ans;
144 sub setnonblock {
145 my $fd = shift;
146 my $flags = fcntl($fd, F_GETFL, 0);
147 defined($flags) or die "fcntl failed: $!";
148 fcntl($fd, F_SETFL, $flags | O_NONBLOCK) or die "fcntl failed: $!";
151 sub setblock {
152 my $fd = shift;
153 my $flags = fcntl($fd, F_GETFL, 0);
154 defined($flags) or die "fcntl failed: $!";
155 fcntl($fd, F_SETFL, $flags & ~O_NONBLOCK) or die "fcntl failed: $!";
158 package Throttle;
161 ## Throttle protocol
163 ## 1) Process needing throttle services acquire a control file descriptor
164 ## a) Either as a result of a fork + exec (the write end of a pipe)
165 ## b) Or by connecting to the taskd socket (not yet implemented)
167 ## 2) The process requesting throttle services will be referred to
168 ## as the supplicant or just "supp" for short.
170 ## 3) The supp first completes any needed setup which may include
171 ## gathering data it needs to perform the action -- if that fails
172 ## then there's no need for any throttling.
174 ## 4) The supp writes a throttle request to the control descriptor in
175 ## this format:
176 ## throttle <pid> <class>\n
177 ## for example if the supp's pid was 1234 and it was requesting throttle
178 ## control as a member of the mail class it would write this message:
179 ## throttle 1234 mail\n
180 ## Note that if the control descriptor happens to be a pipe rather than a
181 ## socket, the message should be preceded by another "\n" just be be safe.
182 ## If the control descriptor is a socket, not a pipe, the message may be
183 ## preceded by a "\n" but that's not recommended.
185 ## 5) For supplicants with a control descriptor that is a pipe
186 ## (getsockopt(SO_TYPE) returns ENOTSOCK) the (5a) protocol should be used.
187 ## If the control descriptor is a socket (getsockname succeeds) then
188 ## protocol (5b) should be used.
190 ## 5a) The supp now enters a "pause" loop awaiting either a SIGUSR1, SIGUSR2 or
191 ## SIGTERM. It should wake up periodically (SIGALRM works well) and attempt
192 ## to write a "keepalive\n" message to the control descriptor. If that
193 ## fails, the controller has gone away and it may make its own decision
194 ## whether or not to proceed at that point. If, on the other hand, it
195 ## receives a SIGTERM, the process limit for its class has been reached
196 ## and it should abort without performing its action. If it receives
197 ## SIGUSR1, it may proceed without writing anything more to the control
198 ## descriptor, any MAY even close the control descriptor. Finally, a
199 ## SIGUSR2 indicates rejection of the throttle request for some other reason
200 ## such as unrecognized class name or invalid pid in which case the supp may
201 ## make its own decision how to proceed.
203 ## 5b) The supp now enters a read wait on the socket -- it need accomodate no
204 ## more than 512 bytes and if a '\n' does not appear within that number of
205 ## bytes the read should be considered failed. Otherwise the read should
206 ## be retried until either a full line has been read or the socket is
207 ## closed from the other end. If the lone read is "proceed\n" then it may
208 ## proceed without reading or writing anything more to the control
209 ## descriptor, but MUST keep the control descriptor open and not call
210 ## shutdown on it either. Any other result (except EINTR or EAGAIN which
211 ## should be retried) constitutes failure. If a full line starting with at
212 ## least one alpha character was read but it was not "proceed" then it
213 ## should abort without performing its action. For any other failure it
214 ## may make its own decision whether or not to proceed as the controller has
215 ## gone away.
217 ## 6) The supp now performs its throttled action.
219 ## 7) The supp now closes its control descriptor (if it hasn't already in the
220 ## case of (5a)) and exits -- in the case of a socket, the other end receives
221 ## notification that the socket has been closed (read EOF). In the case of
222 ## a pipe the other end receives a SIGCHLD (multiple processes have a hold
223 ## of the other end of the pipe, so it will not reaach EOF by the supp's
224 ## exit in that case).
227 # keys are class names, values are hash refs with these fields:
228 # 'maxproc' => integer; maximum number of allowed supplicants (the sum of how
229 # many may be queued waiting plus how many may be
230 # concurrently active) with 0 meaning no limit.
231 # 'maxjobs' => integer; how many supplicants may proceed simultaneously a value
232 # of 0 is unlimited but the number of concurrent
233 # supplicants will always be limited to no more than
234 # the 'maxproc' value (if > 0) no matter what the
235 # 'maxjobs' value is.
236 # 'total' -> integer; the total number of pids belonging to this clase that
237 # can currently be found in %pid.
238 # 'active' -> integer; the number of currently active supplicants which should
239 # be the same as (the number of elements of %pid with a
240 # matching class name) - (number of my class in @queue).
241 # 'interval' -> integer; minimum number of seconds between 'proceed' responses
242 # or SIGUSR1 signals to members of this class.
243 # 'lastqueue' -> time; last time a supplicant was successfully queued.
244 # 'lastproceed' => time; last time a supplicant was allowed to proceed.
245 # 'lastthrottle' => time; last time a supplicant was throttled
246 # 'lastdied' => time; last time a supplicant in this class died/exited/etc.
247 my %classes = ();
249 # keys are pid numbers, values are array refs with these elements:
250 # [0] => name of class (key to classes hash)
251 # [1] => supplicant state (0 => queued, non-zero => time it started running)
252 # [2] => descriptive text (e.g. project name)
253 my %pid = ();
255 # minimum number of seconds between any two proceed responses no matter what
256 # class. this takes priority in that it can effectively increase the
257 # class's 'interval' value by delaying proceed notifications if the minimum
258 # interval has not yet elapsed.
259 my $interval = 1;
261 # fifo of pids awaiting notification as soon as the next $interval elapses
262 # provided interval and maxjobs requirements are satisfied
263 # for the class of the pid that will next be triggered.
264 my @queue = ();
266 # time of most recent successful call to AddSupplicant
267 my $lastqueue = 0;
269 # time of most recent proceed notification
270 my $lastproceed = 0;
272 # time of most recent throttle
273 my $lastthrottle = 0;
275 # time of most recent removal
276 my $lastdied = 0;
278 # lifetime count of how many have been queued
279 my $totalqueue = 0;
281 # lifetime count of how many have been allowed to proceed
282 my $totalproceed = 0;
284 # lifetime count of how many have been throttled
285 my $totalthrottle = 0;
287 # lifetime count of how many have died
288 # It should always be true that $totalqueued - $totaldied == $curentlyactive
289 my $totaldied = 0;
291 # Returns an unordered list of currently registered class names
292 sub GetClassList {
293 return keys(%classes);
296 sub _max {
297 return $_[0] if $_[0] >= $_[1];
298 return $_[1];
301 sub _getnum {
302 my ($min, $val, $default) = @_;
303 my $ans;
304 if (defined($val) && $val =~ /^[+-]?\d+$/) {
305 $ans = 0 + $val;
306 } else {
307 $ans = &$default;
309 return _max($min, $ans);
312 # [0] => name of class to find
313 # [1] => if true, create class if it doesn't exist, if a hashref then
314 # it contains initial values for maxproc, maxjobs and interval.
315 # Otherwise maxjobs defaults to max(cpu cores/4, 1), maxprocs
316 # defaults to the max(5, number of cpu cores + maxjobs) and interval
317 # defaults to 1.
318 # Returns a hash ref with info about the class on success
319 sub GetClassInfo {
320 my ($classname, $init) = @_;
321 defined($classname) && $classname =~ /^[a-zA-Z][a-zA-Z0-9._+-]*$/
322 or return;
323 $classname = lc($classname);
324 my %info;
325 if ($classes{$classname}) {
326 %info = %{$classes{$classname}};
327 return \%info;
329 return unless $init;
330 my %newclass = ();
331 ref($init) eq 'HASH' or $init = {};
332 $newclass{'maxjobs'} = _getnum(0, $init->{'maxjobs'}, sub{_max(1, int(::cpucount() / 4))});
333 $newclass{'maxproc'} = _getnum(0, $init->{'maxproc'}, sub{_max(5, ::cpucount() + $newclass{'maxjobs'})});
334 $newclass{'interval'} = _getnum(0, $init->{'interval'}, sub{1});
335 $newclass{'total'} = 0;
336 $newclass{'active'} = 0;
337 $newclass{'lastqueue'} = 0;
338 $newclass{'lastproceed'} = 0;
339 $newclass{'lastthrottle'} = 0;
340 $newclass{'lastdied'} = 0;
341 $classes{$classname} = \%newclass;
342 %info = %newclass;
343 return \%info;
346 # [0] => pid to look up
347 # Returns () if not found otherwise ($classname, $timestarted, $description)
348 # Where $timestarted will be 0 if it's still queued otherwise a time() value
349 sub GetPidInfo {
350 my $pid = shift;
351 return () unless exists $pid{$pid};
352 return @{$pid{$pid}};
355 # Returns array of pid numbers that are currently running sorted
356 # by time started (oldest to newest). Can return an empty array.
357 sub GetRunningPids {
358 return sort({ ${$pid{$a}}[1] <=> ${$pid{$b}}[1] }
359 grep({ ${$pid{$_}}[1] } keys(%pid)));
362 # Returns a hash with various about the current state
363 # 'interval' => global minimum interval between proceeds
364 # 'active' => how many pids are currently queued + how many are running
365 # 'queue' => how many pids are currently queued
366 # 'lastqueue' => time (epoch seconds) of last queue
367 # 'lastproceed' => time (epoch seconds) of last proceed
368 # 'lastthrottle' => time (epoch seconds) of last throttle
369 # 'lastdied' => time (epoch seconds) of last removal
370 # 'totalqueue' => lifetime total number of processes queued
371 # 'totalproceed' => lifetime total number of processes proceeded
372 # 'totalthrottle' => lifetime total number of processes throttled
373 # 'totaldied' => lifetime total number of removed processes
374 sub GetInfo {
375 return {
376 interval => $interval,
377 active => scalar(keys(%pid)) - scalar(@queue),
378 queue => scalar(@queue),
379 lastqueue => $lastqueue,
380 lastproceed => $lastproceed,
381 lastthrottle => $lastthrottle,
382 lastdied => $lastdied,
383 totalqueue => $totalqueue,
384 totalproceed => $totalproceed,
385 totalthrottle => $totalthrottle,
386 totaldied => $totaldied
390 # with no args get the global interval
391 # with one arg set it, returns previous value if set
392 sub Interval {
393 my $ans = $interval;
394 $interval = 0 + $_[0] if defined($_[0]) && $_[0] =~ /^\d+$/;
395 return $ans;
398 sub RemoveSupplicant;
400 # Perform queue service (i.e. send SIGUSR1 to any eligible queued process)
401 # Returns minimum interval until next proceed is possible
402 # Returns undef if there's nothing waiting to proceed or
403 # the 'maxjobs' limits have been reached for all queued items (in which
404 # case it won't be possible to proceed until one of them exits, hence undef)
405 # This is called automatially by AddSupplicant and RemoveSupplicant
406 sub ServiceQueue {
407 RETRY:
408 return undef unless @queue; # if there's nothing queued, nothing to do
409 my $now = time;
410 my $min = _max(0, $interval - ($now - $lastproceed));
411 my $classmin = undef;
412 my $classchecked = 0;
413 my %seenclass = ();
414 my $classcount = scalar(keys(%classes));
415 for (my $i=0; $i <= $#queue && $classchecked < $classcount; ++$i) {
416 my $pid = $queue[$i];
417 my $procinfo = $pid{$pid};
418 if (!$procinfo) {
419 RemoveSupplicant($pid, 1);
420 goto RETRY;
422 my $classinfo = $classes{$$procinfo[0]};
423 if (!$classinfo) {
424 RemoveSupplicant($pid, 1);
425 goto RETRY;
427 if (!$seenclass{$$procinfo[0]}) {
428 $seenclass{$$procinfo[0]} = 1;
429 ++$classchecked;
430 if (!$classinfo->{'maxjobs'} || $classinfo->{'active'} < $classinfo->{'maxjobs'}) {
431 my $cmin = _max(0, $classinfo->{'interval'} - ($now - $classinfo->{'lastproceed'}));
432 if (!$cmin && !$min) {
433 $now = time;
434 $$procinfo[1] = $now;
435 splice(@queue, $i, 1);
436 ++$totalproceed;
437 $lastproceed = $now;
438 $classinfo->{'lastproceed'} = $now;
439 ++$classinfo->{'active'};
440 kill("USR1", $pid) or RemoveSupplicant($pid, 1);
441 goto RETRY;
443 $classmin = $cmin unless defined($classmin) && $classmin < $cmin;
447 return defined($classmin) ? _max($min, $classmin) : undef;
450 # $1 => pid to add (must not already be in %pids)
451 # $2 => class name (must exist)
452 # Returns -1 if no such class or pid already present or invalid
453 # Returns 0 if added successfully (and possibly already SIGUSR1'd)
454 # Return 1 if throttled and cannot be added
455 sub AddSupplicant {
456 my ($pid, $classname, $text, $noservice) = @_;
457 return -1 unless $pid && $pid =~ /^[1-9][0-9]*$/;
458 $pid += 0;
459 kill(0, $pid) or return -1;
460 my $classinfo = $classes{$classname};
461 return -1 unless $classinfo;
462 return -1 if $pid{$pid};
463 $text = '' unless defined($text);
464 my $now = time;
465 if ($classinfo->{'maxproc'} && $classinfo->{'total'} >= $classinfo->{'maxproc'}) {
466 ++$totalthrottle;
467 $lastthrottle = $now;
468 $classinfo->{'lastthrottle'} = $now;
469 return 1;
471 ++$totalqueue;
472 $lastqueue = $now;
473 $pid{$pid} = [$classname, 0, $text];
474 ++$classinfo->{'total'};
475 $classinfo->{'lastqueue'} = $now;
476 push(@queue, $pid);
477 ServiceQueue unless $noservice;
478 return 0;
481 # $1 => pid to remove (died, killed, exited normally, doesn't matter)
482 # Returns 0 if removed
483 # Returns -1 if unknown pid or other error during removal
484 sub RemoveSupplicant {
485 my ($pid, $noservice) = @_;
486 return -1 unless defined($pid) && $pid =~ /^\d+$/;
487 $pid += 0;
488 my $pidinfo = $pid{$pid};
489 $pidinfo or return -1;
490 my $now = time;
491 $lastdied = $now;
492 ++$totaldied;
493 delete $pid{$pid};
494 if (!$$pidinfo[1]) {
495 for (my $i=0; $i<=$#queue; ++$i) {
496 if ($queue[$i] == $pid) {
497 splice(@queue, $i, 1);
498 --$i;
502 my $classinfo = $classes{$$pidinfo[0]};
503 ServiceQueue, return -1 unless $classinfo;
504 --$classinfo->{'active'} if $$pidinfo[1];
505 --$classinfo->{'total'};
506 $classinfo->{'lastdied'} = $now;
507 ServiceQueue unless $noservice;
508 return 0;
511 # Instance Methods
513 package main;
516 ## ---------
517 ## Functions
518 ## ---------
521 my @reapedpids = ();
522 my %signame = (
523 # http://pubs.opengroup.org/onlinepubs/000095399/utilities/trap.html
524 1 => 'SIGHUP',
525 2 => 'SIGINT',
526 3 => 'SIGQUIT',
527 6 => 'SIGABRT',
528 9 => 'SIGKILL',
529 14 => 'SIGALRM',
530 15 => 'SIGTERM',
532 sub REAPER {
533 local $!;
534 my $child;
535 my $waitedpid;
536 while (($waitedpid = waitpid(-1, WNOHANG)) > 0) {
537 my $code = $? & 0xffff;
538 $idlestart = time if !--$children;
539 my $codemsg = '';
540 if (!($code & 0xff)) {
541 $codemsg = " with exit code ".($code >> 8) if $code;
542 } elsif ($code & 0x7f) {
543 my $signum = ($code & 0x7f);
544 $codemsg = " with signal ".
545 ($signame{$signum}?$signame{$signum}:$signum);
547 logmsg "reaped $waitedpid$codemsg";
548 push(@reapedpids, $waitedpid);
550 $SIG{CHLD} = \&REAPER; # loathe sysV
553 $SIG{CHLD} = \&REAPER; # Apollo 440
555 my ($piperead, $pipewrite);
556 sub spawn {
557 my $coderef = shift;
559 my $pid = fork;
560 if (not defined $pid) {
561 logmsg "cannot fork: $!";
562 return;
563 } elsif ($pid) {
564 $idlestart = time if !++$children;
565 $idlestatus = 0;
566 logmsg "begat $pid";
567 return; # I'm the parent
570 close(Server) unless fileno(Server) == 0;
571 close($piperead);
572 $SIG{'CHLD'} = sub {};
574 open STDIN, "+<&Client" or die "can't dup client to stdin";
575 close(Client);
576 exit &$coderef();
579 # returns:
580 # < 0: error
581 # = 0: proceed
582 # > 0: throttled
583 sub request_throttle {
584 use POSIX qw(sigprocmask sigsuspend SIG_SETMASK);
585 my $classname = shift;
586 my $text = shift;
588 Throttle::GetClassInfo($classname)
589 or return -1; # no such throttle class
591 my $throttled = 0;
592 my $proceed = 0;
593 my $error = 0;
594 my $controldead = 0;
595 my $setempty = POSIX::SigSet->new;
596 my $setfull = POSIX::SigSet->new;
597 $setempty->emptyset();
598 $setfull->fillset();
599 $SIG{'TERM'} = sub {$throttled = 1};
600 $SIG{'USR1'} = sub {$proceed = 1};
601 $SIG{'USR2'} = sub {$error = 1};
602 $SIG{'PIPE'} = sub {$controldead = 1};
603 $SIG{'ALRM'} = sub {};
605 # After writing we can expect a SIGTERM, SIGUSR1 or SIGUSR2
606 print $pipewrite "\nthrottle $$ $classname $text\n";
607 my $old = POSIX::SigSet->new;
608 sigprocmask(SIG_SETMASK, $setfull, $old);
609 until ($controldead || $throttled || $proceed || $error) {
610 alarm(30);
611 sigsuspend($setempty);
612 alarm(0);
613 sigprocmask(SIG_SETMASK, $setempty, $old);
614 print $pipewrite "\nkeepalive $$\n";
615 sigprocmask(SIG_SETMASK, $setfull, $old);
617 sigprocmask(SIG_SETMASK, $setempty, $old);
618 $SIG{'TERM'} = "DEFAULT";
619 $SIG{'USR1'} = "DEFAULT";
620 $SIG{'USR2'} = "DEFAULT";
621 $SIG{'ALRM'} = "DEFAULT";
622 $SIG{'PIPE'} = "DEFAULT";
624 my $result = -1;
625 if ($throttled) {
626 $result = 1;
627 } elsif ($proceed) {
628 $result = 0;
630 return $result;
633 sub clone {
634 my ($name) = @_;
635 Girocco::Project::does_exist($name, 1) or die "no such project: $name";
636 my $proj = Girocco::Project->load($name);
637 $proj or die "failed to load project $name";
638 $proj->{clone_in_progress} or die "project $name is not marked for cloning";
639 $proj->{clone_logged} and die "project $name is already being cloned";
640 request_throttle("clone", $name) <= 0 or die "cloning $name aborted (throttled)";
641 statmsg "cloning $name";
642 open STDOUT, '>', "$Girocco::Config::reporoot/$name.git/.clonelog" or die "cannot open clonelog: $!";
643 open STDERR, ">&STDOUT";
644 open STDIN, '<', '/dev/null';
645 exec "$Girocco::Config::basedir/taskd/clone.sh", "$name.git" or die "exec failed: $!";
648 sub ref_indicator {
649 return ' -> ' unless $showff && defined($_[0]);
650 my ($git_dir, $old, $new) = @_;
651 return '..' unless defined($old) && defined($new) && $old !~ /^0+$/ && $new !~ /^0+$/ && $old ne $new;
652 # In many cases `git merge-base` is slower than this even if using the
653 # `--is-ancestor` option available since Git 1.8.0, but it's never faster
654 my $ans = get_git("--git-dir=$git_dir", "rev-list", "-n", "1", "^$new^0", "$old^0", "--") ? '...' : '..';
655 return wantarray ? ($ans, 1) : $ans;
658 sub ref_change {
659 my ($arg) = @_;
660 my ($username, $name, $oldrev, $newrev, $ref) = split(/\s+/, $arg);
661 $username && $name && $oldrev && $newrev && $ref or return 0;
662 $oldrev =~ /^[0-9a-f]{40}$/ && $newrev =~ /^[0-9a-f]{40}$/ && $ref =~ m{^refs/} or return 0;
663 $newrev ne $oldrev or return 0;
665 Girocco::Project::does_exist($name, 1) or die "no such project: $name";
666 my $proj = Girocco::Project->load($name);
667 $proj or die "failed to load project $name";
668 my $has_notify = $proj->has_notify;
669 my $type = $has_notify ? "notify" : "change";
671 my $user;
672 if ($username && $username !~ /^%.*%$/) {
673 Girocco::User::does_exist($username, 1) or die "no such user: $username";
674 $user = Girocco::User->load($username);
675 $user or die "failed to load user $username";
676 } elsif ($username eq "%$name%") {
677 $username = "-";
680 request_throttle("ref-change", $name) <= 0 or die "ref-change $name aborted (throttled)";
681 my $ind = ref_indicator($proj->{path}, $oldrev, $newrev);
682 statmsg "ref-$type $username $name ($ref: @{[substr($oldrev,0,$abbrev)]}$ind@{[substr($newrev,0,$abbrev)]})";
683 open STDIN, '<', '/dev/null';
684 Girocco::Notify::ref_change($proj, $user, $ref, $oldrev, $newrev) if $has_notify;
685 return 0;
688 sub ref_changes {
689 my ($arg) = @_;
690 my ($username, $name) = split(/\s+/, $arg);
691 $username && $name or return 0;
693 Girocco::Project::does_exist($name, 1) or die "no such project: $name";
694 my $proj = Girocco::Project->load($name);
695 $proj or die "failed to load project $name";
696 my $has_notify = $proj->has_notify;
697 my $type = $has_notify ? "notify" : "change";
699 my $user;
700 if ($username && $username !~ /^%.*%$/) {
701 Girocco::User::does_exist($username, 1) or die "no such user: $username";
702 $user = Girocco::User->load($username);
703 $user or die "failed to load user $username";
704 } elsif ($username eq "%$name%") {
705 $username = "-";
708 my @changes = ();
709 while (my $change = <STDIN>) {
710 my ($oldrev, $newrev, $ref) = split(/\s+/, $change);
711 $oldrev =~ /^[0-9a-f]{40}$/ && $newrev =~ /^[0-9a-f]{40}$/ && $ref =~ m{^refs/} or next;
712 $newrev ne $oldrev or next;
713 push(@changes, [$oldrev, $newrev, $ref]);
715 return 0 unless @changes;
716 open STDIN, '<', '/dev/null';
717 request_throttle("ref-change", $name) <= 0 or die "ref-changes $name aborted (throttled)";
718 foreach my $change (@changes) {
719 my ($oldrev, $newrev, $ref) = @$change;
720 my ($ind, $rangit) = ref_indicator($proj->{path}, $oldrev, $newrev);
721 statmsg "ref-$type $username $name ($ref: @{[substr($oldrev,0,$abbrev)]}$ind@{[substr($newrev,0,$abbrev)]})";
722 Girocco::Notify::ref_change($proj, $user, $ref, $oldrev, $newrev) if $has_notify;
723 sleep 1 if $has_notify || $rangit;
725 return 0;
728 sub throttle {
729 my ($arg) = @_;
730 my ($pid, $classname, $text) = split(/\s+/, $arg);
731 $pid =~ /^\d+/ or return 0; # invalid pid
732 $pid += 0;
733 $pid > 0 or return 0; # invalid pid
734 kill(0, $pid) || $!{EPERM} or return 0; # no such process
735 Throttle::GetClassInfo($classname) or return 0; # no such throttle class
736 defined($text) && $text ne '' or return 0; # no text no service
738 my $throttled = 0;
739 my $proceed = 0;
740 my $error = 0;
741 my $controldead = 0;
742 my $suppdead = 0;
743 my ($waker, $wakew);
744 pipe($waker, $wakew) or die "pipe failed: $!";
745 select((select($wakew),$|=1)[0]);
746 setnonblock($wakew);
747 $SIG{'TERM'} = sub {$throttled = 1; syswrite($wakew, '!')};
748 $SIG{'USR1'} = sub {$proceed = 1; syswrite($wakew, '!')};
749 $SIG{'USR2'} = sub {$error = 1; syswrite($wakew, '!')};
750 $SIG{'PIPE'} = sub {$controldead = 1; syswrite($wakew, '!')};
751 select((select(STDIN),$|=1)[0]);
753 logmsg "throttle $pid $classname $text request";
754 # After writing we can expect a SIGTERM or SIGUSR1
755 print $pipewrite "\nthrottle $$ $classname $text\n";
757 # NOTE: the only way to detect the socket close is to read all the
758 # data until EOF is reached -- recv can be used to peek.
759 my $v = '';
760 vec($v, fileno(STDIN), 1) = 1;
761 vec($v, fileno($waker), 1) = 1;
762 setnonblock(\*STDIN);
763 setnonblock($waker);
764 until ($controldead || $throttled || $proceed || $error || $suppdead) {
765 my ($r, $e);
766 select($r=$v, undef, $e=$v, 30);
767 my ($bytes, $discard);
768 do {$bytes = sysread($waker, $discard, 512)} while (defined($bytes) && $bytes > 0);
769 do {$bytes = sysread(STDIN, $discard, 4096)} while (defined($bytes) && $bytes > 0);
770 $suppdead = 1 unless !defined($bytes) && $!{EAGAIN};
771 print $pipewrite "\nkeepalive $$\n";
773 setblock(\*STDIN);
775 if ($throttled && !$suppdead) {
776 print STDIN "throttled\n";
777 logmsg "throttle $pid $classname $text throttled";
778 } elsif ($proceed && !$suppdead) {
779 print STDIN "proceed\n";
780 logmsg "throttle $pid $classname $text proceed";
781 $SIG{'TERM'} = 'DEFAULT';
782 # Stay alive until the child dies which we detect by EOF on STDIN
783 setnonblock(\*STDIN);
784 until ($controldead || $suppdead) {
785 my ($r, $e);
786 select($r=$v, undef, $e=$v, 30);
787 my ($bytes, $discard);
788 do {$bytes = sysread($waker, $discard, 512)} while (defined($bytes) && $bytes > 0);
789 do {$bytes = sysread(STDIN, $discard, 512)} while (defined($bytes) && $bytes > 0);
790 $suppdead = 1 unless !defined($bytes) && $!{EAGAIN};
791 print $pipewrite "\nkeepalive $$\n";
793 setblock(\*STDIN);
794 } else {
795 my $prefix = '';
796 $prefix = "control" if $controldead && !$suppdead;
797 logmsg "throttle $pid $classname $text ${prefix}died";
799 exit 0;
802 sub process_pipe_msg {
803 my ($act, $pid, $cls, $text) = split(/\s+/, $_[0]);
804 if ($act eq "throttle") {
805 $pid =~ /^\d+$/ or return 0;
806 $pid += 0;
807 $pid > 0 or return 0; # invalid pid
808 kill(0, $pid) or return 0; # invalid pid
809 defined($cls) && $cls ne "" or kill('USR2', $pid), return 0;
810 defined($text) && $text ne "" or kill('USR2', $pid), return 0;
811 Throttle::GetClassInfo($cls) or kill('USR2', $pid), return 0;
812 # the AddSupplicant call could send SIGUSR1 before it returns
813 my $result = Throttle::AddSupplicant($pid, $cls, $text);
814 kill('USR2', $pid), return 0 if $result < 0;
815 kill('TERM', $pid), return 0 if $result > 0;
816 # $pid was added to class $cls and will receive SIGUSR1 when
817 # it's time for it to proceed
818 return 0;
819 } elsif ($act eq "keepalive") {
820 # nothing to do although we could verify pid is valid and
821 # still in %Throttle::pids and send a SIGUSR2 if not, but
822 # really keepalive should just be ignored.
823 return 0;
825 print STDERR "discarding unknown pipe message \"$_[0]\"\n";
826 return 0;
830 ## -------
831 ## OStream
832 ## -------
835 package OStream;
837 # Set to 1 for only syslog output (if enabled by mode)
838 # Set to 2 for only stderr output (if enabled by mode)
839 our $only = 0; # This is a hack
841 use Carp 'croak';
842 use Sys::Syslog qw(:DEFAULT :macros);
844 sub writeall {
845 use POSIX qw();
846 use Errno;
847 my ($fd, $data) = @_;
848 my $offset = 0;
849 my $remaining = length($data);
850 while ($remaining) {
851 my $bytes = POSIX::write(
852 $fd,
853 substr($data, $offset, $remaining),
854 $remaining);
855 next if !defined($bytes) && $!{EINTR};
856 croak "POSIX::write failed: $!" unless defined $bytes;
857 croak "POSIX::write wrote 0 bytes" unless $bytes;
858 $remaining -= $bytes;
859 $offset += $bytes;
863 sub dumpline {
864 use POSIX qw(STDERR_FILENO);
865 my ($self, $line) = @_;
866 $only = 0 unless defined($only);
867 writeall(STDERR_FILENO, $line) if $self->{'stderr'} && $only != 1;
868 substr($line, -1, 1) = '' if substr($line, -1, 1) eq "\n";
869 return unless length($line);
870 syslog(LOG_NOTICE, "%s", $line) if $self->{'syslog'} && $only != 2;
873 sub TIEHANDLE {
874 my $class = shift || 'OStream';
875 my $mode = shift;
876 my $syslogname = shift;
877 my $syslogfacility = shift;
878 defined($syslogfacility) or $syslogfacility = LOG_USER;
879 my $self = {};
880 $self->{'syslog'} = $mode > 0;
881 $self->{'stderr'} = $mode <= 0 || $mode > 1;
882 $self->{'lastline'} = '';
883 if ($self->{'syslog'}) {
884 # Some Sys::Syslog have a stupid default setlogsock order
885 eval {Sys::Syslog::setlogsock("native"); 1;} or
886 eval {Sys::Syslog::setlogsock("unix");};
887 openlog($syslogname, "ndelay,pid", $syslogfacility)
888 or croak "Sys::Syslog::openlog failed: $!";
890 return bless $self, $class;
893 sub BINMODE {return 1}
894 sub FILENO {return undef}
895 sub EOF {return 0}
896 sub CLOSE {return 1}
898 sub PRINTF {
899 my $self = shift;
900 my $template = shift;
901 return $self->PRINT(sprintf $template, @_);
904 sub PRINT {
905 my $self = shift;
906 my $data = join('', $self->{'lastline'}, @_);
907 my $pos = 0;
908 while ((my $idx = index($data, "\n", $pos)) >= 0) {
909 ++$idx;
910 my $line = substr($data, $pos, $idx - $pos);
911 substr($data, $pos, $idx - $pos) = '';
912 $pos = $idx;
913 $self->dumpline($line);
915 $self->{'lastline'} = $data;
916 return 1;
919 sub DESTROY {
920 my $self = shift;
921 $self->dumpline($self->{'lastline'})
922 if length($self->{'lastline'});
923 closelog;
926 sub WRITE {
927 my $self = shift;
928 my ($scalar, $length, $offset) = @_;
929 $scalar = '' if !defined($scalar);
930 $length = length($scalar) if !defined($length);
931 croak "OStream::WRITE invalid length $length"
932 if $length < 0;
933 $offset = 0 if !defined($offset);
934 $offset += length($scalar) if $offset < 0;
935 croak "OStream::WRITE invalid write offset"
936 if $offset < 0 || $offset > $length;
937 my $max = length($scalar) - $offset;
938 $length = $max if $length > $max;
939 $self->PRINT(substr($scalar, $offset, $length));
940 return $length;
944 ## ----
945 ## main
946 ## ----
949 package main;
951 close(DATA) if fileno(DATA);
952 my $sfac;
953 Getopt::Long::Configure('bundling');
954 my ($stiv, $idiv);
955 my $parse_res = GetOptions(
956 'help|?|h' => sub {pod2usage(-verbose => 2, -exitval => 0)},
957 'quiet|q' => \$quiet,
958 'no-quiet' => sub {$quiet = 0},
959 'progress|P' => \$progress,
960 'inetd|i' => sub {$inetd = 1; $syslog = 1; $quiet = 1;},
961 'idle-timeout|t=i' => \$idle_timeout,
962 'syslog|s:s' => \$sfac,
963 'no-syslog' => sub {$syslog = 0; $sfac = undef;},
964 'stderr' => \$stderr,
965 'abbrev=i' => \$abbrev,
966 'show-fast-forward-info' => \$showff,
967 'no-show-fast-forward-info' => sub {$showff = 0},
968 'status-interval=i' => \$stiv,
969 'idle-status-interval=i' => \$idiv,
970 ) || pod2usage(2);
971 $syslog = 1 if defined($sfac);
972 $progress = 1 unless $quiet;
973 $abbrev = 128 unless $abbrev > 0;
974 if (defined($idle_timeout)) {
975 die "--idle-timeout must be a whole number" unless $idle_timeout =~ /^\d+$/;
976 die "--idle-timeout may not be used without --inetd" unless $inetd;
978 if (defined($stiv)) {
979 die "--status-interval must be a whole number" unless $stiv =~ /^\d+$/;
980 $statusintv = $stiv * 60;
982 if (defined($idiv)) {
983 die "--idle-status-interval must be a whole number" unless $idiv =~ /^\d+$/;
984 $idleintv = $idiv * 60;
987 open STDOUT, '>&STDERR' if $inetd;
988 if ($syslog) {
989 use Sys::Syslog qw();
990 my $mode = 1;
991 ++$mode if $stderr;
992 $sfac = "user" unless defined($sfac) && $sfac ne "";
993 my $ofac = $sfac;
994 $sfac = uc($sfac);
995 $sfac = 'LOG_'.$sfac unless $sfac =~ /^LOG_/;
996 my $facility;
997 my %badfac = map({("LOG_$_" => 1)}
998 (qw(PID CONS ODELAY NDELAY NOWAIT PERROR FACMASK NFACILITIES PRIMASK LFMT)));
999 eval "\$facility = Sys::Syslog::$sfac; 1" or die "invalid syslog facility: $ofac";
1000 die "invalid syslog facility: $ofac"
1001 if ($facility & ~0xf8) || ($facility >> 3) > 23 || $badfac{$sfac};
1002 tie *STDERR, 'OStream', $mode, $progname, $facility or die "tie failed";
1004 if ($quiet) {
1005 open STDOUT, '>', '/dev/null';
1006 } elsif ($inetd) {
1007 *STDOUT = *STDERR;
1010 my $NAME;
1012 if ($inetd) {
1013 open Server, '<&=0' or die "open: $!";
1014 my $sockname = getsockname Server;
1015 die "getsockname: $!" unless $sockname;
1016 die "socket already connected! must be 'wait' socket" if getpeername Server;
1017 die "getpeername: $!" unless $!{ENOTCONN};
1018 my $st = getsockopt Server, SOL_SOCKET, SO_TYPE;
1019 die "getsockopt(SOL_SOCKET, SO_TYPE): $!" unless $st;
1020 my $socktype = unpack('i', $st);
1021 die "stream socket required" unless defined $socktype && $socktype == SOCK_STREAM;
1022 die "AF_UNIX socket required" unless sockaddr_family($sockname) == AF_UNIX;
1023 $NAME = unpack_sockaddr_un $sockname;
1024 my $expected = $Girocco::Config::chroot.'/etc/taskd.socket';
1025 warn "listening on \"$NAME\" but expected \"$expected\"" unless $NAME eq $expected;
1026 my $mode = (stat($NAME))[2];
1027 die "stat: $!" unless $mode;
1028 $mode &= 07777;
1029 if (($mode & 0660) != 0660) {
1030 chmod(($mode|0660), $NAME) == 1 or die "chmod ug+rw \"$NAME\" failed: $!";
1032 } else {
1033 $NAME = $Girocco::Config::chroot.'/etc/taskd.socket';
1034 my $uaddr = sockaddr_un($NAME);
1036 socket(Server, PF_UNIX, SOCK_STREAM, 0) or die "socket failed: $!";
1037 unlink($NAME);
1038 bind(Server, $uaddr) or die "bind failed: $!";
1039 listen(Server, SOMAXCONN) or die "listen failed: $!";
1040 chmod 0666, $NAME or die "chmod failed: $!";
1043 foreach my $throttle (@Girocco::Config::throttle_classes, @throttle_defaults) {
1044 my $classname = $throttle->{"name"};
1045 $classname or next;
1046 Throttle::GetClassInfo($classname, $throttle);
1049 sub _min {
1050 return $_[0] <= $_[1] ? $_[0] : $_[1];
1053 pipe($piperead, $pipewrite) or die "pipe failed: $!";
1054 setnonblock($piperead);
1055 select((select($pipewrite), $|=1)[0]);
1056 my $pipebuff = '';
1057 my $fdset_both = '';
1058 vec($fdset_both, fileno($piperead), 1) = 1;
1059 my $fdset_pipe = $fdset_both;
1060 vec($fdset_both, fileno(Server), 1) = 1;
1061 my $penalty = 0;
1062 my $t = time;
1063 my $penaltytime = $t;
1064 my $nextwakeup = $t + 60;
1065 my $nextstatus = undef;
1066 $nextstatus = $t + $statusintv if $statusintv;
1067 statmsg "listening on $NAME";
1068 while (1) {
1069 my ($rout, $eout, $nfound);
1070 do {
1071 my $wait;
1072 my $now = time;
1073 my $adjustpenalty = sub {
1074 if ($penaltytime < $now) {
1075 my $credit = $now - $penaltytime;
1076 $penalty = $penalty > $credit ? $penalty - $credit : 0;
1077 $penaltytime = $now;
1080 if (defined($nextstatus) && $now >= $nextstatus) {
1081 unless ($idlestatus && !$children && (!$idleintv || $now - $idlestatus < $idleintv)) {
1082 my $statmsg = "STATUS: $children active";
1083 my @running = ();
1084 if ($children) {
1085 my @stats = ();
1086 my $cnt = 0;
1087 foreach my $cls (sort(Throttle::GetClassList())) {
1088 my $inf = Throttle::GetClassInfo($cls);
1089 if ($inf->{'total'}) {
1090 $cnt += $inf->{'total'};
1091 push(@stats, substr(lc($cls),0,1)."=".
1092 $inf->{'total'}.'/'.$inf->{'active'});
1095 push(@stats, "?=".($children-$cnt)) if @stats && $cnt < $children;
1096 $statmsg .= " (".join(" ",@stats).")" if @stats;
1097 foreach (Throttle::GetRunningPids()) {
1098 my ($cls, $ts, $desc) = Throttle::GetPidInfo($_);
1099 next unless $ts;
1100 push(@running, "[${cls}::$desc] ".duration($now-$ts));
1103 my $idlesecs;
1104 $statmsg .= ", idle " . duration($idlesecs)
1105 if !$children && ($idlesecs = $now - $idlestart) >= 2;
1106 statmsg $statmsg;
1107 statmsg "STATUS: currently running: ".join(", ", @running)
1108 if @running;
1109 $idlestatus = $now if !$children;
1111 $nextstatus += $statusintv while $nextstatus <= $now;
1113 $nextwakeup += 60, $now = time while ($wait = $nextwakeup - $now) <= 0;
1114 $wait = _min($wait, (Throttle::ServiceQueue()||60));
1115 &$adjustpenalty; # this prevents ignoring accept when we shouldn't
1116 my $fdset;
1117 if ($penalty <= $maxspawn) {
1118 $fdset = $fdset_both;
1119 } else {
1120 $fdset = $fdset_pipe;
1121 $wait = $penalty - $maxspawn if $wait > $penalty - $maxspawn;
1123 $nfound = select($rout=$fdset, undef, $eout=$fdset, $wait);
1124 logmsg("select failed: $!"), exit(1) unless $nfound >= 0 || $!{EINTR} || $!{EAGAIN};
1125 my $reaped;
1126 Throttle::RemoveSupplicant($reaped) while ($reaped = shift(@reapedpids));
1127 $now = time;
1128 &$adjustpenalty; # this prevents banking credits for elapsed time
1129 if ($idle_timeout && !$children && !$nfound && $now - $idlestart >= $idle_timeout) {
1130 statmsg "idle timeout (@{[duration($idle_timeout)]}) exceeded now exiting";
1131 exit 0;
1133 } while $nfound < 1;
1134 my $reout = $rout | $eout;
1135 if (vec($reout, fileno($piperead), 1)) {{
1136 my $nloff = -1;
1138 my $bytes;
1139 do {$bytes = sysread($piperead, $pipebuff, 512, length($pipebuff))}
1140 while (!defined($bytes) && $!{EINTR});
1141 last if !defined($bytes) && $!{EAGAIN};
1142 die "sysread failed: $!" unless defined $bytes;
1143 # since we always keep a copy of $pipewrite open EOF is fatal
1144 die "sysread returned EOF on pipe read" unless $bytes;
1145 $nloff = index($pipebuff, "\n", 0);
1146 if ($nloff < 0 && length($pipebuff) >= 512) {
1147 $pipebuff = '';
1148 print STDERR "discarding 512 bytes of control pipe data with no \\n found\n";
1150 redo unless $nloff >= 0;
1152 last unless $nloff >= 0;
1153 do {
1154 my $msg = substr($pipebuff, 0, $nloff);
1155 substr($pipebuff, 0, $nloff + 1) = '';
1156 $nloff = index($pipebuff, "\n", 0);
1157 process_pipe_msg($msg) if length($msg);
1158 } while $nloff >= 0;
1159 redo;
1161 next unless vec($reout, fileno(Server), 1);
1162 unless (accept(Client, Server)) {
1163 logmsg "accept failed: $!" unless $!{EINTR};
1164 next;
1166 logmsg "connection on $NAME";
1167 ++$penalty;
1168 spawn sub {
1169 my $inp = <STDIN>;
1170 $inp = <STDIN> if defined($inp) && $inp eq "\n";
1171 chomp $inp if defined($inp);
1172 $inp or exit 0; # ignore empty connects
1173 my ($cmd, $arg) = $inp =~ /^([a-zA-Z][a-zA-Z0-9._+-]*)(?:\s+(.*))?$/;
1174 defined($arg) or $arg = '';
1175 if ($cmd eq 'ref-changes') {
1176 ref_changes($arg);
1177 } elsif ($cmd eq 'clone') {
1178 clone($arg);
1179 } elsif ($cmd eq 'ref-change') {
1180 ref_change($arg);
1181 } elsif ($cmd eq 'throttle') {
1182 throttle($arg);
1183 } else {
1184 die "ignoring unknown command: $cmd\n";
1187 close Client;
1191 ## -------------
1192 ## Documentation
1193 ## -------------
1196 __END__
1198 =head1 NAME
1200 taskd.pl - Perform Girocco service tasks
1202 =head1 SYNOPSIS
1204 taskd.pl [options]
1206 Options:
1207 -h | --help detailed instructions
1208 -q | --quiet run quietly
1209 --no-quiet do not run quietly
1210 -P | --progress show occasional status updates
1211 -i | --inetd run as inetd unix stream wait service
1212 implies --quiet --syslog
1213 -t SECONDS | --idle-timeout=SECONDS how long to wait idle before exiting
1214 requires --inetd
1215 -s | --syslog[=facility] send messages to syslog instead of
1216 stderr but see --stderr
1217 enabled by --inetd
1218 --no-syslog do not send message to syslog
1219 --stderr always send messages to stderr too
1220 --abbrev=n abbreviate hashes to n (default is 8)
1221 --show-fast-forward-info show fast-forward info (default is on)
1222 --no-show-fast-forward-info disable showing fast-forward info
1223 --status-interval=MINUTES status update interval (default 1)
1224 --idle-status-interval=IDLEMINUTES idle status interval (default 60)
1226 =head1 OPTIONS
1228 =over 8
1230 =item B<--help>
1232 Print the full description of taskd.pl's options.
1234 =item B<--quiet>
1236 Suppress non-error messages, e.g. for use when running this task as an inetd
1237 service. Enabled by default by --inetd.
1239 =item B<--no-quiet>
1241 Enable non-error messages. When running in --inetd mode these messages are
1242 sent to STDERR instead of STDOUT.
1244 =item B<--progress>
1246 Show information about the current status of the task operation occasionally.
1247 This is automatically enabled if --quiet is not given.
1249 =item B<--inetd>
1251 Run as an inetd wait service. File descriptor 0 must be an unconnected unix
1252 stream socket ready to have accept called on it. To be useful, the unix socket
1253 should be located at "$Girocco::Config::chroot/etc/taskd.socket". A warning
1254 will be issued if the socket is not in the expected location. Socket file
1255 permissions will be adjusted if necessary and if they cannot be taskd.pl will
1256 die. The --inetd option also enables the --quiet and --syslog options but
1257 --no-quiet and --no-syslog may be used to alter that.
1259 The correct specification for the inetd socket is a "unix" protocol "stream"
1260 socket in "wait" mode with user and group writable permissions (0660). An
1261 attempt will be made to alter the socket's file mode if needed and if that
1262 cannot be accomplished taskd.pl will die.
1264 Although most inetd stream services run in nowait mode, taskd.pl MUST be run
1265 in wait mode and will die if the passed in socket is already connected.
1267 Note that while *BSD's inetd happily supports unix sockets (and so does
1268 Darwin's launchd), neither xinetd nor GNU's inetd supports unix sockets.
1269 However, systemd does seem to.
1271 =item B<--idle-timeout=SECONDS>
1273 Only permitted when running in --inetd mode. After SECONDS of inactivity
1274 (i.e. all outstanding tasks have completed and no new requests have come in)
1275 exit normally. The default is no timeout at all (a SECONDS value of 0).
1276 Note that it may actually take up to SECONDS+60 for the idle exit to occur.
1278 =item B<--syslog[=facility]>
1280 Normally error output is sent to STDERR. With this option it's sent to
1281 syslog instead. Note that when running in --inetd mode non-error output is
1282 also affected by this option as it's sent to STDERR in that case. If
1283 not specified, the default for facility is LOG_USER. Facility names are
1284 case-insensitive and the leading 'LOG_' is optional. Messages are logged
1285 with the LOG_NOTICE priority.
1287 =item B<--no-syslog>
1289 Send error message output to STDERR but not syslog.
1291 =item B<--stderr>
1293 Always send error message output to STDERR. If --syslog is in effect then
1294 a copy will also be sent to syslog. In --inetd mode this applies to non-error
1295 messages as well.
1297 =item B<--abbrev=n>
1299 Abbreviate displayed hash values to only the first n hexadecimal characters.
1300 The default is 8 characters. Set to 0 for no abbreviation at all.
1302 =item B<--show-fast-forward-info>
1304 Instead of showing ' -> ' in ref-change/ref-notify update messages, show either
1305 '..' for a fast-forward, creation or deletion or '...' for non-fast-forward.
1306 This requires running an extra git command for each ref update that is not a
1307 creation or deletion in order to determine whether or not it's a fast forward.
1309 =item B<--no-show-fast-forward-info>
1311 Disable showing of fast-forward information for ref-change/ref-notify update
1312 messages. Instead just show a ' -> ' indicator.
1314 =item B<--status-interval=MINUTES>
1316 If progress is enabled (with --progress or by default if no --inetd or --quiet)
1317 status updates are shown at each MINUTES interval. Setting the interval to 0
1318 disables them entirely even with --progress.
1320 =item B<--idle-status-interval=IDLEMINUTES>
1322 Two consecutive "idle" status updates with no intervening activity will not be
1323 shown unless IDLEMINUTES have elapsed between them. The default is 60 minutes.
1324 Setting the interval to 0 prevents any consecutive idle updates (with no
1325 activity between them) from appearing at all.
1327 =back
1329 =head1 DESCRIPTION
1331 taskd.pl is Girocco's service request servant; it listens for service requests
1332 such as new clone requests and ref update notifications and spawns a task to
1333 perform the requested action.
1335 =cut