mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-02 22:57:24 +08:00
Add vector of cleanup/termination events to be executed before quit
This commit is contained in:
parent
e045b045da
commit
8c14f0f30f
@ -78,6 +78,7 @@ static void debug_shared(const wchar_t msg_level, const wcstring &msg);
|
|||||||
|
|
||||||
const wcstring whitespace = L" \t\r\n\v";
|
const wcstring whitespace = L" \t\r\n\v";
|
||||||
const char *whitespace_narrow = " \t\r\n\v";
|
const char *whitespace_narrow = " \t\r\n\v";
|
||||||
|
std::stack<std::function<void()>> before_exit;
|
||||||
|
|
||||||
bool is_whitespace(const wchar_t input) {
|
bool is_whitespace(const wchar_t input) {
|
||||||
for (auto c : whitespace) {
|
for (auto c : whitespace) {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stack>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@ -423,6 +424,8 @@ void assert_is_background_thread(const char *who);
|
|||||||
#define ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(x) assert_is_background_thread(x)
|
#define ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(x) assert_is_background_thread(x)
|
||||||
#define ASSERT_IS_BACKGROUND_THREAD() ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(__FUNCTION__)
|
#define ASSERT_IS_BACKGROUND_THREAD() ASSERT_IS_BACKGROUND_THREAD_TRAMPOLINE(__FUNCTION__)
|
||||||
|
|
||||||
|
extern std::stack<std::function<void()>> before_exit;
|
||||||
|
|
||||||
// fish_mutex is a wrapper around std::mutex that tracks whether it is locked, allowing for checking
|
// fish_mutex is a wrapper around std::mutex that tracks whether it is locked, allowing for checking
|
||||||
// if the mutex is locked. It owns a boolean guarded by the lock that records whether the lock is
|
// if the mutex is locked. It owns a boolean guarded by the lock that records whether the lock is
|
||||||
// currently locked; this is only used by assertions for correctness.
|
// currently locked; this is only used by assertions for correctness.
|
||||||
|
@ -359,6 +359,12 @@ static bool can_use_posix_spawn_for_job(const job_t *job, const process_t *proce
|
|||||||
void internal_exec(job_t *j, const io_chain_t &&all_ios) {
|
void internal_exec(job_t *j, const io_chain_t &&all_ios) {
|
||||||
// Do a regular launch - but without forking first...
|
// Do a regular launch - but without forking first...
|
||||||
|
|
||||||
|
// since we are about to quit, make sure to run pending cleanup tasks
|
||||||
|
while (!before_exit.empty()) {
|
||||||
|
before_exit.top()();
|
||||||
|
before_exit.pop();
|
||||||
|
}
|
||||||
|
|
||||||
// setup_child_process makes sure signals are properly set up.
|
// setup_child_process makes sure signals are properly set up.
|
||||||
|
|
||||||
// PCA This is for handling exec. Passing all_ios here matches what fish 2.0.0 and 1.x did.
|
// PCA This is for handling exec. Passing all_ios here matches what fish 2.0.0 and 1.x did.
|
||||||
|
@ -466,6 +466,12 @@ int main(int argc, char **argv) {
|
|||||||
parser.emit_profiling(s_profiling_output_filename);
|
parser.emit_profiling(s_profiling_output_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// since we exit without destructors, we need some way to run cleanup code when necessary
|
||||||
|
while (!before_exit.empty()) {
|
||||||
|
before_exit.top()();
|
||||||
|
before_exit.pop();
|
||||||
|
}
|
||||||
|
|
||||||
history_save_all();
|
history_save_all();
|
||||||
proc_destroy();
|
proc_destroy();
|
||||||
exit_without_destructors(exit_status);
|
exit_without_destructors(exit_status);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user