Page MenuHomeFreeBSD

Daemon(8) additional syslog logging capabilities
Needs ReviewPublic

Authored by grell64_gmail.com on Jul 28 2016, 7:16 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 13 2024, 1:13 AM
Unknown Object (File)
Jan 22 2024, 8:36 PM
Unknown Object (File)
Dec 2 2023, 10:04 AM
Unknown Object (File)
Oct 3 2023, 11:35 PM
Unknown Object (File)
Aug 9 2023, 7:59 PM
Unknown Object (File)
Aug 6 2023, 7:50 AM
Unknown Object (File)
Jun 25 2023, 3:34 AM
Unknown Object (File)
Jun 13 2023, 4:21 PM

Details

Reviewers
None
Group Reviewers
Src Committers
Summary

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

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

grell64_gmail.com retitled this revision from to Daemon(8) additional syslog logging capabilities.
grell64_gmail.com updated this object.
grell64_gmail.com edited the test plan for this revision. (Show Details)
grell64_gmail.com set the repository for this revision to rS FreeBSD src repository - subversion.
grell64_gmail.com 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)

daemon_syslog.c
212

I don't think this comment is relevant

243

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.

daemon_syslog.c
218

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);
    fclose(fp);
    
    fp = popen(logger_cmd, "w");
    if (fp == NULL)
        goto exit;

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