-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathServerSignal.cpp
More file actions
95 lines (85 loc) · 2.27 KB
/
ServerSignal.cpp
File metadata and controls
95 lines (85 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright (C) 2012 Yee Young Han <websearch@naver.com> (http://blog.naver.com/websearch)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "SipPlatformDefine.h"
#include "Log.h"
#include <signal.h>
#include <string>
#include "MemoryDebug.h"
#ifndef WIN32
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#endif
bool gbStop = false;
/**
* @ingroup ServerPlatform
* @brief signal function
* @param sig 신호 번호
*/
void LastMethod( int sig )
{
char szText[21];
szText[0] = '\0';
switch( sig )
{
case SIGINT:
snprintf( szText, sizeof(szText), "SIGINT" );
break;
case SIGSEGV:
snprintf( szText, sizeof(szText), "SIGSEGV" );
break;
case SIGTERM:
snprintf( szText, sizeof(szText), "SIGTERM" );
break;
#ifndef WIN32
case SIGQUIT:
snprintf( szText, sizeof(szText), "SIGQUIT" );
break;
#endif
case SIGABRT:
snprintf( szText, sizeof(szText), "SIGABRT" );
break;
}
CLog::Print( LOG_ERROR, "signal%s%s(%d) is received. terminated", strlen(szText) > 0 ? "-" : "", szText, sig );
#ifndef WIN32
if( sig == SIGSEGV )
{
CLog::PrintCallStack( LOG_ERROR );
signal( sig, SIG_DFL );
kill( getpid(), sig );
return;
}
#endif
gbStop = true;
}
/**
* @ingroup ServerPlatform
* @brief 서버를 위한 signal 함수를 호출한다.
*/
void ServerSignal()
{
signal( SIGINT, LastMethod );
signal( SIGTERM, LastMethod );
signal( SIGABRT, LastMethod );
#ifndef WIN32
signal( SIGSEGV, LastMethod );
signal( SIGKILL, LastMethod );
signal( SIGQUIT, LastMethod );
signal( SIGPIPE, SIG_IGN );
#endif
}