init_env fails if open(2) returns an unexpected file descriptor

Issue #649 resolved
alan somers created an issue

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)

  1. alan somers 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 returned EBADF 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 the VBAD 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.

  2. Tildeslash repo owner

    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>>

  3. Log in to comment