I have a simple C app running on both Ubuntu and Raspberry PI.
It need to write to a log file periodically and when run from the command line as root (or sudo) it creates / writes to the log file perfectly.
The log file is in /var/log/app-name/app-name.log (where app-name is the name of my app).
It first checks to see if the folder exists and if not then create it. It then opens the log file for create/append and outputs to it.
However, when I start the app from rc.local the app still does everything else perfectly, reading remote telnet servers, reads / writes to a local mysql database etc, but it never creates the /var/log folder or writes to the log file, even if it already exits (the fopen returns a 0).
I'm sure it's going to be something really simple, but I can't put my finger on it.
I've tried setuid etc and nothing has worked.
Any ideas?
Testing & creating the folder for the log goes like this. This works if run from the command line but failes when run from rc.local
void checkVarLogDir()
{
struct stat st = {0};
if (stat("/var/log/phone_log", &st) == -1)
{
mkdir("/var/log/phone_log", 0744);
}
}
Running from rc.local looking like this:
/path-to-app/phlog &
I could add the fopen/fwrite/fclose here as well but it's simple stuff that works when not run from rc.local.