diff options
author | Pere Orga <gotrunks@gmail.com> | 2011-03-12 18:13:15 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-03-12 18:13:15 +0100 |
commit | cf8b55c40b65a30a6b397f66658d83f0f31f4ed1 (patch) | |
tree | 8d690e32be965f055cfd6b2a5bb515c660fa3349 | |
parent | 5c942713b7369d239b1303c0cfc7049d898564d4 (diff) | |
download | busybox-w32-cf8b55c40b65a30a6b397f66658d83f0f31f4ed1.tar.gz busybox-w32-cf8b55c40b65a30a6b397f66658d83f0f31f4ed1.tar.bz2 busybox-w32-cf8b55c40b65a30a6b397f66658d83f0f31f4ed1.zip |
pwdx: new applet
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@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/pwdx.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/procps/pwdx.c b/procps/pwdx.c new file mode 100644 index 000000000..781810488 --- /dev/null +++ b/procps/pwdx.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * pwdx implementation for busybox | ||
4 | * | ||
5 | * Copyright (c) 2004 Nicholas Miell | ||
6 | * ported from procps by Pere Orga <gotrunks@gmail.com> 2011 | ||
7 | * | ||
8 | * Licensed under GPLv2, see file LICENSE in this source tree. | ||
9 | */ | ||
10 | |||
11 | //config:config PWDX | ||
12 | //config: bool "pwdx" | ||
13 | //config: default y | ||
14 | //config: help | ||
15 | //config: Report current working directory of a process | ||
16 | |||
17 | //applet:IF_PWDX(APPLET(pwdx, BB_DIR_USR_BIN, BB_SUID_DROP)) | ||
18 | |||
19 | //kbuild:lib-$(CONFIG_PWDX) += pwdx.o | ||
20 | |||
21 | //usage:#define pwdx_trivial_usage | ||
22 | //usage: "PID..." | ||
23 | //usage:#define pwdx_full_usage "\n\n" | ||
24 | //usage: "Show current directory for PIDs\n" | ||
25 | |||
26 | #include "libbb.h" | ||
27 | |||
28 | int pwdx_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
29 | int pwdx_main(int argc UNUSED_PARAM, char **argv) | ||
30 | { | ||
31 | opt_complementary = "-1"; | ||
32 | getopt32(argv, ""); | ||
33 | argv += optind; | ||
34 | |||
35 | do { | ||
36 | char buf[sizeof("/proc/%u/cwd") + sizeof(int)*3]; | ||
37 | unsigned pid; | ||
38 | char *s; | ||
39 | char *arg = *argv; | ||
40 | |||
41 | // Allowed on the command line: | ||
42 | // /proc/NUM | ||
43 | // NUM | ||
44 | if (strncmp(arg, "/proc/", 6) == 0) | ||
45 | arg += 6; | ||
46 | |||
47 | pid = bb_strtou(arg, NULL, 10); | ||
48 | if (errno) | ||
49 | bb_error_msg_and_die("invalid process id: '%s'", arg); | ||
50 | |||
51 | sprintf(buf, "/proc/%u/cwd", pid); | ||
52 | |||
53 | s = xmalloc_readlink(buf); | ||
54 | // "pwdx /proc/1" says "/proc/1: DIR", not "1: DIR" | ||
55 | printf("%s: %s\n", *argv, s ? s : strerror(errno == ENOENT ? ESRCH : errno)); | ||
56 | free(s); | ||
57 | } while (*++argv); | ||
58 | |||
59 | return EXIT_SUCCESS; | ||
60 | } | ||