[BusyBox] [patch] ps w
Rainer Weikusat
rainer.weikusat at sncag.com
Thu Feb 3 20:50:59 UTC 2005
Bernhard Fischer <rep.nop at aon.at> writes:
[...]
> 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.
Cool. May suggest a small modification, namely, to enable wide output
if WIDEPIPE is selected and stdout does not refer to a tty device?
Index: busybox//procps/Config.in
===================================================================
RCS file: /data/repo/busybox/procps/Config.in,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Config.in
--- busybox//procps/Config.in 30 Nov 2004 16:02:32 -0000 1.1.1.1
+++ busybox//procps/Config.in 3 Feb 2005 20:48:47 -0000
@@ -43,6 +43,21 @@
help
ps gives a snapshot of the current processes.
+config CONFIG_PS_FEATURE_WIDEPIPE
+ bool " Default to wide on descriptors not refering to tty devices"
+ default n
+ depends on CONFIG_PS
+ help
+ Automatically use wide format if output goes to a descriptor
+ that does not refer to a terminal device.
+
+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
Index: busybox//procps/ps.c
===================================================================
RCS file: /data/repo/busybox/procps/ps.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 ps.c
--- busybox//procps/ps.c 30 Nov 2004 16:02:33 -0000 1.1.1.1
+++ busybox//procps/ps.c 3 Feb 2005 20:48:47 -0000
@@ -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 @@
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,20 @@
use_selinux = 1;
#endif
+#ifdef CONFIG_PS_FEATURE_WIDEPIPE
+ /* do not truncate the output if it goes to a non-tty device */
+ if (!isatty(STDOUT_FILENO)) 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 +110,7 @@
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