Click to See Complete Forum and Search --> : Pppd does not wait for the chat script to finish


ruchika
08-27-2003, 05:29 PM
Hi,

I was going through the pppd man pages and it mentioned the following -

"PPPd invokes scripts at various stages in its processing which can be used to perform site-specific ancillary processing. These scripts are ususally shell scripts, but could be executable files instead. Pppd does not wait for the scripts to finish. The scripts are executed as root, so that they can do things such as update routing tables or run privileged deamons."

My questions is - if pppd does not wait for the script to finish how does it know if the script executed/terminated propely or not. More specifically, pppd runs the chat script, now how would pppd know the exit code of chat script if it does not wait for the chat script to finish?

I have a C function that starts the script as follows.
int ret = system("./ppp-on")
printf("%d", WEXITSTATUS(ret));

The ppp-on script looks as follows (only relevant portions have been posted) -

exec /usr/sbin/pppd /dev/ttyS0 115200 persist idle 3600 usepeerdns debug lock modem crtscts noauth bsdcomp 0 deflate 0 kdebug 0 asyncmap 0 connect $DIALER_SCRIPT

The DIALER_SCRIPT looks as follows -

exec /usr/sbin/chat -v
ABORT 'NOCARRIER'
ABORT 'RING'
'' AT
OK ATD$PHONE
TIMEOUT 15
CONNECT ''

The system() call returns immedialtely and prints '0' irrespective of whether the chat script establishes the connection successfully or not. Am I missing something here? I want the C function to know chat was able to establish the connection succesfully or not. How can I do this if pppd returns immedialetly without waiting for chat script to finish?

Any pointers will be highly appreciated.

Thanks.

bwkaz
08-27-2003, 06:46 PM
Get rid of all the "exec"s.

When you put exec into a shell script, the shell will delete itself from memory when running that command. So the rest of the shell script will never execute.

ruchika
08-27-2003, 07:17 PM
Thanks for the help bwkaz.

I removed "exec" from the script but still pppd returns 0 and doesn't wait for the chat script to finish.

Even with exec in the script, both the ppp-on script and the chat script were running. From the logs I could see that the modem being initilaized and the connection being established by the chat script. The problem is that I want to return the status of chat script - SUCCESS/FAILURE - to be returned to the calling program.

Ruchika

bwkaz
08-27-2003, 10:30 PM
Oh, sorry, I didn't see that that was all on one line (the first script, at least).

If they are truly both shell scripts (I'm sure that ppp-on is, but I don't know about the other; that doesn't look like shell to me...), then you can do an exit $? after running a program, to return the exit status of that program. $? expands to "the exit status of the last program that was run", and so that command would take that exit status and relay it...

It is also a possibility that Perl's "system" function doesn't work like C's "system" function, though I don't know if that's actually the case or not. If Perl's system() just forks and runs the program in the child process, not waiting in the parent for the child to exit, then this is entirely possible.

But don't take my word for it; I've done almost no Perl ever...

Oh, and I've just reread all of your first post. This sounds exactly like what pppd does -- it fork()s, runs the script in the child process, and doesn't wait for it to exit in the parent. As for "how does it know whether it was successful or not?", well, it doesn't. Apparently it doesn't care.

It's also possible that pppd installs a signal handler for SIGCHLD (a signal that's sent whenever a child process exits). It can extract the return status in that signal handler if it really needs to know it. But for you to get that, you'd need to change pppd's source...