Changeset View
Changeset View
Standalone View
Standalone View
src/kcrash.cpp
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | |||||
85 | 85 | | |||
86 | #define LAUNCHER_OK 4 | 86 | #define LAUNCHER_OK 4 | ||
87 | #define LAUNCHER_EXEC_NEW 12 | 87 | #define LAUNCHER_EXEC_NEW 12 | ||
88 | 88 | | |||
89 | namespace KCrash | 89 | namespace KCrash | ||
90 | { | 90 | { | ||
91 | KCRASH_EXPORT bool loadedByKdeinit = false; | 91 | KCRASH_EXPORT bool loadedByKdeinit = false; | ||
92 | void setApplicationFilePath(const QString &filePath); | 92 | void setApplicationFilePath(const QString &filePath); | ||
93 | // Create socket path to transfer ptrace scope and open connection | ||||
94 | #ifdef Q_OS_LINUX | ||||
95 | QByteArray socketpath; | ||||
dfaure: prepend `static`, it's only used in this file. | |||||
96 | #endif | ||||
93 | } | 97 | } | ||
94 | 98 | | |||
95 | static KCrash::HandlerType s_emergencySaveFunction = nullptr; | 99 | static KCrash::HandlerType s_emergencySaveFunction = nullptr; | ||
96 | static KCrash::HandlerType s_crashHandler = nullptr; | 100 | static KCrash::HandlerType s_crashHandler = nullptr; | ||
97 | static char *s_appName = nullptr; | 101 | static char *s_appName = nullptr; | ||
98 | static char *s_autoRestartCommand = nullptr; | 102 | static char *s_autoRestartCommand = nullptr; | ||
99 | static char *s_appPath = nullptr; | 103 | static char *s_appPath = nullptr; | ||
100 | static int s_autoRestartArgc = 0; | 104 | static int s_autoRestartArgc = 0; | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 163 | { | |||
172 | } | 176 | } | ||
173 | 177 | | |||
174 | if (QCoreApplication::instance()) { | 178 | if (QCoreApplication::instance()) { | ||
175 | KCrash::setApplicationFilePath(QCoreApplication::applicationFilePath()); | 179 | KCrash::setApplicationFilePath(QCoreApplication::applicationFilePath()); | ||
176 | } else { | 180 | } else { | ||
177 | qWarning() << "This process needs a QCoreApplication instance in order to use KCrash"; | 181 | qWarning() << "This process needs a QCoreApplication instance in order to use KCrash"; | ||
178 | } | 182 | } | ||
179 | 183 | | |||
184 | #ifdef Q_OS_LINUX | ||||
185 | // Create socket path to transfer ptrace scope and open connection | ||||
186 | socketpath = QFile::encodeName( | ||||
187 | QStringLiteral("%1/kcrash_%2").arg(QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation)) | ||||
188 | .arg(getpid())); | ||||
189 | #endif | ||||
190 | | ||||
180 | s_coreConfig(); // Initialize. | 191 | s_coreConfig(); // Initialize. | ||
181 | } | 192 | } | ||
182 | 193 | | |||
183 | void | 194 | void | ||
184 | KCrash::setEmergencySaveFunction(HandlerType saveFunction) | 195 | KCrash::setEmergencySaveFunction(HandlerType saveFunction) | ||
185 | { | 196 | { | ||
186 | s_emergencySaveFunction = saveFunction; | 197 | s_emergencySaveFunction = saveFunction; | ||
187 | 198 | | |||
▲ Show 20 Lines • Show All 455 Lines • ▼ Show 20 Line(s) | 652 | #ifdef Q_OS_LINUX | |||
643 | // For now that will be DrKonqi, which may ask to transfer the ptrace scope to | 654 | // For now that will be DrKonqi, which may ask to transfer the ptrace scope to | ||
644 | // a debugger it is not an ancestor of (because it was started via kdeinit or | 655 | // a debugger it is not an ancestor of (because it was started via kdeinit or | ||
645 | // KProcess::startDetached()) using a socket. | 656 | // KProcess::startDetached()) using a socket. | ||
646 | #ifndef PR_SET_PTRACER | 657 | #ifndef PR_SET_PTRACER | ||
647 | # define PR_SET_PTRACER 0x59616d61 | 658 | # define PR_SET_PTRACER 0x59616d61 | ||
648 | #endif | 659 | #endif | ||
649 | prctl(PR_SET_PTRACER, pid, 0, 0, 0); | 660 | prctl(PR_SET_PTRACER, pid, 0, 0, 0); | ||
650 | 661 | | |||
651 | // Create socket path to transfer ptrace scope and open connection | 662 | using KCrash::socketpath; | ||
It would be more consistent with the other global vars to name it s_socketpath dfaure: It would be more consistent with the other global vars to name it `s_socketpath`
(and outside… | |||||
652 | const QByteArray socketpath = QFile::encodeName( | | |||
653 | QStringLiteral("%1/kcrash_%2").arg(QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation)) | | |||
654 | .arg(getpid())); | | |||
655 | int sockfd = openDrKonqiSocket(socketpath); | 663 | int sockfd = openDrKonqiSocket(socketpath); | ||
656 | 664 | | |||
657 | if (sockfd >= 0) { | 665 | if (sockfd >= 0) { | ||
658 | // Wait while DrKonqi is running and the socket connection exists | 666 | // Wait while DrKonqi is running and the socket connection exists | ||
659 | // If the process was started directly, use waitpid(), as it's a child... | 667 | // If the process was started directly, use waitpid(), as it's a child... | ||
660 | while ((running = waitpid(pid, nullptr, WNOHANG) != pid) && pollDrKonqiSocket(pid, sockfd) >= 0) {} | 668 | while ((running = waitpid(pid, nullptr, WNOHANG) != pid) && pollDrKonqiSocket(pid, sockfd) >= 0) {} | ||
661 | close(sockfd); | 669 | close(sockfd); | ||
662 | unlink(socketpath.constData()); | 670 | unlink(socketpath.constData()); | ||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |
prepend static, it's only used in this file.