Skip to content
Advertisement

Calling pppd within C program blocks the thread

I have a script which I call from within the C program. I do this before I start the threads as I need the ppp link up before these threads start. I do the below:

int main(){
    int ret = 0;
    ret = WEXITSTATUS(system("./nbiot_telit_ppp_installer.sh"));
    printf("ret = %drn", ret);

    // Never gets here after ppp is up
    /* Start the threads */
    ==> starts thread-1
    ==> starts thread-2
}

I tried calling the script within a thread-1 like below:

void *thread1(void *thPtr)
{
    int ret = 0;
    ret = WEXITSTATUS(system("./nbiot_telit_ppp_installer.sh"));
    printf("ret = %drn", ret);

    // Never gets here after ppp is up
    /* Some aws init code */

    while(1){
    }
} 

On the success of the script, I get below:

  Script /etc/ppp/ip-up started (pid 7771)
  Script /etc/ppp/ip-up finished (pid 7771), status = 0x0

After the above, no code beyond or under it is executed. It returns only if the script is terminated.

Irrespective to ppp link success or failure, I’d like to get the “status” value in my c code and make decisions based on this. I have experience working on bare metal but fairly new to Linux. And would be great to get some insights on this issue from experts and suggestions on how to achieve this.

Advertisement

Answer

When ppp links comes up, it executes a file /etc/ppp/ip-up When it goes down, it executes /etc/ppp/ip-down. If you put something in these files, you can use that as a flag.

My ip-up file:

#!/bin/sh
echo ppp is up > /var/run/ppp-up-flag

My ip-down file:

#!/bin/sh
rm /var/run/ppp-up-flag

Now my program can test for /var/run/ppp-up-flag.

Detect ppp link thread

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement