Compare commits
235 Commits
combined_g
...
master
Author | SHA1 | Date |
---|---|---|
Peter J. Holzer | 5de6672e2a | |
Peter J. Holzer | 8013784ff0 | |
Peter J. Holzer | f84e48fd1b | |
Peter J. Holzer | 59e958e160 | |
Peter J. Holzer | e27477085c | |
Peter J. Holzer | 75b3f4bea7 | |
Peter J. Holzer | b58b1b1dc5 | |
Peter J. Holzer | fdd9010646 | |
Peter J. Holzer | 51abe1d11a | |
Peter J. Holzer | 473a272066 | |
Peter J. Holzer | f3d48b2cdc | |
Peter J. Holzer | 2209823843 | |
Peter J. Holzer | be21bc6ff8 | |
Peter J. Holzer | 52d52cb258 | |
Peter J. Holzer | df8c3bcbb5 | |
hjp | 8e2f03dc0b | |
hjp | cd81f6a2ba | |
hjp | ce339c38c7 | |
hjp | 247743c9dd | |
hjp | 0520500523 | |
hjp | 108136917f | |
hjp | 5935f6a0e6 | |
hjp | f052403e23 | |
hjp | 712d3d1c9a | |
hjp | d941663269 | |
hjp | 3944b561fd | |
hjp | 469ef14cb4 | |
hjp | 099d15ec1d | |
hjp | f155ff878c | |
hjp | 1c961289e9 | |
hjp | 89e5b8a3ff | |
hjp | e78b9530ef | |
hjp | e3c6f75cfd | |
hjp | 8260d39d4e | |
hjp | 1bc6615651 | |
hjp | 9fa521b60c | |
hjp | 3ef0c01ff0 | |
hjp | 378a0a9f70 | |
hjp | 0c72134b24 | |
hjp | e4f841f6c3 | |
hjp | a5b3940dfe | |
hjp | 5a638ec8fd | |
hjp | 0984229b9b | |
hjp | dd02446c69 | |
hjp | c39c0c22ac | |
hjp | 42bd431dca | |
hjp | da899cbf29 | |
hjp | 8187b62fc6 | |
hjp | 7aa8246502 | |
hjp | 2552b38965 | |
hjp | 6a45dceeaf | |
hjp | 243c54a8ef | |
hjp | 7083ad9026 | |
hjp | e999d2e7b2 | |
hjp | 9a4119c6f0 | |
hjp | 61aff0e077 | |
hjp | defe773283 | |
hjp | e7af75898f | |
hjp | 8c6d58eee8 | |
hjp | 126d734171 | |
hjp | abf8fdc9ba | |
hjp | e80dfbc808 | |
hjp | b38c18c0ff | |
hjp | 4e4e6bf042 | |
hjp | 5028818f22 | |
hjp | 81ddb6bcba | |
hjp | 03ebbfe2ec | |
hjp | 2aa370cff1 | |
hjp | ba64495861 | |
hjp | 0fa224e001 | |
hjp | c5acc52b65 | |
hjp | 1419d9dbc3 | |
hjp | 61124dd1c6 | |
hjp | 27babc338d | |
hjp | 224ef8747d | |
hjp | 0d6d25b899 | |
hjp | 34cd011527 | |
hjp | a4e646ed83 | |
hjp | ed590c329e | |
hjp | 3a526a613a | |
hjp | 0f501292a0 | |
hjp | 3163f7d94d | |
hjp | ef1903e49f | |
hjp | 9ad679573c | |
hjp | db8cc1f569 | |
hjp | e315472e63 | |
hjp | 64d708aeeb | |
hjp | 6a95311ee1 | |
hjp | 888f0a58eb | |
hjp | d6329c4c03 | |
hjp | 5d345eedcd | |
hjp | 8f74fc527d | |
hjp | 64863e9553 | |
hjp | bbb0b7f6dd | |
hjp | 4ebc2b2a57 | |
hjp | 7d35c95bc5 | |
hjp | 070a6da94b | |
hjp | 72c7f8d3e4 | |
gina | ec0216b5a9 | |
hjp | 27306a9b51 | |
hjp | 0150503c41 | |
hjp | 7949fda3ba | |
hjp | 69187e640a | |
hjp | 60f1952973 | |
hjp | 163fc81775 | |
hjp | 90cfb3a468 | |
hjp | 520a335ee6 | |
hjp | f347d67dcf | |
hjp | dfa2f8c764 | |
hjp | 382b39f4be | |
hjp | 32199d9d7c | |
hjp | 6e21e0d270 | |
hjp | d41157029d | |
hjp | 3836ca8c1c | |
hjp | 14352801e4 | |
hjp | fecfa0af0a | |
hjp | 0e56ed880b | |
hjp | 3f46eea7cc | |
hjp | 999f82157e | |
hjp | 18feafbe66 | |
hjp | 1488372199 | |
hjp | c5c941a868 | |
hjp | 1d4e979fba | |
hjp | 6899d0d971 | |
hjp | 230addcf34 | |
hjp | 582f0fc6ac | |
hjp | b7eb8717bd | |
hjp | 3808d97c6d | |
hjp | 09751207a7 | |
hjp | 9394650a77 | |
hjp | 153a63a73b | |
hjp | 32dd4a8f0e | |
hjp | 01edfbc263 | |
hjp | cfbe44bddf | |
hjp | 46594d873d | |
hjp | 3a821e8bbb | |
hjp | 71c3303e51 | |
hjp | 9b7a8ad925 | |
hjp | 6a46455436 | |
hjp | 496e9a3fc8 | |
hjp | e235387a3a | |
hjp | c65dcaf182 | |
hjp | 034a1fa1ae | |
hjp | 068ed2ebf2 | |
hjp | cf51e84792 | |
hjp | a52fa0d688 | |
hjp | 029195aa65 | |
hjp | 89bbb2d768 | |
hjp | 060b616766 | |
hjp | e36613df54 | |
hjp | 71d8515467 | |
hjp | b7acf57799 | |
hjp | 4911233973 | |
hjp | a8b5e5243a | |
hjp | 9a1b2a14f9 | |
hjp | 1784620bb9 | |
hjp | a7c1de55a7 | |
hjp | 0260bffa03 | |
hjp | abc1605cf1 | |
hjp | 0fb55290ad | |
hjp | af75f9b864 | |
hjp | e8c3f76218 | |
hjp | fd3d3341ca | |
hjp | 9d6f178d2e | |
hjp | 934b8a9eb6 | |
hjp | 6b9f79a261 | |
hjp | 002657d522 | |
hjp | a22110e328 | |
hjp | a43fc516f4 | |
hjp | b8bd8e778a | |
hjp | 761ae98837 | |
hjp | b39af7c8d8 | |
hjp | 750ef31e0c | |
hjp | f3f6f7006e | |
hjp | 7c90e8b0ec | |
hjp | 493001ee19 | |
hjp | ab957ed401 | |
hjp | 8e67f3563e | |
hjp | 5c46c7c080 | |
hjp | 3b37f9b952 | |
hjp | 46f4512ed3 | |
hjp | 22e6213acb | |
hjp | 5b03cacb9d | |
hjp | 73952330cb | |
hjp | 590f489d1f | |
hjp | 8327e6a6f4 | |
hjp | 51c015f368 | |
hjp | ea29f84073 | |
hjp | c56b63d964 | |
hjp | d79e2212ca | |
hjp | e85052e3d6 | |
hjp | a6c79cefd9 | |
hjp | 955d49149e | |
hjp | 609868d588 | |
hjp | 2ce9f5b473 | |
hjp | 22a6dba7b1 | |
hjp | bda379820d | |
hjp | cd3d0fa151 | |
hjp | 7227f9bb20 | |
hjp | 30ecd2ef1b | |
hjp | 9f7f0f7b9e | |
hjp | a1822cb42c | |
hjp | 7fdaf9d95c | |
hjp | ef10f1a79f | |
hjp | e643f0affd | |
hjp | a1164ac024 | |
hjp | 670b1bac07 | |
hjp | 4b3a42c2fa | |
hjp | 300b4fbd25 | |
hjp | 56b5f6480f | |
hjp | 6ab44ef499 | |
hjp | 5db287df64 | |
hjp | da2f85d5e4 | |
hjp | b9699494bb | |
hjp | 53bae2019f | |
hjp | 1b2cac4a52 | |
hjp | 1d321d0f4b | |
hjp | 439ec1a2ed | |
hjp | 7dfd0f68ae | |
hjp | e52d92dfc2 | |
hjp | 5f95823fae | |
hjp | b2a0e6b973 | |
hjp | a139e5334b | |
hjp | 6f278ae0cb | |
hjp | 878496aeee | |
hjp | 78c3f75328 | |
hjp | 60b99b5cde | |
hjp | 22489c6971 | |
hjp | efe5d8b4a1 | |
hjp | 08a6803030 | |
hjp | 861c35e4db | |
hjp | c831f707f9 | |
hjp | cadf194099 | |
hjp | b8e4527242 | |
hjp | 0e5c1c441d |
|
@ -0,0 +1,3 @@
|
|||
GNUmakerules
|
||||
GNUmakevars
|
||||
*.o
|
|
@ -0,0 +1,35 @@
|
|||
include GNUmakevars
|
||||
|
||||
BINDIR=/usr/local/bin
|
||||
|
||||
all: agestat
|
||||
|
||||
clean:
|
||||
rm -f agestat customize
|
||||
|
||||
distclean: clean
|
||||
rm -f GNUmakevars GNUmakerules
|
||||
|
||||
install: $(BINDIR) $(BINDIR)/agestat
|
||||
|
||||
%: %.pl customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
%: %.sh customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
customize: configure
|
||||
sh ./configure
|
||||
|
||||
$(BINDIR):
|
||||
mkdir -p $@
|
||||
|
||||
GNUmakevars: GNUmakevars.sh
|
||||
sh ./$^ > $@
|
||||
GNUmakerules: GNUmakerules.sh
|
||||
sh ./$^ > $@
|
||||
|
||||
|
||||
include GNUmakerules
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
echo "\$(BINDIR)/%: %"
|
||||
echo " cp \$^ \$@"
|
||||
echo "\$(MAN1DIR)/%: %"
|
||||
echo " cp \$^ \$@"
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
prefix=${prefix:-/usr/local}
|
||||
echo "BINDIR=$prefix/bin"
|
||||
|
||||
for i in "$prefix/share/man/man1" "$prefix/man/man1"
|
||||
do
|
||||
if [ -d "$i" -a -w "$i" ]
|
||||
then
|
||||
echo "MAN1DIR=$i"
|
||||
break;
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
echo "all:"
|
|
@ -0,0 +1,137 @@
|
|||
#!@@@perl@@@ -w
|
||||
#
|
||||
# $Id: agestat.pl,v 1.10 2015-08-25 16:00:39 hjp Exp $
|
||||
#
|
||||
|
||||
use strict;
|
||||
use File::stat;
|
||||
use File::Find;
|
||||
use Getopt::Long;
|
||||
|
||||
sub usage {
|
||||
print STDERR "Usage: $0 [-atime|-mtime] [-scale=(k|M)] [-buckets=(cal|log2)]\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
my $now = time();
|
||||
my @bucket_max;
|
||||
|
||||
my %opts = (buckets => 'log2');
|
||||
GetOptions(\%opts, "atime", "mtime", "scale=s", "buckets=s") or usage();
|
||||
my $scale;
|
||||
if (!defined($opts{scale})) {
|
||||
$scale = 1;
|
||||
} elsif ($opts{scale} eq 'k') {
|
||||
$scale = 1024;
|
||||
} elsif ($opts{scale} eq 'M') {
|
||||
$scale = 1024*1024;
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
|
||||
if ($opts{buckets} eq "log2") {
|
||||
for (my ($b, $s) = (0, 1); $b < 32; $b++, $s *= 2) {
|
||||
$bucket_max[$b] = $s;
|
||||
}
|
||||
} elsif ($opts{buckets} eq "cal") {
|
||||
@bucket_max = (
|
||||
3600,
|
||||
86400,
|
||||
7 * 86400,
|
||||
30 * 86400,
|
||||
182 * 86400,
|
||||
1 * 365.2422 * 86400,
|
||||
2 * 365.2422 * 86400,
|
||||
3 * 365.2422 * 86400,
|
||||
4 * 365.2422 * 86400,
|
||||
5 * 365.2422 * 86400,
|
||||
);
|
||||
} elsif ($opts{buckets} =~ /^days=(\d+)/) {
|
||||
@bucket_max = map $_ * 86400, (1 .. $1);
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
|
||||
|
||||
my @hist;
|
||||
|
||||
sub wanted {
|
||||
|
||||
my $st = lstat($_);
|
||||
return unless $st;
|
||||
my $age = $now - (
|
||||
$opts{atime} ? $st->atime :
|
||||
$opts{mtime} ? $st->mtime :
|
||||
(! -d && $st->atime > $st->mtime ? $st->atime
|
||||
: $st->mtime ));
|
||||
my $b = 0;
|
||||
while ($b <= $#bucket_max && $age > $bucket_max[$b]) { $b++ };
|
||||
#print $File::Find::name, ": $age sec, ", $st->size, " bytes, ", $st->nlink, " links, bucket $b\n";
|
||||
$hist[$b] += $st->size / $st->nlink;
|
||||
}
|
||||
|
||||
sub time2str {
|
||||
my ($t) = (@_);
|
||||
|
||||
if ($t < 60) {
|
||||
return sprintf ("%6.1f s", $t);
|
||||
} elsif ($t < 3600) {
|
||||
return sprintf ("%6.1f m", $t/60);
|
||||
} elsif ($t < 3600 * 24) {
|
||||
return sprintf ("%6.1f h", $t/3600);
|
||||
} elsif ($t < 3600 * 24 * 365.2422) {
|
||||
return sprintf ("%6.1f d", $t/(3600*24));
|
||||
} else {
|
||||
return sprintf ("%6.1f y", $t/(3600*24*365.2422));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (@ARGV == 0) { push (@ARGV, "."); }
|
||||
find(\&wanted, @ARGV);
|
||||
|
||||
print "\n\n";
|
||||
|
||||
my $sum = 0;
|
||||
|
||||
for (my $i = 0; $i <= $#hist; $i++) {
|
||||
$sum += ($hist[$i] || 0);
|
||||
}
|
||||
|
||||
|
||||
my $c = 0;
|
||||
for (my $i = 0; $i <= $#hist; $i++) {
|
||||
my $h = ($hist[$i] || 0);
|
||||
$c += $h;
|
||||
printf("%2d\t%s\t%12.0f\t%5.1f\t%12.0f\t%5.1f\n",
|
||||
$i,
|
||||
$i <= $#bucket_max ? time2str($bucket_max[$i]) : "infinity",
|
||||
$h/$scale, $h * 100 / $sum, $c/$scale, $c * 100 / $sum);
|
||||
}
|
||||
|
||||
# $Log: agestat.pl,v $
|
||||
# Revision 1.10 2015-08-25 16:00:39 hjp
|
||||
# New bucket type days
|
||||
#
|
||||
# Revision 1.9 2012-10-22 09:20:05 hjp
|
||||
# fixed usage message
|
||||
#
|
||||
# Revision 1.8 2007-02-09 15:36:37 hjp
|
||||
# Automatically create GNUmakerules and GNUmakevars if they don't exist.
|
||||
# Print usage if unknown option is given.
|
||||
#
|
||||
# Revision 1.7 2006/02/17 13:50:23 hjp
|
||||
# Fixed error when oldest file was older than oldest bucket.
|
||||
# Realigned columns.
|
||||
#
|
||||
# Revision 1.6 2006/02/17 13:31:41 hjp
|
||||
# Added option --buckets.
|
||||
#
|
||||
# Revision 1.5 2002/03/18 20:33:46 hjp
|
||||
# Ignore atime for directories
|
||||
#
|
||||
# Revision 1.4 2001/01/19 19:06:01 hjp
|
||||
# Removed superfluous "total" line.
|
||||
# Fixed usage message.
|
||||
#
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
echo "#!/bin/sh" > customize.$$
|
||||
echo "sed \\" >> customize.$$
|
||||
chmod +x customize.$$
|
||||
|
||||
################################################################
|
||||
# find a working perl:
|
||||
#
|
||||
for i in /usr/bin/perl /usr/local/bin/perl /usr/bin/perl5 /usr/local/bin/perl5
|
||||
do
|
||||
if $i -e 'exit ($] < 5.000)'
|
||||
then
|
||||
echo $i works
|
||||
perl="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$perl" ]
|
||||
then
|
||||
could not find a working perl command, sorry.
|
||||
exit 1
|
||||
fi
|
||||
echo " -e 's,@@@perl@@@,$perl,g' \\" >> customize.$$
|
||||
|
||||
|
||||
echo >> customize.$$
|
||||
|
||||
mv customize.$$ customize
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
include GNUmakevars
|
||||
include GNUmakerules
|
||||
|
||||
base64: base64.o
|
||||
$(CC) $^ -lant -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o base64 core foo bar
|
||||
|
||||
install: $(BINDIR)/base64
|
||||
|
||||
distclean: clean
|
||||
rm -f *.bak *.d
|
|
@ -0,0 +1,55 @@
|
|||
#include <ant/base64.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *cmnd;
|
||||
|
||||
static void usage(void) {
|
||||
fprintf(stderr, "Usage: %s [-d|-e]\n", cmnd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char buf1[1024+1];
|
||||
char buf2[1024+1];
|
||||
enum { NONE, ENCODE, DECODE} mode = NONE;
|
||||
int c;
|
||||
int r1, r2;
|
||||
cmnd = argv[0];
|
||||
while ((c = getopt(argc, argv, "de")) != EOF) {
|
||||
switch(c) {
|
||||
case 'd':
|
||||
mode = DECODE;
|
||||
break;
|
||||
case 'e':
|
||||
mode = ENCODE;
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
switch(mode) {
|
||||
case NONE:
|
||||
usage();
|
||||
case ENCODE:
|
||||
while ((r1 = fread(buf1, 1, 57, stdin)) > 0) {
|
||||
r2 = base64_encode(buf2, sizeof(buf2), buf1, r1, 76);
|
||||
fwrite(buf2, 1, r2, stdout);
|
||||
putchar('\n');
|
||||
}
|
||||
break;
|
||||
case DECODE:
|
||||
while (fgets(buf1, sizeof(buf1), stdin)) {
|
||||
r1 = strlen(buf1);
|
||||
if (buf1[r1-1] == '\n') r1--;
|
||||
r2 = base64_decode(buf2, sizeof(buf2), buf1, r1);
|
||||
fwrite(buf2, 1, r2, stdout);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
# $Id: cgigw.cgi,v 1.1 1998-04-28 22:01:23 hjp Exp $
|
||||
#
|
||||
# This is a simpe CGI gateway script.
|
||||
#
|
||||
# It can be used to access CGI scripts on a different server and/or
|
||||
# port.
|
||||
# Possible scenarios where this is useful:
|
||||
# * Your real CGI scripts have to run on a machine behind a firewall.
|
||||
# In this case you may also want to modify this script to check
|
||||
# parameters.
|
||||
# * Your real CGI scripts have to run on a different server (e.g., one
|
||||
# with some special database installed), but you don't want to expose
|
||||
# that server's address in your URLs.
|
||||
# * Your real CGI scripts have to run on a Web server which doesn't
|
||||
# speak SSL.
|
||||
#
|
||||
# Usage: Change the customization section to point to the script which
|
||||
# you really want to call. Install this script in some convenient
|
||||
# place. Make sure the target script generates only links to your
|
||||
# "official" server (If this is not possible, you might want to
|
||||
# tweak its output just before "print @rest;" at the very bottom
|
||||
# of this script.
|
||||
#
|
||||
# $Log: cgigw.cgi,v $
|
||||
# Revision 1.1 1998-04-28 22:01:23 hjp
|
||||
# Initial release.
|
||||
# Only tested with a few CGIs and the Roxen web server.
|
||||
#
|
||||
#
|
||||
|
||||
use IO::Socket;
|
||||
|
||||
# BEGIN customization section
|
||||
$serv_addr = "internal.host.com";
|
||||
$serv_port = 80;
|
||||
$serv_script = "/some/script.cgi";
|
||||
# END customization section
|
||||
|
||||
$sock = IO::Socket::INET->new(PeerAddr => $serv_addr,
|
||||
PeerPort => $serv_port);
|
||||
if (!$sock) {
|
||||
print "Status: 500\r\n";
|
||||
print "Content-type: text/html\r\n";
|
||||
print "\r\n";
|
||||
print "<html><body>\n";
|
||||
print "<h1>Internal error</h1>\n";
|
||||
print "Connection to $serv_addr:$serv_port failed: $!\n";
|
||||
print "</body></html>\n";
|
||||
}
|
||||
|
||||
$method = $ENV{REQUEST_METHOD};
|
||||
$query_string = $ENV{QUERY_STRING};
|
||||
print STDERR "$0: method = $method\n";
|
||||
|
||||
$sock->print("$method $serv_script");
|
||||
if ($query_string ne "") {
|
||||
$sock->print("?$query_string");
|
||||
}
|
||||
$sock->print(" HTTP/1.0\r\n");
|
||||
for $i (keys(%ENV)) {
|
||||
if ($i =~ m/^HTTP_(.*)/) {
|
||||
$key = $1;
|
||||
$key =~ s/_/-/g;
|
||||
$val = $ENV{$i};
|
||||
$sock->print("$key: $val\r\n");
|
||||
print STDERR "$0: Header: $key: $val\n";
|
||||
} else {
|
||||
$val = $ENV{$i};
|
||||
print STDERR "$0: Env: $i: $val\n";
|
||||
}
|
||||
}
|
||||
$content_length = $ENV{CONTENT_LENGTH};
|
||||
if ($content_length) {
|
||||
$sock->print("Content-Length: ", $content_length, "\r\n\r\n");
|
||||
for ($i = 0; $i < $content_length; $i++) {
|
||||
read(STDIN, $c, 1);
|
||||
print STDERR "$0: Body: $i of $content_length: $c\n";
|
||||
$sock->print($c);
|
||||
}
|
||||
# padding:
|
||||
$sock->print("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n");
|
||||
} else {
|
||||
$sock->print("\r\n");
|
||||
}
|
||||
$sock->flush();
|
||||
print STDERR "$0: Flushing\n";
|
||||
|
||||
$status = $sock->getline();
|
||||
print STDERR "$0: Status: $status\n";
|
||||
if ($status =~ m|^HTTP/\d+\.\d+ (\d+) |) {
|
||||
print "Status: $1\r\n";
|
||||
} elsif ($status =~ m|:|) {
|
||||
# error: Assume this is a header and just pass it on
|
||||
print $status;
|
||||
} else {
|
||||
# error: not a header. Assume this is HTML
|
||||
print "Content-Type: text/html\r\n";
|
||||
print "\r\n";
|
||||
print $status;
|
||||
}
|
||||
@rest = $sock->getlines;
|
||||
print @rest;
|
||||
|
||||
print STDERR "$0: Finished\n";
|
|
@ -0,0 +1 @@
|
|||
charhist
|
|
@ -0,0 +1,21 @@
|
|||
include GNUmakevars
|
||||
include GNUmakerules
|
||||
|
||||
all: charhist
|
||||
|
||||
charhist: charhist.pl
|
||||
cp $^ $@
|
||||
|
||||
chartab:
|
||||
clean:
|
||||
rm -f charhist core foo bar baz
|
||||
|
||||
distclean: clean
|
||||
rm -f GNUmakerules GNUmakevars
|
||||
|
||||
GNUmakevars: GNUmakevars.sh
|
||||
sh ./$^ > $@
|
||||
GNUmakerules: GNUmakerules.pl
|
||||
perl ./$^ > $@
|
||||
|
||||
install: $(BINDIR)/charhist
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
print "\$(BINDIR)/%: %\n";
|
||||
print "\tinstall -m 755 \$^ \$@\n";
|
||||
print "\$(MAN1DIR)/%: %\n";
|
||||
print "\tinstall -m 644 \$^ \$@\n";
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
prefix=${prefix:-/usr/local}
|
||||
echo "BINDIR=$prefix/bin"
|
||||
echo
|
||||
echo "all:"
|
|
@ -0,0 +1,21 @@
|
|||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
long hist[UCHAR_MAX+1];
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
while ((c = getchar()) != EOF) {
|
||||
hist[c]++;
|
||||
}
|
||||
for (c = 0; c <= UCHAR_MAX; c++) {
|
||||
if (hist[c]) {
|
||||
printf ("%x %d %o %c\t%ld\n", c, c, c, isprint(c) ? c : '.', hist[c]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
use autodie;
|
||||
|
||||
use Getopt::Long;
|
||||
use I18N::Langinfo qw(langinfo CODESET);
|
||||
use Pod::Usage;
|
||||
|
||||
my $encoding = langinfo(CODESET);
|
||||
|
||||
GetOptions('encoding=s', \$encoding) or pod2usage();
|
||||
|
||||
my %hist;
|
||||
if (@ARGV) {
|
||||
readfile($_) for @ARGV;
|
||||
} else {
|
||||
readfile();
|
||||
}
|
||||
|
||||
my $total = 0;
|
||||
$total += $_ for values %hist;
|
||||
|
||||
binmode STDOUT, ":encoding(UTF-8)";
|
||||
for (sort keys %hist) {
|
||||
my $cp = ord;
|
||||
printf("%x\t%d\t%o\t%s\t%7d\t%f\n",
|
||||
$cp, $cp, $cp, /\p{Graph}/ ? $_ : ".", $hist{$_}, $hist{$_} / $total);
|
||||
}
|
||||
|
||||
sub readfile {
|
||||
my ($filename) = @_;
|
||||
my $fh;
|
||||
if (defined $filename) {
|
||||
open $fh, "<", $filename;
|
||||
} else {
|
||||
$fh = \*STDIN;
|
||||
|
||||
}
|
||||
binmode $fh, ":encoding($encoding)";
|
||||
while (<$fh>) {
|
||||
for my $c (split(//)) {
|
||||
$hist{$c}++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
include GNUmakevars
|
||||
|
||||
all: chartab ctype-test
|
||||
|
||||
chartab:
|
||||
ctype-test:
|
||||
clean:
|
||||
rm chartab
|
||||
install: $(BINDIR)/chartab $(BINDIR)/ctype-test
|
||||
|
||||
include GNUmakerules
|
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
int i;
|
||||
for (i = 0; i < 256; i++) {
|
||||
printf ("%x %d %o %c\t", i, i, i, i);
|
||||
if (i % 4 == 3) printf ("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
use charnames ();
|
||||
|
||||
use Getopt::Long;
|
||||
use Pod::Usage;
|
||||
|
||||
my $all;
|
||||
|
||||
GetOptions(
|
||||
'all' => \$all
|
||||
) or pod2usage(2);
|
||||
|
||||
binmode STDOUT, ":encoding(UTF-8)";
|
||||
for my $c (0 .. 0xFFFF) {
|
||||
my $cc = pack('U', $c);
|
||||
if (charnames::viacode($c) || $all) {
|
||||
printf("%04x %5d %06o %s %s\n",
|
||||
$c,
|
||||
$c,
|
||||
$c,
|
||||
(($cc =~ /[[:print:]]/) ? $cc : '.'),
|
||||
charnames::viacode($c) || ''
|
||||
);
|
||||
}
|
||||
}
|
||||
print "\n";
|
|
@ -0,0 +1,17 @@
|
|||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
for (i = 0; i <= UCHAR_MAX; i++) {
|
||||
printf ("%2x: ", i);
|
||||
printf("%c ", isprint(i) ? i : '.');
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
version 5.0
|
||||
map! >I<yypa/O
|
||||
set autoindent
|
||||
set exrc
|
||||
set number
|
||||
set shiftwidth=4
|
|
@ -0,0 +1,47 @@
|
|||
include GNUmakevars
|
||||
|
||||
TARGETS = cleandir cleandir.1
|
||||
CONFDIR=../../configure
|
||||
CONFDIR_exists=$(shell [ -d $(CONFDIR) ] && echo ok)
|
||||
|
||||
all: configure $(TARGETS)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGETS) *.bak core foo bar baz *.ps
|
||||
|
||||
distclean: clean
|
||||
rm -f customize
|
||||
|
||||
install: $(BINDIR) $(BINDIR)/cleandir $(MAN1DIR)/cleandir.1
|
||||
|
||||
%.1: %.pl
|
||||
pod2man $< > $@
|
||||
|
||||
%: %.pl customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
%: %.sh customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
customize: configure
|
||||
sh ./configure
|
||||
|
||||
$(SBINDIR):
|
||||
mkdir -p $@
|
||||
|
||||
ifeq ($(CONFDIR_exists),ok)
|
||||
|
||||
configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish
|
||||
cat $^ > $@
|
||||
|
||||
endif
|
||||
|
||||
GNUmakevars: GNUmakevars.sh
|
||||
sh ./$^ > $@
|
||||
GNUmakerules: GNUmakerules.sh
|
||||
sh ./$^ > $@
|
||||
|
||||
|
||||
include GNUmakerules
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
echo "\$(BINDIR)/%: %"
|
||||
echo -e "\tcp \$^ \$@"
|
||||
echo "\$(MAN1DIR)/%: %"
|
||||
echo -e "\tcp \$^ \$@"
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
prefix=${prefix:-/usr/local}
|
||||
echo "BINDIR=$prefix/bin"
|
||||
|
||||
for i in "$prefix/share/man/man1" "$prefix/man/man1"
|
||||
do
|
||||
if [ -d "$i" -a -w "$i" ]
|
||||
then
|
||||
echo "MAN1DIR=$i"
|
||||
break;
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
echo "all:"
|
|
@ -0,0 +1,282 @@
|
|||
#!@@@perl@@@ -w
|
||||
|
||||
=head1 NAME
|
||||
|
||||
cleandir - remove unused files from directory
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
cleandir [-d days] [-n] [-m] [-v] [-s] [-i|-x regex] directory...
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
cleandir recursively searches each directory given on the commandline
|
||||
for files and subdirectories which have not been accessed for n days and
|
||||
deletes them. It is intended to be used on /tmp and other world-writable
|
||||
directories and implements a number of checks to prevent symlink or
|
||||
directory switching attacks. It also does not cross mount points.
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<-d days>
|
||||
|
||||
Delete files which have not been accessed for the given number of days.
|
||||
The default is 14.
|
||||
|
||||
=item B<-m>
|
||||
|
||||
Consider only the last modification time of the file, not the last access time.
|
||||
|
||||
=item B<-c>
|
||||
|
||||
Consider only the inode change time of the file.
|
||||
|
||||
=item B<-n>
|
||||
|
||||
No-op. Don't delete any files.
|
||||
|
||||
=item B<-s>
|
||||
|
||||
Skip sockets and named pipes. Some programs (notably X11 and some
|
||||
databases) create sockets and named pipes in /tmp and foolishly expect
|
||||
them to survive. This option exists to humour them.
|
||||
|
||||
=item B<-v>
|
||||
|
||||
Verbose. Can be repeated to increase verbosity.
|
||||
|
||||
=item B<-i>|B<-x> regex
|
||||
|
||||
Include and exclude patterns. The filenames (not the complete path) of
|
||||
all files and directories to be removed are compared against these
|
||||
patterns in order. The first hit determines the action. These patterns
|
||||
can also be used to override the -s option and to cross mount points.
|
||||
|
||||
=back
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Peter J. Holzer <hjp@hjp.at>. Thanks to Chris Mason for some
|
||||
enhancements.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use File::stat;
|
||||
use POSIX;
|
||||
use Getopt::Long;
|
||||
use Pod::Usage;
|
||||
use List::Util qw(max);
|
||||
|
||||
my $verbose = 0;
|
||||
my $nop = 0;
|
||||
my $skip_fifos = 0;
|
||||
my $mtime_only = 0;
|
||||
my $ctime_only = 0;
|
||||
|
||||
|
||||
sub cleandir {
|
||||
my ($dir, $since, $level, $inex) = (@_);
|
||||
my $notremoved = 0;
|
||||
|
||||
if ($verbose > 1) {
|
||||
print STDERR "$0:", " " x $level, " cleandir $dir $since {\n";
|
||||
}
|
||||
if (!opendir(DIR, ".")) {
|
||||
printf STDERR "$0:", " " x $level, " cannot opendir $dir: $!";
|
||||
return;
|
||||
}
|
||||
my $std = lstat(".");
|
||||
my $fs = $std->dev;
|
||||
|
||||
for my $i (readdir(DIR)) {
|
||||
if ($i eq "." || $i eq "..") {next}
|
||||
if ($verbose > 2) {
|
||||
print STDERR "$0:", " " x $level, " checking $dir/$i\n";
|
||||
}
|
||||
my $st = lstat("$i");
|
||||
if (!defined($st)) {
|
||||
# file has vanished
|
||||
next;
|
||||
}
|
||||
|
||||
my $action = 'i';
|
||||
# Skip anything on a different filesystem
|
||||
if ($st->dev != $fs) {
|
||||
$action = 'x';
|
||||
}
|
||||
|
||||
# Skip sockets and pipes
|
||||
if ($skip_fifos && (-p _ || -S _)) {
|
||||
$action = 'x';
|
||||
}
|
||||
|
||||
for (@$inex) {
|
||||
if ($i =~ /$_->[0]/) {
|
||||
$action = $_->[1];
|
||||
last;
|
||||
}
|
||||
}
|
||||
if ($action eq 'x') {
|
||||
$notremoved++;
|
||||
next;
|
||||
}
|
||||
|
||||
if ($verbose > 3) {
|
||||
print STDERR "$0:", " " x $level, " mtime=", $st->mtime, " atime=", $st->atime, " ctime=", $st->ctime, "\n";
|
||||
}
|
||||
if (-d _) {
|
||||
my $cwd = getcwd();
|
||||
if (chdir($i)) {
|
||||
my $remaining = -1;
|
||||
my $st1 = lstat(".");
|
||||
if ($st->dev == $st1->dev && $st->ino == $st1->ino) {
|
||||
$remaining = cleandir("$dir/$i", $since, $level+1, $inex);
|
||||
} else {
|
||||
print STDERR "$0:", " " x $level,
|
||||
" $dir/$i changed dev/inode from ",
|
||||
$st->dev, "/", $st->ino,
|
||||
" to ",
|
||||
$st1->dev, "/", $st1->ino,
|
||||
"\n";
|
||||
}
|
||||
chdir($cwd);
|
||||
my $std1 = lstat(".");
|
||||
if (!($std->dev == $std1->dev && $std->ino == $std1->ino)) {
|
||||
print STDERR "$0:", " " x $level,
|
||||
" $cwd changed dev/inode from ",
|
||||
$std->dev, "/", $std->ino,
|
||||
" to ",
|
||||
$std1->dev, "/", $std1->ino,
|
||||
"\n";
|
||||
return ++$notremoved;
|
||||
}
|
||||
my $rtime = $ctime_only ? $st->ctime : $st->mtime;
|
||||
if ($remaining == 0 && $rtime < $since) {
|
||||
if ($verbose > 0) {
|
||||
print STDERR "$0:", " " x $level, "rmdir $dir/$i\n";
|
||||
}
|
||||
unless ($nop) {
|
||||
if (rmdir("$i")) {next}
|
||||
print STDERR "$0:", " " x $level, "rmdir $dir/$i failed: $!\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print STDERR "$0:", " " x $level, " chdir $dir/$i failed: $!\n";
|
||||
}
|
||||
|
||||
} else {
|
||||
my $rtime = $ctime_only ? $st->ctime :
|
||||
$mtime_only ? $st->mtime :
|
||||
max($st->mtime, $st->atime);
|
||||
if ($rtime < $since) {
|
||||
if ($verbose > 0) {
|
||||
print STDERR "$0:", " " x $level, " removing $dir/$i\n";
|
||||
}
|
||||
unless ($nop) {
|
||||
if (unlink("$i")) {next}
|
||||
print STDERR "$0:", " " x $level, " removing $dir/$i failed: $!\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
$notremoved++;
|
||||
}
|
||||
if ($verbose > 1) {
|
||||
print STDERR "$0:", " " x $level, " cleandir: $notremoved }\n";
|
||||
}
|
||||
return $notremoved;
|
||||
}
|
||||
|
||||
sub main {
|
||||
my $since = time() - 14 * 86400;;
|
||||
my $help;
|
||||
my @inex;
|
||||
|
||||
GetOptions('help|?' => \$help,
|
||||
'days|d=f' => sub { $since = time() - $_[1] * 86400; },
|
||||
'verbose|v' => sub { $verbose++ },
|
||||
'nop|n' => \$nop,
|
||||
'skip-fifos|s' => \$skip_fifos,
|
||||
'mtime-only|m' => \$mtime_only,
|
||||
'ctime-only|c' => \$ctime_only,
|
||||
'include|i=s' => sub { push @inex, [ $_[1], 'i' ] },
|
||||
'exclude|x=s' => sub { push @inex, [ $_[1], 'x' ] },
|
||||
) or pod2usage(2);
|
||||
pod2usage(1) if $help;
|
||||
pod2usage(2) unless (@ARGV);
|
||||
|
||||
|
||||
while (my $i = shift(@ARGV)) {
|
||||
my $cwd = getcwd();
|
||||
if (chdir($i)) {
|
||||
cleandir($i, $since, 0, \@inex);
|
||||
chdir($cwd);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
# $Log: cleandir.pl,v $
|
||||
# Revision 1.10 2012-03-02 11:29:42 hjp
|
||||
# (Nov 12 2009)
|
||||
# Implemented option -c Consider only the inode change time of the file.
|
||||
#
|
||||
# Revision 1.9 2006-08-25 09:57:10 hjp
|
||||
# Added --include (-i) and --exclude (-x) options.
|
||||
#
|
||||
# Revision 1.8 2005/04/04 16:05:40 hjp
|
||||
# Print whole directory at rmdir with verbose output.
|
||||
#
|
||||
# Revision 1.7 2004/11/02 09:01:12 hjp
|
||||
# Critical bug fix: Empty directories were removed even with -n.
|
||||
# Minor cleanup: Message "removing ..." is now the same with and without -n.
|
||||
#
|
||||
# Revision 1.6 2003/05/16 14:44:58 hjp
|
||||
# Added -m option to synopsis.
|
||||
#
|
||||
# Revision 1.5 2003/05/16 13:38:25 hjp
|
||||
# Included -m (mtime-only) option (CVS is nice, but only if it used).
|
||||
# Improved pod a bit.
|
||||
#
|
||||
# Revision 1.4 2003/05/15 10:49:33 hjp
|
||||
# Changed tests on skip_fifo to use _ instead of $i. The latter caused
|
||||
# extra calls to stat which clobbered the state of _ which caused spurious
|
||||
# errors/warnings on symlinks.
|
||||
#
|
||||
# Revision 1.3 2003/05/14 11:49:56 hjp
|
||||
# Added yet another patch by Chris Mason.
|
||||
#
|
||||
# Added POD.
|
||||
#
|
||||
# Changed option processing to use Getopt::Long and Pod::Usage.
|
||||
#
|
||||
# Revision 1.2 2002/02/25 23:33:29 hjp
|
||||
# Applied patch from "Chris L. Mason" <cmason@somanetworks.com> to prevent
|
||||
# filesystem traversal.
|
||||
#
|
||||
# Return immediately if we cannot chdir back to the directory we came
|
||||
# from.
|
||||
#
|
||||
# Revision 1.1 2001/06/25 17:55:03 hjp
|
||||
# Added configure script to figure out perl location.
|
||||
#
|
||||
# Revision 1.4 2000/11/20 21:10:08 hjp
|
||||
# Checks introduced in last version prevented deletion of unused subdirs.
|
||||
# Fixed.
|
||||
#
|
||||
# revision 1.3
|
||||
# date: 2000/09/10 16:16:41; author: hjp; state: Exp; lines: +37 -6
|
||||
# Added checks to detect directory/symlink switching attacks.
|
||||
# ----------------------------
|
||||
# revision 1.2
|
||||
# date: 1999/08/21 12:37:53; author: hjp; state: Exp; lines: +25 -13
|
||||
# More levels of verbosity.
|
||||
# ----------------------------
|
||||
# revision 1.1
|
||||
# date: 1999/07/09 21:05:26; author: hjp; state: Exp;
|
||||
# Added cleandir
|
||||
#
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
echo "#!/bin/sh" > customize.$$
|
||||
echo "sed \\" > customize.$$
|
||||
chmod +x customize.$$
|
||||
|
||||
################################################################
|
||||
# find a working perl:
|
||||
#
|
||||
for i in /usr/bin/perl /usr/local/bin/perl /usr/bin/perl5 /usr/local/bin/perl5
|
||||
do
|
||||
if $i -e 'exit ($] < 5.000)'
|
||||
then
|
||||
echo $i works
|
||||
perl="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$perl" ]
|
||||
then
|
||||
echo could not find a working perl command, sorry.
|
||||
exit 1
|
||||
fi
|
||||
echo " -e 's,@@@perl@@@,$perl,g' \\" >> customize.$$
|
||||
|
||||
|
||||
################################################################
|
||||
# finish
|
||||
# Add trailing newline and rename temp file to final name
|
||||
#
|
||||
echo >> customize.$$
|
||||
|
||||
mv customize.$$ customize
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
CFLAGS = -Wall -O9
|
||||
all: collatz collatz2 collatz3 modf
|
||||
|
||||
collatz:
|
||||
|
||||
collatz2: collatz2.o
|
||||
$(CC) -o $@ $^ -lm
|
||||
|
||||
clean:
|
||||
rm -f collatz collatz2 collatz3 modf *.o core
|
|
@ -0,0 +1,40 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef int T;
|
||||
#define FT "%d"
|
||||
|
||||
int main(void) {
|
||||
T i = 1;
|
||||
long c_max = 0;
|
||||
|
||||
for(;;) {
|
||||
T j = i;
|
||||
long c = 0;
|
||||
while (j != 1) {
|
||||
if (j % 2 == 1) {
|
||||
T j2 = j * 3 + 1;
|
||||
if ((j2 - 1) / 3 != j) {
|
||||
printf(FT " is not 3 * " FT " + 1 at starting point " FT, j2, j, i);
|
||||
exit(1);
|
||||
}
|
||||
j = j2;
|
||||
} else {
|
||||
j = j / 2;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (c > c_max) {
|
||||
printf("new longest sequence starting at " FT ": %ld steps\n", i, c);
|
||||
c_max = c;
|
||||
}
|
||||
|
||||
if (i + 1 > i) {
|
||||
i = i + 1;
|
||||
} else {
|
||||
printf(FT " is not greater than " FT "\n", i + 1, i);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define USE_DOUBLE 1
|
||||
|
||||
#ifdef USE_INT
|
||||
typedef int T;
|
||||
#define FT "%d"
|
||||
#define even(x) ((x) % 2 == 0)
|
||||
#elif USE_LONG
|
||||
typedef long T;
|
||||
#define FT "%ld"
|
||||
#define even(x) ((x) % 2 == 0)
|
||||
#elif USE_LONG_LONG
|
||||
typedef long long T;
|
||||
#define FT "%lld"
|
||||
#define even(x) ((x) % 2 == 0)
|
||||
#elif USE_DOUBLE
|
||||
typedef double T;
|
||||
#define FT "%20.1f"
|
||||
#ifdef USE_FLOOR
|
||||
#define even(x) (floor((x) / 2) == ((x) / 2))
|
||||
#else
|
||||
#define even(x) (fmod((x), 2.0) == 0.0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
long collatz(T j) {
|
||||
|
||||
long c = 0;
|
||||
while (j != 1) {
|
||||
printf("%ld: " FT "\n", c, j);
|
||||
if (even(j)) {
|
||||
j = j / 2;
|
||||
} else {
|
||||
j = j * 3 + 1;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
T i = 113383;
|
||||
long c = collatz(i);
|
||||
printf("%ld\n", c);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define USE_INT 1
|
||||
|
||||
#ifdef USE_INT
|
||||
typedef int T;
|
||||
#define FT "%d"
|
||||
#define odd(x) ((x) % 2 == 1)
|
||||
#elif USE_LONG
|
||||
typedef long T;
|
||||
#define FT "%ld"
|
||||
#define odd(x) ((x) % 2 == 1)
|
||||
#elif USE_DOUBLE
|
||||
typedef double T;
|
||||
#define FT "%20g"
|
||||
#define odd(x) (floor((x) / 2) != ((x) / 2))
|
||||
#endif
|
||||
|
||||
long collatz(T j) {
|
||||
|
||||
long c = 0;
|
||||
while (j != 1) {
|
||||
printf("%ld: " FT "\n", c, j);
|
||||
if (odd(j)) {
|
||||
j = j * 3 + 1;
|
||||
} else {
|
||||
j = j / 2;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
T i = 113383;
|
||||
long c = collatz(i);
|
||||
printf("%ld\n", c);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(void) {
|
||||
double x = 3.14;
|
||||
double y, z;
|
||||
|
||||
y = modf(x, &z);
|
||||
printf("%g, %g\n", y, z);
|
||||
|
||||
y = modf(x, NULL);
|
||||
printf("%g, %g\n", y, z);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
Ich kannte dieses Problem ursprünglich als "Ulams Vermutung".
|
||||
|
||||
Laut http://de.wikipedia.org/wiki/Collatz-Problem stammt es aber
|
||||
ursprünglich von Lothar Collatz.
|
|
@ -0,0 +1,22 @@
|
|||
include GNUmakerules
|
||||
include GNUmakevars
|
||||
|
||||
count:
|
||||
|
||||
install: $(ROOT)/usr/local/bin/count
|
||||
|
||||
install_all:
|
||||
$(MAKE) install ROOT=/nfs/wsrdb
|
||||
$(MAKE) install ROOT=/nfs/wsrcom
|
||||
$(MAKE) install ROOT=/nfs/wifosv
|
||||
$(MAKE) install ROOT=/nfs/ihssv
|
||||
$(MAKE) install ROOT=/nfs/wsrtest
|
||||
|
||||
$(ROOT)/usr/local/bin/%: %
|
||||
$(INSTALL) $< $@
|
||||
|
||||
$(ROOT)/usr/local/man/man8/%.8: %.man
|
||||
$(INSTALL) $< $@
|
||||
|
||||
clean:
|
||||
rm count
|
|
@ -0,0 +1,30 @@
|
|||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
unsigned long start = 0;
|
||||
unsigned long stop = ULONG_MAX;
|
||||
unsigned long i;
|
||||
|
||||
switch (argc) {
|
||||
case 0:
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
stop = strtoul(argv[1], NULL, 0);
|
||||
break;
|
||||
case 3:
|
||||
start = strtoul(argv[1], NULL, 0);
|
||||
stop = strtoul(argv[2], NULL, 0);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Usage: %s [[start] stop]\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (i = start; i < stop; i++) {
|
||||
printf("%ld\n", i);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
version 5.0
|
||||
map! >I<yypa/O
|
||||
set autoindent
|
||||
set exrc
|
||||
set ruler
|
||||
set shiftwidth=4
|
|
@ -0,0 +1,24 @@
|
|||
include GNUmakevars
|
||||
|
||||
all: cvsdiffmin
|
||||
|
||||
clean:
|
||||
rm cvsdiffmin customize
|
||||
|
||||
install: $(BINDIR) $(BINDIR)/cvsdiffmin
|
||||
|
||||
%: %.pl customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
%: %.sh customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
customize: configure
|
||||
sh ./configure
|
||||
|
||||
$(BINDIR):
|
||||
mkdir -p $@
|
||||
|
||||
include GNUmakerules
|
|
@ -0,0 +1,68 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
echo "#!/bin/sh" > customize.$$
|
||||
echo "sed \\" > customize.$$
|
||||
chmod +x customize.$$
|
||||
|
||||
################################################################
|
||||
# find a working perl:
|
||||
#
|
||||
for i in /usr/bin/perl /usr/local/bin/perl /usr/bin/perl5 /usr/local/bin/perl5
|
||||
do
|
||||
if $i -e 'exit ($] < 5.000)'
|
||||
then
|
||||
echo $i works
|
||||
perl="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$perl" ]
|
||||
then
|
||||
could not find a working perl command, sorry.
|
||||
exit 1
|
||||
fi
|
||||
echo " -e 's,@@@perl@@@,$perl,g' \\" >> customize.$$
|
||||
|
||||
|
||||
################################################################
|
||||
# find a diff which understands --changed-group-format
|
||||
# and related options (like gnu diff)
|
||||
#
|
||||
echo 'a
|
||||
b
|
||||
c' > diff_format-test.$$.1
|
||||
echo 'a
|
||||
B
|
||||
c' > diff_format-test.$$.2
|
||||
|
||||
wanted="<b
|
||||
=B
|
||||
>"
|
||||
for i in /usr/bin/diff /usr/local/bin/diff
|
||||
do
|
||||
a="`$i --unchanged-group-format='' --changed-group-format='<%<=%>>' diff_format-test.$$.1 diff_format-test.$$.2`"
|
||||
echo "$a"
|
||||
|
||||
if [ "x$a" = "x$wanted" ]
|
||||
then
|
||||
echo $i works
|
||||
diff_format="$i"
|
||||
fi
|
||||
done
|
||||
if [ -z "$diff_format" ]
|
||||
then
|
||||
echo could not find a working diff_format command, sorry.
|
||||
exit 1
|
||||
fi
|
||||
echo " -e 's,@@@diff_format@@@,$diff_format,g' \\" >> customize.$$
|
||||
rm diff_format-test.$$.?
|
||||
|
||||
|
||||
################################################################
|
||||
# finish
|
||||
# Add trailing newline and rename temp file to final name
|
||||
#
|
||||
echo >> customize.$$
|
||||
|
||||
mv customize.$$ customize
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#!@@@perl@@@ -w
|
||||
#
|
||||
# $Id: cvsdiffmin.pl,v 1.3 2000-02-08 17:21:38 hjp Exp $
|
||||
#
|
||||
# cvsdiffmin - minimize output of cvs diff
|
||||
#
|
||||
|
||||
use strict;
|
||||
|
||||
use File::Slurp;
|
||||
|
||||
my $diff = "@@@diff_format@@@";
|
||||
|
||||
my $state = 'EQ';
|
||||
my %text = ();
|
||||
my %cap = ();
|
||||
my $count = 0;
|
||||
|
||||
local $| = 1;
|
||||
|
||||
while (<>) {
|
||||
|
||||
if ($state eq 'EQ' && /^\<{7} /) {
|
||||
$state = 'V1';
|
||||
$text{$state} = "";
|
||||
s/'/_/g;
|
||||
$cap{$state} = $_;
|
||||
next;
|
||||
}
|
||||
if ($state eq 'V1' && /^\={7}$/) {
|
||||
$state = 'V2';
|
||||
$text{$state} = "";
|
||||
next;
|
||||
}
|
||||
if ($state eq 'V2' && /^\>{7} /) {
|
||||
s/'/_/g;
|
||||
$cap{$state} = $_;
|
||||
write_file("cvsdiffmin.$$.$count.1", $text{V1});
|
||||
write_file("cvsdiffmin.$$.$count.2", $text{V2});
|
||||
open (DIFF,
|
||||
"$diff " .
|
||||
" --unchanged-group-format='\%='" .
|
||||
" --changed-group-format='${cap{V1}}\%<=======\n\%>${cap{V2}}'" .
|
||||
" --old-group-format='${cap{V1}}\%<=======\n\%>${cap{V2}}'" .
|
||||
" --new-group-format='${cap{V1}}\%<=======\n\%>${cap{V2}}'" .
|
||||
" cvsdiffmin.$$.$count.1" .
|
||||
" cvsdiffmin.$$.$count.2" .
|
||||
"|") or die "cannot invoke diff: $!";
|
||||
while (<DIFF>) {
|
||||
print;
|
||||
}
|
||||
close(DIFF);
|
||||
unlink ("cvsdiffmin.$$.$count.1", "cvsdiffmin.$$.$count.2")
|
||||
or die "cannot unlink temporary files cvsdiffmin.$$.$count.1, cvsdiffmin.$$.$count.2: $!";
|
||||
|
||||
|
||||
$state = 'EQ';
|
||||
$count++;
|
||||
next;
|
||||
}
|
||||
if ($state eq 'EQ') {
|
||||
print;
|
||||
} else {
|
||||
$text{$state} .= $_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# vim:sw=4
|
|
@ -0,0 +1,38 @@
|
|||
include GNUmakevars
|
||||
|
||||
CONFDIR=../../configure
|
||||
CONFDIR_exists=$(shell [ -d $(CONFDIR) ] && echo ok)
|
||||
|
||||
all: configure find_cvs_not_up_to_date
|
||||
|
||||
clean:
|
||||
rm -f find_cvs_not_up_to_date customize
|
||||
|
||||
distclean: clean
|
||||
|
||||
|
||||
install: $(BINDIR) $(BINDIR)/find_cvs_not_up_to_date
|
||||
|
||||
%: %.pl customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
%: %.sh customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
customize: configure
|
||||
sh ./configure
|
||||
|
||||
ifeq ($(CONFDIR_exists),ok)
|
||||
|
||||
configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish
|
||||
cat $^ > $@
|
||||
|
||||
endif
|
||||
|
||||
$(BINDIR):
|
||||
mkdir -p $@
|
||||
|
||||
include GNUmakerules
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
echo "#!/bin/sh" > customize.$$
|
||||
echo "sed \\" > customize.$$
|
||||
chmod +x customize.$$
|
||||
|
||||
################################################################
|
||||
# find a working perl:
|
||||
#
|
||||
for i in /usr/bin/perl /usr/local/bin/perl /usr/bin/perl5 /usr/local/bin/perl5
|
||||
do
|
||||
if $i -e 'exit ($] < 5.000)'
|
||||
then
|
||||
echo $i works
|
||||
perl="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$perl" ]
|
||||
then
|
||||
could not find a working perl command, sorry.
|
||||
exit 1
|
||||
fi
|
||||
echo " -e 's,@@@perl@@@,$perl,g' \\" >> customize.$$
|
||||
|
||||
|
||||
################################################################
|
||||
# finish
|
||||
# Add trailing newline and rename temp file to final name
|
||||
#
|
||||
echo >> customize.$$
|
||||
|
||||
mv customize.$$ customize
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#!@@@perl@@@ -w
|
||||
use strict;
|
||||
use File::Find;
|
||||
use Getopt::Long;
|
||||
|
||||
my $debug = 0;
|
||||
|
||||
sub check_cvs {
|
||||
local $/ =
|
||||
"===================================================================\n";
|
||||
return unless (-d "$_/CVS");
|
||||
print STDERR "checking $File::Find::dir/$_\n" if ($debug);
|
||||
|
||||
# $_ is a CVS working dir
|
||||
|
||||
open (CVSSTATUS, "cd $_ && cvs -q status|");
|
||||
while(<CVSSTATUS>) {
|
||||
print if (/Status/ && !/Status: Up-to-date/);
|
||||
}
|
||||
close(CVSSTATUS);
|
||||
|
||||
# don't recurse, cvs already did:
|
||||
$File::Find::prune = 1;
|
||||
}
|
||||
|
||||
GetOptions("debug" => \$debug);
|
||||
@ARGV = (".") unless (@ARGV);
|
||||
find(\&check_cvs, @ARGV);
|
|
@ -0,0 +1,177 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
=head1 NAME
|
||||
|
||||
dumpsql - dump output of an SQL query
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
dumpsql
|
||||
[ --vertical
|
||||
[ --escape ]
|
||||
|
|
||||
--xhtml
|
||||
[ --style uri ]
|
||||
]
|
||||
query
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Connects to the database identified by the environment variable
|
||||
DBI_CREDENTIAL_FILE, executes the query given on the command line and
|
||||
prints the output to stdout.
|
||||
|
||||
By default the output is tab-separated. Two alternate formats are
|
||||
available:
|
||||
|
||||
--vertical prints each field in a separate line in "Columnname: Value"
|
||||
format. Rows are separated by empty lines. --Escape escapes unprintable
|
||||
characters.
|
||||
|
||||
--xhtml prints the table as an XHTML file. Optionally a style sheet can
|
||||
be specified with --style.
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
The --escape option only works with --vertical. It should also work with
|
||||
the other two styles.
|
||||
|
||||
=cut
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use DBI;
|
||||
use Getopt::Long;
|
||||
use Encode qw(:fallbacks encode);
|
||||
use I18N::Langinfo qw(langinfo CODESET);
|
||||
use Pod::Usage;
|
||||
|
||||
my $charset = langinfo(CODESET);
|
||||
binmode STDOUT, "encoding($charset)";
|
||||
|
||||
|
||||
my $help;
|
||||
my $vertical; # use vertical output format
|
||||
my $escape; # escape non-printable characters
|
||||
my $xhtml; # produce XHTML output
|
||||
my $style; # produce XHTML output
|
||||
|
||||
GetOptions(
|
||||
'help|?' => \$help,
|
||||
'vertical' => \$vertical,
|
||||
'xhtml' => \$xhtml,
|
||||
'escape' => \$escape,
|
||||
'style:s' => \$style,
|
||||
) || pod2usage(2);
|
||||
pod2usage(1) if $help;
|
||||
|
||||
|
||||
# read credits from file
|
||||
sub _read_cred {
|
||||
my ($fn) = @_;
|
||||
|
||||
open(FN, "<$fn") or die "cannot open $fn: $!";
|
||||
my $line = <FN>;
|
||||
close(FN);
|
||||
my @cred = split(/\s+/, $line);
|
||||
return @cred;
|
||||
}
|
||||
|
||||
|
||||
my $dbh;
|
||||
|
||||
sub dbiconnect {
|
||||
my $cred_file = $ENV{DBI_CREDENTIAL_FILE};
|
||||
if (! defined($cred_file)) {
|
||||
$cred_file = "$ENV{HOME}/.dbi/default";
|
||||
} elsif ($cred_file !~ m{/}) {
|
||||
$cred_file = "$ENV{HOME}/.dbi/$cred_file";
|
||||
}
|
||||
|
||||
$dbh = DBI->connect(_read_cred($cred_file), {RaiseError => 1, AutoCommit => 0});
|
||||
|
||||
my $driver = $dbh->{Driver}->{Name};
|
||||
if ($driver eq 'Pg') {
|
||||
$dbh->{pg_enable_utf8} = 1;
|
||||
}
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
$dbh = dbiconnect();
|
||||
$dbh->{LongReadLen} = 0x1_0000;
|
||||
|
||||
my $query = shift(@ARGV);
|
||||
my @args = @ARGV;
|
||||
my $sth = $dbh->prepare($query);
|
||||
$sth->execute(@args);
|
||||
if ($xhtml) {
|
||||
print qq{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n};
|
||||
print qq{<html>\n};
|
||||
print qq{<head>\n};
|
||||
print qq{<title>}, xmlencode($query), qq{</title>\n};
|
||||
if ($style) {
|
||||
print qq{<link rel='stylesheet' type='text/css' href='},
|
||||
xmlencode($style),
|
||||
qq{'/>\n};
|
||||
}
|
||||
print qq{</head>\n};
|
||||
print qq{<head>\n};
|
||||
print qq{<body>\n};
|
||||
print qq{<h1>}, xmlencode($query), qq{</h1>\n};
|
||||
if (@args) {
|
||||
print qq{<ul>\n};
|
||||
for (@args) {
|
||||
print qq{<li>}, xmlencode($_), qq{</li>\n};
|
||||
}
|
||||
print qq{</ul>\n};
|
||||
}
|
||||
print qq{<table>\n};
|
||||
print qq{<tr>},
|
||||
(
|
||||
map {
|
||||
"<th>" . xmlencode($_) . "</th>"
|
||||
} @{$sth->{NAME}}
|
||||
),
|
||||
"</tr>\n";
|
||||
while (my @a = $sth->fetchrow_array()) {
|
||||
print qq{<tr>},
|
||||
(
|
||||
map {
|
||||
"<td>"
|
||||
. (defined($_) ? xmlencode($_) : '<em>NULL</em>')
|
||||
. "</td>"
|
||||
} @a
|
||||
),
|
||||
"</tr>\n";
|
||||
}
|
||||
print qq{</table>\n};
|
||||
print qq{</body>\n};
|
||||
print qq{</html>\n};
|
||||
} elsif ($vertical) {
|
||||
while (my @a = $sth->fetchrow_array()) {
|
||||
for my $i (0 .. $#a) {
|
||||
print $sth->{NAME}[$i], ": ";
|
||||
if ($escape) {
|
||||
if (defined($a[$i])) {
|
||||
print encode("us-ascii", $a[$i], FB_PERLQQ), "\n";
|
||||
} else {
|
||||
print "NULL\n";
|
||||
}
|
||||
} else {
|
||||
print $a[$i] // "NULL", "\n";
|
||||
}
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
} else {
|
||||
no warnings 'uninitialized';
|
||||
print join("\t", @{$sth->{NAME}}), "\n";
|
||||
while (my @a = $sth->fetchrow_array()) {
|
||||
print join("\t", @a), "\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub xmlencode {
|
||||
my ($s) = @_;
|
||||
return encode("us-ascii", $s, FB_XMLCREF);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
# $Id: GNUmakefile,v 1.4 2002-03-18 20:49:54 hjp Exp $
|
||||
|
||||
include GNUmakevars
|
||||
|
||||
ddm: ddm.o
|
||||
$(CC) $^ $(ANTLIB) -o $@
|
||||
|
||||
ddm.o: ddm.c
|
||||
|
||||
clean:
|
||||
rm -f ddm ddm.o
|
||||
|
||||
distclean: clean
|
||||
rm -f cfg/mnttab.h
|
||||
|
||||
install: $(SBINDIR)/ddm
|
||||
|
||||
cfg/%.h: cfg/%.sh
|
||||
sh $< > $@
|
||||
|
||||
include GNUmakerules
|
||||
|
||||
-include ddm.d
|
||||
|
||||
# $Log: GNUmakefile,v $
|
||||
# Revision 1.4 2002-03-18 20:49:54 hjp
|
||||
# Added target distclean
|
||||
#
|
||||
# Revision 1.3 2000/06/04 16:33:20 hjp
|
||||
# Removed MNTTAB autodetection again as it seems to be already defined.
|
||||
# Don't skip rest of mountpoints if one is not accessible.
|
||||
# chdir to / while sleeping to avoid blocking automounters
|
||||
# increased default sleep interval to 1 hour max.
|
||||
#
|
||||
# Revision 1.2 2000/06/04 16:11:12 hjp
|
||||
# Added autodetection of /etc/m(nt)?tab.
|
||||
#
|
||||
# Revision 1.1 2000/06/04 15:53:18 hjp
|
||||
# Pre-Version. Options are still missing.
|
||||
#
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
for i in /etc/mnttab /etc/mtab
|
||||
do
|
||||
if [ -f $i ]
|
||||
then
|
||||
echo '#define PATH_MNTTAB "'$i'"'
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
exit 1
|
|
@ -0,0 +1,231 @@
|
|||
char ddm_c_rcs_id[] =
|
||||
"$Id: ddm.c,v 1.6 2001-02-21 16:02:46 hjp Exp $";
|
||||
/*
|
||||
* ddm - disk delay monitor
|
||||
*
|
||||
* chdirs to a list of filesystems (mount points by default) and does
|
||||
* the equivalent of an ls -l.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <ant/da.h>
|
||||
#include <ant/io.h>
|
||||
#include <ant/globals.h>
|
||||
|
||||
#include "cfg/mnttab.h"
|
||||
|
||||
|
||||
typedef enum { MODE_NONE, MODE_ARGS, MODE_MNTTAB, MODE_DIRFILE } modeT;
|
||||
|
||||
|
||||
static double gettimestamp(void) {
|
||||
struct timeval tm;
|
||||
|
||||
gettimeofday(&tm, NULL);
|
||||
return tm.tv_sec + tm.tv_usec/1E6;
|
||||
}
|
||||
|
||||
static void usage(void) {
|
||||
fprintf(stderr, "Usage: %s [-d dirfile | -m mnttab | directory ... ] [-s max_sleep_time]\n",
|
||||
cmnd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void printtimestamp (const char *fmt, ...) {
|
||||
static double lts = 0;
|
||||
double ts = gettimestamp();
|
||||
va_list ap;
|
||||
|
||||
fprintf(stderr, "%s: %.6f: %.6f: ", cmnd, ts, ts - lts);
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
lts = ts;
|
||||
}
|
||||
|
||||
int main(int argc, char**argv) {
|
||||
char **dirs = NULL;
|
||||
modeT mode = MODE_NONE;
|
||||
int nr_dirs;
|
||||
int c;
|
||||
char *filename = NULL;
|
||||
double maxsleeptime = 3600;
|
||||
|
||||
cmnd = argv[0];
|
||||
|
||||
while ((c = getopt(argc, argv, "d:m:s:")) != EOF) {
|
||||
switch (c) {
|
||||
char *p;
|
||||
|
||||
case 'd':
|
||||
mode = MODE_DIRFILE;
|
||||
filename = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
mode = MODE_MNTTAB;
|
||||
filename = optarg;
|
||||
break;
|
||||
case 's':
|
||||
maxsleeptime = strtod(optarg, &p);
|
||||
if (p == optarg || *p) usage();
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == MODE_NONE) {
|
||||
if (optind == argc) {
|
||||
mode = MODE_MNTTAB;
|
||||
filename = PATH_MNTTAB;
|
||||
} else {
|
||||
mode = MODE_ARGS;
|
||||
dirs = argv + optind;
|
||||
nr_dirs = argc - optind;
|
||||
}
|
||||
} else {
|
||||
if (optind != argc) usage();
|
||||
}
|
||||
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (;;) {
|
||||
int i;
|
||||
int sleeptime;
|
||||
|
||||
/* Get list of directories
|
||||
*/
|
||||
switch (mode) {
|
||||
case MODE_MNTTAB: {
|
||||
FILE *mtp;
|
||||
struct mntent *me;
|
||||
|
||||
printtimestamp("open %s\n", filename);
|
||||
if ((mtp = setmntent(filename, "r")) == NULL) {
|
||||
fprintf(stderr, "%s: cannot open %s: %s\n",
|
||||
argv[0], filename, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
for (i = 0;(me = getmntent(mtp)); i++) {
|
||||
DA_MKIND_INI(dirs, i, NULL);
|
||||
if (dirs[i]) free(dirs[i]);
|
||||
dirs[i] = strdup(me->mnt_dir);
|
||||
printtimestamp("mountpoint %s\n", dirs[i]);
|
||||
}
|
||||
endmntent(mtp);
|
||||
|
||||
nr_dirs = i;
|
||||
break;
|
||||
}
|
||||
case MODE_DIRFILE: {
|
||||
FILE *fp;
|
||||
char *p;
|
||||
|
||||
printtimestamp("open %s\n", filename);
|
||||
fp = efopen(filename, "r");
|
||||
for (i = 0;(p = getline(fp)); i++) {
|
||||
DA_MKIND_INI(dirs, i, NULL);
|
||||
if (dirs[i]) free(dirs[i]);
|
||||
dirs[i] = strdup(p);
|
||||
printtimestamp("directory %s\n", dirs[i]);
|
||||
}
|
||||
efclose(fp);
|
||||
|
||||
nr_dirs = i;
|
||||
break;
|
||||
}
|
||||
case MODE_ARGS:
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
|
||||
/* Now read them
|
||||
*/
|
||||
for (i = 0; i < nr_dirs; i++) {
|
||||
int j;
|
||||
char **entries = NULL;
|
||||
int nr_entries;
|
||||
DIR *dp;
|
||||
struct dirent *de;
|
||||
|
||||
printtimestamp("start %s\n", dirs[i]);
|
||||
if (chdir(dirs[i]) == -1) {
|
||||
printtimestamp("chdir %s failed: %s\n", dirs[i], strerror(errno));
|
||||
continue;
|
||||
}
|
||||
printtimestamp("chdir %s ok\n", dirs[i]);
|
||||
|
||||
if ((dp = opendir(".")) == NULL) {
|
||||
printtimestamp("opendir %s failed: %s\n", dirs[i], strerror(errno));
|
||||
continue;
|
||||
}
|
||||
for (j = 0;(de = readdir(dp)); j++) {
|
||||
DA_MKIND_INI(entries, j, NULL);
|
||||
if (entries[j]) free(entries[j]);
|
||||
entries[j] = strdup(de->d_name);
|
||||
printtimestamp("entry %s\n", entries[j]);
|
||||
}
|
||||
closedir(dp);
|
||||
nr_entries = j;
|
||||
|
||||
for (j = 0; j < nr_entries; j++) {
|
||||
struct stat st;
|
||||
stat (entries[j], &st);
|
||||
printtimestamp("stat entry %s\n", entries[j]);
|
||||
}
|
||||
}
|
||||
|
||||
chdir("/");
|
||||
|
||||
sleeptime = rand() * maxsleeptime / RAND_MAX;
|
||||
printtimestamp("sleeping %d seconds\n", sleeptime);
|
||||
sleep(sleeptime);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* $Log: ddm.c,v $
|
||||
* Revision 1.6 2001-02-21 16:02:46 hjp
|
||||
* Added config test for mnttab again.
|
||||
* Added option -s (max sleep time)
|
||||
* Added script stats.sh to generate stats.
|
||||
*
|
||||
* Revision 1.5 2000/09/07 10:12:35 hjp
|
||||
* Added alternate ways to specify directories to be monitored.
|
||||
*
|
||||
* Revision 1.4 2000/06/04 16:33:21 hjp
|
||||
* Removed MNTTAB autodetection again as it seems to be already defined.
|
||||
* Don't skip rest of mountpoints if one is not accessible.
|
||||
* chdir to / while sleeping to avoid blocking automounters
|
||||
* increased default sleep interval to 1 hour max.
|
||||
*
|
||||
* Revision 1.3 2000/06/04 16:19:00 hjp
|
||||
* Fixed order of args in fprintf (segfault).
|
||||
*
|
||||
* Revision 1.2 2000/06/04 16:11:12 hjp
|
||||
* Added autodetection of /etc/m(nt)?tab.
|
||||
*
|
||||
* Revision 1.1 2000/06/04 15:53:19 hjp
|
||||
* Pre-Version. Options are still missing.
|
||||
*
|
||||
*/
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
# simple statistics (min, avg, max) for ddm output
|
||||
|
||||
awk -F : '{ n[$4] ++; s[$4] += $3; if ($3 < min[$4]) min[$4] = $3; if ($3 > max[$4]) max[$4] = $3; }
|
||||
END { for (i in n) { printf "%10.6f %10.6f %10.6f %s\n", min[i], s[i]/n[i], max[i], i } }' "$@" | sort -n +2
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
include GNUmakevars
|
||||
|
||||
all: gethostbyaddr gethostbyname fqdn query check
|
||||
install: \
|
||||
$(BINDIR)/axfr \
|
||||
$(BINDIR)/fqdn \
|
||||
$(BINDIR)/gethostbyaddr \
|
||||
$(BINDIR)/gethostbyname \
|
||||
$(BINDIR)/minnet \
|
||||
$(BINDIR)/query \
|
||||
$(BINDIR)/dns-inc-serial \
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.bak *.o core gethostbyaddr gethostbyname fqdn check
|
||||
|
||||
distclean: clean
|
||||
rm -f *.d GNUmakevars GNUmakerules
|
||||
|
||||
cfg/%:
|
||||
$(MAKE) -C cfg all
|
||||
|
||||
gethostbyname: gethostbyname.o hstrerror.o
|
||||
|
||||
fqdn: fqdn.o hstrerror.o
|
||||
|
||||
hstrerror.o: cfg/have_hstrerror.h
|
||||
|
||||
axfr:
|
||||
|
||||
%: %.pl
|
||||
cp $< $@
|
||||
chmod +x $@
|
||||
|
||||
GNUmakevars: GNUmakevars.sh
|
||||
sh ./$^ > $@
|
||||
GNUmakerules: GNUmakerules.sh
|
||||
sh ./$^ > $@
|
||||
|
||||
include GNUmakerules
|
||||
|
||||
-include *.d
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
echo "\$(BINDIR)/%: %"
|
||||
echo "\tcp \$^ \$@"
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
prefix=${prefix:-/usr/local}
|
||||
echo "BINDIR=$prefix/bin"
|
||||
echo
|
||||
echo "all:"
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
use Net::DNS;
|
||||
|
||||
sub usage {
|
||||
print STDERR "Usage: $0 zone nameserver\n" unless (@ARGV == 2);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
usage() unless (@ARGV == 2);
|
||||
|
||||
my $res = new Net::DNS::Resolver;
|
||||
$res->nameservers($ARGV[1]);
|
||||
my @zone = $res->axfr($ARGV[0]);
|
||||
if (@zone) {
|
||||
foreach my $rr (@zone) {
|
||||
$rr->print;
|
||||
}
|
||||
} else {
|
||||
print STDERR "query failed: ", $res->errorstring, "\n";
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
all: have_hstrerror.h
|
||||
|
||||
%.h: %.sh
|
||||
CC='$(CC)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh $^ > $@
|
||||
|
||||
clean:
|
||||
rm *.h
|
|
@ -0,0 +1,11 @@
|
|||
cat > has_hstrerror_$$.c <<EOF
|
||||
#include <netdb.h>
|
||||
int main(void) { hstrerror(0); }
|
||||
EOF
|
||||
if $CC $CFLAGS has_hstrerror_$$.c $LDFLAGS -o has_hstrerror_$$
|
||||
then
|
||||
echo '#define HAVE_HSTRERROR 1'
|
||||
else
|
||||
echo '#define HAVE_HSTRERROR 0'
|
||||
fi
|
||||
rm has_hstrerror_$$.c has_hstrerror_$$
|
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
use Net::DNS;
|
||||
|
||||
sub usage {
|
||||
print STDERR "Usage: $0 ip-address\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
usage() unless (@ARGV == 1);
|
||||
|
||||
# generic resolver
|
||||
my $res0 = new Net::DNS::Resolver;
|
||||
|
||||
my $ipv4 = $ARGV[0];
|
||||
|
||||
my $rev_domain = join(".", reverse (split(/\./, $ipv4)), "in-addr", "arpa");
|
||||
print STDERR "$rev_domain\n";
|
||||
|
||||
my $reply = $res0->send($rev_domain, 'PTR');
|
||||
|
||||
if ($reply->answer) {
|
||||
for my $rr ($reply->answer) {
|
||||
if ($rr->type eq 'PTR') {
|
||||
print STDERR "\t", $rr->ptrdname, "\n";
|
||||
check_a($rr->ptrdname, $ipv4);
|
||||
}
|
||||
}
|
||||
} elsif ($reply->authority) {
|
||||
for my $rr ($reply->authority) {
|
||||
if ($rr->type eq 'SOA') {
|
||||
print STDERR "\t", $rr->mname, "\n";
|
||||
my $res1 = Net::DNS::Resolver->new();
|
||||
$res1->nameservers($rr->mname);
|
||||
my @zone = $res1->axfr($rev_domain);
|
||||
for my $rr (@zone) {
|
||||
if ($rr->type eq 'PTR') {
|
||||
print STDERR "\t\t", $rr->ptrdname, "\n";
|
||||
my $ipv4 = join(".", (reverse(split(/\./, $rr->name)))[2..5]);
|
||||
check_a($rr->ptrdname, $ipv4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$reply->print
|
||||
}
|
||||
|
||||
sub check_a {
|
||||
my ($domain_name, $a) = @_;
|
||||
# check that $domain_name resolves to $a
|
||||
|
||||
my $reply = $res0->send($domain_name, 'A');
|
||||
|
||||
if ($reply->answer) {
|
||||
for my $rr ($reply->answer) {
|
||||
if ($rr->type eq 'A') {
|
||||
print STDERR "\t\t", $rr->address, "\n";
|
||||
if ($rr->address eq $a) {
|
||||
print STDERR "\t\t\tfound\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print " $a $domain_name FWD_FAIL\n";
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,317 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
use Net::DNS;
|
||||
|
||||
sub usage {
|
||||
print STDERR "Usage: $0 domainname-or-ip-address\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
my $verbose;
|
||||
|
||||
if (($ARGV[0] || '') eq '-v') {
|
||||
$verbose = 1;
|
||||
shift @ARGV;
|
||||
}
|
||||
|
||||
usage() unless (@ARGV == 1);
|
||||
|
||||
# generic resolver
|
||||
my $res0 = new Net::DNS::Resolver;
|
||||
|
||||
# special resolver to query specific nameservers
|
||||
my $res1 = new Net::DNS::Resolver;
|
||||
my $zone;
|
||||
if ($ARGV[0] =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
|
||||
check_ptr($ARGV[0]);
|
||||
} else {
|
||||
check_a($ARGV[0]);
|
||||
}
|
||||
check_zone($ARGV[0]) if ($zone);
|
||||
|
||||
exit 0;
|
||||
|
||||
my %addr_to_name;
|
||||
my %name_to_addr;
|
||||
|
||||
sub check_ptr {
|
||||
my ($addr, $name) = @_;
|
||||
|
||||
my @names;
|
||||
if (defined $addr_to_name{$addr}) {
|
||||
@names = @{ $addr_to_name{$addr} };
|
||||
} else {
|
||||
# XXX - ipv6?
|
||||
my $q = join('.', reverse (split(/\./, $addr)), "in-addr", "arpa");
|
||||
my $reply = $res0->send($q, 'PTR');
|
||||
for my $ans ($reply->answer) {
|
||||
if ($ans->type eq 'PTR') {
|
||||
push @names, $ans->ptrdname;
|
||||
} else {
|
||||
die "cannot happen";
|
||||
}
|
||||
}
|
||||
if (@names == 0) {
|
||||
print "[$addr] $q has no PTR record\n";
|
||||
}
|
||||
$addr_to_name{$addr} = \@names;
|
||||
get_zone($reply) unless $zone;
|
||||
}
|
||||
if ($name) {
|
||||
unless (grep { $_ eq $name } @names) {
|
||||
print "$name not found in PTR records of [$addr]\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
for my $name (@names) {
|
||||
print "I: [$addr] -> $name\n" if $verbose;
|
||||
check_a($name, $addr);
|
||||
}
|
||||
}
|
||||
|
||||
sub check_a {
|
||||
my ($name, $addr) = @_;
|
||||
|
||||
my @addrs;
|
||||
if (defined $name_to_addr{$name}) {
|
||||
@addrs = @{ $name_to_addr{$name} };
|
||||
} else {
|
||||
my $reply = $res0->send($name, 'A');
|
||||
for my $ans ($reply->answer) {
|
||||
if ($ans->type eq 'A') {
|
||||
push @addrs, $ans->address;
|
||||
} elsif ($ans->type eq 'CNAME') {
|
||||
die "cnames not yet supported";
|
||||
} else {
|
||||
print "unexpected response to A query for $name\n";
|
||||
$ans->print;
|
||||
}
|
||||
}
|
||||
if (@addrs == 0) {
|
||||
print "$name has no A record\n";
|
||||
}
|
||||
$name_to_addr{$name} = \@addrs;
|
||||
get_zone($reply) unless $zone;
|
||||
}
|
||||
if ($addr) {
|
||||
unless (grep { $_ eq $addr } @addrs) {
|
||||
print "[$addr] not found in A records of $name\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
for my $addr (@addrs) {
|
||||
print "I: $name -> [$addr]\n" if $verbose;
|
||||
check_ptr($addr, $name);
|
||||
}
|
||||
}
|
||||
|
||||
sub get_zone {
|
||||
my ($reply) = @_;
|
||||
|
||||
for my $auth ($reply->authority) {
|
||||
if (defined $zone) {
|
||||
if ($zone ne $auth->name) {
|
||||
print "inconsistent authority RRs:\n";
|
||||
print $auth->print;
|
||||
print "doesn't match previously found zone $zone\n";
|
||||
}
|
||||
} else {
|
||||
$zone = $auth->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub check_zone {
|
||||
my ($name) = @_;
|
||||
|
||||
my $rootns = chr(rand(13) + 65) . ".root-servers.net.";
|
||||
my $reply = $res0->send($rootns, 'A');
|
||||
my @ns = (($reply->answer)[0]->address);
|
||||
my %authns;
|
||||
my %seen;
|
||||
while (@ns) {
|
||||
my $ns = shift (@ns);
|
||||
$res1->nameservers($ns);
|
||||
my $reply = $res1->send($zone, 'NS');
|
||||
|
||||
# if the reply contains a non-empty answer section, use it as
|
||||
# a list of authoritative name servers.
|
||||
if ($reply->answer) {
|
||||
for my $rr ($reply->answer) {
|
||||
if ($rr->type eq 'NS') {
|
||||
print STDERR "$ns reported NS ", $rr->nsdname, "\n";;
|
||||
|
||||
$authns{$ns}{$rr->nsdname} = 1;
|
||||
$authns{ALL}{$rr->nsdname} = 1;
|
||||
for (get_addresses($rr->nsdname)) {
|
||||
unless ($seen{$_}) {
|
||||
push @ns, $_;
|
||||
$seen{$_} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
next;
|
||||
}
|
||||
#
|
||||
if ($reply->authority) {
|
||||
for my $rr ($reply->authority) {
|
||||
if ($rr->type eq 'NS') {
|
||||
if ($rr->name eq $name) {
|
||||
# if the reply contains an authority section with the right
|
||||
# domain, use it as a list of authoritative name servers.
|
||||
print STDERR "$ns reported NS ", $rr->nsdname, "\n";;
|
||||
|
||||
$authns{$ns}{$rr->nsdname} = 1;
|
||||
$authns{ALL}{$rr->nsdname} = 1;
|
||||
for (get_addresses($rr->nsdname)) {
|
||||
unless ($seen{$_}) {
|
||||
push @ns, $_;
|
||||
$seen{$_} = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# Otherwise, just add the nameservers from the authority section
|
||||
# to the list of nameservers still to query.
|
||||
for (get_addresses($rr->nsdname)) {
|
||||
unless ($seen{$_}) {
|
||||
push @ns, $_;
|
||||
$seen{$_} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
next;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
# We must make sure that we get a result from all authoritative
|
||||
# name servers
|
||||
#
|
||||
# XXX
|
||||
#
|
||||
# Isn't that included in the next test? If an authoritative
|
||||
# nameserver doesn't answer, it will be reported as not reporting
|
||||
# all nameservers.
|
||||
|
||||
# All lists of nameservers must be identical.
|
||||
#
|
||||
for my $authns (sort keys %{ $authns{ALL} }) {
|
||||
for my $origns (sort keys %authns) {
|
||||
print "$origns doesn't report $authns\n" unless $authns{$origns}{$authns};
|
||||
}
|
||||
}
|
||||
|
||||
my @noaxfr;
|
||||
my %zone;
|
||||
for my $authns (sort keys %{ $authns{ALL} }) {
|
||||
$res1->nameservers($authns);
|
||||
my @zone = $res1->axfr($zone);
|
||||
push @noaxfr, $authns unless @zone;
|
||||
for my $rr (@zone) {
|
||||
my $key = rr2key($rr);
|
||||
|
||||
$zone{$authns}{$rr->name}{$rr->type}{$key} = 1;
|
||||
$zone{ALL}{$rr->name}{$rr->type}{$key} = 1;
|
||||
}
|
||||
}
|
||||
for my $authns (@noaxfr) {
|
||||
$res1->nameservers($authns);
|
||||
for my $name (sort keys %{ $zone{ALL} }) {
|
||||
for my $type (sort keys %{ $zone{ALL}{$name} }) {
|
||||
my $reply = $res1->send($name, $type);
|
||||
for my $rr ($reply->answer) {
|
||||
if ($rr->type eq $type) {
|
||||
my $key = rr2key($rr);
|
||||
$zone{$authns}{$rr->name}{$rr->type}{$key} = 1;
|
||||
$zone{ALL}{$rr->name}{$rr->type}{$key} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for my $authns (sort keys %zone) {
|
||||
# next if $authns eq 'ALL';
|
||||
for my $name (sort keys %{ $zone{ALL} }) {
|
||||
for my $type (sort keys %{ $zone{ALL}{$name} }) {
|
||||
for my $key (sort keys %{ $zone{ALL}{$name}{$type} }) {
|
||||
unless ($zone{$authns}{$name}{$type}{$key}) {
|
||||
print STDERR "$authns is missing $name $type $key\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
sub get_addresses {
|
||||
my ($name) = @_;
|
||||
my @addrs;
|
||||
my $reply = $res0->send($name, 'A');
|
||||
for my $rr ($reply->answer) {
|
||||
if ($rr->type eq 'A') {
|
||||
push @addrs, $rr->address;
|
||||
}
|
||||
# XXX - resolve CNAMEs?
|
||||
}
|
||||
return @addrs;
|
||||
}
|
||||
|
||||
sub rr2key {
|
||||
my ($rr) = @_;
|
||||
|
||||
my $key;
|
||||
|
||||
if ($rr->type eq 'A') {
|
||||
$key = $rr->address;
|
||||
} elsif ($rr->type eq 'SOA') {
|
||||
$key = join(' ', $rr->mname, $rr->rname, $rr->serial, $rr->refresh, $rr->retry, $rr->expire, $rr->minimum);
|
||||
} elsif ($rr->type eq 'NS') {
|
||||
$key = $rr->nsdname;
|
||||
} elsif ($rr->type eq 'MX') {
|
||||
$key = join(' ', $rr->preference, $rr->exchange);
|
||||
} elsif ($rr->type eq 'CNAME') {
|
||||
$key = $rr->cname;
|
||||
} elsif ($rr->type eq 'TXT') {
|
||||
$key = $rr->txtdata;
|
||||
} elsif ($rr->type eq 'SRV') {
|
||||
$key = join(' ', $rr->priority, $rr->weight, $rr->port, $rr->target);
|
||||
} elsif ($rr->type eq 'PTR') {
|
||||
$key = $rr->ptrdname;
|
||||
} elsif ($rr->type eq 'HINFO') {
|
||||
$key = join(' ', $rr->cpu, $rr->os);
|
||||
} elsif ($rr->type eq 'LOC') {
|
||||
# sloppy
|
||||
my ($lat, $lon) = $rr->latlon;
|
||||
$key = join(' ', $lat, $lon, $rr->altitude);
|
||||
} else {
|
||||
print STDERR "unhandled RR:\n";
|
||||
print STDERR $rr->string, "\n";
|
||||
exit(1);
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
# Notes:
|
||||
#
|
||||
# for every a record, check ptr.
|
||||
#
|
||||
# for every ptr, check a
|
||||
#
|
||||
# find the zone (authority section).
|
||||
#
|
||||
# Check name servers (starting at random root).
|
||||
#
|
||||
# Try axfr.
|
||||
# check each record:
|
||||
# the same on all nameservers?
|
||||
# A to PTR and vice versa
|
||||
# MX
|
||||
#
|
||||
# vim: tw=0 sw=4 expandtab
|
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use Getopt::Long;
|
||||
use Net::DNS::Resolver;
|
||||
|
||||
my $cfg;
|
||||
GetOptions('config:s' => \$cfg);
|
||||
|
||||
my %file2zone;
|
||||
my $res;
|
||||
|
||||
if ($cfg) {
|
||||
# XXX - this is very simplistic
|
||||
open(my $fh, '<', $cfg) or die "cannot open $cfg: $!";
|
||||
my $currentzone;
|
||||
while (<$fh>) {
|
||||
if (/zone "(.*?)"/) {
|
||||
$currentzone = $1;
|
||||
} elsif (m{file ".*/(.*)"}) {
|
||||
$file2zone{$1} = $currentzone;
|
||||
}
|
||||
}
|
||||
$res = Net::DNS::Resolver->new();
|
||||
}
|
||||
|
||||
for my $f (@ARGV) {
|
||||
my $maxserial = 0;
|
||||
if (my $zone = $file2zone{$f}) {
|
||||
my $reply = $res->send($zone, 'NS');
|
||||
my @nsnames;
|
||||
for my $ans ($reply->answer) {
|
||||
push @nsnames, $ans->nsdname;
|
||||
}
|
||||
my @nsips;
|
||||
for (@nsnames) {
|
||||
my $reply = $res->send($_, 'A');
|
||||
for my $ans ($reply->answer) {
|
||||
push @nsips, $ans->address if $ans->type eq 'A';
|
||||
}
|
||||
}
|
||||
for (@nsips) {
|
||||
$res->nameservers($_);
|
||||
my $reply = $res->send($zone, 'SOA');
|
||||
for my $ans ($reply->answer) {
|
||||
if ($ans->type eq 'SOA') {
|
||||
# XXX assume no wraparound
|
||||
if ($ans->serial > $maxserial) {
|
||||
$maxserial = $ans->serial;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open (my $in, '<', "$f") or die "cannot open $f: $!";
|
||||
open (my $out, '>', "$f.new") or die "cannot open $f.new: $!";
|
||||
while (<$in>) {
|
||||
if (/(.*\bSOA\b.*?)(\d+)( \d+ \d+ \d+ \d+)/) {
|
||||
my $serial = $2;
|
||||
$maxserial = $serial if ($serial > $maxserial);
|
||||
$maxserial++;
|
||||
print $out "$1$maxserial$3\n";
|
||||
} else {
|
||||
print $out $_;
|
||||
}
|
||||
}
|
||||
close($out) or die "cannot close $f.new: $!";
|
||||
rename "$f.new", $f || die "cannot rename $f.new to $f: $!";
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
use autodie;
|
||||
|
||||
for my $zonefile (@ARGV) {
|
||||
open my $in, '<', $zonefile;
|
||||
open my $out, '>', "$zonefile.$$";
|
||||
while (<$in>) {
|
||||
# @ SOA ns1.wsr.ac.at. hostmaster.wsr.ac.at. 1957 14400 3600 604800 86400
|
||||
if ( my ($prefix, $master, $rp, $serial, $refresh, $retry, $expire, $negttl)
|
||||
= m/(.*)SOA\s+(\S+)\s+(\S+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)/
|
||||
) {
|
||||
# maximum time recommended by RFC 2308, also enforced by
|
||||
# BIND (by default).
|
||||
if ($negttl >= 3 * 3600) {
|
||||
$negttl = 3600;
|
||||
$serial++;
|
||||
}
|
||||
print $out "${prefix}SOA\t$master $rp $serial $refresh $retry $expire $negttl\n";
|
||||
} else {
|
||||
print $out $_;
|
||||
}
|
||||
}
|
||||
rename "$zonefile.$$", $zonefile;
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* fqdn - print fully qualified domain name(s)
|
||||
*
|
||||
* resolve all host names given on the comman line and print their
|
||||
* fully qualified canonical names.
|
||||
*
|
||||
* If no argument is given, print the system's FQDN.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include "hstrerror.h"
|
||||
|
||||
char cvs_id[] = "$Id: fqdn.c,v 1.5 2004-05-17 18:13:46 hjp Exp $";
|
||||
|
||||
char *cmnd;
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr, "Usage: %s [hostname ...]\n", cmnd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
int rc = 0;
|
||||
char hostname[256];
|
||||
char *fake_argv[] = { NULL, hostname, NULL };
|
||||
|
||||
cmnd = argv[0];
|
||||
|
||||
if (argc < 2) {
|
||||
if (gethostname(hostname, sizeof(hostname)) == -1) {
|
||||
fprintf(stderr, "%s: cannot get hostname: %s\n",
|
||||
cmnd, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
argv = fake_argv;
|
||||
argc = 2;
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
struct hostent *he = gethostbyname(argv[i]);
|
||||
int found = 0;
|
||||
|
||||
if (!he) {
|
||||
fprintf(stderr, "%s: cannot resolve %s: %s\n",
|
||||
cmnd, argv[i], hstrerror(h_errno));
|
||||
rc++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strchr(he->h_name, '.')) {
|
||||
printf("%s\n", he->h_name);
|
||||
found = 1;
|
||||
} else {
|
||||
char **a;
|
||||
fprintf(stderr, "Canonical name doesn't contain a dot.\n");
|
||||
fprintf(stderr, "Please shoot the administrator of this box.\n");
|
||||
fprintf(stderr, "In the mean time I try to find a suitable alias.\n");
|
||||
for (a = he->h_aliases; !found && *a; a++) {
|
||||
if (strchr(*a, '.')) {
|
||||
printf("%s\n", *a);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
fprintf(stderr, "No alias, either. Consider more painful methods than shooting.\n");
|
||||
rc++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return rc;
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "hstrerror.h"
|
||||
|
||||
char *cmnd;
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr, "Usage: %s [hostname ...]\n", cmnd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
int rc = 0;
|
||||
|
||||
cmnd = argv[0];
|
||||
|
||||
if (argc < 2) {
|
||||
usage();
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
struct in_addr ia;
|
||||
if (!inet_aton(argv[i], &ia)) {
|
||||
fprintf(stderr, "%s: cannot parse %s\n",
|
||||
argv[0], argv[i]);
|
||||
continue;
|
||||
}
|
||||
struct hostent *he = gethostbyaddr(&ia, sizeof(ia), AF_INET);
|
||||
char **a;
|
||||
|
||||
if (!he) {
|
||||
fprintf(stderr, "%s: cannot resolve %s: %s\n",
|
||||
argv[0], argv[i], hstrerror(h_errno));
|
||||
rc++;
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s\n", argv[i]);
|
||||
printf("\tCanonical: %s\n", he->h_name);
|
||||
for (a = he->h_aliases; *a; a++) {
|
||||
printf("\tAlias: %s\n", *a);
|
||||
}
|
||||
for (a = he->h_addr_list; *a; a++) {
|
||||
int j;
|
||||
printf("\tAddress: ");
|
||||
for (j = 0; j < he->h_length; j++) {
|
||||
printf("%s%d", j ? "." : "", (unsigned char)(*a)[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return rc;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "hstrerror.h"
|
||||
|
||||
char *cmnd;
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr, "Usage: %s [hostname ...]\n", cmnd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
int rc = 0;
|
||||
|
||||
cmnd = argv[0];
|
||||
|
||||
if (argc < 2) {
|
||||
usage();
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
struct hostent *he = gethostbyname(argv[i]);
|
||||
char **a;
|
||||
|
||||
if (!he) {
|
||||
fprintf(stderr, "%s: cannot resolve %s: %s\n",
|
||||
argv[0], argv[i], hstrerror(h_errno));
|
||||
rc++;
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s\n", argv[i]);
|
||||
printf("\tCanonical: %s\n", he->h_name);
|
||||
for (a = he->h_aliases; *a; a++) {
|
||||
printf("\tAlias: %s\n", *a);
|
||||
}
|
||||
for (a = he->h_addr_list; *a; a++) {
|
||||
int j;
|
||||
printf("\tAddress: ");
|
||||
for (j = 0; j < he->h_length; j++) {
|
||||
printf("%s%d", j ? "." : "", (unsigned char)(*a)[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return rc;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#include "cfg/have_hstrerror.h"
|
||||
#include "hstrerror.h"
|
||||
|
||||
#if (!HAVE_HSTRERROR)
|
||||
const char *hstrerror(int err) {
|
||||
static char errstr[80];
|
||||
|
||||
snprintf(errstr, sizeof(errstr), "resolver error %d", err);
|
||||
return errstr;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1 @@
|
|||
const char * hstrerror(int err);
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
my $min = 0xFFFF_FFFF;
|
||||
my $max = 0x0000_0000;
|
||||
|
||||
for (@ARGV) {
|
||||
if (/(\d+)\.(\d+)\.(\d+)\.(\d+)/) {
|
||||
my $adr = $1 * 0x100_0000 + $2 * 0x1_0000 + $3 * 0x100 + $4;
|
||||
$max = $adr if ($adr > $max);
|
||||
$min = $adr if ($adr < $min);
|
||||
}
|
||||
}
|
||||
|
||||
my $diff = $min ^ $max;
|
||||
|
||||
# printf "min = %08x max = %08x diff = %08x\n", $min, $max, $diff;
|
||||
|
||||
my $netmaskbits = 32;
|
||||
my $netmask = 0xFFFF_FFFF;
|
||||
|
||||
while ($diff > 0) {
|
||||
$netmaskbits--;
|
||||
$diff >>= 1;
|
||||
$netmask <<= 1;
|
||||
}
|
||||
|
||||
my $net = $min & $netmask;
|
||||
my $bcast = $min | ~$netmask;
|
||||
|
||||
printf "net = %s/%d (%s/%s) bcast = %s\n",
|
||||
dottedquad($net),
|
||||
$netmaskbits,
|
||||
dottedquad($net),
|
||||
dottedquad($netmask),
|
||||
dottedquad($bcast);
|
||||
|
||||
sub dottedquad {
|
||||
my ($adr) = @_;
|
||||
return sprintf "%d.%d.%d.%d",
|
||||
($adr >> 24) & 0xFF,
|
||||
($adr >> 16) & 0xFF,
|
||||
($adr >> 8) & 0xFF,
|
||||
($adr >> 0) & 0xFF;
|
||||
}
|
||||
|
||||
exit(0);
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
use Net::DNS;
|
||||
|
||||
sub usage {
|
||||
print STDERR "Usage: $0 domainname type nameserver\n" unless (@ARGV == 2);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
usage() unless (@ARGV == 3);
|
||||
|
||||
my $res = new Net::DNS::Resolver;
|
||||
$res->nameservers($ARGV[2]);
|
||||
my $answer = $res->query($ARGV[0], $ARGV[1]);
|
||||
if ($answer) {
|
||||
$answer->print;
|
||||
} else {
|
||||
print STDERR "query failed: ", $res->errorstring, "\n";
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use File::Find;
|
||||
|
||||
use MIME::Parser;
|
||||
my $parser = new MIME::Parser;
|
||||
$parser->output_to_core(1);
|
||||
$parser->tmp_to_core(1);
|
||||
|
||||
my %files;
|
||||
my %messages;
|
||||
sub check_file {
|
||||
unless (-f) {
|
||||
return;
|
||||
}
|
||||
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
||||
$atime,$mtime,$ctime,$blksize,$blocks) = stat(_);
|
||||
if ($files{"$dev.$ino"}) {
|
||||
# we already looked at this file - skip
|
||||
return;
|
||||
}
|
||||
my $entity = $parser->parse_open($_);
|
||||
unless ($entity) {
|
||||
print STDERR "$File::Find::name cannot be parsed: skipping\n";
|
||||
return;
|
||||
}
|
||||
my $mid = $entity->head->get('Message-Id');
|
||||
unless ($mid) {
|
||||
print STDERR "$File::Find::name contains no message id: skipping\n";
|
||||
return;
|
||||
}
|
||||
if ($messages{$mid}) {
|
||||
# duplicate!
|
||||
print STDERR "$File::Find::name is a duplicate of ",
|
||||
$files{$messages{$mid}},
|
||||
"\n";
|
||||
my $ft = $File::Find::name;
|
||||
$ft =~ s|(.*/)(.*)|$1|;
|
||||
$ft .= "removedups.$$." . rand;
|
||||
link ($files{$messages{$mid}}, $ft) && rename ($ft, $File::Find::name) || do {
|
||||
print STDERR "\terror: $!\n";
|
||||
};
|
||||
return;
|
||||
}
|
||||
$messages{$mid} = "$dev.$ino";
|
||||
$files{"$dev.$ino"} = $File::Find::name;
|
||||
}
|
||||
|
||||
find(\&check_file, @ARGV);
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use File::Find;
|
||||
use Digest::SHA1;
|
||||
use Data::Dumper;
|
||||
|
||||
my %files;
|
||||
sub check_file {
|
||||
unless (-f) {
|
||||
return;
|
||||
}
|
||||
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
||||
$atime,$mtime,$ctime,$blksize,$blocks) = stat(_);
|
||||
$files{$size}{i}{"$dev.$ino"}{n}{$File::Find::name} = 1;
|
||||
}
|
||||
|
||||
print STDERR "sorting files by size\n";
|
||||
find(\&check_file, @ARGV);
|
||||
print STDERR "... done\n";
|
||||
|
||||
for my $s (sort { $a <=> $b } keys %files) {
|
||||
print STDERR "checking files of size $s\n";
|
||||
if (scalar keys %{$files{$s}{i}} == 1) {
|
||||
print STDERR "only one file of size $s: skipping\n";
|
||||
} else {
|
||||
for my $i (keys %{$files{$s}{i}}) {
|
||||
my $f = (keys %{$files{$s}{i}{$i}{n}})[0];
|
||||
if (open (F, "<", $f)) {
|
||||
# print STDERR "\tcomputing checksum of $f\n";
|
||||
my $sha1 = Digest::SHA1->new;
|
||||
$sha1->addfile(*F);
|
||||
my $d = $sha1->b64digest;
|
||||
if ($files{$s}{d}{$d}) {
|
||||
print STDERR "\t\tduplicate found\n";
|
||||
my $fo = (keys %{$files{$s}{d}{$d}{n}})[0];
|
||||
for my $fd (keys %{$files{$s}{i}{$i}{n}}) {
|
||||
print "\t\t\tlinking $fd to $fo\n";
|
||||
my $ft = $fd;
|
||||
$ft =~ s|(.*/)(.*)|$1|;
|
||||
$ft .= "removedups.$$." . rand;
|
||||
link ($fo, $ft) && rename ($ft, $fd) || do {
|
||||
print STDERR "\t\t\t\terror: $!\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$files{$s}{d}{$d} = $files{$s}{i}{$i};
|
||||
}
|
||||
} else {
|
||||
print STDERR "cannot open $f: $!: ignoring\n";
|
||||
}
|
||||
delete $files{$s}{i}{$i};
|
||||
}
|
||||
# print Dumper $files{$s};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
install: $(ROOT)/usr/local/bin/duwatch
|
||||
install_all:
|
||||
make install ROOT=/nfs/wsrdb
|
||||
make install ROOT=/nfs/wifosv
|
||||
make install ROOT=/nfs/ihssv
|
||||
make install ROOT=/nfs/wsrcom
|
||||
|
||||
$(ROOT)/usr/local/bin/%: %
|
||||
install $< $@
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
$avgfile = "/usr/local/lib/duwatch.avg";
|
||||
$root = "/";
|
||||
$thresh = 20000;
|
||||
$period = 30;
|
||||
|
||||
open AVG, $avgfile || die;
|
||||
while (<AVG>) {
|
||||
($size, $name) = split;
|
||||
$avgdu{$name} = $size;
|
||||
$all{$name} = 1;
|
||||
}
|
||||
close AVG;
|
||||
|
||||
open NEW, "/bin/du -t hfs $root |" || die;
|
||||
while (<NEW>) {
|
||||
($size, $name) = split;
|
||||
$size /= 2; # du reports 512 byte blocks :-(
|
||||
if ($size < $thresh) {next};
|
||||
$newdu{$name} = $size;
|
||||
$all{$name} = 1;
|
||||
}
|
||||
close NEW;
|
||||
|
||||
for $i (keys %all) {
|
||||
if ($newdu{"$i"} > 2 * ($avgdu{"$i"})) {
|
||||
printf "%s: %d -> %d\n", $i, $avgdu{$i}, $newdu{$i};
|
||||
}
|
||||
$avgdu{$i} = ($avgdu{$i} * ($period - 1) + $newdu{$i}) / $period;
|
||||
}
|
||||
|
||||
open AVG, ">" . $avgfile || die;
|
||||
for $i (keys %avgdu) {
|
||||
printf AVG "%d %s\n", $avgdu{$i}, $i;
|
||||
}
|
||||
close AVG;
|
|
@ -0,0 +1,48 @@
|
|||
# $Id: GNUmakefile,v 1.8 2016-07-05 19:52:03 hjp Exp $
|
||||
# $Log: GNUmakefile,v $
|
||||
# Revision 1.8 2016-07-05 19:52:03 hjp
|
||||
# Add target distclean
|
||||
#
|
||||
# Revision 1.7 2011-01-30 19:41:15 hjp
|
||||
# Replaced GNUmakerules.sh with GNUmakerules.pl because Debian now uses a
|
||||
# /bin/sh which doesn't understand echo -e.
|
||||
#
|
||||
# Revision 1.6 2011-01-30 19:33:28 hjp
|
||||
# removed duplicate rules
|
||||
#
|
||||
# Revision 1.5 2011-01-30 19:32:33 hjp
|
||||
# create GNUmakerules and GNUmakevars
|
||||
#
|
||||
# Revision 1.4 2008-04-05 10:04:53 hjp
|
||||
# added GNUmake*.sh
|
||||
#
|
||||
# Revision 1.3 2003/02/14 11:59:43 hjp
|
||||
# Added list of #defines from HP-UX.
|
||||
#
|
||||
# Revision 1.2 1998/05/31 01:20:06 hjp
|
||||
# GNUmakerules split into GNUmakerules and GNUmakevars.
|
||||
#
|
||||
|
||||
include GNUmakevars
|
||||
|
||||
all: errno
|
||||
|
||||
errno: errno.o errno_list.o
|
||||
errno_list.c: errno.list make_errno_list
|
||||
./make_errno_list
|
||||
|
||||
clean:
|
||||
rm errno
|
||||
|
||||
distclean: clean
|
||||
rm -f GNUmakevars GNUmakerules errno_list.c
|
||||
|
||||
install: $(BINDIR)/errno
|
||||
|
||||
GNUmakevars: GNUmakevars.sh
|
||||
sh ./$^ > $@
|
||||
GNUmakerules: GNUmakerules.pl
|
||||
perl ./$^ > $@
|
||||
|
||||
include GNUmakerules
|
||||
-include *.d
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
print "\$(BINDIR)/%: %\n";
|
||||
print "\tcp \$^ \$@\n";
|
||||
print "\$(MAN1DIR)/%: %\n";
|
||||
print "\tcp \$^ \$@\n";
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
prefix=${prefix:-/usr/local}
|
||||
echo "BINDIR=$prefix/bin"
|
||||
|
||||
for i in "$prefix/share/man/man1" "$prefix/man/man1"
|
||||
do
|
||||
if [ -d "$i" -a -w "$i" ]
|
||||
then
|
||||
echo "MAN1DIR=$i"
|
||||
break;
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
echo "all:"
|
|
@ -0,0 +1,61 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "errno_list.h"
|
||||
|
||||
char errno_c_rcs_id[] = "$Id: errno.c,v 1.5 2003-02-27 13:28:45 hjp Exp $";
|
||||
char *cmnd;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
|
||||
cmnd = argv[0];
|
||||
|
||||
if (argc <= 1) {
|
||||
int i;
|
||||
for (i = 0; i < wke_nr; i++) {
|
||||
int e = wke[i].number;
|
||||
char *d = wke[i].define;
|
||||
printf("%d\t%s\t%s\n", e, d, strerror(e));
|
||||
}
|
||||
} else {
|
||||
for (i = 1; i < argc; i++) {
|
||||
char *p;
|
||||
int e = strtoul(argv[i], &p, 0);
|
||||
|
||||
if (*p) {
|
||||
/* This is not a number, so we assume it is a define */
|
||||
char *d = argv[i];
|
||||
int j;
|
||||
|
||||
for (j = 0; j < wke_nr; j++) {
|
||||
if (strcmp(wke[j].define, d) == 0) {
|
||||
e = wke[j].number;
|
||||
printf("%d\t%s\t%s\n", e, d, strerror(e));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
/* it is a number */
|
||||
char *d = "(unknown)";
|
||||
int j;
|
||||
|
||||
for (j = 0; j < wke_nr; j++) {
|
||||
if (wke[j].number == e) {
|
||||
d = wke[j].define;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\t%s\t%s\n", e, d, strerror(e));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* vim:sw=4
|
||||
*/
|
|
@ -0,0 +1,137 @@
|
|||
E2BIG
|
||||
EACCES
|
||||
EADDRINUSE
|
||||
EADDRNOTAVAIL
|
||||
EADV
|
||||
EAFNOSUPPORT
|
||||
EAGAIN
|
||||
EALREADY
|
||||
EBADE
|
||||
EBADF
|
||||
EBADFD
|
||||
EBADMSG
|
||||
EBADR
|
||||
EBADRQC
|
||||
EBADSLT
|
||||
EBADVER
|
||||
EBFONT
|
||||
EBUSY
|
||||
ECANCELED
|
||||
ECHILD
|
||||
ECHRNG
|
||||
ECOMM
|
||||
ECONFIG
|
||||
ECONNABORTED
|
||||
ECONNREFUSED
|
||||
ECONNRESET
|
||||
EDEADLK
|
||||
EDEADLOCK
|
||||
EDESTADDRREQ
|
||||
EDOM
|
||||
EDOTDOT
|
||||
EDQUOT
|
||||
EEXIST
|
||||
EFAULT
|
||||
EFBIG
|
||||
EHOSTDOWN
|
||||
EHOSTUNREACH
|
||||
EIDRM
|
||||
EILSEQ
|
||||
EINPROGRESS
|
||||
EINTR
|
||||
EINVAL
|
||||
EIO
|
||||
EISCONN
|
||||
EISDIR
|
||||
EISNAM
|
||||
EL2HLT
|
||||
EL2NSYNC
|
||||
EL3HLT
|
||||
EL3RST
|
||||
ELIBACC
|
||||
ELIBBAD
|
||||
ELIBEXEC
|
||||
ELIBMAX
|
||||
ELIBSCN
|
||||
ELNRNG
|
||||
ELOOP
|
||||
EMEDIUMTYPE
|
||||
EMFILE
|
||||
EMLINK
|
||||
EMSGSIZE
|
||||
EMULTIHOP
|
||||
ENAMETOOLONG
|
||||
ENAVAIL
|
||||
ENETDOWN
|
||||
ENETRESET
|
||||
ENETUNREACH
|
||||
ENFILE
|
||||
ENOANO
|
||||
ENOBUFS
|
||||
ENOCSI
|
||||
ENODATA
|
||||
ENODEV
|
||||
ENOENT
|
||||
ENOEXEC
|
||||
ENOLCK
|
||||
ENOLINK
|
||||
ENOLOAD
|
||||
ENOMATCH
|
||||
ENOMEDIUM
|
||||
ENOMEM
|
||||
ENOMSG
|
||||
ENONET
|
||||
ENOPKG
|
||||
ENOPROTOOPT
|
||||
ENOREG
|
||||
ENOSPC
|
||||
ENOSR
|
||||
ENOSTR
|
||||
ENOSYM
|
||||
ENOSYS
|
||||
ENOTBLK
|
||||
ENOTCONN
|
||||
ENOTDIR
|
||||
ENOTEMPTY
|
||||
ENOTNAM
|
||||
ENOTSOCK
|
||||
ENOTSUP
|
||||
ENOTTY
|
||||
ENOTUNIQ
|
||||
ENOUNLD
|
||||
ENOUNREG
|
||||
ENXIO
|
||||
EOPNOTSUPP
|
||||
EOVERFLOW
|
||||
EPERM
|
||||
EPFNOSUPPORT
|
||||
EPIPE
|
||||
EPROTO
|
||||
EPROTONOSUPPORT
|
||||
EPROTOTYPE
|
||||
ERANGE
|
||||
EREFUSED
|
||||
ERELOC
|
||||
EREMCHG
|
||||
EREMOTE
|
||||
EREMOTEIO
|
||||
EREMOTERELEASE
|
||||
ERESTART
|
||||
EROFS
|
||||
ESHUTDOWN
|
||||
ESOCKTNOSUPPORT
|
||||
ESPIPE
|
||||
ESRCH
|
||||
ESRMNT
|
||||
ESTALE
|
||||
ESTRPIPE
|
||||
ETIME
|
||||
ETIMEDOUT
|
||||
ETOOMANYREFS
|
||||
ETXTBSY
|
||||
EUCLEAN
|
||||
EUNATCH
|
||||
EUSERS
|
||||
EWOULDBLOCK
|
||||
EXDEV
|
||||
EXFULL
|
|
@ -0,0 +1,9 @@
|
|||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
int number;
|
||||
char *define;
|
||||
} errno_T;
|
||||
|
||||
extern errno_T wke[];
|
||||
extern const size_t wke_nr;
|
|
@ -0,0 +1,11 @@
|
|||
echo '#include <errno.h>' > errno_list.c
|
||||
echo '#include "errno_list.h"' >> errno_list.c
|
||||
echo 'errno_T wke[] = {' >> errno_list.c
|
||||
for e in `cat errno.list`
|
||||
do
|
||||
echo " #if defined($e)" >> errno_list.c
|
||||
echo " { $e, \"$e\" }," >> errno_list.c
|
||||
echo " #endif" >> errno_list.c
|
||||
done
|
||||
echo '};' >> errno_list.c
|
||||
echo 'const size_t wke_nr = sizeof(wke)/sizeof(wke[0]);' >> errno_list.c
|
|
@ -0,0 +1,35 @@
|
|||
include GNUmakevars
|
||||
|
||||
CONFDIR=../../configure
|
||||
CONFDIR_exists=$(shell [ -d $(CONFDIR) ] && echo ok)
|
||||
|
||||
all: configure fact
|
||||
|
||||
clean:
|
||||
rm fact customize
|
||||
|
||||
install: $(BINDIR) $(BINDIR)/fact
|
||||
|
||||
%: %.pl customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
%: %.sh customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
customize: configure
|
||||
sh ./configure
|
||||
|
||||
ifeq ($(CONFDIR_exists),ok)
|
||||
|
||||
configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish
|
||||
cat $^ > $@
|
||||
|
||||
endif
|
||||
|
||||
$(BINDIR):
|
||||
mkdir -p $@
|
||||
|
||||
include GNUmakerules
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
echo "#!/bin/sh" > customize.$$
|
||||
echo "sed \\" > customize.$$
|
||||
chmod +x customize.$$
|
||||
|
||||
################################################################
|
||||
# find a working perl:
|
||||
#
|
||||
for i in /usr/bin/perl /usr/local/bin/perl /usr/bin/perl5 /usr/local/bin/perl5
|
||||
do
|
||||
if $i -e 'exit ($] < 5.000)'
|
||||
then
|
||||
echo $i works
|
||||
perl="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$perl" ]
|
||||
then
|
||||
could not find a working perl command, sorry.
|
||||
exit 1
|
||||
fi
|
||||
echo " -e 's,@@@perl@@@,$perl,g' \\" >> customize.$$
|
||||
|
||||
|
||||
################################################################
|
||||
# finish
|
||||
# Add trailing newline and rename temp file to final name
|
||||
#
|
||||
echo >> customize.$$
|
||||
|
||||
mv customize.$$ customize
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#!@@@perl@@@ -w
|
||||
use strict;
|
||||
|
||||
sub usage {
|
||||
print STDERR "Usage: $0 number\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sub fact {
|
||||
my ($n) = @_;
|
||||
|
||||
my $d = 2;
|
||||
|
||||
my @f = ();
|
||||
|
||||
while ($d <= $n) {
|
||||
if ($n % $d == 0) {
|
||||
push (@f, $d);
|
||||
$n /= $d;
|
||||
} else {
|
||||
$d++;
|
||||
}
|
||||
}
|
||||
return @f;
|
||||
}
|
||||
|
||||
if (@ARGV != 1) { usage(); }
|
||||
my @f = fact($ARGV[0]);
|
||||
print "@f\n";
|
||||
|
||||
#vim:sw=4
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
use File::Find;
|
||||
|
||||
my %seen;
|
||||
my %hist;
|
||||
|
||||
sub collect {
|
||||
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
||||
$atime,$mtime,$ctime,$blksize,$blocks) = lstat($_);
|
||||
return if $seen{"$dev:$ino"};
|
||||
$hist{$size}++;
|
||||
$seen{"$dev:$ino"} = 1;
|
||||
}
|
||||
|
||||
find(\&collect, @ARGV ? @ARGV : ("."));
|
||||
|
||||
my $total_count;
|
||||
for my $c (values %hist) {
|
||||
$total_count += $c;
|
||||
}
|
||||
|
||||
my $ac = 0;
|
||||
for my $s (sort {$a <=> $b } keys %hist) {
|
||||
$ac += $hist{$s};
|
||||
printf "%g %g %6.2f\n", $s, $ac, 100 * $ac/$total_count;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
use LWP::UserAgent;
|
||||
use Time::HiRes qw(time);
|
||||
|
||||
my $verbose = 0;
|
||||
|
||||
my $ua = LWP::UserAgent->new();
|
||||
|
||||
my @proxies;
|
||||
for my $proxy (@ARGV) {
|
||||
print STDERR "trying proxy $proxy\n" if $verbose;
|
||||
$ua->proxy('http', $proxy);
|
||||
my $t0 = time();
|
||||
my $response = $ua->get('http://www.hjp.at');
|
||||
if ($response->is_success) {
|
||||
my $dt = time() - $t0;
|
||||
print STDERR "\tsucceded in $dt seconds\n" if $verbose;
|
||||
push @proxies, [ $dt, $proxy ];
|
||||
} else {
|
||||
print STDERR "\tfailed\n" if $verbose;
|
||||
}
|
||||
}
|
||||
|
||||
if (@proxies) {
|
||||
@proxies = sort { $a->[0] <=> $b->[0] } @proxies;
|
||||
print $proxies[0]->[1], "\n";
|
||||
} else {
|
||||
print STDERR "no proxies found\n" if $verbose;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
BINDIR=/usr/local/bin
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -ansi -pedantic -O2 -g
|
||||
fix2var: fix2var.o
|
||||
$(CC) $^ -lant -o $@
|
||||
|
||||
install: $(BINDIR)/fix2var
|
||||
$(BINDIR)/%: %
|
||||
install $< $@
|
|
@ -0,0 +1,94 @@
|
|||
char fix2var_c_rcs_id[] =
|
||||
"$Id: fix2var.c,v 1.1 1996-08-30 12:25:22 hjp Exp $";
|
||||
/*
|
||||
* fix2var - convert fixed length record data to line oriented format
|
||||
*
|
||||
* This program simply copies fixed length chunks from a file to
|
||||
* stdout. Each chunk is terminated with a '\n' character.
|
||||
* Optionally trailing white space can be stripped.
|
||||
*
|
||||
* $Log: fix2var.c,v $
|
||||
* Revision 1.1 1996-08-30 12:25:22 hjp
|
||||
* Initial release.
|
||||
*
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <ant/io.h>
|
||||
#include <ant/alloc.h>
|
||||
|
||||
char *cmnd;
|
||||
|
||||
unsigned long width = 80;
|
||||
int strip = 1;
|
||||
|
||||
void usage(void) {
|
||||
fprintf(stderr, "Usage: %s [-l width] [file ...]\n", cmnd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
void fix2var(const char *filename) {
|
||||
FILE *fp;
|
||||
char *buf = emalloc(width+1);
|
||||
size_t rc;
|
||||
int i;
|
||||
|
||||
if (strcmp(filename, "-") == 0) {
|
||||
fp = stdin;
|
||||
} else {
|
||||
fp = efopen(filename, "r");
|
||||
}
|
||||
while ((rc = fread (buf, 1, width, fp)) != 0 && (rc != (size_t)-1)) {
|
||||
if (rc < width) {
|
||||
fprintf(stderr, "%s: warning: short record (%lu bytes)"
|
||||
" encountered\n", cmnd, (unsigned long)rc);
|
||||
}
|
||||
assert (rc <= INT_MAX);
|
||||
if (strip) {
|
||||
for (i = rc - 1; i >= 0 && isspace(buf[i]); i--);
|
||||
buf[i+1] = '\0';
|
||||
} else {
|
||||
buf[rc] = '\0';
|
||||
}
|
||||
puts(buf);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int c;
|
||||
int i;
|
||||
char *p;
|
||||
|
||||
cmnd = argv[0];
|
||||
|
||||
while ((c = getopt(argc, argv, "sw:")) != EOF) {
|
||||
switch (c) {
|
||||
case 's':
|
||||
strip= 1;
|
||||
break;
|
||||
case 'w':
|
||||
width= strtoul(optarg, &p, 0);
|
||||
if (width == 0 || *p) usage();
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
if (optind == argc) {
|
||||
fix2var("-");
|
||||
} else {
|
||||
for (i = optind; i < argc; i++) {
|
||||
fix2var(argv[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
CC = gcc
|
||||
CFLAGS = -O2
|
||||
|
||||
BINDIR = /usr/local/bin
|
||||
|
||||
fortune: fortune.c
|
||||
$(CC) $(CFLAGS) -o fortune fortune.c -lant
|
||||
|
||||
clean:
|
||||
rm fortune core
|
||||
|
||||
install: $(BINDIR)/fortune
|
||||
|
||||
$(BINDIR)/fortune: fortune
|
||||
cp fortune $(BINDIR)/fortune
|
||||
|
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* Fortune -- Print one fortune out of an indexed fortune file
|
||||
*/
|
||||
|
||||
static char fortune_c_rcsid[] = "$Id: fortune.c,v 3.4 1994-01-08 18:05:00 hjp Exp $";
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ant/io.h>
|
||||
#include <ant/string.h>
|
||||
#include <ant/globals.h>
|
||||
|
||||
/* The following parameters will have to be adapted to your system */
|
||||
#define DELIMITER "%%\n"
|
||||
#define MAXLINE (80 + 1 + 1)
|
||||
char * fortunefile = "/usr/lib/fortune.dat";
|
||||
char indexfile [PATH_MAX] = "/usr/lib/fortune.idx";
|
||||
#define RECLEN 4 /* length of a record in the index
|
||||
* file. This would normally be the
|
||||
* size of a long, but could be more
|
||||
* or less if you want the program
|
||||
* run on systems with different lengths
|
||||
* of a long and share the same index
|
||||
* file.
|
||||
*/
|
||||
/* The rest should be generic */
|
||||
|
||||
|
||||
|
||||
void fwritelong (FILE *fp, long offset, long value) {
|
||||
unsigned char c [RECLEN];
|
||||
|
||||
assert (value < (1UL << (8 * RECLEN - 1)));
|
||||
|
||||
if (fseek (fp, offset, SEEK_SET) != 0) {
|
||||
eprintf ("%s: cannot seek to %ld in %s: %s\n",
|
||||
cmnd, offset, indexfile, strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
c [0] = value & 0xFF;
|
||||
c [1] = (value >> 8) & 0xFF;
|
||||
c [2] = (value >> 16) & 0xFF;
|
||||
c [3] = (value >> 24) & 0xFF;
|
||||
|
||||
if (fwrite (c, RECLEN, 1, fp) != 1) {
|
||||
eprintf ("%s: cannot write to %s: %s\n",
|
||||
cmnd, indexfile, strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
long freadlong (FILE *fp, long offset) {
|
||||
unsigned char c [RECLEN];
|
||||
unsigned long value;
|
||||
|
||||
if (fseek (fp, offset, SEEK_SET) != 0) {
|
||||
eprintf ("%s: cannot seek to %ld in %s: %s\n",
|
||||
cmnd, offset, indexfile, strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (fread (c, RECLEN, 1, fp) != 1) {
|
||||
eprintf ("%s: cannot write to %s: %s\n",
|
||||
cmnd, indexfile, strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
value = c [0] + (c [1] << 8) + (c [2] << 16) + (c [3] << 24);
|
||||
return value > LONG_MAX ? - (long) (- value) : value;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(
|
||||
int argc,
|
||||
char **argv
|
||||
){
|
||||
FILE * ffp, * ifp;
|
||||
char * p;
|
||||
long pos, ipos, /* position in fortune and
|
||||
* index file
|
||||
*/
|
||||
cnt, /* Number of fortunes in the file
|
||||
*/
|
||||
nr, /* number of fortune to read */
|
||||
fortune_time; /* time the fortune file was last
|
||||
* updated.
|
||||
*/
|
||||
struct stat statbuf;
|
||||
char line [MAXLINE];
|
||||
|
||||
cmnd = argv [0];
|
||||
|
||||
if (argc >= 2){
|
||||
fortunefile = argv [1];
|
||||
strncpy (indexfile, argv [1], PATH_MAX);
|
||||
if ((p = strrchr (indexfile, '.'))) {
|
||||
strcpy (p, ".idx");
|
||||
} else {
|
||||
strcat (indexfile, ".idx");
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printf ("fortunefile = \"%s\"\n", fortunefile);
|
||||
printf ("indexfile = \"%s\"\n", indexfile);
|
||||
#endif /* DEBUG */
|
||||
|
||||
/* First check if index file is younger than fortune file
|
||||
* and rebuild it if necessary.
|
||||
*/
|
||||
|
||||
if (stat (fortunefile, &statbuf) < 0) {
|
||||
eprintf ("%s: Cannot stat \"%s\": %s",
|
||||
argv [0], fortunefile, strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
fortune_time = statbuf.st_mtime;
|
||||
if (stat (indexfile, &statbuf) < 0) {
|
||||
/* Index file does not exit -- force its creation
|
||||
* and pretend it is older than fortune file
|
||||
*/
|
||||
|
||||
if ((ifp = fopen (indexfile, "wb")) == NULL) {
|
||||
eprintf ("%s: Cannot fopen \"%s\": %s",
|
||||
argv [0], indexfile, strerror (errno));
|
||||
exit (3);
|
||||
}
|
||||
fclose (ifp);
|
||||
statbuf.st_mtime = 0;
|
||||
}
|
||||
if (statbuf.st_mtime < fortune_time) {
|
||||
/* Index file does either not exist or is older
|
||||
* than fortune file.
|
||||
*/
|
||||
|
||||
if ((ffp = fopen (fortunefile, "r")) == NULL) {
|
||||
eprintf ("%s: Cannot fopen \"%s\": %s",
|
||||
argv [0], fortunefile, strerror (errno));
|
||||
exit (2);
|
||||
}
|
||||
if ((ifp = fopen (indexfile, "r+b")) == NULL) {
|
||||
eprintf ("%s: Cannot fopen \"%s\": %s",
|
||||
argv [0], indexfile, strerror (errno));
|
||||
exit (3);
|
||||
}
|
||||
cnt = 0;
|
||||
fwritelong (ifp, 0, cnt);
|
||||
ipos = RECLEN * 2;
|
||||
while (fgets (line, sizeof (line), ffp)) {
|
||||
if (STREQ (line, DELIMITER)) {
|
||||
pos = ftell (ffp);
|
||||
fwritelong (ifp, ipos, pos);
|
||||
++ cnt;
|
||||
ipos += RECLEN;
|
||||
}
|
||||
}
|
||||
fwritelong (ifp, 0, cnt);
|
||||
fclose (ifp);
|
||||
fclose (ffp);
|
||||
}
|
||||
|
||||
/* Now that we have a valid index file, open it and choose a fortune
|
||||
*/
|
||||
|
||||
if ((ifp = fopen (indexfile, "r+b")) == NULL) {
|
||||
eprintf ("%s: Cannot fopen \"%s\": %s",
|
||||
argv [0], indexfile, strerror (errno));
|
||||
exit (4);
|
||||
}
|
||||
|
||||
if ((ffp = fopen (fortunefile, "r")) == NULL) {
|
||||
eprintf ("%s: Cannot fopen \"%s\": %s",
|
||||
argv [0], fortunefile, strerror (errno));
|
||||
exit (5);
|
||||
}
|
||||
|
||||
/* Get number of entries */
|
||||
cnt = freadlong (ifp, 0);
|
||||
|
||||
if (cnt == 0) {
|
||||
eprintf ("%s: empty fortune file\n", argv [0]);
|
||||
exit (6);
|
||||
}
|
||||
|
||||
nr = freadlong (ifp, RECLEN);
|
||||
nr ++;
|
||||
if (nr >= cnt) nr = 0;
|
||||
fwritelong (ifp, RECLEN, nr);
|
||||
|
||||
/* Now look for the start of the fortune in the index file */
|
||||
pos = freadlong (ifp, (nr + 2) * RECLEN);
|
||||
|
||||
/* And seek to it in the fortune file */
|
||||
fseek (ffp, pos, SEEK_SET);
|
||||
|
||||
/* write one fortune */
|
||||
while (fgets (line, sizeof (line), ffp) && ! STREQ (line, DELIMITER)) {
|
||||
fputs (line, stdout);
|
||||
}
|
||||
fclose (ifp);
|
||||
fclose (ffp);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
include GNUmakevars
|
||||
include GNUmakerules
|
||||
|
||||
fotoindex:
|
||||
|
||||
install: /usr/local/bin/fotoindex
|
||||
|
||||
|
||||
/usr/local/man/man8/%.8: %.man
|
||||
$(INSTALL) $< $@
|
||||
|
||||
clean:
|
||||
rm -f *.gif *.jpg core foo bar baz
|
|
@ -0,0 +1,57 @@
|
|||
#!/usr/local/bin/perl
|
||||
#
|
||||
# Combine several images into an index image (e.g., for use as an imagemap).
|
||||
#
|
||||
# Usage: fotoindex [-o outputfile] [templatefile]
|
||||
#
|
||||
# The first three lines give the width and height of the thumbnails and
|
||||
# the number of thumbnails per row. The remaining lines are file names
|
||||
# of the images to be combined.
|
||||
|
||||
open(STDERR, ">/tmp/fotoindex.$$.debug");
|
||||
|
||||
$giftopnm = "/usr/local/bin/giftopnm";
|
||||
$pnmscale = "/usr/local/bin/pnmscale";
|
||||
$pbmmake = "/usr/local/bin/pbmmake";
|
||||
$pnmpaste = "/usr/local/bin/pnmpaste";
|
||||
$cjpeg = "/usr/local/bin/cjpeg";
|
||||
|
||||
if ($ARGV[0] eq "-o") {
|
||||
shift;
|
||||
$outputredirect = ">" . shift;
|
||||
}
|
||||
|
||||
@file = (<>);
|
||||
chomp(@file);
|
||||
|
||||
# Remove empty and comment lines
|
||||
for ($i = 0; $i <= $#file;) {
|
||||
if ($file[$i] =~ m/^(\#|\s*$)/ ) {
|
||||
splice(@file, $i, 1);
|
||||
} else {
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
$tnw = shift(@file);
|
||||
$tnh = shift(@file);
|
||||
$fw = shift(@file);
|
||||
$fh = int(($#file + 1 + ($fw - 1)) / $fw);
|
||||
|
||||
system ("$pbmmake " . $fw * $tnw . " " . $fh * $tnh . "> /tmp/fotoindex.$$.1.pnm");
|
||||
|
||||
|
||||
for ($i = 0; $i < $fh; $i ++) {
|
||||
for ($j = 0; $j < $fw; $j++) {
|
||||
$pic = $file[$i * $fw + $j];
|
||||
if (-f $pic) {
|
||||
$cmnd = "$giftopnm $pic | $pnmscale -xysize $tnw $tnh > $pic.$$.pnm";
|
||||
system ($cmnd);
|
||||
system ("$pnmpaste $pic.$$.pnm " . $j * $tnw . " " . $i * $tnh . " /tmp/fotoindex.$$.1.pnm > /tmp/fotoindex.$$.2.pnm");
|
||||
rename ("/tmp/fotoindex.$$.2.pnm", "/tmp/fotoindex.$$.1.pnm");
|
||||
unlink ("$pic.$$.pnm");
|
||||
}
|
||||
}
|
||||
}
|
||||
system("$cjpeg -progressive /tmp/fotoindex.$$.1.pnm $outputredirect");
|
||||
unlink ("/tmp/fotoindex.$$.1.pnm");
|
|
@ -0,0 +1,13 @@
|
|||
include GNUmakevars
|
||||
include GNUmakerules
|
||||
|
||||
ftcp: ftcp.o
|
||||
$(CC) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o ftcp core foo bar
|
||||
|
||||
install: $(BINDIR)/ftcp
|
||||
|
||||
distclean: clean
|
||||
rm -f *.bak *.d
|
|
@ -0,0 +1,105 @@
|
|||
char ftcp_rcs_id[] =
|
||||
"$Id: ftcp.c,v 1.1 2002-03-18 20:40:08 hjp Exp $";
|
||||
/*
|
||||
ftcp - fault tolerant copy
|
||||
|
||||
copy one file to another, ignoring any errors.
|
||||
This is useful for copying files from defective media.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <ant/io.h>
|
||||
#include <ant/string.h>
|
||||
|
||||
char *cmnd;
|
||||
|
||||
|
||||
off_t skip_size = 512;
|
||||
size_t buf_size = 512;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-s skip_size] source dest\n", cmnd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
static int ftcp(char const *src, char const *dest)
|
||||
{
|
||||
int sfd, dfd, count;
|
||||
char *buf;
|
||||
off_t off = 0;
|
||||
|
||||
if ((buf = malloc(buf_size)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
sfd = open(src, O_RDONLY);
|
||||
if (sfd < 0)
|
||||
return -1;
|
||||
dfd = open(dest, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
||||
if (dfd < 0)
|
||||
{
|
||||
close(sfd);
|
||||
return -1;
|
||||
}
|
||||
for (;;) {
|
||||
lseek(sfd, off, SEEK_SET);
|
||||
count = read(sfd, buf, buf_size);
|
||||
switch (count) {
|
||||
case -1:
|
||||
fprintf(stderr, "%s: error at offset %lu: %s\n",
|
||||
cmnd, (unsigned long)off, strerror(errno));
|
||||
off += skip_size;
|
||||
break;
|
||||
case 0:
|
||||
goto the_end;
|
||||
default:
|
||||
lseek(dfd, off, SEEK_SET);
|
||||
write(dfd, buf, count);
|
||||
off += count;
|
||||
}
|
||||
}
|
||||
the_end:
|
||||
|
||||
close(sfd);
|
||||
close(dfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
char *p;
|
||||
|
||||
cmnd = argv[0];
|
||||
|
||||
while ((c = getopt(argc, argv, "s:")) != EOF) {
|
||||
switch (c) {
|
||||
case 's':
|
||||
skip_size = strtoul(optarg, &p, 0);
|
||||
if (p == optarg || *p != '\0') usage();
|
||||
break;
|
||||
case '?':
|
||||
usage();
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind != argc - 2) {
|
||||
usage();
|
||||
}
|
||||
ftcp(argv[optind], argv[optind+1]);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
include GNUmakevars
|
||||
|
||||
CONFDIR=../../configure
|
||||
CONFDIR_exists=$(shell [ -d $(CONFDIR) ] && echo ok)
|
||||
|
||||
all: configure grouplist groupmatch groupcount
|
||||
|
||||
clean:
|
||||
rm grouplist groupmatch
|
||||
|
||||
install: \
|
||||
$(BINDIR)/grouplist \
|
||||
$(BINDIR)/groupmatch \
|
||||
$(BINDIR)/groupcount \
|
||||
|
||||
|
||||
%: %.pl customize
|
||||
sh ./customize < $< > $@
|
||||
chmod +x $@
|
||||
|
||||
customize: configure
|
||||
sh ./configure
|
||||
|
||||
ifeq ($(CONFDIR_exists),ok)
|
||||
|
||||
configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish
|
||||
cat $^ > $@
|
||||
|
||||
endif
|
||||
|
||||
GNUmakevars: GNUmakevars.sh
|
||||
sh ./$^ > $@
|
||||
GNUmakerules: GNUmakerules.pl
|
||||
perl ./$^ > $@
|
||||
|
||||
include GNUmakerules
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/perl
|
||||
use warnings;
|
||||
use strict;
|
||||
|
||||
print "\$(BINDIR)/%: %\n";
|
||||
print "\tcp \$^ \$@\n";
|
||||
print "\$(MAN1DIR)/%: %\n";
|
||||
print "\tcp \$^ \$@\n";
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
echo "\$(BINDIR)/%: %"
|
||||
echo -e "\tcp \$^ \$@"
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
prefix=${prefix:-/usr/local}
|
||||
echo "BINDIR=$prefix/bin"
|
||||
echo
|
||||
echo "all:"
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
echo "#!/bin/sh" > customize.$$
|
||||
echo "sed \\" > customize.$$
|
||||
chmod +x customize.$$
|
||||
|
||||
################################################################
|
||||
# find a working perl:
|
||||
#
|
||||
for i in /usr/bin/perl /usr/local/bin/perl /usr/bin/perl5 /usr/local/bin/perl5
|
||||
do
|
||||
if $i -e 'exit ($] < 5.000)'
|
||||
then
|
||||
echo $i works
|
||||
perl="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$perl" ]
|
||||
then
|
||||
echo could not find a working perl command, sorry.
|
||||
exit 1
|
||||
fi
|
||||
echo " -e 's,@@@perl@@@,$perl,g' \\" >> customize.$$
|
||||
|
||||
|
||||
################################################################
|
||||
# finish
|
||||
# Add trailing newline and rename temp file to final name
|
||||
#
|
||||
echo >> customize.$$
|
||||
|
||||
mv customize.$$ customize
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#!@@@perl@@@ -w
|
||||
|
||||
=head1 NAME
|
||||
|
||||
groupcount - count number of groups of all users
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
groupcount
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This script counts the number of groups each user is a member of.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Peter J. Holzer <hjp@wsr.ac.at>
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
id(1)
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
|
||||
my $debug = 0;
|
||||
my $fullname = 0;
|
||||
GetOptions("debug" => \$debug,
|
||||
"fullname" => \$fullname);
|
||||
|
||||
|
||||
my $u = {};
|
||||
my $g = {};
|
||||
|
||||
while (my @gr = getgrent()) {
|
||||
|
||||
my ($name,$passwd,$gid,$members) = @gr;
|
||||
$g->{$gid} = $name;
|
||||
for my $i (split(/ /, $members)) {
|
||||
print STDERR "getgrent: $gid: $i\n" if($debug);
|
||||
$u->{$i}{$name} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
while (my @pw = getpwent()) {
|
||||
my ($name,$passwd,$uid,$gid, $quota,$comment,$gcos,$dir,$shell,$expire) = @pw;
|
||||
$u->{$name}{$g->{$gid}} = 1;
|
||||
printf("%-10s %3d\n", $name, scalar(keys(%{$u->{$name}})));
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
#!@@@perl@@@ -w
|
||||
|
||||
=head1 NAME
|
||||
|
||||
groulist - list all members of a group
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
grouplist [--fullname] group
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This script lists all members of a group.
|
||||
For each user, the loginname, whether this is the primary or a supplemental group
|
||||
of the user, and optionally the full name (from the GECOS field) is printed.
|
||||
|
||||
=head2 Options
|
||||
|
||||
=over 4
|
||||
|
||||
=item --fullname
|
||||
|
||||
Print the GECOS field.
|
||||
|
||||
=item --debug
|
||||
|
||||
Prints some debug output to stderr.
|
||||
|
||||
=back
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Peter J. Holzer <hjp@wsr.ac.at>
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
id(1)
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
|
||||
my $debug = 0;
|
||||
my $fullname = 0;
|
||||
GetOptions("debug" => \$debug,
|
||||
"fullname" => \$fullname);
|
||||
|
||||
|
||||
my $u = {};
|
||||
|
||||
my @gr;
|
||||
@gr = getgrnam($ARGV[0]);
|
||||
unless (@gr) {
|
||||
print STDERR "$0: Group $ARGV[0] not found\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
my ($name,$passwd,$gid,$members) = @gr;
|
||||
for my $i (split(/ /, $members)) {
|
||||
print STDERR "getgrent: $gid: $i\n" if($debug);
|
||||
$u->{$i}{s} = 1;
|
||||
}
|
||||
|
||||
while (my @pw = getpwent()) {
|
||||
my ($name,$passwd,$uid,$ugid, $quota,$comment,$gcos,$dir,$shell,$expire) = @pw;
|
||||
print STDERR "getpwent: $ugid: $name\n" if($debug);
|
||||
if ($ugid == $gid) {
|
||||
$u->{$name}{p} = 1;
|
||||
$u->{$name}{fn} = $gcos;
|
||||
}
|
||||
}
|
||||
|
||||
for my $i (keys %$u) {
|
||||
printf("%-10s %1s%1s", $i, $u->{$i}{p} ? "p" : " ", $u->{$i}{s} ? "s" : " ");
|
||||
if ($fullname) {
|
||||
if (!$u->{$i}{fn}) {
|
||||
my @pw = getpwnam($i);
|
||||
my ($name,$passwd,$uid,$ugid, $quota,$comment,$gcos,$dir,$shell,$expire) = @pw;
|
||||
$u->{$i}{fn} = $gcos;
|
||||
}
|
||||
printf(" %s", $u->{$i}{fn});
|
||||
}
|
||||
print "\n";
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
#!@@@perl@@@ -w
|
||||
|
||||
=head1 NAME
|
||||
|
||||
groupmatch - find best matching group for list of users
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
groupmatch [--cut value] [--allmembers] [--debug] [--miss value] user ...
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This script takes a list of users and prints the group(s) which
|
||||
are the closest match (i.e. have the least number of missing or
|
||||
superfluous users).
|
||||
|
||||
For each group, the gid, group name, number of differences, and list of
|
||||
users which are missing (marked (-)) or too much (+) is printed.
|
||||
|
||||
=head2 Options
|
||||
|
||||
=over 4
|
||||
|
||||
=item --cut value
|
||||
|
||||
Sets the cutoff value. Only groups with at most this number of
|
||||
differences to the specified list of users are printed. By default the
|
||||
cutoff value is set so that only the best matching group(s) are printed.
|
||||
|
||||
=item --allmembers
|
||||
|
||||
Prints all members of the group, not only the differences to the
|
||||
specified list. Users which are already in the group are marked (*).
|
||||
|
||||
=item --debug
|
||||
|
||||
Prints some debug output to stderr.
|
||||
|
||||
=item --miss value
|
||||
|
||||
Penalty for missing users in a group. Default is 1, i.e., a user missing
|
||||
is just as bad as a superfluous user. Larger values bias towards groups
|
||||
with too many users, smaller values bias towards groups with too few users.
|
||||
|
||||
=back
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Peter J. Holzer <hjp@wsr.ac.at>
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
id(1)
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
|
||||
sub diffsym {
|
||||
my ($diff) = @_;
|
||||
if ($diff == 0) { return "*"; }
|
||||
if ($diff < 0) { return "-"; }
|
||||
if ($diff > 0) { return "+"; }
|
||||
return "?";
|
||||
}
|
||||
|
||||
my $cut = undef;
|
||||
my $debug = 0;
|
||||
my $allmembers = 0;
|
||||
my $miss = 1;
|
||||
GetOptions("cut=i" => \$cut,
|
||||
"debug" => \$debug,
|
||||
"allmembers" => \$allmembers,
|
||||
"miss=f" => \$miss,
|
||||
);
|
||||
my $gr = {};
|
||||
|
||||
my @gr;
|
||||
while (@gr = getgrent) {
|
||||
my ($name,$passwd,$gid,$members) = @gr;
|
||||
for my $i (split(/ /, $members)) {
|
||||
print STDERR "getgrent: $gid: $i\n" if($debug);
|
||||
$gr->{$gid}->{Members}->{$i} = 1;
|
||||
$gr->{$gid}->{Name} = $name;
|
||||
}
|
||||
}
|
||||
my @pw;
|
||||
while (@pw = getpwent()) {
|
||||
my ($name,$passwd,$uid,$gid, $quota,$comment,$gcos,$dir,$shell,$expire) = @pw;
|
||||
print STDERR "getpwent: $gid: $name\n" if($debug);
|
||||
$gr->{$gid}->{Members}->{$name} = 1;
|
||||
|
||||
}
|
||||
for my $g (keys %$gr) {
|
||||
for my $u (@ARGV) {
|
||||
$gr->{$g}->{Members}->{$u} = (($gr->{$g}->{Members}->{$u} || 0) - 1) * $miss;
|
||||
}
|
||||
my $score = 0;
|
||||
for my $u (keys(%{$gr->{$g}->{Members}})) {
|
||||
$score += abs($gr->{$g}->{Members}->{$u});
|
||||
}
|
||||
print STDERR "$g: $score\n" if($debug);
|
||||
$gr->{$g}->{Score} = $score;
|
||||
}
|
||||
if ($debug) {
|
||||
print STDERR "\nScore list:\n";
|
||||
for my $g (keys %$gr) {
|
||||
print STDERR "$g: ", $gr->{$g}->{Score}, "\n";
|
||||
}
|
||||
print STDERR "\n";
|
||||
}
|
||||
|
||||
for my $g (sort { $gr->{$a}->{Score} <=> $gr->{$b}->{Score} } keys %$gr) {
|
||||
$cut = $gr->{$g}->{Score} unless ($cut);
|
||||
next unless ($gr->{$g}->{Name});
|
||||
last if ($gr->{$g}->{Score} > $cut);
|
||||
|
||||
print "$g: ",
|
||||
$gr->{$g}->{Name}, ": ",
|
||||
$gr->{$g}->{Score}, ": ";
|
||||
for my $u (sort keys(%{$gr->{$g}->{Members}})) {
|
||||
if ($allmembers || $gr->{$g}->{Members}->{$u}) {
|
||||
print "$u(", diffsym($gr->{$g}->{Members}->{$u}), ") ";
|
||||
}
|
||||
}
|
||||
print "\n";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
int main(void) {
|
||||
for (;;);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/perl
|
||||
use v5.20;
|
||||
use warnings;
|
||||
|
||||
use Time::HiRes qw(time);
|
||||
my $t0 = time;
|
||||
for (;;) {
|
||||
my $dt = time - $t0;
|
||||
last if $dt > $ARGV[0];
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
size_t size = strtoul(argv[1], NULL, 0);
|
||||
char *p = malloc(size);
|
||||
printf("%zu bytes at %p\n", size, p);
|
||||
sleep(10);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void) {
|
||||
size_t s = 0x100000;
|
||||
size_t sum = 0;
|
||||
|
||||
while (s) {
|
||||
void *p;
|
||||
errno = 0;
|
||||
if (p = malloc(s)) {
|
||||
sum += s;
|
||||
printf("%lu - %lu\n",
|
||||
(unsigned long)s,
|
||||
(unsigned long)sum);
|
||||
sleep (1);
|
||||
memset(p, 'a', s);
|
||||
s *= 2;
|
||||
} else {
|
||||
printf("%lu - %lu: %s\n",
|
||||
(unsigned long)s,
|
||||
(unsigned long)sum,
|
||||
strerror(errno)
|
||||
);
|
||||
s /= 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
ieeefloat
|
|
@ -0,0 +1,20 @@
|
|||
include GNUmakevars
|
||||
|
||||
all: ieeefloat
|
||||
install: $(BINDIR)/ieeefloat
|
||||
|
||||
clean:
|
||||
rm -f *.bak *.o core ieeefloat
|
||||
|
||||
distclean: clean
|
||||
rm -f *.d GNUmakerules GNUmakevars
|
||||
|
||||
ieeefloat: ieeefloat.o
|
||||
|
||||
GNUmakevars: GNUmakevars.sh
|
||||
sh ./$^ > $@
|
||||
GNUmakerules: GNUmakerules.sh
|
||||
sh ./$^ > $@
|
||||
|
||||
include GNUmakerules
|
||||
-include *.d
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue