2 * @file signal-handlers.c
3 * @brief シグナルハンドラの管理 / Controlling signal handlers
8 #include "signal-handlers.h"
13 #include "io/write-diary.h"
14 #include "cmd/cmd-dump.h"
15 #include "floor-events.h"
17 s16b signal_count; /* Hack -- Count interupts */
24 * @brief OSからのシグナルを受けてサスペンド状態に入る /
25 * Handle signals -- suspend
26 * @param sig 受け取ったシグナル
28 * Actually suspend the game, and then resume cleanly
30 static void handle_signal_suspend(int sig)
32 (void)signal(sig, SIG_IGN);
35 Term_xtra(TERM_XTRA_ALIVE, 0);
36 (void)kill(0, SIGSTOP);
37 Term_xtra(TERM_XTRA_ALIVE, 1);
41 (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)
71 (void)strcpy(p_ptr->died_from, _("強制終了", "Abortion"));
72 forget_lite(p_ptr->current_floor_ptr);
73 forget_view(p_ptr->current_floor_ptr);
74 clear_mon_lite(p_ptr->current_floor_ptr);
76 quit(_("強制終了", "interrupt"));
78 else if (signal_count >= 5)
80 (void)strcpy(p_ptr->died_from, _("強制終了中", "Interrupting"));
81 forget_lite(p_ptr->current_floor_ptr);
82 forget_view(p_ptr->current_floor_ptr);
83 clear_mon_lite(p_ptr->current_floor_ptr);
84 p_ptr->playing = FALSE;
85 p_ptr->is_dead = TRUE;
86 p_ptr->leaving = TRUE;
88 quit(_("強制終了", "interrupt"));
90 else if (signal_count >= 4)
92 Term_xtra(TERM_XTRA_NOISE, 0);
93 Term_erase(0, 0, 255);
94 Term_putstr(0, 0, -1, TERM_WHITE, _("熟慮の上の自殺!", "Contemplating suicide!"));
97 else if (signal_count >= 2)
99 Term_xtra(TERM_XTRA_NOISE, 0);
102 (void)signal(sig, handle_signal_simple);
107 * todo ここにp_ptrを追加すると関数ポインタ周りの収拾がつかなくなるので保留
108 * @brief OSからのシグナルを受けて強制終了する /
109 * Handle signal -- abort, kill, etc
110 * @param sig 受け取ったシグナル
114 * This function was causing a *huge* number of problems, so it has
115 * been simplified greatly. We keep a global variable which counts
116 * the number of times the user attempts to kill the process, and
117 * we commit suicide if the user does this a certain number of times.
118 * We attempt to give "feedback" to the user as he approaches the
119 * suicide thresh-hold, but without penalizing accidental keypresses.
120 * To prevent messy accidents, we should reset this global variable
121 * whenever the user enters a keypress, or something like that.
124 static void handle_signal_abort(int sig)
127 Term_get_size(&wid, &hgt);
129 (void)signal(sig, SIG_IGN);
130 if (!current_world_ptr->character_generated || current_world_ptr->character_saved) quit(NULL);
132 forget_lite(p_ptr->current_floor_ptr);
133 forget_view(p_ptr->current_floor_ptr);
134 clear_mon_lite(p_ptr->current_floor_ptr);
136 Term_erase(0, hgt - 1, 255);
137 Term_putstr(0, hgt - 1, -1, TERM_RED,
138 _("恐ろしいソフトのバグが飛びかかってきた!", "A gruesome software bug LEAPS out at you!"));
140 Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ...", "Panic save..."));
142 exe_write_diary(p_ptr, DIARY_GAMESTART, 0, _("----ゲーム異常終了----", "-- Tried Panic Save and Aborted Game --"));
145 p_ptr->panic_save = 1;
146 (void)strcpy(p_ptr->died_from, _("(緊急セーブ)", "(panic save)"));
148 signals_ignore_tstp();
150 if (save_player(p_ptr))
152 Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ成功!", "Panic save succeeded!"));
156 Term_putstr(45, hgt - 1, -1, TERM_RED, _("緊急セーブ失敗!", "Panic save failed!"));
160 quit(_("ソフトのバグ", "software bug"));
165 * @brief OSからのSIGTSTPシグナルを無視する関数 /
166 * Ignore SIGTSTP signals (keyboard suspend)
170 void signals_ignore_tstp(void)
173 (void)signal(SIGTSTP, SIG_IGN);
179 * @brief OSからのSIGTSTPシグナルハンドラ /
180 * Handle SIGTSTP signals (keyboard suspend)
184 void signals_handle_tstp(void)
187 (void)signal(SIGTSTP, handle_signal_suspend);
193 * @brief OSからのシグナルハンドルを初期化する /
194 * Prepare to handle the relevant signals
198 void signals_init(void)
201 (void)signal(SIGHUP, SIG_IGN);
205 (void)signal(SIGTSTP, handle_signal_suspend);
209 (void)signal(SIGINT, handle_signal_simple);
213 (void)signal(SIGQUIT, handle_signal_simple);
217 (void)signal(SIGFPE, handle_signal_abort);
221 (void)signal(SIGILL, handle_signal_abort);
225 (void)signal(SIGTRAP, handle_signal_abort);
229 (void)signal(SIGIOT, handle_signal_abort);
233 (void)signal(SIGKILL, handle_signal_abort);
237 (void)signal(SIGBUS, handle_signal_abort);
241 (void)signal(SIGSEGV, handle_signal_abort);
245 (void)signal(SIGTERM, handle_signal_abort);
249 (void)signal(SIGPIPE, handle_signal_abort);
253 (void)signal(SIGEMT, handle_signal_abort);
257 (void)signal(SIGDANGER, handle_signal_abort);
261 (void)signal(SIGSYS, handle_signal_abort);
265 (void)signal(SIGXCPU, handle_signal_abort);
269 (void)signal(SIGPWR, handle_signal_abort);
279 void signals_ignore_tstp(void)
288 void signals_handle_tstp(void)
297 void signals_init(void)