mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(misc1): move preserve_exit() to related functions in main.c
This commit is contained in:
parent
d9c1669a54
commit
a59589ca01
@ -12,6 +12,7 @@
|
||||
#include "nvim/event/rstream.h"
|
||||
#include "nvim/log.h"
|
||||
#include "nvim/memory.h"
|
||||
#include "nvim/main.h"
|
||||
#include "nvim/misc1.h"
|
||||
#include "nvim/vim.h"
|
||||
|
||||
|
@ -696,6 +696,50 @@ void getout(int exitval)
|
||||
os_exit(exitval);
|
||||
}
|
||||
|
||||
/// Preserve files and exit.
|
||||
/// @note IObuff must contain a message.
|
||||
/// @note This may be called from deadly_signal() in a signal handler, avoid
|
||||
/// unsafe functions, such as allocating memory.
|
||||
void preserve_exit(void)
|
||||
FUNC_ATTR_NORETURN
|
||||
{
|
||||
// 'true' when we are sure to exit, e.g., after a deadly signal
|
||||
static bool really_exiting = false;
|
||||
|
||||
// Prevent repeated calls into this method.
|
||||
if (really_exiting) {
|
||||
if (input_global_fd() >= 0) {
|
||||
// normalize stream (#2598)
|
||||
stream_set_blocking(input_global_fd(), true);
|
||||
}
|
||||
exit(2);
|
||||
}
|
||||
|
||||
really_exiting = true;
|
||||
// Ignore SIGHUP while we are already exiting. #9274
|
||||
signal_reject_deadly();
|
||||
mch_errmsg(IObuff);
|
||||
mch_errmsg("\n");
|
||||
ui_flush();
|
||||
|
||||
ml_close_notmod(); // close all not-modified buffers
|
||||
|
||||
FOR_ALL_BUFFERS(buf) {
|
||||
if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) {
|
||||
mch_errmsg("Vim: preserving files...\r\n");
|
||||
ui_flush();
|
||||
ml_sync_all(false, false, true); // preserve all swap files
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ml_close_all(false); // close all memfiles, without deleting
|
||||
|
||||
mch_errmsg("Vim: Finished.\r\n");
|
||||
|
||||
getout(1);
|
||||
}
|
||||
|
||||
/// Gets the integer value of a numeric command line argument if given,
|
||||
/// such as '-o10'.
|
||||
///
|
||||
|
@ -788,50 +788,6 @@ int match_user(char_u *name)
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Preserve files and exit.
|
||||
/// @note IObuff must contain a message.
|
||||
/// @note This may be called from deadly_signal() in a signal handler, avoid
|
||||
/// unsafe functions, such as allocating memory.
|
||||
void preserve_exit(void)
|
||||
FUNC_ATTR_NORETURN
|
||||
{
|
||||
// 'true' when we are sure to exit, e.g., after a deadly signal
|
||||
static bool really_exiting = false;
|
||||
|
||||
// Prevent repeated calls into this method.
|
||||
if (really_exiting) {
|
||||
if (input_global_fd() >= 0) {
|
||||
// normalize stream (#2598)
|
||||
stream_set_blocking(input_global_fd(), true);
|
||||
}
|
||||
exit(2);
|
||||
}
|
||||
|
||||
really_exiting = true;
|
||||
// Ignore SIGHUP while we are already exiting. #9274
|
||||
signal_reject_deadly();
|
||||
mch_errmsg(IObuff);
|
||||
mch_errmsg("\n");
|
||||
ui_flush();
|
||||
|
||||
ml_close_notmod(); // close all not-modified buffers
|
||||
|
||||
FOR_ALL_BUFFERS(buf) {
|
||||
if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL) {
|
||||
mch_errmsg("Vim: preserving files...\r\n");
|
||||
ui_flush();
|
||||
ml_sync_all(false, false, true); // preserve all swap files
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ml_close_all(false); // close all memfiles, without deleting
|
||||
|
||||
mch_errmsg("Vim: Finished.\r\n");
|
||||
|
||||
getout(1);
|
||||
}
|
||||
|
||||
/// os_call_shell() wrapper. Handles 'verbose', :profile, and v:shell_error.
|
||||
/// Invalidates cached tags.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user