12
12
#include < tinyformat.h>
13
13
#include < util/system.h>
14
14
15
+ #include < boost/algorithm/string.hpp>
15
16
#include < functional>
16
17
#include < memory>
18
+ #include < signal.h>
17
19
#include < stdexcept>
18
20
#include < stdio.h>
19
21
#include < stdlib.h>
25
27
26
28
namespace ipc {
27
29
namespace {
30
+ // ! Send stop signal to current process to aid debugging if directed by STOP
31
+ // ! environment variable.
32
+ void DebugStop (const char * exe_name, int argc, char * argv[])
33
+ {
34
+ FILE* gdb = fsbridge::fopen (" /tmp/gdb.txt" , " a" );
35
+ fprintf (gdb, " %i %s\n " , getpid (), argv[0 ]);
36
+ fclose (gdb);
37
+ if (const char * env_stop = getenv (" STOP" )) {
38
+ std::string stop = env_stop;
39
+ std::vector<std::string> stops;
40
+ if (stop.size ()) boost::split (stops, stop, boost::is_space (), boost::token_compress_on);
41
+ for (const auto & s : stops) {
42
+ if (strstr (exe_name, s.c_str ())) {
43
+ printf (" Pid %i stopping for GDB\n " , getpid ());
44
+ printf (" sudo gdb -ex c %s %i\n " , argv[0 ], getpid ());
45
+ raise (SIGSTOP);
46
+ break ;
47
+ }
48
+ }
49
+ }
50
+ }
51
+
28
52
class IpcImpl : public interfaces ::Ipc
29
53
{
30
54
public:
@@ -47,6 +71,7 @@ class IpcImpl : public interfaces::Ipc
47
71
}
48
72
bool startSpawnedProcess (int argc, char * argv[], int & exit_status) override
49
73
{
74
+ DebugStop (m_exe_name, argc, argv);
50
75
exit_status = EXIT_FAILURE;
51
76
int32_t fd = -1 ;
52
77
if (!m_process->checkSpawned (argc, argv, fd)) {
0 commit comments