[BusyBox] [patch] ps w
Bernhard Fischer
rep.nop at aon.at
Thu Feb 3 20:01:35 UTC 2005
Hi,
ps calls TIOCGWINSZ to obtain the line-length (minus one) used when
printing the process table. Usually the line-length thus is set to a
low value (79 to be specific).
Certain scripts, however, do rely on getting a "full" commandline of the
running processes with their arguments.
The attached patch adds an option CONFIG_PS_FEATURE_WIDE which adds
support for the argument w for printing up to 511 chars of command and
args.
While at it, i added another option -- CONFIG_PS_FEATURE_WIDEPIPE --
which looks if stdout is a fifo and if so, also sets the maximum
line-length to 511.
Please apply.
Thank you,
-------------- next part --------------
diff -X ../excl -rup upstream/busybox/procps/Config.in busybox.b/procps/Config.in
--- upstream/busybox/procps/Config.in 2003-12-24 07:02:11.000000000 +0100
+++ busybox.b/procps/Config.in 2005-02-03 20:22:58.000000000 +0100
@@ -43,6 +43,20 @@ config CONFIG_PS
help
ps gives a snapshot of the current processes.
+config CONFIG_PS_FEATURE_WIDEPIPE
+ bool " Default to wide on pipe"
+ default n
+ depends on CONFIG_PS
+ help
+ Automatically use wide format if output goes to a pipe.
+
+config CONFIG_PS_FEATURE_WIDE
+ bool " Support argument for wide output"
+ default y
+ depends on CONFIG_PS
+ help
+ Support argument 'w' for untruncated output.
+
config CONFIG_RENICE
bool "renice"
default n
diff -X ../excl -rup upstream/busybox/procps/ps.c busybox.b/procps/ps.c
--- upstream/busybox/procps/ps.c 2004-03-15 09:29:03.000000000 +0100
+++ busybox.b/procps/ps.c 2005-02-03 20:17:53.000000000 +0100
@@ -29,6 +29,9 @@
#include <string.h>
#include <termios.h>
#include <sys/ioctl.h>
+#ifdef CONFIG_PS_FEATURE_WIDEPIPE
+#include <sys/stat.h>
+#endif
#include "busybox.h"
#ifdef CONFIG_SELINUX
#include <fs_secure.h>
@@ -43,6 +46,9 @@ static const int TERMINAL_WIDTH = 79;
extern int ps_main(int argc, char **argv)
{
procps_status_t * p;
+#ifdef CONFIG_PS_FEATURE_WIDEPIPE
+ struct stat stat_buf;
+#endif
int i, len;
int terminal_width = TERMINAL_WIDTH;
@@ -53,6 +59,22 @@ extern int ps_main(int argc, char **argv
use_selinux = 1;
#endif
+#ifdef CONFIG_PS_FEATURE_WIDEPIPE
+ /* do not truncate the output if it goes to a pipe */
+ fstat(STDOUT_FILENO, &stat_buf);
+ if (S_ISFIFO(stat_buf.st_mode))
+ terminal_width = 512;
+ else
+#endif
+#ifdef CONFIG_PS_FEATURE_WIDE
+ /* handle argument w */
+ if (argv[1]) {
+ while (*(argv[1])!='\0' && *(argv[1]) != 'w') { (argv[1])++; }
+ if (*argv[1] == 'w')
+ terminal_width = 512;
+ } else
+#endif
+
get_terminal_width_height(0, &terminal_width, NULL);
/* Go one less... */
terminal_width--;
@@ -90,7 +112,7 @@ extern int ps_main(int argc, char **argv
if(namecmd != 0 && namecmd[0] != 0) {
if(i < 0)
- i = 0;
+ i = 0;
if(strlen(namecmd) > i)
namecmd[i] = 0;
printf("%s\n", namecmd);
More information about the busybox
mailing list