]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc-utils: verify writing to streams was successful
authorSami Kerola <kerolasa@iki.fi>
Wed, 4 Apr 2012 17:56:48 +0000 (19:56 +0200)
committerSami Kerola <kerolasa@iki.fi>
Wed, 4 Apr 2012 17:56:48 +0000 (19:56 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
17 files changed:
misc-utils/blkid.c
misc-utils/cal.c
misc-utils/ddate.c
misc-utils/findfs.c
misc-utils/findmnt.c
misc-utils/kill.c
misc-utils/logger.c
misc-utils/look.c
misc-utils/lsblk.c
misc-utils/lslocks.c
misc-utils/mcookie.c
misc-utils/namei.c
misc-utils/rename.c
misc-utils/uuidd.c
misc-utils/uuidgen.c
misc-utils/whereis.c
misc-utils/wipefs.c

index 978661903b298fb81da691390d46190b4330657d..3793c524fc88316a31d37c497db9ce59ae15fb57 100644 (file)
@@ -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) {
index c9efdf074efa18cec251e3a22f0b99d84602cd97..918cbab09b90b8400a77643a4c7f26fee82865ba 100644 (file)
@@ -67,6 +67,7 @@
 #include <errno.h>
 
 #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"))) {
index 323cb9e2ddba36f4c830ddd84912ffd4a7f2036b..c0b4ce41dfa9792df21929f8bffe898a7f9a1843 100644 (file)
@@ -63,6 +63,7 @@
 #include <stdio.h>
 
 #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 */
index 761c6e91fa8236643442ebceb36d939b389de9fe..bc4a843131db6540eb4aaf59da9ccb9823411a58 100644 (file)
@@ -12,6 +12,7 @@
 #include <blkid.h>
 
 #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
index fe91abb5f495ba2264982057b421a5509c9e6363..172f38915b0ec0a49bee76a7a41ed1756aee3385 100644 (file)
@@ -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;
index 15bb470516302aad4af28c556e6aee50e808f7ce..dc024924cb84f2c21489609af337425b05d7e5a8 100644 (file)
@@ -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 */
index c89fca70a505f5ccd2d34bff2561269eac7e17aa..e3b67d2a2029153aa84fb621a985a500d5ca1579 100644 (file)
@@ -52,6 +52,7 @@
 #include <getopt.h>
 
 #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;
index 3d9623bfb83dc65596dede201920f02688f4ebd7..de231c96eb6281b890d446fe20ab5a4a6de76914 100644 (file)
@@ -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, "");
 
index 76356efbbf6b53c7b62a0a952b6f5e16e18ce268..22c8e82d2de17e8648c837f6416655770e5f229f 100644 (file)
@@ -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));
index 0abc2a4bfdf82488f799584c92497241879d4092..f5390dceec54666ddc008410be01f9b13082c69f 100644 (file)
@@ -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) {
index 5bef4c541c83bde43b14d5cadd8fa146f1af2c06..b10f5c6fa5592c029f67c8eafaff05ba367fedba 100644 (file)
@@ -21,6 +21,8 @@
 #include "c.h"
 #include "md5.h"
 #include "nls.h"
+#include "closestream.h"
+
 #include <fcntl.h>
 #include <getopt.h>
 #include <stddef.h>
@@ -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;
 }
index e53b4c9a475655ec8b5dbb5b34092e32d5ca42df..9b8ede901a9f56667893820e6f9ed029130dc5b4 100644 (file)
@@ -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) {
index f7c88cdaa188148ff17eee53ff4de3f501710fb7..b17e03bb132b07610093e2bf1a13d7c8a5a3a9de 100644 (file)
@@ -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) {
index 492ae4d03a13ce6a49b7357f9adee29fd8d25ba4..7c19615b5f0776da5990ea18667249cb8fb4c050 100644 (file)
@@ -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,
index 2a98bc8be8b386b2fc642f9a255e944f5edf0e2c..219be8b623ba007500fe14d8f4144e860f647805 100644 (file)
@@ -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) {
index 4a123f1a7aca864ef96b98feac7a30b230e249cc..6807b8a6880885e5045459b328cc4a48b44c7b06 100644 (file)
@@ -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)
index bd20997a1576b0049ed819342b09891e16959ac4..a9d74f04356caf70f52080c51637376a3e7c05bc 100644 (file)
@@ -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) {