Add QLockFilePrivate::processNameByPid implementation for GNU/kFreeBSD
GLIBC does not provide kinfo_getproc, so we need to call sysctl manually. Change-Id: I3bf22959ff74b3b6c34b5360738e52086a3ff1b4 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>bb10
parent
4dca8314c3
commit
a8f4fa217d
|
|
@ -56,7 +56,13 @@
|
|||
# include <cstdio>
|
||||
#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)
|
||||
# include <sys/user.h>
|
||||
# if defined(__GLIBC__) && defined(__FreeBSD_kernel__)
|
||||
# include <sys/cdefs.h>
|
||||
# include <sys/param.h>
|
||||
# include <sys/sysctl.h>
|
||||
# else
|
||||
# include <libutil.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -234,9 +240,27 @@ QString QLockFilePrivate::processNameByPid(qint64 pid)
|
|||
buf[len] = 0;
|
||||
return QFileInfo(QFile::decodeName(buf)).fileName();
|
||||
#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)
|
||||
# if defined(__GLIBC__) && defined(__FreeBSD_kernel__)
|
||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
|
||||
size_t len = 0;
|
||||
if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0)
|
||||
return QString();
|
||||
kinfo_proc *proc = static_cast<kinfo_proc *>(malloc(len));
|
||||
# else
|
||||
kinfo_proc *proc = kinfo_getproc(pid);
|
||||
# endif
|
||||
if (!proc)
|
||||
return QString();
|
||||
# if defined(__GLIBC__) && defined(__FreeBSD_kernel__)
|
||||
if (sysctl(mib, 4, proc, &len, NULL, 0) < 0) {
|
||||
free(proc);
|
||||
return QString();
|
||||
}
|
||||
if (proc->ki_pid != pid) {
|
||||
free(proc);
|
||||
return QString();
|
||||
}
|
||||
# endif
|
||||
QString name = QFile::decodeName(proc->ki_comm);
|
||||
free(proc);
|
||||
return name;
|
||||
|
|
|
|||
Loading…
Reference in New Issue