Subject: | sysopen failure doesn't die as expected |
The 'sysopen' calls in the 'read' and 'write' functions do not cause 'die' to be invoked as the
code seems to indicate. For example, lines 282 and 283 from 'read':
sysopen $fh, $self->{path}, O_RDWR|O_CREAT
|| die qq/Cannot open pid file "$self->{path}": $!\n/;
In the event that the path cannot be opened, this will not die, but will instead fail silently.
This in turn will cause the flock call to fail complaining about the invalid file descriptor.
The problem is that '||' has higher precedence than ',', so
O_RDWR|O_CREAT || die qq/Cannot open pid file "$self->{path}": $!\n/
is the third argument to sysopen. O_RDWR|O_CREAT evaluates to true, so the 'die' statement
is never evaluated.
The fix is to add parens around the sysopen arguments or to use 'or' instead of '||' (or both).
Thanks,
Derek