]> granicus.if.org Git - procps-ng/commitdiff
all: check stdout and stderr status at exit
authorSami Kerola <kerolasa@iki.fi>
Fri, 23 Mar 2012 12:32:24 +0000 (13:32 +0100)
committerSami Kerola <kerolasa@iki.fi>
Fri, 23 Mar 2012 14:57:53 +0000 (15:57 +0100)
If stream status is not checked at the end of execution below problem
would not report error, or non-zero exit code.  The uptime is just an
example same was true with all commands of the project.

$ uptime >&- ; echo $?
uptime: write error: Bad file descriptor
1
$ uptime >/dev/full ; echo $?
uptime: write error: No space left on device
1

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
17 files changed:
Makefile.am
free.c
pgrep.c
pmap.c
ps/Makefile.am
ps/display.c
pwdx.c
skill.c
slabtop.c
sysctl.c
tload.c
top/Makefile.am
top/top.c
uptime.c
vmstat.c
w.c
watch.c

index b26ad1a92d2334991ada765b914bc49a282a6e6b..87b88ec087ee29afc5b7abae83bdaf76e5a65446 100644 (file)
@@ -46,6 +46,7 @@ dist_man_MANS = \
 if BUILD_KILL
 bin_PROGRAMS = kill
 dist_man_MANS += kill.1
+kill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c $(top_srcdir)/lib/fileutils.c
 endif
 
 if WITH_NCURSES
@@ -55,9 +56,9 @@ usrbin_exec_PROGRAMS += \
 dist_man_MANS += \
        slabtop.1 \
        watch.1
-slabtop_SOURCES = slabtop.c $(top_srcdir)/lib/strutils.c
+slabtop_SOURCES = slabtop.c $(top_srcdir)/lib/strutils.c $(top_srcdir)/lib/fileutils.c
 slabtop_LDADD = @NCURSES_LIBS@
-watch_SOURCES = watch.c $(top_srcdir)/lib/strutils.c
+watch_SOURCES = watch.c $(top_srcdir)/lib/strutils.c $(top_srcdir)/lib/fileutils.c
 watch_LDADD = @WATCH_NCURSES_LIBS@
 endif
 
@@ -65,18 +66,23 @@ if BUILD_SKILL
 usrbin_exec_PROGRAMS += \
        skill \
        snice
-skill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
-snice_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
+skill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c $(top_srcdir)/lib/fileutils.c
+snice_SOURCES = skill.c $(top_srcdir)/lib/strutils.c $(top_srcdir)/lib/fileutils.c
 dist_man_MANS += \
        skill.1 \
        snice.1
 endif
 
-kill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
-tload_SOURCES = tload.c $(top_srcdir)/lib/strutils.c
-pkill_SOURCES = pgrep.c
-free_SOURCES = free.c $(top_srcdir)/lib/strutils.c
-vmstat_SOURCES = vmstat.c $(top_srcdir)/lib/strutils.c
+free_SOURCES = free.c $(top_srcdir)/lib/strutils.c $(top_srcdir)/lib/fileutils.c
+pgrep_SOURCES = pgrep.c $(top_srcdir)/lib/fileutils.c
+pkill_SOURCES = pgrep.c $(top_srcdir)/lib/fileutils.c
+pmap_SOURCES = pmap.c $(top_srcdir)/lib/fileutils.c
+pwdx_SOURCES = pwdx.c $(top_srcdir)/lib/fileutils.c
+sysctl_SOURCES = sysctl.c $(top_srcdir)/lib/fileutils.c
+tload_SOURCES = tload.c $(top_srcdir)/lib/strutils.c $(top_srcdir)/lib/fileutils.c
+uptime_SOURCES = uptime.c $(top_srcdir)/lib/fileutils.c
+vmstat_SOURCES = vmstat.c $(top_srcdir)/lib/strutils.c $(top_srcdir)/lib/fileutils.c
+w_SOURCES = w.c $(top_srcdir)/lib/fileutils.c
 
 sysconf_DATA = sysctl.conf
 
diff --git a/free.c b/free.c
index 7df8563a912fb1d3eebd3a0e37fbb8f10180b146..849f4e4cfd26dd187a8499c4a87cc616dbbdcf9a 100644 (file)
--- a/free.c
+++ b/free.c
@@ -32,6 +32,7 @@
 #include "c.h"
 #include "nls.h"
 #include "strutils.h"
+#include "fileutils.h"
 
 #include <locale.h>
 #include <errno.h>
