Hi guys i am trying to make a daemon server that writes to syslog but i can't get it to work..
i have rsyslog
installed and configured with facility
local0.info /var/log/simple-server.log
Some of my code: server.c
// includes
int main (void)
{
pid_t pid, sid;
pid = fork ();
if (pid == -1)
{
printf ("server failed to fork daemon");
exit (1);
}
else
{
exit (0);
}
umask (0);
setlogmask (LOG_UPTO (LOG_INFO));
openlog ("simpleServer", LOG_PID | LOG_NDELAY, LOG_LOCAL0);
sid = setsid ();
if (sid == -1)
syslog(LOG_WARNING, "child failed to get session ID");
signal (SIGKILL, sig_handle);
// more sig handling
if ((chdir ("/")) == -1)
{
syslog(LOG_ERR, "process failed ...");
}
close (STDIN_FILENO);
//close stdout and stderr
while (1)
{
// do stuff
}
closelog();`
}
Is there something I'm doing wrong? or is my rsyslog configuration the problem?
EDIT
rsyslog
has some log entry's from the kernel in /var/log/syslog
that refer to a segfault in the process of server.c but nothing else the error happens after openlog()
and multiple syslog()
commands but the only thing that gets logged is the segfault...