IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 1, 2026, 4:53:16 PM (7 weeks ago)
Author:
eugene
Message:

working on modernizing the error_code trapping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-pstamp-20260421/pstamp/scripts/pstamp_save_server_status.pl

    r42981 r43048  
    1111use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    1212use Pod::Usage qw( pod2usage );
     13use Scalar::Util qw(looks_like_number);
    1314
    1415my $updatelink;
     
    6364my $command = "pstamp_server_status --workdir $pstamp_workdir > $file";
    6465#my $command = "pstamp_server_status > $file";
    65 my  ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     66my  ( $success, $error_msgo, $full_buf, $stdout_buf, $stderr_buf ) =
    6667    run(command => $command, verbose => $verbose);
     68my $error_code = &parse_error_message ($success, $error_msg, $command);
    6769unless ($success) {
    68     $error_code = (($error_code >> 8) or 1);
     70    $error_code = ($error_code or 1);
    6971    warn("$command failed. exit status: $error_code");
    7072    exit $error_code;
     
    8082
    8183exit 0;
     84
     85# if the program exited normally, the exit value is returned
     86# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
     87# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
     88sub parse_error_message {
     89    my $success = shift;
     90    my $error_msg = shift;
     91    my $command = shift;
     92
     93    if ($success) { return 0; }
     94
     95    print "raw error_msg: $error_msg\n";
     96    print "full command: $command\n";
     97
     98    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
     99       
     100    # which of these match?
     101    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
     102    if (defined $error_code) { return $error_code; }
     103   
     104    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
     105#   if (defined $error_code) { return (128 + $error_code); }
     106    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
     107   
     108    # probably failed to execute:
     109    return (-1*$PS_EXIT_PROG_ERROR);
     110}
Note: See TracChangeset for help on using the changeset viewer.