OS – Linux


I have a Perl script which exec’s the sz command to send files over modems (Z MODEM protocol). In some instances (for example when the power goes out on the receiving modem) the sz command hangs and ZNAK errors are written to a log file causing the process to hang and log file to rapidly grow. For example:


Retry 0: Bad CRC
Retry 0: Got ERROR
Retry 0: Bad CRC
Retry 0: Got ERROR
Retry 0: Got ZNAK
Retry 0: Got ZNAK
Retry 0: Got ZNAK
Retry 0: Got ZNAK

How can I trap for such errors/terminate the process as soon as there is a problem? Is there a parameter I can pass?


Sample code (exec $cmd is where it hangs):

my $gSendCommand = "sz -b -u" my $ret = Run("$gSendCommand $gUploadFile", 1); sub Run # ($cmd, $serial) { my ($cmd, $serial) = @_; my $ret = fork; ptUtil::fatal("Could not fork to run $cmd") if $ret < 0; if ($ret == 0) { if ($serial) { my $fileno = $gSerial->{FD}; my $flags = 0; # redirect STDIN and STDOUT to modem open(STDIN, "<&=" . $fileno) or ptUtil::fatal("Could not +dup2 STDIN!"); open(STDOUT, ">&=" . $fileno) or ptUtil::fatal("Could not +dup2 STDOUT!"); # enable STDIN blocking if (fcntl(STDIN, F_GETFL, $flags)) { $flags &= ~O_NONBLOCK; fcntl(STDIN, F_SETFL, $flags); } # enable STDOUT blocking if (fcntl(STDOUT, F_GETFL, $flags)) { $flags &= ~O_NONBLOCK; fcntl(STDOUT, F_SETFL, $flags); } } # exec command ptUtil::log("Executing $cmd ($?)"); exec($cmd) or ptUtil::fatal("Could not exec $cmd"); ptUtil::log("Executed $cmd ($?)"); } wait; return $?;

In reply to Sz command hanging and outputting ZNAK’s by M1k3

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.