Merge BSD implementations of QLockFilePrivate::processNameByPid()
Until now, several solutions for the implementations of
processNameByPid() on BSD systems existed:
- one for FreeBSD using libutil through kinfo_getproc()
using sysctl() implicitly
- one for GNU/kFreeBSD using sysctl() explicitly added in commit
a8f4fa217d
OpenBSD and NetBSD also had different approaches in their ports patches
using kvm() and sysctl(). The code unifies this for all BSDs using
sysctl().
Change-Id: Iced9ef01e5966d8688f464f51024a7ed562e26a3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Dmitry Shachnev <mitya57@gmail.com>
This commit is contained in:
parent
8fb29ed259
commit
3432742caa
@ -147,7 +147,6 @@ win32 {
|
|||||||
SOURCES += io/qsettings_mac.cpp
|
SOURCES += io/qsettings_mac.cpp
|
||||||
OBJECTIVE_SOURCES += io/qurl_mac.mm
|
OBJECTIVE_SOURCES += io/qurl_mac.mm
|
||||||
}
|
}
|
||||||
freebsd: LIBS_PRIVATE += -lutil # qlockfile_unix.cpp requires this
|
|
||||||
mac {
|
mac {
|
||||||
osx {
|
osx {
|
||||||
OBJECTIVE_SOURCES += io/qfilesystemwatcher_fsevents.mm
|
OBJECTIVE_SOURCES += io/qfilesystemwatcher_fsevents.mm
|
||||||
|
@ -59,14 +59,12 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <cstdio>
|
# include <cstdio>
|
||||||
#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)
|
#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)
|
||||||
|
# if !defined(Q_OS_NETBSD)
|
||||||
# include <sys/user.h>
|
# include <sys/user.h>
|
||||||
# if defined(__GLIBC__) && defined(__FreeBSD_kernel__)
|
# endif
|
||||||
# include <sys/cdefs.h>
|
# include <sys/cdefs.h>
|
||||||
# include <sys/param.h>
|
# include <sys/param.h>
|
||||||
# include <sys/sysctl.h>
|
# include <sys/sysctl.h>
|
||||||
# else
|
|
||||||
# include <libutil.h>
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -269,30 +267,33 @@ QString QLockFilePrivate::processNameByPid(qint64 pid)
|
|||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
return QFileInfo(QFile::decodeName(buf)).fileName();
|
return QFileInfo(QFile::decodeName(buf)).fileName();
|
||||||
#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)
|
#elif defined(Q_OS_BSD4) && !defined(Q_OS_IOS)
|
||||||
# if defined(__GLIBC__) && defined(__FreeBSD_kernel__)
|
# if defined(Q_OS_NETBSD)
|
||||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid };
|
struct kinfo_proc2 kp;
|
||||||
size_t len = 0;
|
int mib[6] = { CTL_KERN, KERN_PROC2, KERN_PROC_PID, (int)pid, sizeof(struct kinfo_proc2), 1 };
|
||||||
if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0)
|
# elif defined(Q_OS_OPENBSD)
|
||||||
return QString();
|
struct kinfo_proc kp;
|
||||||
kinfo_proc *proc = static_cast<kinfo_proc *>(malloc(len));
|
int mib[6] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid, sizeof(struct kinfo_proc), 1 };
|
||||||
# else
|
# else
|
||||||
kinfo_proc *proc = kinfo_getproc(pid);
|
struct kinfo_proc kp;
|
||||||
|
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid };
|
||||||
# endif
|
# endif
|
||||||
if (!proc)
|
size_t len = sizeof(kp);
|
||||||
|
u_int mib_len = sizeof(mib)/sizeof(u_int);
|
||||||
|
|
||||||
|
if (sysctl(mib, mib_len, &kp, &len, NULL, 0) < 0)
|
||||||
return QString();
|
return QString();
|
||||||
# if defined(__GLIBC__) && defined(__FreeBSD_kernel__)
|
|
||||||
if (sysctl(mib, 4, proc, &len, NULL, 0) < 0) {
|
# if defined(Q_OS_OPENBSD) || defined(Q_OS_NETBSD)
|
||||||
free(proc);
|
if (kp.p_pid != pid)
|
||||||
return QString();
|
return QString();
|
||||||
}
|
QString name = QFile::decodeName(kp.p_comm);
|
||||||
if (proc->ki_pid != pid) {
|
# else
|
||||||
free(proc);
|
if (kp.ki_pid != pid)
|
||||||
return QString();
|
return QString();
|
||||||
}
|
QString name = QFile::decodeName(kp.ki_comm);
|
||||||
# endif
|
# endif
|
||||||
QString name = QFile::decodeName(proc->ki_comm);
|
|
||||||
free(proc);
|
|
||||||
return name;
|
return name;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
Q_UNUSED(pid);
|
Q_UNUSED(pid);
|
||||||
return QString();
|
return QString();
|
||||||
|
Loading…
Reference in New Issue
Block a user