If ENV_NAME_FDS is not set then init_from_environment() was called for
each hooked function, instead of just once.
static int (*real_close)(int);
static size_t (*real_fwrite)(const void *, size_t, size_t, FILE *);
+/* Did we already (try to) parse the environment and setup the necessary
+ * variables? */
+static int initialized;
+
#include "constants.h"
#ifdef DEBUG
}
/* Load state from environment. Only necessary once per process. */
- if (!tracked_fds) {
+ if (!initialized) {
init_from_environment();
}
debug("%d -> %d\t\t\t[%d]\n", oldfd, newfd, getpid());
#endif
- if (!tracked_fds) {
+ if (!initialized) {
init_from_environment();
}
if (tracked_fds_count == 0) {
debug("%d -> .\t\t\t[%d]\n", fd, getpid());
#endif
- if (!tracked_fds) {
+ if (!initialized) {
init_from_environment();
}
* ENV_NAME_FDS has the following format: Each descriptor as string followed
* by a comma; there's a trailing comma. Example: "2,4,". */
static void init_from_environment(void) {
+ initialized = 1;
tracked_fds_count = 0;
const char *env = getenv(ENV_NAME_FDS);