I wrote a small c app that uses the syslog c interface to write messages (from man 3 syslog):

void openlog(const char *ident, int logopt, int facility);
void syslog(int priority, const char *message, ...);
void closelog(void);

My question: I'm writing messages to LOCAL0 in /var/log/local0.log. I also have cron calling logrotate on /var/log/local0.log. I've noticed that after the rotation, my app continues writing to the file that was rotated out instead of the new /var/log/local0.log.

What is the best way to fix this with a postrotate script?

  1. Easy, but not ideal: completely restart the rsyslog daemon.

  2. Send and handle SIGHUP in my app. This seems like the most appropriate solution. But I'm not sure what I need to do when I get the HUP. Do I just need to call closelog() then openlog()?


Another decent workaround, which doesn't quite fit your situation but can be used "in a pinch" is the copytruncate option in logrotate. It means whatever is writing to the logfile does not need to be notified.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy