[git commit master 1/1] pwdx: new applet

Denys Vlasenko vda.linux at googlemail.com
Sat Mar 12 17:13:15 UTC 2011


commit: http://git.busybox.net/busybox/commit/?id=cf8b55c40b65a30a6b397f66658d83f0f31f4ed1
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
pwdx_main                                              -     197    +197
packed_usage                                       28237   28261     +24
applet_names                                        2391    2396      +5
applet_main                                         1392    1396      +4
applet_nameofs                                       696     698      +2
applet_install_loc                                   174     175      +1
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/0 up/down: 233/0)             Total: 233 bytes

Signed-off-by: Pere Orga <gotrunks at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 procps/pwdx.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)
 create mode 100644 procps/pwdx.c

diff --git a/procps/pwdx.c b/procps/pwdx.c
new file mode 100644
index 0000000..7818104
--- /dev/null
+++ b/procps/pwdx.c
@@ -0,0 +1,60 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * pwdx implementation for busybox
+ *
+ * Copyright (c) 2004 Nicholas Miell
+ * ported from procps by Pere Orga <gotrunks at gmail.com> 2011
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ */
+
+//config:config PWDX
+//config:	bool "pwdx"
+//config:	default y
+//config:	help
+//config:	  Report current working directory of a process
+
+//applet:IF_PWDX(APPLET(pwdx, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_PWDX) += pwdx.o
+
+//usage:#define pwdx_trivial_usage
+//usage:       "PID..."
+//usage:#define pwdx_full_usage "\n\n"
+//usage:       "Show current directory for PIDs\n"
+
+#include "libbb.h"
+
+int pwdx_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int pwdx_main(int argc UNUSED_PARAM, char **argv)
+{
+	opt_complementary = "-1";
+	getopt32(argv, "");
+	argv += optind;
+
+	do {
+		char buf[sizeof("/proc/%u/cwd") + sizeof(int)*3];
+		unsigned pid;
+		char *s;
+		char *arg = *argv;
+
+		// Allowed on the command line:
+		// /proc/NUM
+		// NUM
+		if (strncmp(arg, "/proc/", 6) == 0)
+			arg += 6;
+
+		pid = bb_strtou(arg, NULL, 10);
+		if (errno)
+			bb_error_msg_and_die("invalid process id: '%s'", arg);
+
+		sprintf(buf, "/proc/%u/cwd", pid);
+
+		s = xmalloc_readlink(buf);
+		// "pwdx /proc/1" says "/proc/1: DIR", not "1: DIR"
+		printf("%s: %s\n", *argv, s ? s : strerror(errno == ENOENT ? ESRCH : errno));
+		free(s);
+	} while (*++argv);
+
+	return EXIT_SUCCESS;
+}
-- 
1.7.3.4



More information about the busybox-cvs mailing list