check for /proc/<pid>/exe and /proc/<pid>/cmdline during build

NetBSD also support them in current version

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2020-12-02 03:55:49 +00:00
parent d03dc1564d
commit 3dc031d2b4
4 changed files with 40 additions and 8 deletions

View file

@ -424,6 +424,9 @@ katie_check_function64(mmap64 "sys/mman.h")
katie_check_function64(readdir64 "dirent.h") katie_check_function64(readdir64 "dirent.h")
katie_check_function64(readdir64_r "dirent.h") katie_check_function64(readdir64_r "dirent.h")
katie_check_proc(exe)
katie_check_proc(cmdline)
configure_file( configure_file(
${CMAKE_SOURCE_DIR}/src/core/global/qconfig.h.cmake ${CMAKE_SOURCE_DIR}/src/core/global/qconfig.h.cmake
${CMAKE_BINARY_DIR}/include/QtCore/qconfig.h ${CMAKE_BINARY_DIR}/include/QtCore/qconfig.h

View file

@ -7,8 +7,9 @@ set(KATIE_MOC "bootstrap_moc")
include(CMakePushCheckState) include(CMakePushCheckState)
include(CheckStructHasMember) include(CheckStructHasMember)
include(CheckCXXSourceRuns)
# a function to check for C function/definition, works for external functions. # a function to check for C function/definition, works for external functions
function(KATIE_CHECK_DEFINED FORDEFINITION FROMHEADER) function(KATIE_CHECK_DEFINED FORDEFINITION FROMHEADER)
# see comment in top-level CMake file # see comment in top-level CMake file
set(CMAKE_REQUIRED_INCLUDES /usr/X11R7/include /usr/pkg/include /usr/local/include /usr/include) set(CMAKE_REQUIRED_INCLUDES /usr/X11R7/include /usr/pkg/include /usr/local/include /usr/include)
@ -36,7 +37,7 @@ int main() {
endfunction() endfunction()
# a macro to check for C function presence in header, if function is found a # a macro to check for C function presence in header, if function is found a
# definition is added. # definition is added
macro(KATIE_CHECK_FUNCTION FORFUNCTION FROMHEADER) macro(KATIE_CHECK_FUNCTION FORFUNCTION FROMHEADER)
katie_check_defined("${FORFUNCTION}" "${FROMHEADER}") katie_check_defined("${FORFUNCTION}" "${FROMHEADER}")
@ -62,8 +63,8 @@ function(KATIE_CHECK_FUNCTION64 FORFUNCTION FROMHEADER)
endif() endif()
endfunction() endfunction()
# a macro to check for C struct member presence in header, if member is found a # a function to check for C struct member presence in header, if member is found a
# definition is added. # definition is added
function(KATIE_CHECK_STRUCT FORSTRUCT FORMEMBER FROMHEADER) function(KATIE_CHECK_STRUCT FORSTRUCT FORMEMBER FROMHEADER)
check_struct_has_member("struct ${FORSTRUCT}" "${FORMEMBER}" "${FROMHEADER}" HAVE_${FORSTRUCT}_${FORMEMBER}) check_struct_has_member("struct ${FORSTRUCT}" "${FORMEMBER}" "${FROMHEADER}" HAVE_${FORSTRUCT}_${FORMEMBER})
@ -73,6 +74,34 @@ function(KATIE_CHECK_STRUCT FORSTRUCT FORMEMBER FROMHEADER)
endif() endif()
endfunction() endfunction()
# a function to check for file existence in /proc, if file exists a definition
# is added
function(KATIE_CHECK_PROC FORFILE)
check_cxx_source_runs(
"
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
int main() {
char snprintfbuf[1024];
snprintf(snprintfbuf, sizeof(snprintfbuf), \"/proc/%d/${FORFILE}\", getpid());
struct stat statbuf;
if (lstat(snprintfbuf, &statbuf) == -1) {
return 1;
}
return 0;
}
"
HAVE_proc_${FORFILE}
)
if(HAVE_proc_${FORFILE})
string(TOUPPER "${FORFILE}" upperfile)
add_definitions(-DQT_HAVE_PROC_${upperfile})
endif()
endfunction()
# a macro to write data to file, does nothing if the file exists and its # a macro to write data to file, does nothing if the file exists and its
# content is the same as the data to be written # content is the same as the data to be written
macro(KATIE_WRITE_FILE OUTFILE DATA) macro(KATIE_WRITE_FILE OUTFILE DATA)

View file

@ -1489,7 +1489,7 @@ QString QCoreApplication::applicationFilePath()
if (!d->cachedApplicationFilePath.isNull()) if (!d->cachedApplicationFilePath.isNull())
return d->cachedApplicationFilePath; return d->cachedApplicationFilePath;
#ifdef Q_OS_LINUX #if defined(QT_HAVE_PROC_EXE)
// Try looking for a /proc/<pid>/exe symlink first which points to // Try looking for a /proc/<pid>/exe symlink first which points to
// the absolute path of the executable // the absolute path of the executable
QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(::getpid())); QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(::getpid()));

View file

@ -957,12 +957,12 @@ static void getXDefault(const char *group, const char *key, bool *val)
} }
#endif #endif
#if !defined(QT_NO_DEBUG) && defined(Q_OS_LINUX) #if !defined(QT_NO_DEBUG) && defined(QT_HAVE_PROC_CMDLINE) && defined(QT_HAVE_PROC_EXE)
// Find out if our parent process is gdb by looking at the 'exe' symlink under /proc,. // Find out if our parent process is gdb by looking at the 'exe' symlink under /proc,.
// or, for older Linuxes, read out 'cmdline'. // or, for older Linuxes, read out 'cmdline'.
bool runningUnderDebugger() bool runningUnderDebugger()
{ {
const QString parentProc = QLatin1String("/proc/") + QString::number(getppid()); const QString parentProc = QString::fromLatin1("/proc/%1").arg(::getppid());
const QFileInfo parentProcExe(parentProc + QLatin1String("/exe")); const QFileInfo parentProcExe(parentProc + QLatin1String("/exe"));
if (parentProcExe.isSymLink()) if (parentProcExe.isSymLink())
return parentProcExe.readLink().endsWith(QLatin1String("/gdb")); return parentProcExe.readLink().endsWith(QLatin1String("/gdb"));
@ -1157,7 +1157,7 @@ void qt_init(QApplicationPrivate *priv, int,
priv->argc = j; priv->argc = j;
#if !defined(QT_NO_DEBUG) && defined(Q_OS_LINUX) #if !defined(QT_NO_DEBUG) && defined(QT_HAVE_PROC_CMDLINE) && defined(QT_HAVE_PROC_EXE)
if (!appNoGrab && !appDoGrab && runningUnderDebugger()) { if (!appNoGrab && !appDoGrab && runningUnderDebugger()) {
appNoGrab = true; appNoGrab = true;
qDebug("Qt: gdb: -nograb added to command-line options.\n" qDebug("Qt: gdb: -nograb added to command-line options.\n"