From: Sami Kerola Date: Wed, 4 Apr 2012 17:56:48 +0000 (+0200) Subject: misc-utils: verify writing to streams was successful X-Git-Tag: v2.22-rc1~539^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c05a80ca6385b85c30094390f31615152adfed2e;p=thirdparty%2Futil-linux.git misc-utils: verify writing to streams was successful Signed-off-by: Sami Kerola --- diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index 978661903b..3793c524fc 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -44,6 +44,7 @@ extern int optind; #define STRTOXX_EXIT_CODE 4 /* strtoxx_or_err() */ #include "strutils.h" +#include "closestream.h" const char *progname = "blkid"; @@ -691,6 +692,7 @@ int main(int argc, char **argv) uintmax_t offset = 0, size = 0; show[0] = NULL; + atexit(close_stdout); while ((c = getopt (argc, argv, "c:df:ghilL:n:ko:O:ps:S:t:u:U:w:v")) != EOF) switch (c) { diff --git a/misc-utils/cal.c b/misc-utils/cal.c index c9efdf074e..918cbab09b 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -67,6 +67,7 @@ #include #include "c.h" +#include "closestream.h" #include "nls.h" #include "mbsalign.h" #include "strutils.h" @@ -278,6 +279,7 @@ main(int argc, char **argv) { setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); #if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP) if ((term = getenv("TERM"))) { diff --git a/misc-utils/ddate.c b/misc-utils/ddate.c index 323cb9e2dd..c0b4ce41df 100644 --- a/misc-utils/ddate.c +++ b/misc-utils/ddate.c @@ -63,6 +63,7 @@ #include #include "nls.h" +#include "closestream.h" #include "c.h" #ifndef __GNUC__ @@ -169,6 +170,7 @@ main (int argc, char *argv[]) { setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); srandom(time(NULL)); /* do args here */ diff --git a/misc-utils/findfs.c b/misc-utils/findfs.c index 761c6e91fa..bc4a843131 100644 --- a/misc-utils/findfs.c +++ b/misc-utils/findfs.c @@ -12,6 +12,7 @@ #include #include "nls.h" +#include "closestream.h" #include "c.h" static void __attribute__((__noreturn__)) usage(int rc) @@ -35,6 +36,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); if (argc != 2) /* we return '2' for backward compatibility diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index fe91abb5f4..172f38915b 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -37,6 +37,7 @@ #include "pathnames.h" #include "nls.h" +#include "closestream.h" #include "c.h" #include "tt.h" #include "strutils.h" @@ -991,6 +992,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); /* default output format */ tt_flags |= TT_FL_TREE; diff --git a/misc-utils/kill.c b/misc-utils/kill.c index 15bb470516..dc024924cb 100644 --- a/misc-utils/kill.c +++ b/misc-utils/kill.c @@ -53,6 +53,7 @@ #include "c.h" #include "kill.h" #include "nls.h" +#include "closestream.h" #include "strutils.h" struct signv { @@ -172,6 +173,7 @@ int main (int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); numsig = SIGTERM; do_pid = (! strcmp (progname, "pid")); /* Yecch */ diff --git a/misc-utils/logger.c b/misc-utils/logger.c index c89fca70a5..e3b67d2a20 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -52,6 +52,7 @@ #include #include "c.h" +#include "closestream.h" #include "nls.h" #include "strutils.h" @@ -188,6 +189,7 @@ main(int argc, char **argv) { setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); tag = NULL; pri = LOG_NOTICE; diff --git a/misc-utils/look.c b/misc-utils/look.c index 3d9623bfb8..de231c96eb 100644 --- a/misc-utils/look.c +++ b/misc-utils/look.c @@ -60,6 +60,7 @@ #include "nls.h" #include "xalloc.h" #include "pathnames.h" +#include "closestream.h" #define EQUAL 0 #define GREATER 1 @@ -99,6 +100,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); setlocale(LC_ALL, ""); diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 76356efbbf..22c8e82d2d 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -58,6 +58,7 @@ #include "strutils.h" #include "at.h" #include "sysfs.h" +#include "closestream.h" /* column IDs */ enum { @@ -1186,6 +1187,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); lsblk = &_ls; memset(lsblk, 0, sizeof(*lsblk)); diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c index 0abc2a4bfd..f5390dceec 100644 --- a/misc-utils/lslocks.c +++ b/misc-utils/lslocks.c @@ -40,6 +40,7 @@ #include "at.h" #include "strutils.h" #include "c.h" +#include "closestream.h" /* column IDs */ enum { @@ -515,6 +516,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((c = getopt_long(argc, argv, "p:o:nruhV", long_opts, NULL)) != -1) { diff --git a/misc-utils/mcookie.c b/misc-utils/mcookie.c index 5bef4c541c..b10f5c6fa5 100644 --- a/misc-utils/mcookie.c +++ b/misc-utils/mcookie.c @@ -21,6 +21,8 @@ #include "c.h" #include "md5.h" #include "nls.h" +#include "closestream.h" + #include #include #include @@ -102,6 +104,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((c = getopt_long(argc, argv, "f:vVh", longopts, NULL)) != -1) @@ -183,13 +186,5 @@ int main(int argc, char **argv) printf("%02x", digest[i]); putchar('\n'); - /* - * The following is important for cases like disk full, - * so shell scripts can bomb out properly rather than - * think they succeeded. - */ - if (fflush(stdout) < 0 || fclose(stdout) < 0) - return EXIT_FAILURE; - return EXIT_SUCCESS; } diff --git a/misc-utils/namei.c b/misc-utils/namei.c index e53b4c9a47..9b8ede901a 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -38,6 +38,7 @@ #include "nls.h" #include "widechar.h" #include "strutils.h" +#include "closestream.h" #ifndef MAXSYMLINKS #define MAXSYMLINKS 256 @@ -448,6 +449,7 @@ main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((c = getopt_long(argc, argv, "hVlmnovx", longopts, NULL)) != -1) { switch(c) { diff --git a/misc-utils/rename.c b/misc-utils/rename.c index f7c88cdaa1..b17e03bb13 100644 --- a/misc-utils/rename.c +++ b/misc-utils/rename.c @@ -22,6 +22,7 @@ for i in $@; do N=`echo "$i" | sed "s/$FROM/$TO/g"`; mv "$i" "$N"; done #include "nls.h" #include "xalloc.h" #include "c.h" +#include "closestream.h" static int do_rename(char *from, char *to, char *s, int verbose) { @@ -89,6 +90,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((c = getopt_long(argc, argv, "vVh", longopts, NULL)) != -1) switch (c) { diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c index 492ae4d03a..7c19615b5f 100644 --- a/misc-utils/uuidd.c +++ b/misc-utils/uuidd.c @@ -35,6 +35,7 @@ extern int optind; #include "uuidd.h" #include "writeall.h" +#include "closestream.h" #include "nls.h" #ifdef __GNUC__ @@ -455,6 +456,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((c = getopt_long(argc, argv, "p:s:T:krtn:dqVh", longopts, diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c index 2a98bc8be8..219be8b623 100644 --- a/misc-utils/uuidgen.c +++ b/misc-utils/uuidgen.c @@ -24,6 +24,7 @@ extern int optind; #include "uuid.h" #include "nls.h" #include "c.h" +#include "closestream.h" #define DO_TYPE_TIME 1 #define DO_TYPE_RANDOM 2 @@ -62,6 +63,7 @@ main (int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((c = getopt_long(argc, argv, "rtVh", longopts, NULL)) != -1) switch (c) { diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c index 4a123f1a7a..6807b8a688 100644 --- a/misc-utils/whereis.c +++ b/misc-utils/whereis.c @@ -53,6 +53,7 @@ #include "xalloc.h" #include "nls.h" #include "c.h" +#include "closestream.h" static char *bindirs[] = { "/bin", @@ -417,6 +418,7 @@ main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); argc--, argv++; if (argc == 0) diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index bd20997a15..a9d74f0435 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -38,6 +38,7 @@ #include "writeall.h" #include "match.h" #include "c.h" +#include "closestream.h" struct wipe_desc { loff_t offset; /* magic string offset */ @@ -391,6 +392,7 @@ main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((c = getopt_long(argc, argv, "ahno:pqt:V", longopts, NULL)) != -1) { switch(c) {