Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
senf
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wiback
senf
Commits
24337adf
Commit
24337adf
authored
18 years ago
by
g0dil
Browse files
Options
Downloads
Patches
Plain Diff
Add very simple daemon helpers
parent
8c209f46
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Utils/DaemonTools.cc
+51
-0
51 additions, 0 deletions
Utils/DaemonTools.cc
Utils/DaemonTools.hh
+32
-0
32 additions, 0 deletions
Utils/DaemonTools.hh
with
83 additions
and
0 deletions
Utils/DaemonTools.cc
0 → 100644
+
51
−
0
View file @
24337adf
// $Id$
//
// Copyright (C) 2006
// Definition of non-inline non-template functions
#include
"DaemonTools.hh"
//#include "DaemonTools.ih"
// Custom includes
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<unistd.h>
#include
<fcntl.h>
#include
<errno.h>
#include
"Exception.hh"
//#include "DaemonTools.mpp"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
prefix_
void
satcom
::
lib
::
daemonize
()
{
int
pid
=
fork
();
if
(
pid
<
0
)
throw
satcom
::
lib
::
SystemException
(
"fork"
,
errno
);
if
(
pid
>
0
)
::
_exit
(
0
);
if
(
::
setsid
()
<
0
)
throw
satcom
::
lib
::
SystemException
(
"setsid"
,
errno
);
}
prefix_
void
satcom
::
lib
::
redirect_stdio
(
std
::
string
const
&
path
)
{
int
fd
=
::
open
(
path
.
c_str
(),
O_RDWR
);
if
(
fd
<
0
)
throw
satcom
::
lib
::
SystemException
(
"open"
,
errno
);
if
(
dup2
(
fd
,
0
)
<
0
)
throw
satcom
::
lib
::
SystemException
(
"dup2"
,
errno
);
if
(
dup2
(
fd
,
1
)
<
0
)
throw
satcom
::
lib
::
SystemException
(
"dup2"
,
errno
);
if
(
dup2
(
fd
,
2
)
<
0
)
throw
satcom
::
lib
::
SystemException
(
"dup2"
,
errno
);
if
(
::
close
(
fd
)
<
0
)
throw
satcom
::
lib
::
SystemException
(
"close"
,
errno
);
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "DaemonTools.mpp"
// Local Variables:
// mode: c++
// End:
This diff is collapsed.
Click to expand it.
Utils/DaemonTools.hh
0 → 100644
+
32
−
0
View file @
24337adf
// $Id$
//
// Copyright (C) 2006
#ifndef HH_DaemonTools_
#define HH_DaemonTools_ 1
// Custom includes
#include
<string>
//#include "DaemonTools.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace
satcom
{
namespace
lib
{
void
daemonize
();
void
redirect_stdio
(
std
::
string
const
&
path
=
"/dev/null"
);
}}
///////////////////////////////hh.e////////////////////////////////////////
//#include "DaemonTools.cci"
//#include "DaemonTools.ct"
//#include "DaemonTools.cti"
//#include "DaemonTools.mpp"
#endif
// Local Variables:
// mode: c++
// End:
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment