I have a program which has an error log that is always attached to file descriptor 2, but the log file could change (in particular at one point we attach a daemon to fd 2 that error messages go through). We used to use --log-fd=2 to force all valgrind errors to via that file descriptor, however valgrind seems to have changed behaviour so that if you use --log-fd=2 it dups fd 2 to somewhere else on startup and logs using that new fd. This means valgrind logs to whatever stderr was on on startup rather than what my program has changed stderr to. It would be nice to have valgrind just log to a file descriptor rather than duping it to somewhere else.
this seems like an anti-feature to me, breaking the isolation between valgrind and the tracee. the proper solution would be a log daemon to which both can talk.
Moving the FD is done to preserve isolation by keeping valgrind's file descriptors separate from those of the tracee - valgrind presents a reduced descriptor limit to the tracee and uses the descriptors between that limit and the real one for itself so here it is trying to move the log descriptor into that protected range.