Changeset View
Changeset View
Standalone View
Standalone View
src/debuggerlaunchers.cpp
Show All 10 Lines | 1 | /* | |||
---|---|---|---|---|---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | #include "debuggerlaunchers.h" | 17 | #include "debuggerlaunchers.h" | ||
18 | 18 | | |||
19 | #include <QCoreApplication> | ||||
19 | #include <QDBusConnection> | 20 | #include <QDBusConnection> | ||
20 | 21 | | |||
21 | #include <KShell> | 22 | #include <KShell> | ||
22 | #include <KProcess> | 23 | #include <KProcess> | ||
23 | #include "drkonqi_debug.h" | 24 | #include "drkonqi_debug.h" | ||
24 | 25 | | |||
25 | #include "detachedprocessmonitor.h" | 26 | #include "detachedprocessmonitor.h" | ||
26 | #include "drkonqi.h" | 27 | #include "drkonqi.h" | ||
27 | #include "crashedapplication.h" | 28 | #include "crashedapplication.h" | ||
28 | 29 | | |||
30 | #include "ptracer.h" | ||||
31 | | ||||
29 | DefaultDebuggerLauncher::DefaultDebuggerLauncher(const Debugger & debugger, DebuggerManager *parent) | 32 | DefaultDebuggerLauncher::DefaultDebuggerLauncher(const Debugger & debugger, DebuggerManager *parent) | ||
30 | : AbstractDebuggerLauncher(parent), m_debugger(debugger) | 33 | : AbstractDebuggerLauncher(parent), m_debugger(debugger) | ||
31 | { | 34 | { | ||
32 | m_monitor = new DetachedProcessMonitor(this); | 35 | m_monitor = new DetachedProcessMonitor(this); | ||
33 | connect(m_monitor, &DetachedProcessMonitor::processFinished, this, &DefaultDebuggerLauncher::onProcessFinished); | 36 | connect(m_monitor, &DetachedProcessMonitor::processFinished, this, &DefaultDebuggerLauncher::onProcessFinished); | ||
34 | } | 37 | } | ||
35 | 38 | | |||
36 | QString DefaultDebuggerLauncher::name() const | 39 | QString DefaultDebuggerLauncher::name() const | ||
Show All 9 Lines | 45 | { | |||
46 | } | 49 | } | ||
47 | 50 | | |||
48 | QString str = m_debugger.command(); | 51 | QString str = m_debugger.command(); | ||
49 | Debugger::expandString(str, Debugger::ExpansionUsageShell); | 52 | Debugger::expandString(str, Debugger::ExpansionUsageShell); | ||
50 | 53 | | |||
51 | emit starting(); | 54 | emit starting(); | ||
52 | int pid = KProcess::startDetached(KShell::splitArgs(str)); | 55 | int pid = KProcess::startDetached(KShell::splitArgs(str)); | ||
53 | if ( pid > 0 ) { | 56 | if ( pid > 0 ) { | ||
57 | setPtracer(pid, DrKonqi::pid()); | ||||
ossi: according to my reading of the documentation (https://www.kernel. | |||||
54 | m_monitor->startMonitoring(pid); | 58 | m_monitor->startMonitoring(pid); | ||
55 | } else { | 59 | } else { | ||
56 | qCWarning(DRKONQI_LOG) << "Could not start debugger:" << name(); | 60 | qCWarning(DRKONQI_LOG) << "Could not start debugger:" << name(); | ||
57 | emit finished(); | 61 | emit finished(); | ||
58 | } | 62 | } | ||
59 | } | 63 | } | ||
60 | 64 | | |||
61 | void DefaultDebuggerLauncher::onProcessFinished() | 65 | void DefaultDebuggerLauncher::onProcessFinished() | ||
62 | { | 66 | { | ||
67 | setPtracer(QCoreApplication::applicationPid(), DrKonqi::pid()); | ||||
63 | emit finished(); | 68 | emit finished(); | ||
64 | } | 69 | } | ||
65 | 70 | | |||
66 | #if 0 | 71 | #if 0 | ||
67 | TerminalDebuggerLauncher::TerminalDebuggerLauncher(const Debugger & debugger, DebuggerManager *parent) | 72 | TerminalDebuggerLauncher::TerminalDebuggerLauncher(const Debugger & debugger, DebuggerManager *parent) | ||
68 | : DefaultDebuggerLauncher(debugger, parent) | 73 | : DefaultDebuggerLauncher(debugger, parent) | ||
69 | { | 74 | { | ||
70 | } | 75 | } | ||
71 | 76 | | |||
72 | void TerminalDebuggerLauncher::start() | 77 | void TerminalDebuggerLauncher::start() | ||
73 | { | 78 | { | ||
74 | DefaultDebuggerLauncher::start(); //FIXME | 79 | DefaultDebuggerLauncher::start(); //FIXME | ||
75 | } | 80 | } | ||
76 | #endif | 81 | #endif | ||
77 | 82 | | |||
78 | 83 | | |||
79 | DBusInterfaceLauncher::DBusInterfaceLauncher(const QString &name, DBusInterfaceAdaptor *parent) | 84 | DBusInterfaceLauncher::DBusInterfaceLauncher(const QString &name, qint64 pid, DBusInterfaceAdaptor *parent) | ||
80 | : AbstractDebuggerLauncher(parent), m_name(name) | 85 | : AbstractDebuggerLauncher(parent), m_name(name), m_pid(pid) | ||
81 | { | 86 | { | ||
82 | } | 87 | } | ||
83 | 88 | | |||
84 | QString DBusInterfaceLauncher::name() const | 89 | QString DBusInterfaceLauncher::name() const | ||
85 | { | 90 | { | ||
86 | return m_name; | 91 | return m_name; | ||
87 | } | 92 | } | ||
88 | 93 | | |||
89 | void DBusInterfaceLauncher::start() | 94 | void DBusInterfaceLauncher::start() | ||
90 | { | 95 | { | ||
91 | emit starting(); | 96 | emit starting(); | ||
97 | | ||||
98 | setPtracer(m_pid, DrKonqi::pid()); | ||||
99 | | ||||
92 | emit static_cast<DBusInterfaceAdaptor*>(parent())->acceptDebuggingApplication(m_name); | 100 | emit static_cast<DBusInterfaceAdaptor*>(parent())->acceptDebuggingApplication(m_name); | ||
93 | } | 101 | } | ||
94 | 102 | | |||
95 | 103 | | |||
96 | DBusInterfaceAdaptor::DBusInterfaceAdaptor(DebuggerManager *parent) | 104 | DBusInterfaceAdaptor::DBusInterfaceAdaptor(DebuggerManager *parent) | ||
97 | : QDBusAbstractAdaptor(parent) | 105 | : QDBusAbstractAdaptor(parent) | ||
98 | { | 106 | { | ||
99 | Q_ASSERT(parent); | 107 | Q_ASSERT(parent); | ||
100 | 108 | | |||
101 | if (QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.drkonqi-%1").arg(pid()))) { | 109 | if (QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.drkonqi-%1").arg(pid()))) { | ||
102 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/debugger"), parent); | 110 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/debugger"), parent); | ||
103 | } | 111 | } | ||
104 | } | 112 | } | ||
105 | 113 | | |||
106 | int DBusInterfaceAdaptor::pid() | 114 | int DBusInterfaceAdaptor::pid() | ||
107 | { | 115 | { | ||
108 | return DrKonqi::crashedApplication()->pid(); | 116 | return DrKonqi::crashedApplication()->pid(); | ||
109 | } | 117 | } | ||
110 | 118 | | |||
111 | void DBusInterfaceAdaptor::registerDebuggingApplication(const QString &name) | 119 | void DBusInterfaceAdaptor::registerDebuggingApplication(const QString &name, qint64 pid) | ||
112 | { | 120 | { | ||
113 | if (!name.isEmpty() && !m_launchers.contains(name)) { | 121 | if (!name.isEmpty() && !m_launchers.contains(name)) { | ||
114 | auto launcher = new DBusInterfaceLauncher(name, this); | 122 | auto launcher = new DBusInterfaceLauncher(name, pid, this); | ||
115 | m_launchers.insert(name, launcher); | 123 | m_launchers.insert(name, launcher); | ||
116 | static_cast<DebuggerManager*>(parent())->addDebugger(launcher, true); | 124 | static_cast<DebuggerManager*>(parent())->addDebugger(launcher, true); | ||
117 | } | 125 | } | ||
118 | } | 126 | } | ||
119 | 127 | | |||
120 | void DBusInterfaceAdaptor::debuggingFinished(const QString &name) | 128 | void DBusInterfaceAdaptor::debuggingFinished(const QString &name) | ||
121 | { | 129 | { | ||
122 | auto it = m_launchers.find(name); | 130 | auto it = m_launchers.find(name); | ||
123 | if (it != m_launchers.end()) { | 131 | if (it != m_launchers.end()) { | ||
132 | setPtracer(QCoreApplication::applicationPid(), DrKonqi::pid()); | ||||
124 | emit it.value()->finished(); | 133 | emit it.value()->finished(); | ||
125 | } | 134 | } | ||
126 | } | 135 | } | ||
127 | 136 | | |||
128 | void DBusInterfaceAdaptor::debuggerClosed(const QString &name) | 137 | void DBusInterfaceAdaptor::debuggerClosed(const QString &name) | ||
129 | { | 138 | { | ||
130 | auto it = m_launchers.find(name); | 139 | auto it = m_launchers.find(name); | ||
131 | if (it != m_launchers.end()) { | 140 | if (it != m_launchers.end()) { | ||
132 | emit it.value()->invalidated(); | 141 | emit it.value()->invalidated(); | ||
133 | m_launchers.erase(it); | 142 | m_launchers.erase(it); | ||
134 | } | 143 | } | ||
135 | } | 144 | } |
according to my reading of the documentation (https://www.kernel.org/doc/Documentation/security/Yama.txt) and the kernel source, this is unnecessary in this branch, as descendants of the assigned ptracer have the right as well (that's why the "normal" backtrace creation works without your patch), and not even detaching breaks the chain.