Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stunserver
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Stunserver
Commits
fa78d4c7
Commit
fa78d4c7
authored
Feb 09, 2017
by
jselbie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sigpipe more reliably disabled
parent
0671c418
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
23 deletions
+25
-23
server/main.cpp
server/main.cpp
+25
-23
No files found.
server/main.cpp
View file @
fa78d4c7
...
...
@@ -534,27 +534,31 @@ HRESULT ParseCommandLineArgs(int argc, char** argv, int startindex, StartupArgs*
}
// This routine will set SIGINT And SIGTERM to "blocked" status only so that the
// child worker threads will never have these events raised on them.
HRESULT
InitAppExitListener
()
HRESULT
BlockSignal
(
int
sig
)
{
HRESULT
hr
=
S_OK
;
sigset_t
sigs
;
int
result
=
0
;
sigset_t
signalset
;
sigset_t
oldset
;
sigemptyset
(
&
signalset
);
sigemptyset
(
&
oldset
);
sigaddset
(
&
signalset
,
sig
);
// blocks the signal on *this* thread and all child threads spawned with pthread_create
result
=
pthread_sigmask
(
SIG_BLOCK
,
&
signalset
,
&
oldset
);
if
(
result
!=
0
)
{
hr
=
ERRNO_TO_HRESULT
(
result
);
Logging
::
LogMsg
(
LL_DEBUG
,
"BlockSignal: x%x"
,
hr
);
}
int
ret
;
sigemptyset
(
&
sigs
);
sigaddset
(
&
sigs
,
SIGINT
);
sigaddset
(
&
sigs
,
SIGTERM
);
ret
=
pthread_sigmask
(
SIG_BLOCK
,
&
sigs
,
NULL
);
hr
=
(
ret
==
0
)
?
S_OK
:
ERRNO_TO_HRESULT
(
ret
);
Logging
::
LogMsg
(
LL_DEBUG
,
"InitAppExitListener: x%x"
,
hr
);
return
hr
;
}
// after all the child threads have initialized with a signal mask that blocks SIGINT and SIGTERM
// then the main thread UI can just sit on WaitForAppExitSignal and wait for CTRL-C to get pressed
void
WaitForAppExitSignal
()
...
...
@@ -625,9 +629,6 @@ HRESULT StartTCP(CRefCountedPtr<CTCPServer>& spTCPServer, CStunServerConfig& con
}
int
main
(
int
argc
,
char
**
argv
)
{
HRESULT
hr
=
S_OK
;
...
...
@@ -684,13 +685,14 @@ int main(int argc, char** argv)
DumpConfig
(
config
);
// For now, just swallow sigpipe events globally so TCP server won't blow up
// on a send() call to a disconnected client
// There's other ways to do this (sigaction on each thread, MSG_NOSIGNAL, SO_NOSIGPIPE, etc...)
// This seems just as good, and is the most portable
// block sigpipe so that socket send calls from raising SIGPIPE
signal
(
SIGPIPE
,
SIG_IGN
);
BlockSignal
(
SIGPIPE
);
InitAppExitListener
();
// Block SIGTERM and SIGINT such that the child threads will never get that signal (so that subsequent WaitForAppExitSignal hooks on *this* thread)
BlockSignal
(
SIGTERM
);
BlockSignal
(
SIGINT
);
if
(
config
.
fTCP
==
false
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment