[BusyBox] New ps patch
Christophe Boyanique
totof at raceme.org
Fri Mar 16 14:46:33 UTC 2001
Sorry I made typo errors in the previous ps patch. Here is the final
one...
This mistake shows that time to end the week and leave far, far away for
the week-end has come :)
Christophe.
-------------- next part --------------
diff -ur busybox-0.50.orig/Changelog busybox-0.50/Changelog
--- busybox-0.50.orig/Changelog Thu Mar 15 17:12:42 2001
+++ busybox-0.50/Changelog Fri Mar 16 14:41:13 2001
@@ -1,3 +1,8 @@
+
+ * Christophe Boyanique -- Added optional BB_FEATURE_PS and
+ BB_FEATURE_PS_ALL (option parsing and -a option with ps applet).
+ Corrected show_usage() call in both ps_main() functions.
+
0.50
* Erik Andersen -- added ifconfig interface status reporting
* Erik Andersen -- Debian packaging updates
diff -ur busybox-0.50.orig/Config.h busybox-0.50/Config.h
--- busybox-0.50.orig/Config.h Thu Mar 15 13:58:06 2001
+++ busybox-0.50/Config.h Fri Mar 16 14:50:53 2001
@@ -141,6 +141,18 @@
// space, this can be deadly. For most folks, this works just fine...
//#define BB_FEATURE_BUFFERS_GO_ON_STACK
//
+// Turn this option on to add options parsing to ps (needed for the
+// next ps features to work).
+// Adds approx. 64 bytes (i386 rh62)
+//#define BB_FEATURE_PS
+//
+// Turn this option on to add the a (all) feature to ps:
+// when undefined, ps will print all the users' processes
+// when defined, ps will print only current user's processes except
+// if a option is passed.
+// Adds approx. 64/96 bytes (w/wo TRIVIAL_HELP) (i386 rh62)
+//#define BB_FEATURE_PS_ALL
+//
// Turn this on to use Erik's very cool devps, and devmtab kernel drivers,
// thereby eliminating the need for the /proc filesystem and thereby saving
// lots and lots memory for more important things. NOTE: If you enable this
diff -ur busybox-0.50.orig/ps.c busybox-0.50/ps.c
--- busybox-0.50.orig/ps.c Tue Feb 20 01:14:08 2001
+++ busybox-0.50/ps.c Fri Mar 16 14:31:29 2001
@@ -128,9 +128,38 @@
#else
#define terminal_width TERMINAL_WIDTH
#endif
+#ifdef BB_FEATURE_PS
+ char *ptr = NULL;
+ int parsed;
+#ifdef BB_FEATURE_PS_ALL
+ int all = FALSE;
+ int curUid = getuid();
+#endif
+#endif
-
-
+#ifdef BB_FEATURE_PS
+ for (i = 1; i < argc; i++) {
+ ptr = argv[i];
+ if (*ptr == '-')
+ ptr++;
+ while (*ptr != '\0') {
+ parsed = FALSE;
+#ifdef BB_FEATURE_PS_ALL
+ if (*ptr == 'a') {
+ all = TRUE;
+ parsed = TRUE;
+ }
+#endif
+ if (parsed == FALSE)
+ show_usage();
+ ptr++;
+ }
+ }
+#else
+ if (argc > 1)
+ show_usage();
+#endif
+
dir = opendir("/proc");
if (!dir)
error_msg_and_die("Can't open /proc");
@@ -150,6 +179,11 @@
parse_proc_status(sbuf, &p);
}
+#if defined(BB_FEATURE_PS) && defined(BB_FEATURE_PS_ALL)
+ if ((p.ruid != curUid) && (all == FALSE))
+ continue;
+#endif
+
/* Make some adjustments as needed */
my_getpwuid(uidName, p.ruid);
if (*uidName == '\0')
@@ -205,9 +239,37 @@
#else
#define terminal_width TERMINAL_WIDTH
#endif
+#ifdef BB_FEATURE_PS
+ char *ptr = NULL;
+ int parsed;
+#ifdef BB_FEATURE_PS_ALL
+ int all = FALSE;
+ int curUid = getuid();
+#endif
+#endif
- if (argc > 1 && **(argv + 1) == '-')
+#ifdef BB_FEATURE_PS
+ for (i = 1; i < argc; i++) {
+ ptr = argv[i];
+ if (*ptr == '-')
+ ptr++;
+ while (*ptr != '\0') {
+ parsed = FALSE;
+#ifdef BB_FEATURE_PS_ALL
+ if (*ptr == 'a') {
+ all = TRUE;
+ parsed = TRUE;
+ }
+#endif
+ if (parsed == FALSE)
+ show_usage();
+ ptr++;
+ }
+ }
+#else
+ if (argc > 1)
show_usage();
+#endif
/* open device */
fd = open(device, O_RDONLY);
@@ -243,6 +305,11 @@
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
perror_msg_and_die("\nDEVPS_GET_PID_INFO");
+
+#if defined(BB_FEATURE_PS) && defined(BB_FEATURE_PS_ALL)
+ if ((info.euid != curUid) && (all == FALSE))
+ continue;
+#endif
/* Make some adjustments as needed */
my_getpwuid(uidName, info.euid);
diff -ur busybox-0.50.orig/usage.h busybox-0.50/usage.h
--- busybox-0.50.orig/usage.h Fri Mar 16 03:06:30 2001
+++ busybox-0.50/usage.h Fri Mar 16 14:20:05 2001
@@ -1172,11 +1172,23 @@
"$ printf "Val=%d\n" 5\n" \
"Val=5\n"
+#ifdef BB_FEATURE_PS_ALL
+ #define USAGE_PS_ALL(a) a
+#else
+ #define USAGE_PS_ALL(a)
+#endif
#define ps_trivial_usage \
""
+#ifdef BB_FEATURE_PS
+#define ps_full_usage \
+ "Report process status\n" \
+ "\nOptions:\n" \
+ USAGE_PS_ALL("\ta\tPrint information about every process now running.")
+#else
#define ps_full_usage \
"Report process status\n" \
"\nThis version of ps accepts no options."
+#endif
#define ps_example_usage \
"$ ps\n" \
" PID Uid Gid State Command\n" \
More information about the busybox
mailing list