]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sys-utils: verify writing to streams was successful
authorSami Kerola <kerolasa@iki.fi>
Wed, 4 Apr 2012 17:49:40 +0000 (19:49 +0200)
committerSami Kerola <kerolasa@iki.fi>
Wed, 4 Apr 2012 17:49:40 +0000 (19:49 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
29 files changed:
sys-utils/arch.c
sys-utils/chcpu.c
sys-utils/ctrlaltdel.c
sys-utils/cytune.c
sys-utils/dmesg.c
sys-utils/fallocate.c
sys-utils/flock.c
sys-utils/fsfreeze.c
sys-utils/fstrim.c
sys-utils/ipcmk.c
sys-utils/ipcrm.c
sys-utils/ipcs.c
sys-utils/ldattach.c
sys-utils/losetup.c
sys-utils/lscpu.c
sys-utils/mount.c
sys-utils/mountpoint.c
sys-utils/pivot_root.c
sys-utils/prlimit.c
sys-utils/readprofile.c
sys-utils/renice.c
sys-utils/rtcwake.c
sys-utils/setarch.c
sys-utils/setsid.c
sys-utils/swapon.c
sys-utils/switch_root.c
sys-utils/tunelp.c
sys-utils/umount.c
sys-utils/unshare.c

index 470b12b9aa29760ebffeed6df550cae7033cb5fd..a7305895ae7e300d3b0b70a10ce4df5238466048 100644 (file)
@@ -34,6 +34,7 @@
 #include <sys/utsname.h>
 
 #include "c.h"
+#include "closestream.h"
 #include "nls.h"
 
 static void __attribute__ ((__noreturn__)) usage(FILE * out)
@@ -61,6 +62,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
                switch (ch) {
index 58e40f90dfff94bd272f3ce473608ac22c8853a3..18655927bf5f3bd2a18c1e124215ad72dfd4d803 100644 (file)
@@ -40,6 +40,7 @@
 #include "strutils.h"
 #include "bitops.h"
 #include "path.h"
+#include "closestream.h"
 
 #define _PATH_SYS_CPU          "/sys/devices/system/cpu"
 #define _PATH_SYS_CPU_ONLINE   _PATH_SYS_CPU "/online"
@@ -246,6 +247,7 @@ int main(int argc, char *argv[])
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        maxcpus = get_max_number_of_cpus();
        if (maxcpus < 1)
index ef963226e71e2ef216950e379940d1c367565cf7..2ad56a1bb4847a55aec4411dd2eb413352951a08 100644 (file)
@@ -13,6 +13,7 @@
 #include "linux_reboot.h"
 #include "nls.h"
 #include "c.h"
+#include "closestream.h"
 
 static void __attribute__ ((__noreturn__)) usage(FILE * out)
 {
@@ -37,6 +38,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
                switch (ch) {
index 96d2d640414f407d2e97eb9e271d55660208d624..ecacff2a1a28c0b955bd5fe61c9a3f00793f5822 100644 (file)
@@ -52,6 +52,7 @@
 
 #include "c.h"
 #include "cyclades.h"
+#include "closestream.h"
 #include "strutils.h"
 
 #if 0
@@ -311,6 +312,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((i =
                getopt_long(argc, argv, "qs:S:t:T:gGi:Vh", longopts,
index 9cbe5165839eb79b31c581792c2a9e4373333092..de4b3abc60883325c5969fa814bc8279216034bb 100644 (file)
@@ -29,6 +29,7 @@
 #include "widechar.h"
 #include "writeall.h"
 #include "bitops.h"
+#include "closestream.h"
 
 /* Close the log.  Currently a NOP. */
 #define SYSLOG_ACTION_CLOSE          0
@@ -688,6 +689,7 @@ int main(int argc, char *argv[])
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((c = getopt_long(argc, argv, "CcDdEF:f:hkl:n:rs:TtuVx",
                                longopts, NULL)) != -1) {
index 5fc13fe62f42bc85508a320b4f56d0ab3db1ba47..adfaa70f799a95dbf74130c3e150ab184b951e3f 100644 (file)
@@ -51,7 +51,7 @@
 #include "nls.h"
 #include "strutils.h"
 #include "c.h"
-
+#include "closestream.h"
 
 static void __attribute__((__noreturn__)) usage(FILE *out)
 {
@@ -104,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, "hVnpl:o:", longopts, NULL)) != -1) {
                switch(c) {
index 50cea13920ca045b12275351ef95d08a5986fe96..1db28a294fcbf80df249e2d7c5e1be2c2e857a78 100644 (file)
@@ -42,6 +42,7 @@
 #include "c.h"
 #include "nls.h"
 #include "strutils.h"
+#include "closestream.h"
 
 static void __attribute__((__noreturn__)) usage(int ex)
 {
@@ -161,6 +162,7 @@ int main(int argc, char *argv[])
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        if (argc < 2)
                usage(EX_USAGE);
index 3f03a5241975192606257c978ba2dadd01c31bd0..5d1702158a633a8d3fe4e46bd0ea61995082160b 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "blkdev.h"
 #include "nls.h"
+#include "closestream.h"
 #include "c.h"
 
 static int freeze_f(int fd)
@@ -68,6 +69,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((c = getopt_long(argc, argv, "hfu", longopts, NULL)) != -1) {
                switch(c) {
index 4673e94ab5e7fe5ee004f3a2caeeff12a3fe0051..bb88bb8043c441ecfe42570306059e1e6d6afeab 100644 (file)
@@ -40,6 +40,7 @@
 #include "nls.h"
 #include "strutils.h"
 #include "c.h"
+#include "closestream.h"
 
 #ifndef FITRIM
 struct fstrim_range {
@@ -87,6 +88,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        memset(&range, 0, sizeof(range));
        range.len = ULLONG_MAX;
index 3b3ebb9ba34525267d766f97d14ea531f67a991a..6919d0deadc26defd90be35395d1a0a8ab878fee 100644 (file)
@@ -33,6 +33,7 @@
 #include "c.h"
 #include "nls.h"
 #include "strutils.h"
+#include "closestream.h"
 
 key_t create_key(void)
 {
@@ -98,6 +99,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while((opt = getopt_long(argc, argv, "hM:QS:p:Vh", longopts, NULL)) != -1) {
                switch(opt) {
index c091de349eaa54c93a1f565c4ee71ddc6ad997aa..b452b51ec1fcc9e3ddb4dbd441307cda6997b7bd 100644 (file)
@@ -22,6 +22,7 @@
 #include "c.h"
 #include "nls.h"
 #include "strutils.h"
+#include "closestream.h"
 
 #ifndef HAVE_UNION_SEMUN
 /* according to X/OPEN we have to define it ourselves */
@@ -316,6 +317,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        /* check to see if the command is being invoked in the old way if so
         * then remove argument list */
index 48a4dac4f3af40b4e7a7a6bb47d4fdcab28f58d6..fc416482341dbdf22df2f91c400494c10381ad28 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "c.h"
 #include "nls.h"
+#include "closestream.h"
 
 /*
  * SHM_DEST and SHM_LOCKED are defined in kernel headers, but inside
@@ -162,6 +163,7 @@ int main (int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) {
                switch (opt) {
index d331413fd7185d2c43bf5e3ed4245114b756f2cb..2917d4e833b1e4fbc4645afabd98f827c6604a9d 100644 (file)
@@ -27,6 +27,7 @@
 #include "c.h"
 #include "nls.h"
 #include "strutils.h"
+#include "closestream.h"
 
 #ifndef N_GIGASET_M101
 # define N_GIGASET_M101 16
@@ -234,6 +235,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        /* parse options */
        progname = program_invocation_short_name;
index b8f6762b11da0a82138ec32d3ba0d19083f48d4a..7059d2f8966ad8a436d02f0aaab5e129a9a07672 100644 (file)
@@ -19,6 +19,7 @@
 #include "strutils.h"
 #include "loopdev.h"
 #include "xgetpass.h"
+#include "closestream.h"
 
 enum {
        A_CREATE = 1,           /* setup a new device */
@@ -217,6 +218,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        loopcxt_init(&lc, 0);
        loopcxt_enable_debug(&lc, getenv("LOOPDEV_DEBUG") ? TRUE : FALSE);
index 6e17b2eb55db4df795a57bebd91512c370ea8812..1c2d9b61a0240423396deb410d2e22fd86f427cc 100644 (file)
@@ -41,6 +41,7 @@
 #include "bitops.h"
 #include "tt.h"
 #include "path.h"
+#include "closestream.h"
 
 #define CACHE_MAX 100
 
@@ -1255,6 +1256,7 @@ int main(int argc, char *argv[])
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((c = getopt_long(argc, argv, "abce::hp::s:xV", longopts, NULL)) != -1) {
 
index 664c9865a8f47315e153f7134070f43f84c6214b..0f61406906a6c3e2d97e4cbd416dd5bdd00bb055 100644 (file)
@@ -39,6 +39,7 @@
 #include "xgetpass.h"
 #include "exitcodes.h"
 #include "xalloc.h"
+#include "closestream.h"
 
 /*** TODO: DOCS:
  *
@@ -701,6 +702,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        mnt_init_debug(0);
        cxt = mnt_new_context();
index 63a54469f5f54c5a59a3472e675490bb4b7baf99..6ab813d72ab176878560807c4e376d5c4cf537d5 100644 (file)
@@ -37,6 +37,7 @@
 #include "nls.h"
 #include "xalloc.h"
 #include "c.h"
+#include "closestream.h"
 
 static int quiet;
 
@@ -147,6 +148,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        mnt_init_debug(0);
 
index 044aab22671ebd482c8e6c4cd3a0405ee978a4e3..31ceabb787c69b743b6081e34b48cdcffe98d5ef 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "c.h"
 #include "nls.h"
+#include "closestream.h"
 
 #define pivot_root(new_root,put_old) syscall(SYS_pivot_root,new_root,put_old)
 
@@ -50,6 +51,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
                switch (ch) {
index c45b85efbf87c4ad7ee700391896191934604c15..12271a0790722ca48639c7a4831e435b4a55067b 100644 (file)
@@ -33,6 +33,7 @@
 #include "xalloc.h"
 #include "strutils.h"
 #include "list.h"
+#include "closestream.h"
 
 #ifndef RLIMIT_RTTIME
 # define RLIMIT_RTTIME 15
@@ -513,6 +514,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        INIT_LIST_HEAD(&lims);
 
index 52e64e8e5b415512a85041964d5a7c93ca7cd575..04d9c73753f6334c26bb2aa62d88a0ada7afe282 100644 (file)
@@ -53,6 +53,7 @@
 
 #include "nls.h"
 #include "xalloc.h"
+#include "closestream.h"
 
 #define S_LEN 128
 
@@ -166,6 +167,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        proFile = defaultpro;
        mapFile = defaultmap;
index cd4cafab33984b7ff7e26b3a2cb63ce44f7d88d4..f5d51b66a1a8dec591f7a6d3d4ba569ec28d0071 100644 (file)
@@ -46,6 +46,7 @@
 #include <errno.h>
 #include "nls.h"
 #include "c.h"
+#include "closestream.h"
 
 static int donice(int,int,int);
 
@@ -86,6 +87,7 @@ main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        argc--;
        argv++;
index c18e5e2fc7675db3b18442ed50959d2b5805fe50..4ae2cef296f01656e842333d2a293f9a2b6028eb 100644 (file)
@@ -41,6 +41,7 @@
 #include "usleep.h"
 #include "strutils.h"
 #include "c.h"
+#include "closestream.h"
 
 /* constants from legacy PC/AT hardware */
 #define        RTC_PF  0x40
@@ -285,7 +286,8 @@ static void suspend_system(const char *suspend)
        }
 
        /* this executes after wake from suspend */
-       fclose(f);
+       if (close_stream(f))
+               errx(EXIT_FAILURE, _("write error"));
 }
 
 
@@ -394,6 +396,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((t = getopt_long(argc, argv, "ahd:lm:ns:t:uVv",
                                        long_options, NULL)) != EOF) {
index a61fe391e2f8e51ec6e547e69eb0a6e632d4e4a3..97269f45aef7c0bfb81f4793578c17ba2f3731ca 100644 (file)
@@ -35,6 +35,7 @@
 #include <sys/utsname.h>
 #include "nls.h"
 #include "c.h"
+#include "closestream.h"
 
 #define set_pers(pers) ((long)syscall(SYS_personality, pers))
 
@@ -251,6 +252,7 @@ int main(int argc, char *argv[])
   setlocale(LC_ALL, "");
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
+  atexit(close_stdout);
 
   if (argc < 1)
     show_usage(_("Not enough arguments"));
index 132f4a2abd456c88da63c917822d64da1c828cde..6d1eeda426512d7a81119de4bd287bd32469f4aa 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "c.h"
 #include "nls.h"
+#include "closestream.h"
 
 static void __attribute__ ((__noreturn__)) usage(FILE * out)
 {
@@ -53,6 +54,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((ch = getopt_long(argc, argv, "+Vhc", longopts, NULL)) != -1)
                switch (ch) {
index 25915b32aa3a097d7a56209d9d309a0688e9da24..e1e8455a74f6100d51e090ea7f6e01031373147e 100644 (file)
@@ -26,6 +26,7 @@
 #include "canonicalize.h"
 #include "xalloc.h"
 #include "c.h"
+#include "closestream.h"
 
 #define PATH_MKSWAP    "/sbin/mkswap"
 
@@ -890,6 +891,7 @@ main(int argc, char *argv[]) {
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        progname = program_invocation_short_name;
        if (!progname) {
index 0da7842952bf1daf2916ed580c35dc8329a37f8c..4ff3bff8f957186287c627b31846f34ec081cfb5 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "c.h"
 #include "nls.h"
+#include "closestream.h"
 
 #ifndef MS_MOVE
 #define MS_MOVE 8192
@@ -194,6 +195,7 @@ static void __attribute__((__noreturn__)) usage(FILE *output)
 int main(int argc, char *argv[])
 {
        char *newroot, *init, **initargs;
+       atexit(close_stdout);
 
        if (argv[1] && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))
                usage(stdout);
index 98b00f6efc763bb73e78702069453fb736afe0af..4d9038aecd7632fc0b0866c4ebd8c718a58a17c2 100644 (file)
@@ -63,6 +63,7 @@
 #include "lp.h"
 #include "nls.h"
 #include "xalloc.h"
+#include "closestream.h"
 
 #define EXIT_BAD_VALUE 3
 #define EXIT_LP_IO_ERR 4
@@ -142,6 +143,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        if (argc < 2)
                print_usage(stderr);
index cce4b5375c5a875d743d043f125860065089dfd3..97b2f443b4eb88cb6cc99981b3324c00acfbd966 100644 (file)
@@ -34,6 +34,7 @@
 #include "env.h"
 #include "optutils.h"
 #include "exitcodes.h"
+#include "closestream.h"
 
 static int table_parser_errcb(struct libmnt_table *tb __attribute__((__unused__)),
                        const char *filename, int line)
@@ -309,6 +310,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        mnt_init_debug(0);
        cxt = mnt_new_context();
index 728b860375aa7d30f1b10454aab24cbcefa10313..9de997bdc8ccd6badfa69edef9e537bdb7cb2532 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "nls.h"
 #include "c.h"
+#include "closestream.h"
 
 #ifndef CLONE_NEWSNS
 # define CLONE_NEWNS 0x00020000
@@ -91,6 +92,7 @@ int main(int argc, char *argv[])
        setlocale(LC_MESSAGES, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while((c = getopt_long(argc, argv, "hVmuin", longopts, NULL)) != -1) {
                switch(c) {