Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / tests / ftp.pm
blob2158c79ed1bbfe73ea2d7e1f8eba5740b5e17406
1 #***************************************************************************
2 # _ _ ____ _
3 # Project ___| | | | _ \| |
4 # / __| | | | |_) | |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
8 # Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
21 # $Id: ftp.pm,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
22 ###########################################################################
24 #######################################################################
25 # Return the pid of the server as found in the given pid file
27 sub serverpid {
28 my $PIDFILE = $_[0];
29 open(PFILE, "<$PIDFILE");
30 my $PID=0+<PFILE>;
31 close(PFILE);
32 return $PID;
35 #######################################################################
36 # Check the given test server if it is still alive.
38 sub checkserver {
39 my ($pidfile)=@_;
40 my $pid=0;
42 # check for pidfile
43 if ( -f $pidfile ) {
44 $pid=serverpid($pidfile);
45 if ($pid ne "" && kill(0, $pid)) {
46 return $pid;
48 else {
49 return -$pid; # negative means dead process
52 return 0;
55 #############################################################################
56 # Kill a specific slave
58 sub ftpkillslave {
59 my ($id, $ext, $verbose)=@_;
60 my $base;
61 for $base (('filt', 'data')) {
62 my $f = ".sock$base$id$ext.pid";
63 my $pid = checkserver($f);
64 if($pid > 0) {
65 printf ("* kill pid for %s => %d\n", "ftp-$base$id$ext", $pid) if($verbose);
66 kill (9, $pid); # die!
67 waitpid($pid, 0);
69 unlink($f);
74 #############################################################################
75 # Make sure no FTP leftovers are still running. Kill all slave processes.
76 # This uses pidfiles since it might be used by other processes.
78 sub ftpkillslaves {
79 my ($versbose) = @_;
80 for $ext (("", "ipv6")) {
81 for $id (("", "2")) {
82 ftpkillslave ($id, $ext, $verbose);
88 sub set_advisor_read_lock {
89 my ($filename) = @_;
91 if(open(FILEH, ">$filename")) {
92 close(FILEH);
93 return;
95 printf "Error creating lock file $filename error: $!";
99 sub clear_advisor_read_lock {
100 my ($filename) = @_;
102 if(-f $filename) {
103 unlink($filename);