Commit 8fedac89 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(go_daemon): New function.

(initialize): Call go_daemon().
parent 815c217e
/*
* $Id: ramkomd.c,v 0.46 1994/02/19 04:44:56 ceder Exp $
* $Id: ramkomd.c,v 0.47 1994/04/04 15:10:48 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -31,7 +31,7 @@
* It has grown! /ceder
*/
static char *rcsid = "$Id: ramkomd.c,v 0.46 1994/02/19 04:44:56 ceder Exp $";
static char *rcsid = "$Id: ramkomd.c,v 0.47 1994/04/04 15:10:48 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -56,11 +56,10 @@ USE(rcsid);
#if defined(HAVE_SYS_PARAM_H) && !defined(HAVE_GETCWD)
# include <sys/param.h>
#endif
#if defined(HAVE_GETCWD)
# include <errno.h>
#endif
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include "exp.h"
#include "s-string.h"
......@@ -240,6 +239,53 @@ save_pid(void)
fclose(fp);
}
void
go_daemon(const char *prefix, const char *logf)
{
pid_t child;
int fd;
char *logfile;
if (getppid() != 1)
{
/* We were not invoked from /etc/inittab, so
disassociate from controlling terminal. */
#ifdef SIGTTOU
signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTSTP
signal(SIGTSTP, SIG_IGN);
#endif
child = fork();
if (child < 0)
restart_kom("fork failed: %d\n", errno);
else if (child > 0)
exit (0); /* parent */
setsid();
}
logfile = smalloc(strlen(prefix) + 1 + strlen(logf) + 1);
sprintf(logfile, "%s/%s", prefix, logf);
/* Close all file descriptors */
for (fd = 0; fd < MAX_NO_OF_CONNECTIONS + PROTECTED_FDS; fd++)
close(fd);
if (open("/dev/null", O_RDONLY) != 0
||open("/dev/null", O_WRONLY) != 1
||open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0644) != 2)
{
/* Kinda stupid to try to log an error message now, but
who knows? */
restart_kom(stderr, "open of log file failed: %d\n", errno);
}
sfree(logfile);
}
void
initialize(const char *config_file)
{
......@@ -260,6 +306,7 @@ initialize(const char *config_file)
exit(1);
}
#endif
go_daemon(param.dbase_dir, param.logfile_name);
server_init(param.ip_client_port, param.ip_mux_port);
init_data_base(param.dbase_dir);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment