1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00

liblvm2cmd: ensure standard descriptors are ready

Check if FDs 0,1,2 are available, and in case they are missing,
use /dev/null for them.
This commit is contained in:
Zdenek Kabelac 2012-09-07 11:13:41 +02:00
parent 1f30e048bd
commit 739092e64a
2 changed files with 39 additions and 1 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.98 - Version 2.02.98 -
================================= =================================
Ensure descriptors 0,1,2 are always available.
Use /proc/self/fd for closing openned descriptors. Use /proc/self/fd for closing openned descriptors.
Add missing pkg init with --enable-testing in configure.in (2.02.71). Add missing pkg init with --enable-testing in configure.in (2.02.71).
Fix inability to create, extend or convert to a large (> 1TiB) RAID LV. Fix inability to create, extend or convert to a large (> 1TiB) RAID LV.

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. * Copyright (C) 2004-2012 Red Hat, Inc. All rights reserved.
* *
* This file is part of LVM2. * This file is part of LVM2.
* *
@ -26,6 +26,7 @@
#include <time.h> #include <time.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <dirent.h> #include <dirent.h>
#include <paths.h>
#ifdef HAVE_GETOPTLONG #ifdef HAVE_GETOPTLONG
# include <getopt.h> # include <getopt.h>
@ -1186,6 +1187,39 @@ int lvm_split(char *str, int *argc, char **argv, int max)
return *argc; return *argc;
} }
/* Make sure we have always valid filedescriptors 0,1,2 */
static int _check_standard_fds(void)
{
int err = is_valid_fd(STDERR_FILENO);
if (!is_valid_fd(STDIN_FILENO) &&
!(stdin = fopen(_PATH_DEVNULL, "r"))) {
if (err)
perror("stdin stream open");
else
printf("stdin stream open: %s\n",
strerror(errno));
return 0;
}
if (!is_valid_fd(STDOUT_FILENO) &&
!(stdout = fopen(_PATH_DEVNULL, "w"))) {
if (err)
perror("stdout stream open");
/* else no stdout */
return 0;
}
if (!is_valid_fd(STDERR_FILENO) &&
!(stderr = fopen(_PATH_DEVNULL, "w"))) {
printf("stderr stream open: %s\n",
strerror(errno));
return 0;
}
return 1;
}
static const char *_get_cmdline(pid_t pid) static const char *_get_cmdline(pid_t pid)
{ {
static char _proc_cmdline[32]; static char _proc_cmdline[32];
@ -1450,6 +1484,9 @@ int lvm2_main(int argc, char **argv)
strcmp(base, "initrd-lvm")) strcmp(base, "initrd-lvm"))
alias = 1; alias = 1;
if (!_check_standard_fds())
return -1;
if (!_close_stray_fds(base)) if (!_close_stray_fds(base))
return -1; return -1;