/[LeafOK_CVS]/pvpgn-1.7.4/src/d2cs/handle_signal.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/d2cs/handle_signal.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Mon Jun 12 18:31:17 2006 UTC (19 years, 9 months ago) by sysadm
Branch: MAIN
CVS Tags: pvpgn_1-7-4-0_MIL, HEAD
Changes since 1.1: +8 -1 lines
Content type: text/x-csrc
no message

1 sysadm 1.1 /*
2     * Copyright (C) 2000,2001 Onlyer (onlyer@263.net)
3     *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License
6     * as published by the Free Software Foundation; either version 2
7     * of the License, or (at your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful,
10     * but WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     * GNU General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with this program; if not, write to the Free Software
16     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17     */
18     #include "common/setup_before.h"
19     #include "setup.h"
20    
21     #ifdef STDC_HEADERS
22     # include <stdlib.h>
23     #else
24     # ifdef HAVE_MALLOC_H
25     # include <malloc.h>
26     # endif
27     #endif
28     #include <errno.h>
29     #ifdef HAVE_STRING_H
30     # include <string.h>
31     #else
32     # ifdef HAVE_STRINGS_H
33     # include <strings.h>
34     # endif
35     # ifdef HAVE_MEMORY_H
36     # include <memory.h>
37     # endif
38     #endif
39     #include "compat/strdup.h"
40     #ifdef TIME_WITH_SYS_TIME
41     # include <time.h>
42     # include <sys/time.h>
43     #else
44     # ifdef HAVE_SYS_TIME_H
45     # include <sys/time.h>
46     # else
47     # include <time.h>
48     # endif
49     #endif
50     #ifdef DO_POSIXSIG
51     # include <signal.h>
52     # include "compat/signal.h"
53     #endif
54     #ifdef HAVE_FCNTL_H
55     # include <fcntl.h>
56     #else
57     # ifdef HAVE_SYS_FILE_H
58     # include <sys/file.h>
59     # endif
60     #endif
61     #ifdef HAVE_UNISTD_H
62     # include <unistd.h>
63     #endif
64    
65     #include "d2gs.h"
66     #include "game.h"
67     #include "prefs.h"
68 sysadm 1.2 #include "gs_scope.h"
69 sysadm 1.1 #include "d2ladder.h"
70     #include "cmdline_parse.h"
71     #include "handle_signal.h"
72     #include "common/trans.h"
73     #include "common/eventlog.h"
74     #include "common/xalloc.h"
75     #include "common/setup_after.h"
76    
77     static void on_signal(int s);
78    
79     static volatile struct
80     {
81     unsigned char do_quit;
82     unsigned char cancel_quit;
83     unsigned char reload_config;
84     unsigned char reload_ladder;
85     unsigned char restart_d2gs;
86     unsigned int exit_time;
87     } signal_data ={ 0, 0, 0, 0, 0, 0 };
88    
89     extern int handle_signal(void)
90     {
91     time_t now;
92     char const * levels;
93     char * temp;
94     char const * tok;
95    
96    
97     if (signal_data.cancel_quit) {
98     signal_data.cancel_quit=0;
99     if (!signal_data.exit_time) {
100     eventlog(eventlog_level_info,__FUNCTION__,"there is no previous shutdown to be canceled");
101     } else {
102     signal_data.exit_time=0;
103     eventlog(eventlog_level_info,__FUNCTION__,"shutdown was canceled due to signal");
104     }
105     }
106     if (signal_data.do_quit) {
107     signal_data.do_quit=0;
108     now=time(NULL);
109     if (!signal_data.exit_time) {
110     signal_data.exit_time=now+d2cs_prefs_get_shutdown_delay();
111     } else {
112     signal_data.exit_time-=d2cs_prefs_get_shutdown_decr();
113     }
114     eventlog(eventlog_level_info,__FUNCTION__,"the server is going to shutdown in %lu minutes",(signal_data.exit_time-now)/60);
115     }
116     if (signal_data.exit_time) {
117     now=time(NULL);
118     if (now >= (signed)signal_data.exit_time) {
119     eventlog(eventlog_level_info,__FUNCTION__,"shutdown server due to signal");
120     return -1;
121     }
122     }
123     if (signal_data.reload_config) {
124     signal_data.reload_config=0;
125     eventlog(eventlog_level_info,__FUNCTION__,"reloading configuartion file due to signal");
126     if (prefs_reload(cmdline_get_prefs_file())<0) {
127     eventlog(eventlog_level_error,__FUNCTION__,"error reload configuration file,exitting");
128     return -1;
129     }
130     if (d2gslist_reload(prefs_get_d2gs_list())<0) {
131     eventlog(eventlog_level_error,__FUNCTION__,"error reloading game server list,exitting");
132     return -1;
133     }
134     if (trans_reload(d2cs_prefs_get_transfile(),TRANS_D2CS)<0) {
135 sysadm 1.2 eventlog(eventlog_level_error,__FUNCTION__,"could not reload trans list");
136 sysadm 1.1 }
137 sysadm 1.2 /* Added by Leaflet at 2006-06-05 Begin */
138     if (serve_scope_list_reload(cmdline_get_gsscope_file())) {
139     eventlog(eventlog_level_error,__FUNCTION__,"could not reload gsscope list");
140     }
141     /* End */
142    
143 sysadm 1.1
144     eventlog_clear_level();
145     if ((levels = d2cs_prefs_get_loglevels()))
146     {
147     temp = xstrdup(levels);
148     tok = strtok(temp,","); /* strtok modifies the string it is passed */
149    
150     while (tok)
151     {
152     if (eventlog_add_level(tok)<0)
153     eventlog(eventlog_level_error,__FUNCTION__,"could not add log level \"%s\"",tok);
154     tok = strtok(NULL,",");
155     }
156    
157     xfree(temp);
158     }
159    
160     if (!cmdline_get_debugmode()) eventlog_open(d2cs_prefs_get_logfile());
161     }
162     if (signal_data.reload_ladder) {
163     signal_data.reload_ladder=0;
164     eventlog(eventlog_level_info,__FUNCTION__,"reloading ladder data due to signal");
165     d2ladder_refresh();
166     }
167    
168     if (signal_data.restart_d2gs) {
169     signal_data.restart_d2gs=0;
170     eventlog(eventlog_level_info,__FUNCTION__,"restarting all game servers due to signal");
171     d2gs_restart_all_gs();
172     }
173    
174     return 0;
175     }
176     #ifdef WIN32
177     extern void signal_quit_wrapper(void)
178     {
179     signal_data.do_quit=1;
180     }
181    
182     extern void signal_reload_config_wrapper(void)
183     {
184     signal_data.reload_config = 1;
185     }
186    
187     extern void signal_load_ladder_wrapper(void)
188     {
189     signal_data.reload_ladder = 1;
190     }
191    
192     extern void signal_exit_wrapper(void)
193     {
194     signal_data.exit_time = 1;
195     signal_data.do_quit = 1;
196     }
197    
198     extern void signal_restart_d2gs_wrapper(void)
199     {
200     signal_data.restart_d2gs = 1;
201     }
202     #else
203     extern int handle_signal_init(void)
204     {
205     signal(SIGINT,on_signal);
206     signal(SIGTERM,on_signal);
207     signal(SIGABRT,on_signal);
208     signal(SIGHUP,on_signal);
209     signal(SIGUSR1,on_signal);
210     signal(SIGUSR2,on_signal);
211     signal(SIGPIPE,on_signal);
212     return 0;
213     }
214    
215     static void on_signal(int s)
216     {
217     switch (s) {
218     case SIGINT:
219     eventlog(eventlog_level_debug,__FUNCTION__,"sigint received");
220     signal_data.do_quit=1;
221     break;
222     case SIGTERM:
223     eventlog(eventlog_level_debug,__FUNCTION__,"sigint received");
224     signal_data.do_quit=1;
225     break;
226     case SIGABRT:
227     eventlog(eventlog_level_debug,__FUNCTION__,"sigabrt received");
228     signal_data.cancel_quit=1;
229     break;
230     case SIGHUP:
231     eventlog(eventlog_level_debug,__FUNCTION__,"sighup received");
232     signal_data.reload_config=1;
233     break;
234     case SIGUSR1:
235     eventlog(eventlog_level_debug,__FUNCTION__,"sigusr1 received");
236     signal_data.reload_ladder=1;
237     break;
238     case SIGUSR2:
239     eventlog(eventlog_level_debug,__FUNCTION__,"sigusr2 received");
240     signal_data.restart_d2gs=1;
241     break;
242     case SIGPIPE:
243     eventlog(eventlog_level_debug,__FUNCTION__,"sigpipe received");
244     break;
245     }
246     signal(s,on_signal);
247     }
248     #endif
249    

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1