Debian Codegraph @

debian/patches/extra_send-uucp

raw
1 --- /dev/null
2 +++ b/extra/etc/send-uucp.cf
3 @@ -0,0 +1,26 @@
4 +#
5 +# send-uucp.cf Configuration file for send-uucp
6 +#
7 +# Format: sitename<Space>compressor<Space>maxsize<Space>batchtime
8 +#
9 +# compressor, maxsize and batchtime can be left out and will
10 +# then use the # default values. You can't leave out the second
11 +# field (compressor) and still use the third (maxsize) etc.!
12 +# So if you want to set a maxsize, you HAVE to add a
13 +# compression method.
14 +#
15 +# Compress keywords are: compress gzip none
16 +#
17 +# You can use flags with your compressor, just add them. Use
18 +# the `_' character instead of a space.
19 +# For example compress_-b13 for 13 bits compression.
20 +#
21 +# Remember that the size you set is the size *before* compression!
22 +#
23 +#zoetermeer gzip 1048576 5,18,22
24 +#hoofddorp gzip 1048576 5,18,22
25 +#pa3ebv gzip 1048576 5,18,22
26 +#drinkel gzip 1048576 5,6,18,20,22,0,2
27 +#manhole compress 1048576 5,18,22
28 +#owl compress 1048576 5,18,22
29 +#able compress 1048576 5,18,22
30 --- /dev/null
31 +++ b/extra/send-uucp.pl
32 @@ -0,0 +1,355 @@
33 +#!/usr/bin/perl -w
34 +require '/usr/lib/news/innshellvars.pl';
35 +
36 +##############################################################################
37 +# send-uucp.pl create news batches from the outgoing files
38 +#
39 +# Author: Edvard Tuinder <[email protected]>
40 +#
41 +# Copyright (C) 1994 Edvard Tuinder - ELM Consultancy B.V.
42 +# Copyright (C) 1995-1997 Miquel van Smoorenburg - Cistron Internet Services
43 +#
44 +# Copyright (C) 2003 Marco d'Itri <[email protected]>
45 +# Nearly rewritten. Added syslog support, real errors checking and more.
46 +#
47 +# This program is free software; you can redistribute it and/or modify it
48 +# under the terms of the GNU General Public License as published by the Free
49 +# Software Foundation; either version 2 of the License, or (at your option)
50 +# any later version.
51 +##############################################################################
52 +
53 +use strict;
54 +use Sys::Syslog;
55 +
56 +# for compatibility with INN 1.x
57 +$inn::pathetc ||= '/etc/news';
58 +$inn::syslog_facility ||= 'news';
59 +
60 +# some default values
61 +my $MAXSIZE = 500000;
62 +my $MAXJOBS = 200;
63 +
64 +my %UNBATCHER = (
65 + compress => 'cunbatch',
66 + bzip2 => 'bunbatch',
67 + gzip => 'gunbatch',
68 + xz => 'xunbatch',
69 +);
70 +
71 +my $UUX_FLAGS = '- -z -r -gd';
72 +my $BATCHER_FLAGS = '';
73 +
74 +##############################################################################
75 +my $config_file = $inn::pathetc . '/send-uucp.cf';
76 +my $lockfile = $inn::locks . '/LOCK.send-uucp';
77 +
78 +openlog('send-uucp', 'pid', $inn::syslog_facility);
79 +
80 +my @sitelist;
81 +if (@ARGV) {
82 + foreach my $site (@ARGV) {
83 + my @cfg = read_cf($config_file, $site);
84 + if (not @cfg) {
85 + logmsg("site $site not found in the configuration", 'err');
86 + next;
87 + }
88 + push @sitelist, @cfg;
89 + }
90 +} else {
91 + @sitelist = read_cf($config_file, undef);
92 +}
93 +
94 +if (not @sitelist) {
95 + logmsg('nothing to do', 'debug');
96 + exit 0;
97 +}
98 +
99 +chdir $inn::batch or logdie("Can't access $inn::batch: $!", 'crit');
100 +
101 +shlock($lockfile);
102 +
103 +run_site($_) foreach @sitelist;
104 +unlink $lockfile;
105 +exit 0;
106 +
107 +# lint food
108 +$inn::compress.$inn::locks.$inn::syslog_facility.$inn::have_uustat = 0 if 0;
109 +
110 +##############################################################################
111 +sub read_cf {
112 + my ($conf_file, $site_wanted) = @_;
113 +
114 + my $hour = (localtime time)[2];
115 +
116 + my @sites;
117 + open(CF, $conf_file) or logdie("cannot open $conf_file: $!", 'crit');
118 + while (<CF>) {
119 + chop;
120 + s/\s*\#.*$//;
121 + next if /^$/;
122 +
123 + my ($sitespec, $compress, $size, $time) = split(/\s+/);
124 + next if not $sitespec;
125 +
126 + my ($site, $host) = split(/:/, $sitespec);
127 + $host = $site if not $host;
128 +
129 + $compress =~ s/_/ /g if $compress;
130 +
131 + if ($site_wanted) {
132 + if ($site eq $site_wanted) {
133 + push @sites, [$site, $host, $compress, $size];
134 + last;
135 + }
136 + next;
137 + }
138 +
139 + if ($time) {
140 + foreach my $time (split(/,/, $time)) {
141 + next if $time != $hour;
142 + push @sites, [$site, $host, $compress, $size];
143 + }
144 + } else {
145 + push @sites, [$site, $host, $compress, $size];
146 + }
147 + }
148 + close CF;
149 + return @sites;
150 +}
151 +
152 +##############################################################################
153 +# count number of jobs in the UUCP queue for a given site
154 +sub count_jobs {
155 + my ($site) = @_;
156 +
157 + return 0 if not $inn::have_uustat;
158 + open(JOBS, "uustat -s $site 2> /dev/null |") or logdie("cannot fork: $!");
159 + my $count = grep(/ Executing rnews /, <JOBS>);
160 + close JOBS; # ignore errors, uustat may fail
161 + return $count;
162 +}
163 +
164 +# select the rnews label appropriate for the compressor program used
165 +sub unbatcher {
166 + my ($compressor) = @_;
167 +
168 + $compressor =~ s%.*/%%;
169 + return $UNBATCHER{$compressor} || 'cunbatch';
170 +}
171 +
172 +##############################################################################
173 +# batch articles for one site
174 +sub run_site {
175 + my ($cfg) = @_;
176 + my ($site, $host, $compress, $size) = @$cfg;
177 +
178 + logmsg("checking site $site", 'debug');
179 + my $maxjobs = '';
180 + if ($MAXJOBS) {
181 + my $jobs = count_jobs($site);
182 + if ($jobs >= $MAXJOBS) {
183 + logmsg("too many jobs queued for $site");
184 + return;
185 + }
186 + $maxjobs = '-N ' . ($MAXJOBS - $jobs);
187 + }
188 +
189 + $compress ||= $inn::compress;
190 + $size ||= $MAXSIZE;
191 +
192 + # if exists a .work temp file left by a previous invocation, append
193 + # it to the current batch file
194 + if (-f "$site.work") {
195 + my $err = '';
196 + open(OUT, ">>$site") or logdie("cannot open $site: $!");
197 + open(IN, "$site.work") or logdie("cannot open $site.work: $!");
198 + print OUT while <IN>;
199 + close IN;
200 + close OUT or logdie("cannot close $site: $!");;
201 + }
202 +
203 + if (not -f $site) {
204 + logmsg("no batch file for site $site", 'err');
205 + return;
206 + }
207 +
208 + rename($site, "$site.work") or logdie("cannot rename $site: $!", 'crit');
209 + ctlinnd('-t120', 'flush', $site);
210 + if (not -s "$site.work") {
211 + logmsg("no articles for $site", 'debug');
212 + unlink "$site.work" or logmsg("cannot delete $site.work: $!", 'err');
213 + } else {
214 + if ($compress eq 'none') {
215 + system "batcher -b $size $maxjobs $BATCHER_FLAGS "
216 + . "-p\"uux $UUX_FLAGS %s!rnews\" $host $site.work";
217 + } else {
218 + system "batcher -b $size $maxjobs $BATCHER_FLAGS "
219 + . "-p\"{ echo '#! " . unbatcher($compress)
220 + . "' ; exec $compress; } | "
221 + . "uux $UUX_FLAGS %s!rnews\" $host $site.work";
222 + }
223 + logmsg("batched articles for $site", 'debug');
224 + }
225 +}
226 +
227 +##############################################################################
228 +sub logmsg {
229 + my ($msg, $lvl) = @_;
230 +
231 + syslog($lvl || 'notice', '%s', $msg);
232 +}
233 +
234 +sub logdie {
235 + my ($msg, $lvl) = @_;
236 +
237 + logmsg($msg, $lvl || 'err');
238 + unlink $lockfile;
239 + exit 1;
240 +}
241 +
242 +sub ctlinnd {
243 + my ($cmd, @args) = @_;
244 +
245 + my $st = system("$inn::newsbin/ctlinnd", '-s', $cmd, @args);
246 + logdie('Cannot run ctlinnd: ' . $!) if $st == -1;
247 + logdie('ctlinnd returned status ' . ($st & 255)) if $st > 0;
248 +}
249 +
250 +sub shlock {
251 + my $lockfile = shift;
252 +
253 + my $locktry = 0;
254 + while ($locktry < 60) {
255 + if (system("$inn::newsbin/shlock", '-p', $$, '-f', $lockfile) == 0) {
256 + return 1;
257 + }
258 + $locktry++;
259 + sleep 2;
260 + }
261 +
262 + my $lockreason;
263 + if (open(LOCKFILE, $lockfile)) {
264 + $lockreason = 'held by ' . (<LOCKFILE> || '?');
265 + close LOCKFILE;
266 + } else {
267 + $lockreason = $!;
268 + }
269 + logdie("Cannot get lock $lockfile: $lockreason");
270 + return undef;
271 +}
272 +
273 +__END__
274 +
275 +=head1 NAME
276 +
277 +send-uucp - Send Usenet articles via UUCP
278 +
279 +=head1 SYNOPSIS
280 +
281 +B<send-uucp> [I<SITE> ...]
282 +
283 +=head1 DESCRIPTION
284 +
285 +The B<send-uucp> program processes batch files written by innd(8) to send
286 +Usenet articles to UUCP sites. It reads a configuration file to control how
287 +it behaves with various sites. Normally, it's run periodically out of cron
288 +to put together batches and send them to remote UUCP sites.
289 +
290 +=head1 OPTIONS
291 +
292 +Any arguments provided to the program are interpreted as a list of sites
293 +specfied in F<send-uucp.cf> for which batches should be generated. If no
294 +arguments are supplied then batches will be generated for all sites listed
295 +in that configuration file.
296 +
297 +=head1 CONFIGURATION
298 +
299 +The sites to which articles are to be sent must be configured in the
300 +configuration file F<send-uucp.cf>. Each site is specified with a line of
301 +the form:
302 +
303 + site[:host] [compressor [maxsize [batchtime]]]
304 +
305 +=over 4
306 +
307 +=item I<site>
308 +
309 +The news site name being configured. This must match a site name
310 +from newsfeeds(5).
311 +
312 +=item I<host>
313 +
314 +The UUCP host name to which batches should be sent for this site.
315 +If omitted, the news site name will be used as the UUCP host name.
316 +
317 +=item I<compressor>
318 +
319 +The compression method to use for batches. This should be one of compress,
320 +gzip, bzip2, xz or none. Arguments for the compression command may be specified by
321 +using C<_> instead of spaces. For example, C<gzip_-9>. The default value is
322 +C<compress>.
323 +
324 +=item I<maxsize>
325 +
326 +The maximum size of a single batch before compression. The default value is
327 +500,000 bytes.
328 +
329 +=item I<batchtime>
330 +
331 +A comma separated list of hours during which batches should be generated for
332 +a given site. When B<send-uucp> runs, a site will only be processed if the
333 +current hour matches one of the hours in I<batchtime>. The default is no
334 +limitation on when to generate batches.
335 +
336 +=back
337 +
338 +Fields are seperated by spaces and only the site name needs to be specified,
339 +with defaults being used for unspecified values. If the first character on
340 +a line is a C<#> then the rest of the line is ignored.
341 +
342 +=head1 EXAMPLE
343 +
344 +Here is an example send-uucp.cf configuration file:
345 +
346 + zoetermeer gzip 1048576 5,18,22
347 + hoofddorp gzip 1048576 5,18,22
348 + pa3ebv gzip 1048576 5,18,22
349 + drinkel gzip 1048576 5,6,18,20,22,0,2
350 + manhole compress 1048576 5,18,22
351 + owl compress 1048576
352 + able
353 +
354 +This defines seven UUCP sites. The first four use gzip compression and the
355 +last three use compress. The first six use a batch size of 1MB, and the
356 +last site (able) uses the default of 500,000 bytes. The zoetermeer,
357 +hoofddorp, pa3ebv, and manhole sites will only have batches generated for
358 +them during the hours of 05:00, 18:00, and 22:00, and the drinkel site will
359 +only have batches generated during those hours and 20:00, 00:00, and 02:00.
360 +There are no restrictions on when batches will be generated for owl or able.
361 +
362 +=head1 FILES
363 +
364 +=over 4
365 +
366 +=item I<pathetc>/send-uucp.cf
367 +
368 +Configuration file specifying a list of sites to be processed.
369 +
370 +=back
371 +
372 +=head1 NOTES
373 +
374 +The usual flags used for a UUCP feed in the I<newsfeeds> file are C<Tf,Wfb>.
375 +
376 +=head1 SEE ALSO
377 +
378 +innd(8), newsfeeds(5), uucp(8)
379 +
380 +=head1 AUTHOR
381 +
382 +This program was originally written by Edvard Tuinder <[email protected]> and then
383 +maintained and extended by Miquel van Smoorenburg <[email protected]>.
384 +Marco d'Itri <[email protected]> cleaned up the code for inclusion in INN. This
385 +manual page was written by Mark Brown <[email protected]>.
386 +
387 +=cut