mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 05:03:43 +01:00
Add daemon logic
svn:r185
This commit is contained in:
parent
5dc443a8c5
commit
743e61e8c6
@ -607,6 +607,24 @@ void dump_directory_to_string(char *s, int maxlen) {
|
||||
|
||||
}
|
||||
|
||||
void daemonize() {
|
||||
/* Fork; parent exits. */
|
||||
if (fork())
|
||||
exit(0);
|
||||
|
||||
/* Create new session; make sure we never get a terminal */
|
||||
setsid();
|
||||
if (fork())
|
||||
exit(0);
|
||||
|
||||
chdir("/");
|
||||
umask(000);
|
||||
|
||||
fclose(stdin);
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int retval = 0;
|
||||
|
||||
@ -615,6 +633,9 @@ int main(int argc, char *argv[]) {
|
||||
log(options.loglevel,NULL); /* assign logging severity level from options */
|
||||
global_role = options.Role; /* assign global_role from options. FIXME: remove from global namespace later. */
|
||||
|
||||
if (options.Daemon)
|
||||
daemonize();
|
||||
|
||||
if(options.Role & ROLE_OR_LISTEN) { /* only spawn dns handlers if we're a router */
|
||||
if(dns_master_start() < 0) {
|
||||
log(LOG_ERR,"main(): We're running without a dns handler. Bad news.");
|
||||
|
Loading…
Reference in New Issue
Block a user