[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
find, xargs, locate, etc.: don't hide write failures
From: |
Jim Meyering |
Subject: |
find, xargs, locate, etc.: don't hide write failures |
Date: |
Fri, 07 Jan 2005 14:20:25 +0100 |
Hello James,
[also posted to Savannah as
http://savannah.gnu.org/bugs/index.php?func=detailitem&item_id=11517]
Here's a patch that makes the findutils programs handle disk-full
(and I/O error, writing to closed stdout, etc.) conditions more robustly.
For example, without this change, running `find . > /dev/full' mistakenly
succeeds and gives no indication that there were write errors.
With the patch, I get this:
$ ./find . > /dev/full
./find: write error: No space left on device
2005-01-07 Jim Meyering <address@hidden>
Report the error and fail when writing fails, e.g. to a full disk.
Before, each of these six programs would mistakenly exit successfully
when its standard output was redirected e.g., to a full disk.
* find/find.c: Include closeout.h
(main): Arrange to call close_stdout via atexit.
* locate/locate.c: Likewise.
* xargs/xargs.c: Likewise.
* locate/bigram.c: Likewise.
* locate/code.c: Likewise.
* locate/frcode.c: Likewise.
* import-gnulib.sh (findutils_modules): Add closeout.
Also, you might want to remove the unnecessary `../gnulib/lib/'
prefixes in #include directives, e.g., changing this:
#include "../gnulib/lib/xalloc.h"
to this:
#include "xalloc.h"
Jim
Index: find/find.c
===================================================================
RCS file: /cvsroot/findutils/findutils/find/find.c,v
retrieving revision 1.43
diff -u -p -r1.43 find.c
--- find/find.c 7 Dec 2004 00:22:42 -0000 1.43
+++ find/find.c 7 Jan 2005 11:14:30 -0000
@@ -39,6 +39,7 @@
#include "../gnulib/lib/xalloc.h"
#include "../gnulib/lib/human.h"
#include "../gnulib/lib/canonicalize.h"
+#include "closeout.h"
#include <modetype.h>
#include "../gnulib/lib/savedir.h"
@@ -342,6 +343,7 @@ main (int argc, char **argv)
#endif
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
if (isatty(0))
{
Index: locate/locate.c
===================================================================
RCS file: /cvsroot/findutils/findutils/locate/locate.c,v
retrieving revision 1.27
diff -u -p -r1.27 locate.c
--- locate/locate.c 15 Nov 2004 01:10:01 -0000 1.27
+++ locate/locate.c 7 Jan 2005 11:14:30 -0000
@@ -109,6 +109,7 @@ extern int errno;
#include "../gnulib/lib/xalloc.h"
#include "../gnulib/lib/error.h"
#include "dirname.h"
+#include "closeout.h"
/* Note that this evaluates C many times. */
#ifdef _LIBC
@@ -719,6 +720,7 @@ main (argc, argv)
#endif
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
dbpath = getenv ("LOCATE_PATH");
if (dbpath == NULL)
Index: xargs/xargs.c
===================================================================
RCS file: /cvsroot/findutils/findutils/xargs/xargs.c,v
retrieving revision 1.35
diff -u -p -r1.35 xargs.c
--- xargs/xargs.c 6 Dec 2004 00:38:52 -0000 1.35
+++ xargs/xargs.c 7 Jan 2005 11:14:30 -0000
@@ -166,6 +166,7 @@ typedef int boolean;
#endif
#include <xalloc.h>
+#include "closeout.h"
void error PARAMS ((int status, int errnum, char *message,...));
extern char *version_string;
@@ -378,6 +379,7 @@ main (int argc, char **argv)
#endif
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
+ atexit (close_stdout);
/* IEE Std 1003.1, 2003 specifies that the combined argument and
* environment list shall not exceed {ARG_MAX}-2048 bytes. It also
Index: import-gnulib.sh
===================================================================
RCS file: /cvsroot/findutils/findutils/import-gnulib.sh,v
retrieving revision 1.10
diff -u -p -r1.10 import-gnulib.sh
--- import-gnulib.sh 6 Dec 2004 00:44:50 -0000 1.10
+++ import-gnulib.sh 7 Jan 2005 11:14:30 -0000
@@ -35,7 +35,7 @@ destdir="gnulib"
# Modules needed for findutils itself.
findutils_modules="\
-alloca argmatch dirname error fileblocks fnmatch-gnu \
+alloca argmatch closeout dirname error fileblocks fnmatch-gnu \
getline getopt human idcache lstat malloc memcmp memset mktime \
modechange pathmax quotearg realloc regex rpmatch savedir stat \
stpcpy strdup strftime strstr strtol strtoul strtoull strtoumax \
@@ -132,4 +132,4 @@ printf "%s" "EXTRA_DIST = "
cd gnulib/m4
ls *.m4 | sed -e 's/$/ \\/' | sed -e '$ s/\\$//'
echo
-) > gnulib/m4/Makefile.am
\ No newline at end of file
+) > gnulib/m4/Makefile.am
- find, xargs, locate, etc.: don't hide write failures,
Jim Meyering <=