Hi all,
I am calling a subroutine which checks if a log file is writeable and if not, prints something stdout and also log something into the same file, which doesn't work neither of course.
Anyway, there is enough exit() calls, that should stop it working, but the problem is, that I get the message about the file permissions (which I set on intent to produce the problem) in and infinite loop, though there is no loop calling the functions.
In all these thousands lines of messages I found inbetween this hint:
Deep recursion on subroutine "main::log_me" at /opt/somepath/someprog line 230.
Deep recursion on subroutine "main::print_err" at /opt/somepath/someprog line 256.
These two functions are here:
+233 sub debug {
+234 ($package, $filename, $line) = caller();
+235 print "Package: $package\n";
+236 print "Filename: $filename\n";
+237 print "Line: $line\n";
+238
+239 ## Debugging function
+240 if( $_debug eq lc("on") ){
+241 if( ! open( FH_LOG, ">> $W_LOG" ) ){
+242 my $err_msg = sprintf("ERROR: Can not write log file [ $W_LOG ]: %s", $!);
+243 &print_err($err_msg);
+244 &log_me($the_end);
+245 exit(3);
+246 }
+247 print FH_LOG "DEBUG -- @_\n";
+248 close(FH_LOG);
+249 }
+250 }
+251
+252 sub log_me {
+253 ## Logging function
+254 if( ! open( FH_LOG, ">> $W_LOG" ) ){
+255 my $err_msg = sprintf("ERROR: Can not write log file [ $W_LOG ]: %s", $!);
+256 &print_err($err_msg);
+257 &log_me($the_end);
+258 exit(3);
+259 }
+260 print FH_LOG "$date -- @_\n";
+261 close(FH_LOG);
+262 }
It should at least hit that exit(3);
in log_me(), but it doesn't. Instead I get this spam of messages.
As you can see in the head of debug() I added caller()
to get a clue which is calling it. It showed me it is this line:
+374 &debug("=====> Rotating logs ...");
... which is in the main part of the program and neither in a loop.
Thanks for any hint in forward!
Edit:
I removed the calls of log_me() in both functions because it made no sense of course. Though difference to the original problem.