commit f26a1449bfa18a6fbbe263f084df4e490772e9d3
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Sat Mar 26 12:58:37 2016 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Wed Apr 20 23:08:51 2016 +0100
Add pwdx(1)
Signed-off-by: Mattias Andrée <maandree_AT_kth.se>
diff --git a/Makefile b/Makefile
index 59616a4..453607c 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -70,6 +70,7 @@ BIN = \
pidof \
pivot_root \
ps \
+ pwdx \
readahead \
respawn \
rmmod \
_AT_@ -106,6 +107,7 @@ MAN1 = \
passwd.1 \
pidof.1 \
ps.1 \
+ pwdx.1 \
respawn.1 \
stat.1 \
su.1 \
diff --git a/TODO b/TODO
index 3e89e68..21f5c20 100644
--- a/TODO
+++ b/TODO
_AT_@ -19,7 +19,6 @@ mkswap [-L]
partprobe
pmap
ps (support for more options)
-pwdx
rfkill
rmgroup
rmuser
diff --git a/pwdx.1 b/pwdx.1
new file mode 100644
index 0000000..aadb6b4
--- /dev/null
+++ b/pwdx.1
_AT_@ -0,0 +1,13 @@
+.Dd March 26, 2015
+.Dt PWDX 1
+.Os ubase
+.Sh NAME
+.Nm pwdx
+.Nd print working directory of other processes
+.Sh SYNOPSIS
+.Nm
+.Ar pid...
+.Sh DESCRIPTION
+.Nm
+Prints the current working directory for each
+.Ar pid .
diff --git a/pwdx.c b/pwdx.c
new file mode 100644
index 0000000..57adc72
--- /dev/null
+++ b/pwdx.c
_AT_@ -0,0 +1,51 @@
+/* See LICENSE file for copyright and license details. */
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "util.h"
+
+static void
+usage(void)
+{
+ eprintf("usage: %s pid...\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int ret = 0;
+ char path[PATH_MAX];
+ char target[PATH_MAX + sizeof(" (deleted)")];
+ ssize_t n;
+
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc == 0)
+ usage();
+
+ for (; argc > 0; argc--, argv++) {
+ n = snprintf(path, sizeof(path), "/proc/%s/cwd", *argv);
+ if (n < 0 || n > sizeof(path)) {
+ errno = ESRCH;
+ } else {
+ n = readlink(path, target, sizeof(target) - 1);
+ if (n >= 0) {
+ target[n] = '\0';
+ printf("%s: %s\n", *argv, target);
+ continue;
+ }
+ }
+ if (errno == ENOENT)
+ errno = ESRCH;
+ weprintf("%s:", *argv);
+ ret = 1;
+ }
+
+ return ret;
+}
Received on Thu Apr 21 2016 - 00:08:57 CEST
This archive was generated by hypermail 2.3.0
: Thu Apr 21 2016 - 00:13:01 CEST