|
23 | 23 |
|
24 | 24 | namespace { |
25 | 25 |
|
26 | | -void prepareChild(const std::string& output_name) { |
| 26 | +auto buildChildEnvironment(const std::string& output_name) -> std::vector<std::string> { |
| 27 | + auto names = Glib::listenv(); |
| 28 | + std::vector<std::string> envp; |
| 29 | + envp.reserve(names.size() + 1); |
| 30 | + |
| 31 | + for (const auto& name : names) { |
| 32 | + bool found = false; |
| 33 | + auto value = Glib::getenv(name, found); |
| 34 | + if (!found || name == "WAYBAR_OUTPUT_NAME") { |
| 35 | + continue; |
| 36 | + } |
| 37 | + envp.push_back(name + "=" + value); |
| 38 | + } |
| 39 | + |
| 40 | + if (!output_name.empty()) { |
| 41 | + envp.push_back("WAYBAR_OUTPUT_NAME=" + output_name); |
| 42 | + } |
| 43 | + |
| 44 | + return envp; |
| 45 | +} |
| 46 | + |
| 47 | +void prepareChild() { |
27 | 48 | sigset_t mask; |
28 | 49 | sigfillset(&mask); |
29 | 50 |
|
30 | | - const auto err = pthread_sigmask(SIG_UNBLOCK, &mask, nullptr); |
31 | | - if (err != 0) { |
32 | | - spdlog::error("pthread_sigmask in LineStream failed: {}", std::strerror(err)); |
33 | | - } |
| 51 | + (void)pthread_sigmask(SIG_UNBLOCK, &mask, nullptr); |
34 | 52 |
|
35 | 53 | int deathsig = SIGTERM; |
36 | 54 | #ifdef __linux__ |
37 | | - if (prctl(PR_SET_PDEATHSIG, deathsig) != 0) { |
38 | | - spdlog::error("prctl(PR_SET_PDEATHSIG) in LineStream failed: {}", std::strerror(errno)); |
39 | | - } |
| 55 | + (void)prctl(PR_SET_PDEATHSIG, deathsig); |
40 | 56 | #endif |
41 | 57 | #ifdef __FreeBSD__ |
42 | | - if (procctl(P_PID, 0, PROC_PDEATHSIG_CTL, reinterpret_cast<void*>(&deathsig)) == -1) { |
43 | | - spdlog::error("procctl(PROC_PDEATHSIG_CTL) in LineStream failed: {}", std::strerror(errno)); |
44 | | - } |
| 58 | + (void)procctl(P_PID, 0, PROC_PDEATHSIG_CTL, reinterpret_cast<void*>(&deathsig)); |
45 | 59 | #endif |
46 | 60 |
|
47 | | - if (setpgid(0, 0) != 0) { |
48 | | - spdlog::error("setpgid in LineStream failed: {}", std::strerror(errno)); |
49 | | - } |
50 | | - if (!output_name.empty()) { |
51 | | - setenv("WAYBAR_OUTPUT_NAME", output_name.c_str(), 1); |
52 | | - } |
| 61 | + (void)setpgid(0, 0); |
53 | 62 | } |
54 | 63 |
|
55 | 64 | void emitBufferedLines(std::string& buffer, |
@@ -91,9 +100,10 @@ void waybar::util::command::LineStream::start(const std::string& cmd) { |
91 | 100 | stop(); |
92 | 101 |
|
93 | 102 | std::vector<std::string> argv{"/bin/sh", "-c", cmd}; |
94 | | - Glib::spawn_async_with_pipes("", argv, Glib::SPAWN_DO_NOT_REAP_CHILD | Glib::SPAWN_CLOEXEC_PIPES, |
95 | | - sigc::bind(sigc::ptr_fun(&prepareChild), output_name_), &pid_, |
96 | | - nullptr, &stdout_fd_, nullptr); |
| 103 | + auto envp = buildChildEnvironment(output_name_); |
| 104 | + Glib::spawn_async_with_pipes("", argv, envp, |
| 105 | + Glib::SPAWN_DO_NOT_REAP_CHILD | Glib::SPAWN_CLOEXEC_PIPES, |
| 106 | + sigc::ptr_fun(&prepareChild), &pid_, nullptr, &stdout_fd_, nullptr); |
97 | 107 |
|
98 | 108 | const auto flags = fcntl(stdout_fd_, F_GETFL, 0); |
99 | 109 | if (flags == -1 || fcntl(stdout_fd_, F_SETFL, flags | O_NONBLOCK) == -1) { |
|
0 commit comments