From 8d708158339cd0503580a810814b97e48926a3d4 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 5 Apr 2014 06:51:33 +0200 Subject: s-s-d: Add a native FreeBSD pid_is_exec() method Use the KERN_PROC_PATHNAME sysctl interface to retrieve the process pathname. This will allow to stop requiring the linprocfs fileystem which is not the native procfs and is not usually mounted by default anyway. This still has the problem that the pathname cannot be retrieved when the inode has been unlinked, in the same way as when accessing the /proc//exe symlink from linprocfs. --- utils/start-stop-daemon.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'utils') diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index d1d67e959..44700a602 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -1199,6 +1199,32 @@ pid_is_exec(pid_t pid, const struct stat *esb) return ((dev_t)pst.pst_text.psf_fsid.psfs_id == esb->st_dev && (ino_t)pst.pst_text.psf_fileid == esb->st_ino); } +#elif defined(OSFreeBSD) +static bool +pid_is_exec(pid_t pid, const struct stat *esb) +{ + struct stat sb; + int error, name[4]; + size_t len; + char pathname[PATH_MAX]; + + name[0] = CTL_KERN; + name[1] = KERN_PROC; + name[2] = KERN_PROC_PATHNAME; + name[3] = pid; + len = sizeof(pathname); + + error = sysctl(name, 4, pathname, &len, NULL, 0); + if (error != 0 && errno != ESRCH) + return false; + if (len == 0) + pathname[0] = '\0'; + + if (stat(pathname, &sb) != 0) + return false; + + return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino); +} #elif defined(HAVE_KVM_H) static bool pid_is_exec(pid_t pid, const struct stat *esb) -- cgit v1.2.3