Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
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
Libraries
nghttp2
Commits
b0f5e5cc
Commit
b0f5e5cc
authored
May 28, 2019
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement daemon() using fork() for OSX
parent
8d6ecd66
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
2 deletions
+46
-2
src/nghttpd.cc
src/nghttpd.cc
+1
-1
src/shrpx.cc
src/shrpx.cc
+1
-1
src/util.cc
src/util.cc
+40
-0
src/util.h
src/util.h
+4
-0
No files found.
src/nghttpd.cc
View file @
b0f5e5cc
...
...
@@ -435,7 +435,7 @@ int main(int argc, char **argv) {
#ifdef __sgi
if
(
daemon
(
0
,
0
,
0
,
0
)
==
-
1
)
{
#else
if
(
daemon
(
0
,
0
)
==
-
1
)
{
if
(
util
::
daemonize
(
0
,
0
)
==
-
1
)
{
#endif
perror
(
"daemon"
);
exit
(
EXIT_FAILURE
);
...
...
src/shrpx.cc
View file @
b0f5e5cc
...
...
@@ -1148,7 +1148,7 @@ int call_daemon() {
return
0
;
}
# endif // HAVE_LIBSYSTEMD
return
daemon
(
0
,
0
);
return
util
::
daemonize
(
0
,
0
);
#endif // !__sgi
}
}
// namespace
...
...
src/util.cc
View file @
b0f5e5cc
...
...
@@ -1542,6 +1542,46 @@ std::mt19937 make_mt19937() {
return
std
::
mt19937
(
rd
());
}
int
daemonize
(
int
nochdir
,
int
noclose
)
{
#if defined(__APPLE__)
pid_t
pid
;
pid
=
fork
();
if
(
pid
==
-
1
)
{
return
-
1
;
}
else
if
(
pid
>
0
)
{
_exit
(
EXIT_SUCCESS
);
}
if
(
setsid
()
==
-
1
)
{
return
-
1
;
}
pid
=
fork
();
if
(
pid
==
-
1
)
{
return
-
1
;
}
else
if
(
pid
>
0
)
{
_exit
(
EXIT_SUCCESS
);
}
if
(
nochdir
==
0
)
{
if
(
chdir
(
"/"
)
==
-
1
)
{
return
-
1
;
}
}
if
(
noclose
==
0
)
{
if
(
freopen
(
"/dev/null"
,
"r"
,
stdin
)
==
nullptr
)
{
return
-
1
;
}
if
(
freopen
(
"/dev/null"
,
"w"
,
stdout
)
==
nullptr
)
{
return
-
1
;
}
if
(
freopen
(
"/dev/null"
,
"w"
,
stderr
)
==
nullptr
)
{
return
-
1
;
}
}
return
0
;
#else // !defined(__APPLE__)
return
daemon
(
nochdir
,
noclose
);
#endif // !defined(__APPLE__)
}
}
// namespace util
}
// namespace nghttp2
src/util.h
View file @
b0f5e5cc
...
...
@@ -772,6 +772,10 @@ StringRef extract_host(const StringRef &hostport);
// Returns new std::mt19937 object.
std
::
mt19937
make_mt19937
();
// daemonize calls daemon(3). If __APPLE__ is defined, it implements
// daemon() using fork().
int
daemonize
(
int
nochdir
,
int
noclose
);
}
// namespace util
}
// namespace nghttp2
...
...
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