X-Git-Url: http://git.liburcu.org/?p=lttng-ust.git;a=blobdiff_plain;f=liblttng-ust-fd%2Flttng-ust-fd.c;h=863f0618adefd605ede54dbf1b2cb4981c7338f4;hp=6a095db60803e1cd45f50dce805faaba4d915716;hb=52a20dc78a372394471e3394a8d335ef00cebad3;hpb=16adecf1f2e80025667ed53f4905e725894f076a diff --git a/liblttng-ust-fd/lttng-ust-fd.c b/liblttng-ust-fd/lttng-ust-fd.c index 6a095db6..863f0618 100644 --- a/liblttng-ust-fd/lttng-ust-fd.c +++ b/liblttng-ust-fd/lttng-ust-fd.c @@ -31,6 +31,7 @@ volatile enum ust_loglevel ust_loglevel; static int (*__lttng_ust_fd_plibc_close)(int fd); +static int (*__lttng_ust_fd_plibc_fclose)(FILE *stream); static int _lttng_ust_fd_libc_close(int fd) @@ -45,11 +46,35 @@ int _lttng_ust_fd_libc_close(int fd) return lttng_ust_safe_close_fd(fd, __lttng_ust_fd_plibc_close); } +static +int _lttng_ust_fd_libc_fclose(FILE *stream) +{ + if (!__lttng_ust_fd_plibc_fclose) { + __lttng_ust_fd_plibc_fclose = dlsym(RTLD_NEXT, "fclose"); + if (!__lttng_ust_fd_plibc_fclose) { + fprintf(stderr, "%s\n", dlerror()); + return -1; + } + } + return lttng_ust_safe_fclose_stream(stream, + __lttng_ust_fd_plibc_fclose); +} + int close(int fd) { return _lttng_ust_fd_libc_close(fd); } +/* + * Note: fcloseall() is not an issue because it fcloses only the + * streams it knows about, which differs from the problems caused by + * gnulib close_stdout(), which does an explicit fclose(stdout). + */ +int fclose(FILE *stream) +{ + return _lttng_ust_fd_libc_fclose(stream); +} + #if defined(__sun__) || defined(__FreeBSD__) /* Solaris and FreeBSD. */ void closefrom(int lowfd)