1038
|
1 /* pwdx.c - report current directory of a process.
|
|
2 *
|
|
3 * Copyright 2013 Lukasz Skalski <l.skalski@partner.samsung.com>
|
|
4
|
|
5 USE_PWDX(NEWTOY(pwdx, "<1a", TOYFLAG_USR|TOYFLAG_BIN))
|
|
6
|
|
7 config PWDX
|
|
8 bool "pwdx"
|
|
9 default y
|
|
10 help
|
|
11 usage: pwdx pids ...
|
|
12 */
|
|
13
|
|
14 #include "toys.h"
|
|
15
|
|
16 int pid_dir(char *pid)
|
|
17 {
|
|
18 char *path;
|
|
19 int num_bytes;
|
|
20
|
|
21 path = xmsprintf("/proc/%s/cwd",pid);
|
|
22 num_bytes = readlink(path,toybuf,sizeof(toybuf));
|
|
23 if(num_bytes==-1){
|
|
24 xprintf("%s: %s\n",pid,strerror(errno));
|
|
25 return 1;
|
|
26 }else{
|
|
27 toybuf[num_bytes]='\0';
|
|
28 xprintf("%s: %s\n",pid,toybuf);
|
|
29 return 0;
|
|
30 }
|
|
31 }
|
|
32
|
|
33 void pwdx_main(void)
|
|
34 {
|
|
35 int i;
|
|
36
|
|
37 for (i=0; toys.optargs[i]; i++)
|
|
38 toys.exitval |= pid_dir(toys.optargs[i]);
|
|
39 }
|
|
40
|