MCPcopy Create free account
hub / github.com/MultiMC/Launcher / IndirectOpen

Function IndirectOpen

launcher/DesktopServices.cpp:18–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17template <typename T>
18bool IndirectOpen(T callable, qint64 *pid_forked = nullptr)
19{
20 auto pid = fork();
21 if(pid_forked)
22 {
23 if(pid > 0)
24 *pid_forked = pid;
25 else
26 *pid_forked = 0;
27 }
28 if(pid == -1)
29 {
30 qWarning() << "IndirectOpen failed to fork: " << errno;
31 return false;
32 }
33 // child - do the stuff
34 if(pid == 0)
35 {
36 // unset all this garbage so it doesn't get passed to the child process
37 qunsetenv("LD_PRELOAD");
38 qunsetenv("LD_LIBRARY_PATH");
39 qunsetenv("LD_DEBUG");
40 qunsetenv("QT_PLUGIN_PATH");
41 qunsetenv("QT_FONTPATH");
42
43 // open the URL
44 auto status = callable();
45
46 // detach from the parent process group.
47 setsid();
48
49 // die. now. do not clean up anything, it would just hang forever.
50 _exit(status ? 0 : 1);
51 }
52 else
53 {
54 //parent - assume it worked.
55 int status;
56 while (waitpid(pid, &status, 0))
57 {
58 if(WIFEXITED(status))
59 {
60 return WEXITSTATUS(status) == 0;
61 }
62 if(WIFSIGNALED(status))
63 {
64 return false;
65 }
66 }
67 return true;
68 }
69}
70#endif
71
72namespace DesktopServices {

Callers 4

openDirectoryFunction · 0.85
openFileFunction · 0.85
runFunction · 0.85
openUrlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected