[BusyBox] Added a option to ps
Christophe Boyanique
totof at raceme.org
Wed Mar 7 15:58:31 UTC 2001
Hi,
I've just added the a option to ps with a define in Config.h
When defined, ps no more prints all users process except if a option is
passed.
Christophe.
-------------- next part --------------
diff -ur busybox.orig/Config.h busybox/Config.h
--- busybox.orig/Config.h Fri Mar 2 14:11:26 2001
+++ busybox/Config.h Wed Mar 7 16:54:12 2001
@@ -140,6 +140,12 @@
// 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 the a (all) feature to ps:
+// when undefined, ps print all the process
+// when defined, ps will print only user process except if a option
+// is passed
+//#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.orig/ps.c busybox/ps.c
--- busybox.orig/ps.c Tue Feb 20 01:14:08 2001
+++ busybox/ps.c Wed Mar 7 16:49:28 2001
@@ -128,8 +128,19 @@
#else
#define terminal_width TERMINAL_WIDTH
#endif
+#ifdef BB_FEATURE_PS_ALL
+ int all = 0;
+ int curUid = getuid();
+#endif
-
+#ifdef BB_FEATURE_PS_ALL
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "a") == 0)
+ all=1;
+ else
+ show_usage();
+ }
+#endif
dir = opendir("/proc");
if (!dir)
@@ -149,6 +160,10 @@
if ((file2str(path, sbuf, sizeof sbuf)) != -1) {
parse_proc_status(sbuf, &p);
}
+#ifdef BB_FEATURE_PS_ALL
+ if ((p.ruid != curUid) && (all == 0))
+ continue;
+#endif
/* Make some adjustments as needed */
my_getpwuid(uidName, p.ruid);
@@ -205,9 +220,19 @@
#else
#define terminal_width TERMINAL_WIDTH
#endif
+#ifdef BB_FEATURE_PS_ALL
+ int all = 0;
+ int curUid = getuid();
+#endif
- if (argc > 1 && **(argv + 1) == '-')
- show_usage();
+#ifdef BB_FEATURE_PS_ALL
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "a") == 0)
+ all=1;
+ else
+ show_usage();
+ }
+#endif
/* open device */
fd = open(device, O_RDONLY);
@@ -244,6 +269,11 @@
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
perror_msg_and_die("\nDEVPS_GET_PID_INFO");
+#ifdef BB_FEATURE_PS_ALL
+ if ((info.euid != curUid) && (all == 0))
+ continue;
+#endif
+
/* Make some adjustments as needed */
my_getpwuid(uidName, info.euid);
if (*uidName == '\0')
diff -ur busybox.orig/usage.h busybox/usage.h
--- busybox.orig/usage.h Fri Mar 2 14:08:50 2001
+++ busybox/usage.h Wed Mar 7 16:49:23 2001
@@ -752,9 +752,16 @@
#define ps_trivial_usage \
""
+#ifdef BB_FEATURE_PS_ALL
+#define ps_full_usage \
+ "Report process status\n" \
+ "\nOptions:\n" \
+ "\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 pwd_trivial_usage \
""
More information about the busybox
mailing list