- attached issue_649.c
init_env fails if open(2) returns an unexpected file descriptor
init_env
assumes that open
will always return file descriptors in a certain order, and throws if it doesn't. When invoking monit restart
through STAF, open
returns 3 when init_env
expects 0. I'm not sure why this is, but monit should be able to handle it.
Comments (3)
-
reporter -
reporter I figured out what's going on. STAF detached from its controlling terminal, but never closed stdin. At the end of the boot process, the OS revoked that terminal, invalidating all its open file descriptors . STAF passed that invalid file descriptor to monit.
fstat
returnedEBADF
not because 0 wasn't a file descriptor, but because it was now invalid. In FreeBSD, such a file descriptor is associated with a vnode that has theVBAD
type.The easiest way to reproduce this is by using the
revoke
system call. It's not implemented on Linux, but I think the same file descriptor revocation process applies when you log out of a tty. The attached program will reproduce the problem on FreeBSD. -
repo owner - changed status to resolved
Fixed: Issue
#649: Monit initialization fails if open() returns an unexpected file descriptor. The problem was observed when Monit was executed in STAF test environment. Thanks to Alan Somers for patch.→ <<cset 869a526a8d33>>
- Log in to comment
Reproduction script. Compile with "cc -o issue_649 -Wall issue_649.c"