0

I have a C++ program which is called at startup via a cronjob (in crontab):

@reboot sudo /home/pi/CAN/RCR_datalogging/logfileControl

Which does run logfileControl anytime the Pi is booted as it shows up in the list of running programs (ps -e). LogfileControl contains two system calls to C++ programs related to SocketCAN (SocketCAN is part of the Linux Kernel, it allows for dealing with CAN data as network sockets). I want logfileControl to run on startup so that it can initialize the CAN socket (system call 1) and then start the first logfile (systemcall 2, candumpExternal, this is candump from socketCAN with a minor modification to make the logfile a specific location rather than just where candump is, but using the original version had the same issue). The first systemcall seems to be working properly as if I try and initialize the socket again it is busy, but the second systemcall doesn't appear to be happening as a logfile is not created at all as a logfile is not created. If I manually run logfileControl from the command line it works as expected and creates the logfile which has left me quite confused...

Does anyone have an insight as to what is going on here?

system("sudo /sbin/ip link set can0 up type can bitrate 500000"); 
                                  // This is ran initially as logging should start as soon as the pi is on
system("/home/pi/CAN/RCR_datalogging/candumpExternal can0 -l -s 0"); // candump with the option to log(-l) as well as 
                                  // continue to output to console (-s 0)

std::cout <<"Setup Complete" << std:: endl;

while(true) { //sleeping indefinitely so that the program can stay open and wait for button presses
    sleep(60);
}

Edit: I also tried adding a simple 5 second pause at the beginning of the program, but this didn't seem to make any difference.

  • It could any number of many reasons for something like this. Try redirecting standard error to a log file, see if anything comes out. Or, run everything under strace and see exactly what's going on. – Sam Varshavchik Jan 02 '19 at 02:07
  • Thanks for the good suggestion - I redirected stderr to a logfile based on [this post](https://stackoverflow.com/questions/7400418/writing-a-log-file-in-c-c) and it seems that the logfile wasn't generated when it was ran on startup but is created fine when ran normally - all i did was add the following two lines before the system calls: std::freopen("logfileError.txt", "w", stderr); std::cerr << "Error message" << std::endl; – Jacob Bernard Jan 02 '19 at 23:12

0 Answers0