0

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...

  • Are you attempting to catch SIGKILL ? You can't. – wildplasser Mar 08 '15 at 14:44
  • No i have written a server that should produce lots of log entrys in a specific log file but that log file never gets created by syslog and the only log entry in the system about my serve is a couple of entrys comming from the kernel referring to some segfaults that occurred during execution of the daemon.. – Aristos Miliaressis Mar 08 '15 at 18:00
  • I was referring to this line: `signal (SIGKILL, sig_handle);` BTW: syslogd is often configured to ignore low importance logentries (debug, info) `man rsyslog.conf` – wildplasser Mar 08 '15 at 18:06
  • i have configured `rsyslog.conf` and added a `local0.* /var/log/simple-server.log` entry – Aristos Miliaressis Mar 08 '15 at 20:40

0 Answers0