In the code I originally posted, I included a guard flag that told the program whether it had been restarted.
The code that you have not shown does not seem to guard against an endless restart loop, as evidenced by the small and incomplete part of its output that you've shown.
Maybe now is a good time to revisit the approach I had outlined in my first program?
if( ! $ENV{PDUPRE_RESTART}) {
$ENV{PDUPRE_RESTART} = 1;
print "Restarting as '$0, @ARGV'\n";
...
exec $0, @ARGV
or print "Exec error when restarting $0 @ARGV: $!";
exit 1;
};
Alternatively, if you want to keep the --restarted command, maybe you can check @ARGV whether it contains --restarted?
if( ! grep { /^--restarted$/ @ARGV) {
print "Restarting as '$0 --restarted @ARGV'\n";
exec $0, '--restarted', @ARGV
or print "Exec error when restarting $0 @ARGV: $!";
exit 1;
};
Again, you can help us help you diagnosing things better by posting a twenty-line self-contained example that reproduces the behaviour you're seeing. |