common: FreeBSD+kFreeBSD: Implement get_process_name (same as in Linux)
[nivanova/samba-autobuild/.git] / ctdb / common / system_kfreebsd.c
index 85442ed28d58cacd83e27a7635960fb52ad8c7ae..103c1e0692682c90f99f3c77200c13b342c7da25 100644 (file)
@@ -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)