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_server_status

    r42983 r43048  
    1313use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    1414use Pod::Usage qw( pod2usage );
    15 
     15use Scalar::Util qw(looks_like_number);
    1616
    1717my ($rundir, $workdir, $verbose, $save_temps);
     
    7171    my $serverRunning = 0;
    7272    my $command = "$pantasks_client < $pantasks_script";
    73     my  ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     73    my  ( $success, $error_msg, $full_buf, $stdout_buf, $stderr_buf ) =
    7474        run(command => $command, verbose => $verbose);
     75    my $error_code = &parse_error_message ($success, $error_msg, $command);
    7576    if ($success) {
    7677        $serverRunning = 1;
    7778    } else {
    78         $error_code = (($error_code >> 8) or 1);
     79        $error_code = ($error_code or 1);
    7980        if ($error_code == 12 || $error_code == 13) {
    8081            print "Postage Stamp Server is not running\n<br>";
     
    205206
    206207exit 0;
     208
     209# if the program exited normally, the exit value is returned
     210# if the program exited with a signal (abort, crash, etc), PS_EXIT_PROG_ERROR (4) is returned
     211# if the program failed to run, -PS_EXIT_PROG_ERROR (-4) is returned
     212sub parse_error_message {
     213    my $success = shift;
     214    my $error_msg = shift;
     215    my $command = shift;
     216
     217    if ($success) { return 0; }
     218
     219    print "raw error_msg: $error_msg\n";
     220    print "full command: $command\n";
     221
     222    if (&looks_like_number($error_msg)) { return (($error_msg >> 8) or ($PS_EXIT_PROG_ERROR)); }
     223       
     224    # which of these match?
     225    my ($error_code) = $error_msg =~ m/exited with value (\d+)/;
     226    if (defined $error_code) { return $error_code; }
     227   
     228    ($error_code) = $error_msg =~ m/died with signal (\d+)/;
     229#   if (defined $error_code) { return (128 + $error_code); }
     230    if (defined $error_code) { return ($PS_EXIT_PROG_ERROR); }
     231   
     232    # probably failed to execute:
     233    return (-1*$PS_EXIT_PROG_ERROR);
     234}
Note: See TracChangeset for help on using the changeset viewer.