Page MenuHomeFreeBSD

Daemon(8) additional syslog logging capabilities
Needs ReviewPublic

Authored by on Jul 28 2016, 7:16 PM.


Group Reviewers
Src Committers

This patch uses the logger(1) command line utility to pass over the specified daemonized program's standard output and standard error to syslog. I use dup2 to duplicate the stderr and stdout. The option -s specifies that syslog is to be used, -h gives the user control over the facility and priority of the syslog messages, and -t allows the user to specify a custom tag. I use popen to send data to the logger command.

Diff Detail

rS FreeBSD src repository - subversion
Lint Skipped
Unit Tests Skipped

Event Timeline retitled this revision from to Daemon(8) additional syslog logging capabilities. updated this object. edited the test plan for this revision. (Show Details) set the repository for this revision to rS FreeBSD src repository - subversion. added a subscriber: Src Committers.

Why did you add the core team to the review? What kind of input do you need from us?

I'm not quite sure who to send it to. This is my first time submitting a
patch and I'm unsure where it should go.

Please fix style(9)


I don't think this comment is relevant


This comment is also not relevant

One thing to consider is how to handle incorrectly formatted -p arguments. Does logger log its own error to stderr in that case? Alternatively you would need to do your own validation when parsing it.


Rather than using fixed-size strings, consider using open_memstream(). It lets you use stdio to build a dynamically-sized string. (sbuf is also an option but is in a separate library.) You would do something like this:

if (syslog) {
    FILE *fp;
    char *logger_cmd;
    size_t len;
    int fd;

    fp = open_memstream(&logger_cmd, &len);
    fprintf(fp, "logger");
    if (tag != NULL)
        fprintf(fp, " -t %s", tag);
    if (priority != NULL)
        fprintf(fp, "-p %s", priority);
    fp = popen(logger_cmd, "w");
    if (fp == NULL)
        goto exit;

    fd = fileno(fp);
    dup2(fd, STDOUT_FILENO);
    dup2(fd, STDERR_FILENO);