2 * @file signal-handlers.c
3 * @brief シグナルハンドラの管理 / Controlling signal handlers
8 #include "io/signal-handlers.h"
9 #include "cmd-io/cmd-dump.h"
10 #include "core/game-closer.h"
11 #include "floor/floor-events.h"
12 #include "io/write-diary.h"
13 #include "savedata/save.h"
14 #include "system/system-variables.h"
15 #include "term/term-color-types.h"
16 #include "world/world.h"
18 s16b signal_count; /* Hack -- Count interupts */
25 * @brief OSからのシグナルを受けてサスペンド状態に入る /
26 * Handle signals -- suspend
27 * @param sig 受け取ったシグナル
29 * Actually suspend the game, and then resume cleanly
31 static void handle_signal_suspend(int sig)
33 (void)signal(sig, SIG_IGN);
36 term_xtra(TERM_XTRA_ALIVE, 0);
37 (void)kill(0, SIGSTOP);
38 term_xtra(TERM_XTRA_ALIVE, 1);
42 (void)signal(sig, handle_signal_suspend);
46 * todo ここにplayer_typeを追加すると関数ポインタ周りの収拾がつかなくなるので保留
47 * @brief OSからのシグナルを受けて中断、終了する /
48 * Handle signals -- simple (interrupt and quit)
49 * @param sig 受け取ったシグナル
52 * This function was causing a *huge* number of problems, so it has
53 * been simplified greatly. We keep a global variable which counts
54 * the number of times the user attempts to kill the process, and
55 * we commit suicide if the user does this a certain number of times.
56 * We attempt to give "feedback" to the user as he approaches the
57 * suicide thresh-hold, but without penalizing accidental keypresses.
58 * To prevent messy accidents, we should reset this global variable
59 * whenever the user enters a keypress, or something like that.
62 static void handle_signal_simple(int sig)
64 (void)signal(sig, SIG_IGN);
65 if (!current_world_ptr->character_generated || current_world_ptr->character_saved)
70 (void)strcpy(p_ptr->died_from, _("強制終了", "Abortion"));
71 forget_lite(p_ptr->current_floor_ptr);
72 forget_view(p_ptr->current_floor_ptr);
73 clear_mon_lite(p_ptr->current_floor_ptr);
75 quit(_("強制終了", "interrupt"));
76 } else if (signal_count >= 5) {
77 (void)strcpy(p_ptr->died_from, _("強制終了中", "Interrupting"));
78 forget_lite(p_ptr->current_floor_ptr);
79 forget_view(p_ptr->current_floor_ptr);
80 clear_mon_lite(p_ptr->current_floor_ptr);
81 p_ptr->playing = FALSE;
82 p_ptr->is_dead = TRUE;
83 p_ptr->leaving = TRUE;
85 quit(_("強制終了", "interrupt"));
86 } else if (signal_count >= 4) {
87 term_xtra(TERM_XTRA_NOISE, 0);
88 term_erase(0, 0, 255);
89 term_putstr(0, 0, -1, TERM_WHITE, _("熟慮の上の自殺!", "Contemplating suicide!"));
91 } else if (signal_count >= 2) {
92 term_xtra(TERM_XTRA_NOISE, 0);
95 (void)signal(sig, handle_signal_simple);
99 * todo ここにp_ptrを追加すると関数ポインタ周りの収拾がつかなくなるので保留
100 * @brief OSからのシグナルを受けて強制終了する /
101 * Handle signal -- abort, kill, etc
102 * @param sig 受け取ったシグナル
106 * This function was causing a *huge* number of problems, so it has
107 * been simplified greatly. We keep a global variable which counts
108 * the number of times the user attempts to kill the process, and
109 * we commit suicide if the user does this a certain number of times.
110 * We attempt to give "feedback" to the user as he approaches the
111 * suicide thresh-hold, but without penalizing accidental keypresses.
112 * To prevent messy accidents, we should reset this global variable
113 * whenever the user enters a keypress, or something like that.
116 static void handle_signal_abort(int sig)
119 term_get_size(&wid, &hgt);
121 (void)signal(sig, SIG_IGN);
122 if (!current_world_ptr->character_generated || current_world_ptr->character_saved)
125 forget_lite(p_ptr->current_floor_ptr);
126 forget_view(p_ptr->current_floor_ptr);
127 clear_mon_lite(p_ptr->current_floor_ptr);
129 term_erase(0, hgt - 1, 255);
130 term_putstr(0, hgt - 1, -1, TERM_RED, _("恐ろしいソフトのバグが飛びかかってきた!", "A gruesome software bug LEAPS out at you!"));
132 term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ...", "Panic save..."));
134 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム異常終了----", "-- Tried Panic Save and Aborted Game --"));
137 p_ptr->panic_save = 1;
138 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
140 signals_ignore_tstp();
142 if (save_player(p_ptr)) {
143 term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ成功!", "Panic save succeeded!"));
145 term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ失敗!", "Panic save failed!"));
149 quit(_("ソフトのバグ", "software bug"));
153 * @brief OSからのSIGTSTPシグナルを無視する関数 /
154 * Ignore SIGTSTP signals (keyboard suspend)
158 void signals_ignore_tstp(void)
161 (void)signal(SIGTSTP, SIG_IGN);
166 * @brief OSからのSIGTSTPシグナルハンドラ /
167 * Handle SIGTSTP signals (keyboard suspend)
171 void signals_handle_tstp(void)
174 (void)signal(SIGTSTP, handle_signal_suspend);
179 * @brief OSからのシグナルハンドルを初期化する /
180 * Prepare to handle the relevant signals
184 void signals_init(void)
187 (void)signal(SIGHUP, SIG_IGN);
191 (void)signal(SIGTSTP, handle_signal_suspend);
195 (void)signal(SIGINT, handle_signal_simple);
199 (void)signal(SIGQUIT, handle_signal_simple);
203 (void)signal(SIGFPE, handle_signal_abort);
207 (void)signal(SIGILL, handle_signal_abort);
211 (void)signal(SIGTRAP, handle_signal_abort);
215 (void)signal(SIGIOT, handle_signal_abort);
219 (void)signal(SIGKILL, handle_signal_abort);
223 (void)signal(SIGBUS, handle_signal_abort);
227 (void)signal(SIGSEGV, handle_signal_abort);
231 (void)signal(SIGTERM, handle_signal_abort);
235 (void)signal(SIGPIPE, handle_signal_abort);
239 (void)signal(SIGEMT, handle_signal_abort);
243 (void)signal(SIGDANGER, handle_signal_abort);
247 (void)signal(SIGSYS, handle_signal_abort);
251 (void)signal(SIGXCPU, handle_signal_abort);
255 (void)signal(SIGPWR, handle_signal_abort);
265 void signals_ignore_tstp(void) {}
271 void signals_handle_tstp(void) {}
277 void signals_init(void) {}