ftp.pm 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #######################################################################
  2. # Return the pid of the server as found in the given pid file
  3. #
  4. sub serverpid {
  5. my $PIDFILE = $_[0];
  6. open(PFILE, "<$PIDFILE");
  7. my $PID=0+<PFILE>;
  8. close(PFILE);
  9. return $PID;
  10. }
  11. #######################################################################
  12. # Check the given test server if it is still alive.
  13. #
  14. sub checkserver {
  15. my ($pidfile)=@_;
  16. my $pid=0;
  17. # check for pidfile
  18. if ( -f $pidfile ) {
  19. $pid=serverpid($pidfile);
  20. if ($pid ne "" && kill(0, $pid)) {
  21. return $pid;
  22. }
  23. else {
  24. return -$pid; # negative means dead process
  25. }
  26. }
  27. return 0;
  28. }
  29. #############################################################################
  30. # Kill a specific slave
  31. #
  32. sub ftpkillslave {
  33. my ($id, $ext, $verbose)=@_;
  34. my $base;
  35. for $base (('filt', 'data')) {
  36. my $f = ".sock$base$id$ext.pid";
  37. my $pid = checkserver($f);
  38. if($pid > 0) {
  39. printf ("* kill pid for %s => %d\n", "ftp-$base$id$ext", $pid) if($verbose);
  40. kill (9, $pid); # die!
  41. }
  42. unlink($f);
  43. }
  44. }
  45. #############################################################################
  46. # Make sure no FTP leftovers are still running. Kill all slave processes.
  47. # This uses pidfiles since it might be used by other processes.
  48. #
  49. sub ftpkillslaves {
  50. my ($versbose) = @_;
  51. for $ext (("", "ipv6")) {
  52. for $id (("", "2")) {
  53. ftpkillslave ($id, $ext, $verbose);
  54. }
  55. }
  56. }
  57. 1;