Mailinglist Archive: opensuse-bugs (6470 mails)

< Previous Next >
[Bug 1124481] [Build 20190201] openQA test fails in lvm_thin_check - bash v5 file descriptors for ~/.bash_history
  • From: bugzilla_noreply@xxxxxxxxxx
  • Date: Wed, 03 Jul 2019 08:01:25 +0000
  • Message-id: <bug-1124481-21960-3Ncb5zaXbP@http.bugzilla.suse.com/>
http://bugzilla.suse.com/show_bug.cgi?id=1124481
http://bugzilla.suse.com/show_bug.cgi?id=1124481#c11

--- Comment #11 from heming zhao <heming.zhao@xxxxxxxx> ---
This is not lvm bug.

lvm code analysis:
```c
main
lvm2_main
_close_stray_fds // tools/lvmcmdline.c
_close_descriptor


//this func will close fd start from 3.
_close_stray_fds(const char *command, struct custom_fds *custom_fds)
{
static const char _fd_dir[] = DEFAULT_PROC_DIR "/self/fd";

if (!(d = opendir(_fd_dir))) {
if (errno != ENOENT) {
log_sys_error("opendir", _fd_dir);
return 0; /* broken system */
}

/* Path does not exist, use the old way */
if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
log_sys_error("getrlimit", "RLIMIT_NOFILE");
return 1;
}

for (fd = 3; fd < (int)rlim.rlim_cur; fd++) {
if ((fd != custom_fds->out) &&
(fd != custom_fds->err) &&
(fd != custom_fds->report)) {
_close_descriptor(fd, suppress_warnings, command, ppid,
parent_cmdline);
}
}
return 1;
}


while ((dirent = readdir(d))) {
fd = atoi(dirent->d_name);
if ((fd > 2) &&
(fd != dirfd(d)) &&
(fd != custom_fds->out) &&
(fd != custom_fds->err) &&
(fd != custom_fds->report)) {
_close_descriptor(fd, suppress_warnings,
command, ppid, parent_cmdline);
}
}

... ...
}

//this function show lvm print message after close leaked fd.
static void _close_descriptor(int fd, unsigned suppress_warnings,
const char *command, pid_t ppid,
const char *parent_cmdline)
{
int r;
const char *filename;

/* Ignore bad file descriptors */
if (!is_valid_fd(fd))
return;

if (!suppress_warnings)
filename = _get_filename(fd);

r = close(fd);
if (suppress_warnings)
return;

if (!r) //<=== r is 0, close(fd) returns on success.
fprintf(stderr, "File descriptor %d (%s) leaked on "
"%s invocation.", fd, filename, command);
else if (errno == EBADF)
return;
else
fprintf(stderr, "Close failed on stray file descriptor "
"%d (%s): %s", fd, filename, strerror(errno));

fprintf(stderr, " Parent PID %" PRIpid_t ": %s\n", ppid, parent_cmdline);
}
```

in linux, a process do fork who child will share its opened fd(s).
lvm is child process, who parent open the fd (~/.bash_history).
It looks a secret shell script open ~/.bash_history, and this shell script
execute lvm after open ~/.bash_history.

As Martin Loviska said in comment #2, setting the environment variable
LVM_SUPPRESS_FD_WARNINGS to suppress it.

--
You are receiving this mail because:
You are on the CC list for the bug.
< Previous Next >