Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 51 lines (35 sloc) 1.095 kb
42447b6 adding rn1 systems files.
James Cox authored
1 #!/usr/bin/perl -w
2 use strict;
3
4 my $remote = $ENV{TCPREMOTEIP}
5 or die 'TCPREMOTEIP environment variable not set';
6
7 die "usage: $0 name prog arg ...\n" unless @ARGV;
8
9 my $name = shift;
10
11 use File::Path ();
12
13 File::Path::mkpath("/local/tmp/cxnlimit/$name");
14
15 my $lockfile = "/local/tmp/cxnlimit/$name/$remote";
16
17 if (-e $lockfile) {
18 open FILE, "<$lockfile"
19 or die "unable to open file '$lockfile' for reading: $!\n";
20 my $pid = <FILE>;
21 if (kill 0, $pid) {
22 # warn "refused cxn from $TCPREMOTEIP, already connected (process $pid)\n";
23 print "\@RSYNCD: 26\n\@ERROR: only one simultaneous connection per ip is allowed\n\@RSYNCD: EXIT\n";
24 exit;
25 }
26 close FILE;
27 }
28
29 my $pid = fork();
30 die "fork failed: $!" unless defined $pid;
31
32 exec @ARGV unless $pid;
33
34 $0 = "cxn from $remote";
35
36 open FILE, ">$lockfile"
37 or die "unable to open file '$lockfile' for writing: $!\n";
38 print FILE $pid;
39 close FILE;
40
41 $SIG{PIPE} = 'IGNORE';
42
43 # reopen the file descriptors in the parent
44 open STDOUT, ">/dev/null";
45 open STDERR, ">/dev/null";
46 open STDIN, "</dev/null";
47
48 1 until wait == -1;
49
50 unlink $lockfile;
Something went wrong with that request. Please try again.