mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 18:32:55 +00:00
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:
parent
d03dc1564d
commit
3dc031d2b4
4 changed files with 40 additions and 8 deletions
|
@ -424,6 +424,9 @@ katie_check_function64(mmap64 "sys/mman.h")
|
|||
katie_check_function64(readdir64 "dirent.h")
|
||||
katie_check_function64(readdir64_r "dirent.h")
|
||||
|
||||
katie_check_proc(exe)
|
||||
katie_check_proc(cmdline)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/src/core/global/qconfig.h.cmake
|
||||
${CMAKE_BINARY_DIR}/include/QtCore/qconfig.h
|
||||
|
|
|
@ -7,8 +7,9 @@ set(KATIE_MOC "bootstrap_moc")
|
|||
|
||||
include(CMakePushCheckState)
|
||||
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)
|
||||
# see comment in top-level CMake file
|
||||
set(CMAKE_REQUIRED_INCLUDES /usr/X11R7/include /usr/pkg/include /usr/local/include /usr/include)
|
||||
|
@ -36,7 +37,7 @@ int main() {
|
|||
endfunction()
|
||||
|
||||
# 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)
|
||||
katie_check_defined("${FORFUNCTION}" "${FROMHEADER}")
|
||||
|
||||
|
@ -62,8 +63,8 @@ function(KATIE_CHECK_FUNCTION64 FORFUNCTION FROMHEADER)
|
|||
endif()
|
||||
endfunction()
|
||||
|
||||
# a macro to check for C struct member presence in header, if member is found a
|
||||
# definition is added.
|
||||
# a function to check for C struct member presence in header, if member is found a
|
||||
# definition is added
|
||||
function(KATIE_CHECK_STRUCT FORSTRUCT FORMEMBER FROMHEADER)
|
||||
check_struct_has_member("struct ${FORSTRUCT}" "${FORMEMBER}" "${FROMHEADER}" HAVE_${FORSTRUCT}_${FORMEMBER})
|
||||
|
||||
|
@ -73,6 +74,34 @@ function(KATIE_CHECK_STRUCT FORSTRUCT FORMEMBER FROMHEADER)
|
|||
endif()
|
||||
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
|
||||
# content is the same as the data to be written
|
||||
macro(KATIE_WRITE_FILE OUTFILE DATA)
|
||||
|
|
|
@ -1489,7 +1489,7 @@ QString QCoreApplication::applicationFilePath()
|
|||
if (!d->cachedApplicationFilePath.isNull())
|
||||
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
|
||||
// the absolute path of the executable
|
||||
QFileInfo pfi(QString::fromLatin1("/proc/%1/exe").arg(::getpid()));
|
||||
|
|
|
@ -957,12 +957,12 @@ static void getXDefault(const char *group, const char *key, bool *val)
|
|||
}
|
||||
#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,.
|
||||
// or, for older Linuxes, read out 'cmdline'.
|
||||
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"));
|
||||
if (parentProcExe.isSymLink())
|
||||
return parentProcExe.readLink().endsWith(QLatin1String("/gdb"));
|
||||
|
@ -1157,7 +1157,7 @@ void qt_init(QApplicationPrivate *priv, int,
|
|||
|
||||
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()) {
|
||||
appNoGrab = true;
|
||||
qDebug("Qt: gdb: -nograb added to command-line options.\n"
|
||||
|
|
Loading…
Add table
Reference in a new issue