[BusyBox] [patch] ps w
Bernhard Fischer
rep.nop at aon.at
Thu Feb 3 21:59:22 UTC 2005
On Thu, Feb 03, 2005 at 09:50:59PM +0100, Rainer Weikusat wrote:
>Bernhard Fischer 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?
Also turned the size into an option and adjusted the help text.
That should do it.
thanks,
-------------- next part --------------
diff -X ../excl -rup upstream/busybox/include/usage.h busybox.b/include/usage.h
--- upstream/busybox/include/usage.h 2005-01-24 08:00:01.000000000 +0100
+++ busybox.b/include/usage.h 2005-02-03 22:30:40.000000000 +0100
@@ -1943,18 +1943,29 @@
"$ printf "Val=%d\\n" 5\n" \
"Val=5\n"
+#if !defined(CONFIG_SELINUX) && !defined(CONFIG_PS_FEATURE_WIDE)
+#define USAGE_PS "\n\tThis version of ps accepts no options."
+#else
+#define USAGE_PS "\nOptions:"
+#endif
#ifdef CONFIG_SELINUX
#define USAGE_NONSELINUX(a)
#else
#define USAGE_NONSELINUX(a) a
#endif
+#ifdef CONFIG_PS_FEATURE_WIDE
+#define USAGE_PS_WIDE(a) a
+#else
+#define USAGE_PS_WIDE(a)
+#endif
#define ps_trivial_usage \
""
#define ps_full_usage \
"Report process status\n" \
- USAGE_NONSELINUX("\n\tThis version of ps accepts no options.") \
- USAGE_SELINUX("\nOptions:\n\t-c\tshow SE Linux context")
+ USAGE_PS \
+ USAGE_PS_WIDE("\n\tw\twide output") \
+ USAGE_SELINUX("\n\t-c\tshow SE Linux context")
#define ps_example_usage \
"$ ps\n" \
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 22:44:49.000000000 +0100
@@ -43,6 +43,30 @@ config CONFIG_PS
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 y
+ 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 n
+ depends on CONFIG_PS
+ help
+ Support argument 'w' for untruncated output.
+
+config CONFIG_PS_FEATURE_SIZE
+ int " maximum buffer size"
+ default 512
+ depends on CONFIG_PS_FEATURE_WIDE || CONFIG_PS_FEATURE_WIDEPIPE
+ help
+ Maximum line-length used for printing the process table.
+ The actual value used is this setting descremented by one.
+ Default: 512
+
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 22:42:04.000000000 +0100
@@ -53,6 +53,21 @@ 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 non-tty device */
+ if (!isatty(STDOUT_FILENO))
+ terminal_width = CONFIG_PS_FEATURE_SIZE;
+ 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 = CONFIG_PS_FEATURE_SIZE;
+ } else
+#endif
+
get_terminal_width_height(0, &terminal_width, NULL);
/* Go one less... */
terminal_width--;
@@ -90,7 +105,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