diff options
author | Guillem Jover <guillem@debian.org> | 2014-04-05 06:51:33 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2014-04-21 16:54:28 +0200 |
commit | 8d708158339cd0503580a810814b97e48926a3d4 (patch) | |
tree | 05fc1b7dafac1832f81295692b2ed07b9c06951a /utils | |
parent | 559895751cb775e47e2f6466de10a55a5ee7587c (diff) | |
download | dpkg-8d708158339cd0503580a810814b97e48926a3d4.tar.gz |
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/<PID>/exe symlink from linprocfs.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/start-stop-daemon.c | 26 |
1 files changed, 26 insertions, 0 deletions
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) |