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.
Details
Details
Diff Detail
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
Comment Actions
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.
Comment Actions
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); } |