I have a c++ program that runs on the RPi 3 with a GPRS hat (SIM808) with is connected via UART. Currently I establish my connection with sudo pon <isp-name> and disconnect sudo poff <isp-name>. All of this works as expected.
Because the SIM808 have GPS as well which I use, I want to control the connect and disconnect from my application, which work as well by doing a fork(), but I found that in some instances the application falls over for no reason.
Is there a way for me to establish a pppd connection from code by including header files and calling a method instead of forking the process?
Update
This is my function that I use to do my forking
bool DoFork(const char *method, const char *param1, const char *param2 = NULL, const char *param3 = NULL, const char *SuccessMsg = "Success", const char *ErrorMsg = "Error")
{
pid_t forkid = fork();
int status;
SetLastUsedCommand("DoFork");
switch (forkid) {
case -1:
LogEntry(LOG_CRIT, "Unable to make fork\n");
break;
case 0:
{
int res = execl(method, method, param1, param2, param3, NULL);
LogEntry(LOG_NOTICE, ErrorMsg, res); //"GSM not started. %d\n"
break;
}
default:
fflush(NULL);
if (waitpid(forkid, &status, 0) != -1)
{
if ((status & 0xff00) == 0)
{
sleep(2);
return true;
}
else
return false;
}
break;
}
return false;
}
I then call it like
res = DoFork("/usr/bin/sudo", "pon", "fona", NULL, "GSM Connection Made\n", "GSM not started. %d\n");
I think my problem is that I have threads that is running as well in my application, and the threads is what cause the segmentation problem