Hi,
after ksh update on some machines, we started to get errors from lvm:
File descriptor 11 (/tmp/sf2e.2jb (deleted)) leaked on lvs invocation.
Parent PID 16279: ksh
Reproducer is:
ksh -c 'A=$(lvs)'
which requires lvs command (from lvm2 package on RHEL system). Attached
is fdchecker.c which can be used instead.
Above does not happen with ksh 2010-05-27 and older (2010-06-21 is first
version that reproduces this).
Michal
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/resource.h>
const char *_get_filename(int fd)
{
static char filename[255];
char buf[32]; /* Assumes short DEFAULT_PROC_DIR */
int size;
snprintf(buf, sizeof(buf), "/proc/self/fd/%u", fd);
if ((size = readlink(buf, filename, sizeof(filename) - 1)) == -1)
filename[0] = '\0';
else
filename[size] = '\0';
return filename;
}
int _close_descriptor(int fd)
{
int r;
const char *filename;
/* Ignore bad file descriptors */
if (fcntl(fd, F_GETFD) == -1 && errno == EBADF)
return 0;
filename = _get_filename(fd);
r = close(fd);
if (!r)
fprintf(stderr, "File descriptor %d (%s) leaked on "
"invocation.\n", fd, filename);
else if (errno == EBADF)
return 0;
else
fprintf(stderr, "Close failed on stray file descriptor "
"%d (%s): %s", fd, filename, strerror(errno));
return 1;
}
int main(void)
{
struct rlimit rlim;
int r = 0, fd;
if (getrlimit(RLIMIT_NOFILE, &rlim) < 0)
return -1;
for (fd = 3; fd < (int)rlim.rlim_cur; fd++)
r |= (_close_descriptor(fd) != 0);
return 0;
}
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers