OSDN Git Service

pwdx by Lukasz Skalski.
authorRob Landley <rob@landley.net>
Mon, 2 Sep 2013 10:06:05 +0000 (05:06 -0500)
committerRob Landley <rob@landley.net>
Mon, 2 Sep 2013 10:06:05 +0000 (05:06 -0500)
toys/other/pwdx.c [new file with mode: 0644]

diff --git a/toys/other/pwdx.c b/toys/other/pwdx.c
new file mode 100644 (file)
index 0000000..c3f134f
--- /dev/null
@@ -0,0 +1,40 @@
+/* pwdx.c - report current directory of a process. 
+ *
+ * Copyright 2013 Lukasz Skalski <l.skalski@partner.samsung.com>
+
+USE_PWDX(NEWTOY(pwdx, "<1a", TOYFLAG_USR|TOYFLAG_BIN))
+
+config PWDX
+  bool "pwdx"
+  default y
+  help
+    usage: pwdx pids ...
+*/
+
+#include "toys.h"
+
+int pid_dir(char *pid)
+{
+  char *path;
+  int num_bytes;
+
+  path = xmsprintf("/proc/%s/cwd",pid);
+  num_bytes = readlink(path,toybuf,sizeof(toybuf));
+  if(num_bytes==-1){
+    xprintf("%s: %s\n",pid,strerror(errno));
+    return 1;
+  }else{
+    toybuf[num_bytes]='\0';
+    xprintf("%s: %s\n",pid,toybuf);
+    return 0;
+  }
+}
+
+void pwdx_main(void)
+{
+  int i;
+
+  for (i=0; toys.optargs[i]; i++)
+    toys.exitval |= pid_dir(toys.optargs[i]);
+}
+