mirror of
https://https.git.savannah.gnu.org/git/findutils.git
synced 2026-01-26 15:39:06 +00:00
Applied patch from Jim Meyering; if we open an output file but stderr is closed, ensure that we don't send diagnostics to that file
This commit is contained in:
parent
65805dc57e
commit
92dd7816dc
@ -1,3 +1,12 @@
|
||||
2005-07-01 Jim Meyering <jim@meyering.net>
|
||||
|
||||
With `-fprint F' or `-fprintf F', don't write diagnostics
|
||||
to F when stderr is closed.
|
||||
|
||||
* find/parser.c: Include "stdio-safer.h".
|
||||
(open_output_file): Use fopen_safer, not fopen.
|
||||
* import-gnulib.sh (findutils_modules): Add stdio-safer.
|
||||
|
||||
2005-06-24 Bas van Gompel <patch-findutils.buzz@bavag.tmfweb.nl>
|
||||
|
||||
* locate/locate.c (visit_count, visit_limit): New functions.
|
||||
|
||||
42
find/find.c
42
find/find.c
@ -382,46 +382,6 @@ check_nofollow(void)
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
ensure_std_fds_are_open(void)
|
||||
{
|
||||
const char *safe_file = "/dev/null";
|
||||
int fd, saved_errno
|
||||
|
||||
do
|
||||
{
|
||||
fd = open(safe_file, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
/* /dev/null missing or cannot be opened. Perhaps we are in
|
||||
* a very restrictive chroot() environment. Try using /,
|
||||
* which must be present.
|
||||
*/
|
||||
saved_errno = errno;
|
||||
fd = open("/", O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
/* report the original error, which is probably
|
||||
* more sensible.
|
||||
*/
|
||||
errno = saved_errno;
|
||||
}
|
||||
}
|
||||
|
||||
} while (fd > 0 && fd <= 2);
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
/* If stderr is closed here, we lose. Oh, well. */
|
||||
error(1, errno, _("Cannot open %s"), quote(safe_file));
|
||||
}
|
||||
else
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
@ -435,8 +395,6 @@ main (int argc, char **argv)
|
||||
const struct parser_table *entry_close, *entry_print, *entry_open;
|
||||
|
||||
|
||||
ensure_std_fds_are_open();
|
||||
|
||||
/* We call check_nofollow() before setlocale() because the numbers
|
||||
* for which we check (in the results of uname) definitiely have "."
|
||||
* as the decimal point indicator even under locales for which that
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
#include "quotearg.h"
|
||||
#include "buildcmd.h"
|
||||
#include "nextelem.h"
|
||||
#include "stdio-safer.h"
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
@ -2452,7 +2453,7 @@ open_output_file (char *path)
|
||||
return stderr;
|
||||
else if (!strcmp (path, "/dev/stdout"))
|
||||
return stdout;
|
||||
f = fopen (path, "w");
|
||||
f = fopen_safer (path, "w");
|
||||
if (f == NULL)
|
||||
error (1, errno, "%s", path);
|
||||
return f;
|
||||
|
||||
@ -41,8 +41,8 @@ destdir="gnulib"
|
||||
# Modules needed for findutils itself.
|
||||
findutils_modules="\
|
||||
alloca argmatch dirname error fileblocks fnmatch-gnu \
|
||||
getline getopt human idcache lstat malloc memcmp memset mktime \
|
||||
modechange pathmax quotearg realloc regex rpmatch savedir stat \
|
||||
getline getopt human idcache lstat malloc memcmp memset mktime \
|
||||
modechange pathmax quotearg realloc regex rpmatch savedir stat stdio-safer \
|
||||
stpcpy strdup strftime strstr strtol strtoul strtoull strtoumax \
|
||||
xalloc xalloc-die xgetcwd xstrtol xstrtoumax yesno human filemode \
|
||||
getline stpcpy canonicalize mountlist closeout gettext stat-macros"
|
||||
@ -137,12 +137,3 @@ EOF
|
||||
## ls *.m4 | sed -e 's/$/ \\/' | sed -e '$ s/\\$//'
|
||||
## echo
|
||||
## ) > gnulib/m4/Makefile.am
|
||||
|
||||
|
||||
|
||||
# We also need config.rpath, because configure calls it, but for
|
||||
# some reason, "autoreconf -i" doesn't fetch it.
|
||||
for f in config.rpath
|
||||
do
|
||||
(set -x; cp "$1"/build-aux/"$f" . )
|
||||
done
|
||||
|
||||
@ -292,6 +292,10 @@ new_savedirinfo (const char *dir, struct savedir_extrainfo **extra)
|
||||
free (pex);
|
||||
return buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user