diff options
author | Sami Kerola | 2012-04-04 19:44:04 +0200 |
---|---|---|
committer | Sami Kerola | 2012-04-04 19:46:25 +0200 |
commit | cdd2a8c360c70d16804ace7cc923a6c6bb7c9ca9 (patch) | |
tree | 6e4b7254c8179edc8b8f3f1c0908f7e966732b49 /term-utils | |
parent | text-utils: verify writing to streams was successful (diff) | |
download | kernel-qcow2-util-linux-cdd2a8c360c70d16804ace7cc923a6c6bb7c9ca9.tar.gz kernel-qcow2-util-linux-cdd2a8c360c70d16804ace7cc923a6c6bb7c9ca9.tar.xz kernel-qcow2-util-linux-cdd2a8c360c70d16804ace7cc923a6c6bb7c9ca9.zip |
term-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils')
-rw-r--r-- | term-utils/mesg.c | 3 | ||||
-rw-r--r-- | term-utils/script.c | 16 | ||||
-rw-r--r-- | term-utils/scriptreplay.c | 2 | ||||
-rw-r--r-- | term-utils/setterm.c | 5 | ||||
-rw-r--r-- | term-utils/ttymsg.c | 3 | ||||
-rw-r--r-- | term-utils/wall.c | 5 | ||||
-rw-r--r-- | term-utils/write.c | 3 |
7 files changed, 30 insertions, 7 deletions
diff --git a/term-utils/mesg.c b/term-utils/mesg.c index 4fad6f57a..366c679ac 100644 --- a/term-utils/mesg.c +++ b/term-utils/mesg.c @@ -54,6 +54,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <getopt.h> + +#include "closestream.h" #include "nls.h" #include "c.h" @@ -88,6 +90,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); static const struct option longopts[] = { { "verbose", no_argument, 0, 'v' }, diff --git a/term-utils/script.c b/term-utils/script.c index effedac4f..07be7e987 100644 --- a/term-utils/script.c +++ b/term-utils/script.c @@ -59,6 +59,7 @@ #include <locale.h> #include <stddef.h> +#include "closestream.h" #include "nls.h" #include "c.h" @@ -180,6 +181,7 @@ main(int argc, char **argv) { setlocale(LC_NUMERIC, "C"); /* see comment above */ bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((ch = getopt_long(argc, argv, "ac:efqt::Vh", longopts, NULL)) != -1) switch(ch) { @@ -283,7 +285,8 @@ main(int argc, char **argv) { } doinput(); - fclose(timingfd); + if (close_stream(timingfd) != 0) + errx(EXIT_FAILURE, _("write error")); return EXIT_SUCCESS; } @@ -292,7 +295,8 @@ doinput(void) { ssize_t cc; char ibuf[BUFSIZ]; - fclose(fscript); + if (close_stream(fscript) != 0) + errx(EXIT_FAILURE, _("write error")); while (die == 0) { if ((cc = read(STDIN_FILENO, ibuf, BUFSIZ)) > 0) { @@ -404,6 +408,8 @@ dooutput(FILE *timingfd) { if (flgs) fcntl(master, F_SETFL, flgs); + if (close_stream(timingfd) != 0) + errx(EXIT_FAILURE, _("write error")); done(); } @@ -423,7 +429,8 @@ doshell(void) { getslave(); close(master); - fclose(fscript); + if (close_stream(fscript) != 0) + errx(EXIT_FAILURE, _("write error")); dup2(slave, STDIN_FILENO); dup2(slave, STDOUT_FILENO); dup2(slave, STDERR_FILENO); @@ -484,7 +491,8 @@ done(void) { my_strftime(buf, sizeof buf, "%c\n", localtime(&tvec)); fprintf(fscript, _("\nScript done on %s"), buf); } - fclose(fscript); + if (close_stream(fscript) != 0) + errx(EXIT_FAILURE, _("write error")); close(master); master = -1; diff --git a/term-utils/scriptreplay.c b/term-utils/scriptreplay.c index 5aa8d42af..63dc6fce1 100644 --- a/term-utils/scriptreplay.c +++ b/term-utils/scriptreplay.c @@ -28,6 +28,7 @@ #include <unistd.h> #include <getopt.h> +#include "closestream.h" #include "nls.h" #include "c.h" @@ -153,6 +154,7 @@ main(int argc, char *argv[]) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((ch = getopt_long(argc, argv, "t:s:d:Vh", longopts, NULL)) != -1) switch(ch) { diff --git a/term-utils/setterm.c b/term-utils/setterm.c index 64fe0eb6a..5a652931b 100644 --- a/term-utils/setterm.c +++ b/term-utils/setterm.c @@ -121,6 +121,7 @@ #include "c.h" #include "xalloc.h" #include "nls.h" +#include "closestream.h" #if __GNU_LIBRARY__ < 5 #ifndef __alpha__ @@ -1113,7 +1114,8 @@ perform_sequence(int vcterm) { err(EXIT_DUMPFILE, _("can not open dump file %s for output"), opt_sn_name); screendump(opt_sn_num, F); - fclose(F); + if (close_stream(F) != 0) + errx(EXIT_FAILURE, _("write error")); } /* -msg [on|off]. */ @@ -1225,6 +1227,7 @@ main(int argc, char **argv) { setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); if (argc < 2) bad_arg = TRUE; diff --git a/term-utils/ttymsg.c b/term-utils/ttymsg.c index 5253f7a5c..aea6c2656 100644 --- a/term-utils/ttymsg.c +++ b/term-utils/ttymsg.c @@ -51,8 +51,9 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#include "nls.h" +#include "nls.h" +#include "closestream.h" #include "pathnames.h" #include "ttymsg.h" diff --git a/term-utils/wall.c b/term-utils/wall.c index fb3db2119..f302d454f 100644 --- a/term-utils/wall.c +++ b/term-utils/wall.c @@ -67,6 +67,7 @@ #include "carefulputc.h" #include "c.h" #include "fileutils.h" +#include "closestream.h" #define IGNOREUSER "sleeper" #define WRITE_TIME_OUT 300 /* in seconds */ @@ -114,6 +115,7 @@ main(int argc, char **argv) { setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); static const struct option longopts[] = { { "nobanner", no_argument, 0, 'n' }, @@ -281,6 +283,7 @@ makemsg(char *fname, size_t *mbufsize, int print_banner) if (fread(mbuf, 1, *mbufsize, fp) != *mbufsize) err(EXIT_FAILURE, _("fread failed")); - fclose(fp); + if (close_stream(fp) != 0) + errx(EXIT_FAILURE, _("write error")); return mbuf; } diff --git a/term-utils/write.c b/term-utils/write.c index a70eb7bd1..2a94792e0 100644 --- a/term-utils/write.c +++ b/term-utils/write.c @@ -59,8 +59,10 @@ #include <paths.h> #include <asm/param.h> #include <getopt.h> + #include "c.h" #include "carefulputc.h" +#include "closestream.h" #include "nls.h" static void __attribute__ ((__noreturn__)) usage(FILE * out); @@ -103,6 +105,7 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); + atexit(close_stdout); while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) switch (c) { |