gator2003 has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that times itself out after an hour using alarm. It worked last week and now is not working. Now, alarm is raised immediately ignoring whatever timeout (seconds) I set. I haven't really changed much in the script, and haven't changed anything in the eval block (below). What could be causing it to "alarm" immediately? It times out in less than a second according to the timestamps.

If there is an error in the main() block will it raise an alarm during execution? Is there a better way to see where the script was when the alarm was raised?

I've also included the entire script on my scratch pad, just in case. Thanks for any help! I'm using Perl 5.8.4 on Solaris 5.1 (and I cannot change system Perl or add my own, unfortunately).

my scratchpad
my @output; eval { # Get the timeout value from the properties file $properties_file = $properties_directory."/".$properties_file; %values_hash = load_properties($properties_file); $script_timeout = $values_hash{'script.timeout'}; # Prepare the lockfile my $lock_file_directory = ""; $lock_file = "emc_backups.lck"; $lock_file_directory = abs_path($0); $lock_file_directory =~ s/(.*)\/.*/$1/; $lock_file = $lock_file_directory."/".$lock_file; # Start logging my $log = $values_hash{'logfile'}; startLog($log); # If script is already running, then exit. If not, create a lock f +ile. verify_lockfile($lock_file, $script_timeout); # Kill the script if it runs longer than the timeout value (in sec +onds) local $SIG{ALRM} = sub { die "Timeout\n" }; alarm $script_timeout; @output = main(); alarm 0; }; if ($@) { # Script timed out # Delete aborted copy, if any if ($currentBackupCopying) { purge_backups($currentBackupCopying); } print LOGFILE "ERROR: Backup timed out - ".localtime()."\n"; # Delete Lock File unlink($lock_file); } else { # Script ran successfully print LOGFILE "Backup finished - ".localtime()."\n"; # Delete Lock File unlink($lock_file); }

Replies are listed 'Best First'.
Re: Alarm firing immediately instead of waiting for timeout
by 1arryb (Acolyte) on Dec 15, 2011 at 17:04 UTC

    Hi gator,

    Are you sure that the alarm is the only way your eval block can die? Right now you are logging a "timeout expired" message regardless of what really happened. Try logging the value of $@ and see what you get.

    Cheers,

    Larry

      Ugh. Thank you for noticing that I left $@ out. Sure enough, there was a typo that didn't cause a warning/error in compile but caused a weird crash.
Re: Alarm firing immediately instead of waiting for timeout
by BrowserUk (Patriarch) on Dec 15, 2011 at 16:59 UTC
    I haven't really changed much in the script, and haven't changed anything in the eval block (below). What could be causing it to "alarm" immediately?

    If someone has screwed with the configuration file and either set the timeout to 0, or omitted the 'script.timeout' entry completely, then

    $script_timeout = $values_hash{'script.timeout'};

    would cause it.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?