ftp.pm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2008, Daniel Stenberg, <[email protected]>, et al.
  9. #
  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.
  13. #
  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.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. # $Id$
  22. ###########################################################################
  23. #######################################################################
  24. # Return the pid of the server as found in the given pid file
  25. #
  26. sub serverpid {
  27. my $PIDFILE = $_[0];
  28. open(PFILE, "<$PIDFILE");
  29. my $PID=0+<PFILE>;
  30. close(PFILE);
  31. return $PID;
  32. }
  33. #######################################################################
  34. # Check the given test server if it is still alive.
  35. #
  36. sub checkserver {
  37. my ($pidfile)=@_;
  38. my $pid=0;
  39. # check for pidfile
  40. if ( -f $pidfile ) {
  41. $pid=serverpid($pidfile);
  42. if ($pid ne "" && kill(0, $pid)) {
  43. return $pid;
  44. }
  45. else {
  46. return -$pid; # negative means dead process
  47. }
  48. }
  49. return 0;
  50. }
  51. #############################################################################
  52. # Kill a specific slave
  53. #
  54. sub ftpkillslave {
  55. my ($id, $ext, $verbose)=@_;
  56. my $base;
  57. for $base (('filt', 'data')) {
  58. my $f = ".sock$base$id$ext.pid";
  59. my $pid = checkserver($f);
  60. if($pid > 0) {
  61. printf ("* kill pid for %s => %d\n", "ftp-$base$id$ext", $pid) if($verbose);
  62. kill (9, $pid); # die!
  63. waitpid($pid, 0);
  64. }
  65. unlink($f);
  66. }
  67. }
  68. #############################################################################
  69. # Make sure no FTP leftovers are still running. Kill all slave processes.
  70. # This uses pidfiles since it might be used by other processes.
  71. #
  72. sub ftpkillslaves {
  73. my ($versbose) = @_;
  74. for $ext (("", "ipv6")) {
  75. for $id (("", "2")) {
  76. ftpkillslave ($id, $ext, $verbose);
  77. }
  78. }
  79. }
  80. sub set_advisor_read_lock {
  81. my ($filename) = @_;
  82. if(open(FILEH, ">$filename")) {
  83. close(FILEH);
  84. return;
  85. }
  86. printf "Error creating lock file $filename error: $!";
  87. }
  88. sub clear_advisor_read_lock {
  89. my ($filename) = @_;
  90. if(-f $filename) {
  91. unlink($filename);
  92. }
  93. }
  94. 1;