/RDTJ/RDTJ.pm

https://github.com/rick/rdtj · Perl · 83 lines · 47 code · 17 blank · 19 comment · 2 complexity · b36165bf950db812d1817ed0b032568e MD5 · raw file

  1. #!/usr/bin/perl -w
  2. #
  3. # Common perl routines for rdtj (Roundeye's duct-tape jukebox)
  4. #
  5. # Rick Bradley - roundeye@roundeye.net / rick@eastcore.net
  6. #
  7. # please consult LICENSE file for license information
  8. # CHANGELOG lists history and additional contributor information
  9. #
  10. #
  11. # $Header: /cvsroot/rdtj/rdtj/RDTJ/RDTJ.pm,v 1.2 2001/09/26 05:47:47 roundeye Exp $
  12. #
  13. package RDTJ::RDTJ;
  14. require Exporter;
  15. @ISA = qw(Exporter);
  16. @EXPORT = qw(DIE_LOG WARN_LOG HUP EXIT);
  17. use strict; # enforce some discipline
  18. use RDTJ::Log;
  19. #
  20. # signal handler subroutines
  21. #
  22. sub DIE_LOG
  23. {
  24. my ($i, $frame);
  25. LOG('error', "DIE-ing with message [$_[0]]");
  26. LOG('error', 'stack trace:');
  27. for ($i=0;;$i++)
  28. {
  29. $frame = join(':', caller($i));
  30. last unless $frame;
  31. LOG('error', $frame);
  32. }
  33. exit(1);
  34. }
  35. sub WARN_LOG
  36. {
  37. LOG('warning', "internal warning message [$_[0]]");
  38. }
  39. sub HUP
  40. { # reset logging, rotate log file out of the way (timestamp it)
  41. my $date;
  42. close_LOG();
  43. if ($::logfile ne '-')
  44. { # rotate logfile (don't bother with stdout :-)
  45. $date = `/bin/date +_%Y%m%d%H%M%S`; # generate a sortable timestamp
  46. chomp($date);
  47. system('/bin/mv', $::logfile, $::logfile.".".$date); # rotate
  48. }
  49. open_LOG($::logfile); # and get back to business
  50. $SIG{'HUP'} = \&HUP # reinstall signal handler
  51. }
  52. sub EXIT
  53. { # clean up before dying
  54. close_LOG();
  55. exit(0);
  56. }
  57. sub REAPER
  58. {
  59. wait; # avoid the zombie
  60. die "Shutting down.";
  61. }
  62. #
  63. # end of module
  64. #
  65. # modules must return true
  66. 1;