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

Issue #649 resolved
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. asomers 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. Log in to comment