diff --git a/Makefile.am b/Makefile.am index b26ad1a9..87b88ec0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 7df8563a..849f4e4c 100644 --- a/free.c +++ b/free.c @@ -32,6 +32,7 @@ #include "c.h" #include "nls.h" #include "strutils.h" +#include "fileutils.h" #include #include @@ -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 6c46f310..fed70b98 100644 --- 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 3ba1bfe3..e0447f2e 100644 --- a/pmap.c +++ b/pmap.c @@ -31,6 +31,7 @@ #include #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; diff --git a/ps/Makefile.am b/ps/Makefile.am index 968d27f4..e46f496f 100644 --- a/ps/Makefile.am +++ b/ps/Makefile.am @@ -21,7 +21,8 @@ pscommand_SOURCES = \ parser.c \ select.c \ sortformat.c \ - stacktrace.c + stacktrace.c \ + $(top_srcdir)/lib/fileutils.c EXTRA_DIST = \ HACKING \ diff --git a/ps/display.c b/ps/display.c index 3038600d..a1a0f5bb 100644 --- a/ps/display.c +++ b/ps/display.c @@ -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 fa1a47ed..e83187c9 100644 --- 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 f91d44d6..6c2d582d 100644 --- a/skill.c +++ b/skill.c @@ -35,6 +35,7 @@ #include #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); diff --git a/slabtop.c b/slabtop.c index 16863fe2..9e535d4f 100644 --- a/slabtop.c +++ b/slabtop.c @@ -39,6 +39,7 @@ #include #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; diff --git a/sysctl.c b/sysctl.c index e3619700..4c816891 100644 --- a/sysctl.c +++ b/sysctl.c @@ -40,6 +40,7 @@ #include #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 151ab46a..765ed177 100644 --- 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) diff --git a/top/Makefile.am b/top/Makefile.am index b7c9f9f5..33d8949a 100644 --- a/top/Makefile.am +++ b/top/Makefile.am @@ -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 diff --git a/top/top.c b/top/top.c index da57ab08..97798ffb 100644 --- a/top/top.c +++ b/top/top.c @@ -41,6 +41,7 @@ #include #include +#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 diff --git a/uptime.c b/uptime.c index 995b1b4e..3ea14e76 100644 --- a/uptime.c +++ b/uptime.c @@ -23,6 +23,7 @@ #include #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) { diff --git a/vmstat.c b/vmstat.c index 809915a7..669a263f 100644 --- a/vmstat.c +++ b/vmstat.c @@ -45,6 +45,7 @@ #include #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 db7d75c7..03cf983f 100644 --- 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 6cb4551a..44652683 100644 --- 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))