summaryrefslogtreecommitdiffstats
path: root/ctdb/common
diff options
context:
space:
mode:
authorMathieu Parent <math.parent@gmail.com>2013-01-14 12:13:24 +0100
committerAmitay Isaacs <amitay@gmail.com>2013-01-22 18:03:44 +1100
commitfd8d3cfeba44d7241f91aececbb52d07edaf24e8 (patch)
tree2de0f79ddb53c029266d0dbd90202553ec7c5a2e /ctdb/common
parent384b9b2a7b124436c16682903ad7c967e8891e84 (diff)
common: FreeBSD+kFreeBSD: Implement get_process_name (same as in Linux)
Signed-off-by: Mathieu Parent <math.parent@gmail.com> (This used to be ctdb commit 258092aaf6b7a9bdc14f0fb35e8bd7f7dc742b3f)
Diffstat (limited to 'ctdb/common')
-rw-r--r--ctdb/common/system_freebsd.c16
-rw-r--r--ctdb/common/system_kfreebsd.c17
2 files changed, 30 insertions, 3 deletions
diff --git a/ctdb/common/system_freebsd.c b/ctdb/common/system_freebsd.c
index 2fb3f45ebd..1ce9d3d16d 100644
--- a/ctdb/common/system_freebsd.c
+++ b/ctdb/common/system_freebsd.c
@@ -372,7 +372,21 @@ int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
char *ctdb_get_process_name(pid_t pid)
{
- /* FIXME FreeBSD: get_process_name not implemented */
+ char path[32];
+ char buf[PATH_MAX];
+ char *ptr;
+ int n;
+
+ snprintf(path, sizeof(path), "/proc/%d/exe", pid);
+ n = readlink(path, buf, sizeof(buf));
+ if (n < 0) {
+ return NULL;
+ }
+
+ /* Remove any extra fields */
+ buf[n] = '\0';
+ ptr = strtok(buf, " ");
+ return strdup(ptr);
return NULL;
}
diff --git a/ctdb/common/system_kfreebsd.c b/ctdb/common/system_kfreebsd.c
index 85442ed28d..103c1e0692 100644
--- a/ctdb/common/system_kfreebsd.c
+++ b/ctdb/common/system_kfreebsd.c
@@ -365,8 +365,21 @@ int ctdb_get_peer_pid(const int fd, pid_t *peer_pid)
char *ctdb_get_process_name(pid_t pid)
{
- /* FIXME kFreeBSD: get_process_name not implemented */
- return NULL;
+ char path[32];
+ char buf[PATH_MAX];
+ char *ptr;
+ int n;
+
+ snprintf(path, sizeof(path), "/proc/%d/exe", pid);
+ n = readlink(path, buf, sizeof(buf));
+ if (n < 0) {
+ return NULL;
+ }
+
+ /* Remove any extra fields */
+ buf[n] = '\0';
+ ptr = strtok(buf, " ");
+ return strdup(ptr);
}
bool ctdb_get_lock_info(pid_t req_pid, struct ctdb_lock_info *lock_info)