@@ -226,6 +227,7 @@ int main(int argc, char **argv)
        setlocale (LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((c = getopt_long(argc, argv, "bkmghlotc:s:V", longopts, NULL)) != -1)
                switch (c) {
diff --git a/pgrep.c b/pgrep.c
index 6c46f310340a296779ebf2bab68b1e415a9bc3d6..fed70b98d734671bc440b48e34334b3eab8791dd 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -42,6 +42,7 @@
 #define XALLOC_EXIT_CODE EXIT_FATAL
 
 #include "c.h"
+#include "fileutils.h"
 #include "nls.h"
 #include "xalloc.h"
 #include "proc/readproc.h"
@@ -791,6 +792,7 @@ int main (int argc, char **argv)
        setlocale (LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        parse_opts (argc, argv);
 
diff --git a/pmap.c b/pmap.c
index 3ba1bfe33433b7d935f4ef93f2a3d920d9052ed8..e0447f2eca367879f33fa0c04bbc7abaf7b45ec5 100644 (file)
--- a/pmap.c
+++ b/pmap.c
@@ -31,6 +31,7 @@
 #include <unistd.h>
 
 #include "c.h"
+#include "fileutils.h"
 #include "nls.h"
 #include "proc/escape.h"
 #include "xalloc.h"
@@ -426,6 +427,7 @@ int main(int argc, char **argv)
        setlocale (LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        x_option = d_option = q_option = 0;
 
index 968d27f42a7630d296d2b8105a521189a5b0bac4..e46f496f8477986ff75ebf5c0b91a079d1bf069e 100644 (file)
@@ -21,7 +21,8 @@ pscommand_SOURCES =  \
        parser.c \
        select.c \
        sortformat.c \
-       stacktrace.c
+       stacktrace.c \
+       $(top_srcdir)/lib/fileutils.c
 
 EXTRA_DIST = \
        HACKING \
index 3038600d4a0f07066d68f41b10e1af41eb588215..a1a0f5bb1192b8b86084de63d5509aba377e62d0 100644 (file)
@@ -36,6 +36,7 @@
 #include "../proc/version.h"
 #include "../proc/wchan.h"
 
+#include "../include/fileutils.h"
 #include "common.h"
 
 #ifndef SIGCHLD
@@ -531,6 +532,7 @@ static void fancy_spew(void){
 
 /***** no comment */
 int main(int argc, char *argv[]){
+  atexit(close_stdout);
   myname = strrchr(*argv, '/');
   if (myname) ++myname; else myname = *argv;
 
diff --git a/pwdx.c b/pwdx.c
index fa1a47ed56a77e4cea392d74a0f83ece3ee645c0..e83187c9c78a4db32c4447974fa2384e5a5b29b3 100644 (file)
--- a/pwdx.c
+++ b/pwdx.c
@@ -30,6 +30,7 @@
 #include "c.h"
 #include "nls.h"
 #include "xalloc.h"
+#include "fileutils.h"
 
 static void __attribute__ ((__noreturn__)) usage(FILE * out)
 {
@@ -77,6 +78,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) {
diff --git a/skill.c b/skill.c
index f91d44d6911764470a710592b31af8d43c98e702..6c2d582d0b915c93912985f91286dd809248e8bf 100644 (file)
--- a/skill.c
+++ b/skill.c
@@ -35,6 +35,7 @@
 #include <unistd.h>
 
 #include "c.h"
+#include "fileutils.h"
 #include "strutils.h"
 #include "nls.h"
 #include "xalloc.h"
@@ -375,6 +376,7 @@ static void __attribute__ ((__noreturn__))
        setlocale (LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        if (argc < 2)
                kill_usage(stderr);
index 16863fe2c3fcf549823f96243f8b30873a9ae890..9e535d4fbab4eb25e667b8c0a12773a61edbf273 100644 (file)
--- a/slabtop.c
+++ b/slabtop.c
@@ -39,6 +39,7 @@
 #include <unistd.h>
 
 #include "c.h"
+#include "fileutils.h"
 #include "nls.h"
 #include "strutils.h"
 #include "proc/slab.h"
@@ -303,6 +304,7 @@ int main(int argc, char *argv[])
        setlocale (LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        sort_func = DEF_SORT_FUNC;
 
index e36197006455a28da18374ded338e23ed67cee29..4c8168910f18c41f0102896ecf2d3518332f8a84 100644 (file)
--- a/sysctl.c
+++ b/sysctl.c
@@ -40,6 +40,7 @@
 #include <unistd.h>
 
 #include "c.h"
+#include "fileutils.h"
 #include "nls.h"
 #include "xalloc.h"
 #include "proc/procps.h"
@@ -675,6 +676,7 @@ int main(int argc, char *argv[])
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        PrintName = true;
        PrintNewline = true;
diff --git a/tload.c b/tload.c
index 151ab46ade92fd66c26b9a912929d968281577c7..765ed17725cd61dbd305b1647171d33a7fad117a 100644 (file)
--- a/tload.c
+++ b/tload.c
@@ -27,6 +27,7 @@
 #include "proc/version.h"
 #include "proc/sysinfo.h"
 #include "c.h"
+#include "fileutils.h"
 #include "nls.h"
 #include "strutils.h"
 #include "xalloc.h"
@@ -117,6 +118,7 @@ int main(int argc, char **argv)
        setlocale (LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((opt =
                getopt_long(argc, argv, "s:d:Vh", longopts, NULL)) != -1)
index b7c9f9f5c783b850bb8c5143a3dc35ff9153c482..33d8949a14eb70a79eaa4d3883ffa1a3066ad41f 100644 (file)
@@ -13,7 +13,8 @@ top_SOURCES =  \
        top.h \
        top.c \
        top_nls.h \
-       top_nls.c
+       top_nls.c \
+       $(top_srcdir)/lib/fileutils.c
 
 dist_man_MANS = \
        top.1
index da57ab081bf919d422f543daff292f11266aadfc..97798ffb530a65c167a7e9aa57ffd8514bd75f38 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -41,6 +41,7 @@
 #include <unistd.h>
 #include <values.h>
 
+#include "../include/fileutils.h"
 #include "../include/nls.h"
 
 #include "../proc/devname.h"
@@ -3902,6 +3903,7 @@ static void frame_make (void) {
          * duh... */
 int main (int dont_care_argc, char **argv) {
    (void)dont_care_argc;
+   atexit(close_stdout);
    before(*argv);
                                         //                 +-------------+
    wins_stage_1();                      //                 top (sic) slice
index 995b1b4eef93dcc55d58d72a0bc1598bfe5b1f59..3ea14e761c018afe9d9aa7a91e71f266e57daf69 100644 (file)
--- a/uptime.c
+++ b/uptime.c
@@ -23,6 +23,7 @@
 #include <stdio.h>
 
 #include "c.h"
+#include "fileutils.h"
 #include "nls.h"
 #include "proc/whattime.h"
 #include "proc/version.h"
@@ -53,6 +54,7 @@ int main(int argc, char **argv)
        setlocale (LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((c = getopt_long(argc, argv, "hV", longopts, NULL)) != -1)
                switch (c) {
index 809915a7e807b6881ac709904901f32c07880b6b..669a263fca5bca212d961b885efddab06a04b5ab 100644 (file)
--- a/vmstat.c
+++ b/vmstat.c
@@ -45,6 +45,7 @@
 #include <unistd.h>
 
 #include "c.h"
+#include "fileutils.h"
 #include "nls.h"
 #include "strutils.h"
 #include "proc/sysinfo.h"
@@ -725,6 +726,7 @@ int main(int argc, char *argv[])
        setlocale (LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((c =
                getopt_long(argc, argv, "afmnsdDp:S:hV", longopts,
diff --git a/w.c b/w.c
index db7d75c7bab3c9aa22cb13fb8759c4c37549bd58..03cf983f4e9b7eaee806a86fe7cf060188c7b6ea 100644 (file)
--- a/w.c
+++ b/w.c
@@ -24,6 +24,7 @@
  */
 
 #include "c.h"
+#include "fileutils.h"
 #include "nls.h"
 #include "proc/devname.h"
 #include "proc/escape.h"
@@ -356,6 +357,7 @@ int main(int argc, char **argv)
        setlocale (LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
 #ifndef W_SHOWFROM
        from = 0;
diff --git a/watch.c b/watch.c
index 6cb4551a6c6783d8f0744f4a9695e712e0eda006..4465268391f9cbc6bc2c8ec6b249630d5730a6c7 100644 (file)
--- a/watch.c
+++ b/watch.c
@@ -29,6 +29,7 @@
 
 #include "c.h"
 #include "config.h"
+#include "fileutils.h"
 #include "nls.h"
 #include "proc/procps.h"
 #include "strutils.h"
@@ -588,6 +589,7 @@ int main(int argc, char *argv[])
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((optc =
                getopt_long(argc, argv, "+bced::ghn:pvtx", longopts, (int *)0))