For all you C gurus out there. I'm working on a little program that when an event occurs, it dials out a Verizon Wireless AirCard, does it's thing and then when all events are done, the last event close the card. To close the ppp connection you send it a Ctrl-C, which I'm doing, however it is never working. The code I'm using is as follows: void *sound_alarm ( void * rd_struct ) { RADSPY_STRUCT *ptr_rd_struct; ptr_rd_struct = ( RADSPY_STRUCT * ) rd_struct; /* lock the modem_in_use variable to check to dial modem */ pthread_mutex_lock ( &modem_mutex ); if ( modem_in_use++ == 0 ) { /* we need to dial out the modem */ printf ( "Dialing the modem: %d\n", modem_in_use ); modem_pid = fork(); if ( 0 == modem_pid ) { int ret; /* we are the child so dial out the modem */ ret = execl ( "/usr/sbin/pppd", "pppd", "call", "ac555qnc", NULL ); if ( -1 == ret ) printf ( "Problem dialing modem: %s\n", strerror ( errno ) ); printf ( "Got here.\n" ); exit ( 0 ); } /* hack to wait enough time to let the modem dial */ sleep ( 10 ); } pthread_mutex_unlock ( &modem_mutex ); /* perform the sending of the data */ printf ( "Sounding the alarm: %d.\n", modem_in_use ); sleep ( 1 ); /* code to send away alarms will go here, sleep for now */ /* release the modem in use */ pthread_mutex_lock ( &modem_mutex ); if ( --modem_in_use == 0 ) { /* we need to hangup the modem */ printf ("Hanging up the modem: %d\n", modem_in_use ); kill ( SIGINT, modem_pid ); } pthread_mutex_unlock ( &modem_mutex ); pthread_exit ( (void *) 0 ); } This function is a thread that is spawned by the main loop when an event occurs. This event can occur multiple times, which is why I have the shared variable of how many events are currently occuring (modem_in_use). When I run this program, I'm always getting an error about the modem being locked by pid XXX, so it's never being closed. Anyone have any experience with this kinda thing? Chuck -- Chuck Haines chaines@gmail.com ------------------------------------------- Tau Kappa Epsilon Fraternity WPI Class of 2005 ------------------------------------------- AIM: CyberGrex YIM: CyberGrex_27 ICQ: 3707881 -------------------------------------------
On Wed, 11 Aug 2004 09:43:56 -0400, Chuck Haines <chaines@gmail.com> wrote:
For all you C gurus out there. I'm working on a little program that when an event occurs, it dials out a Verizon Wireless AirCard, does it's thing and then when all events are done, the last event close the card. To close the ppp connection you send it a Ctrl-C, which I'm doing, however it is never working. The code I'm using is as follows:
void *sound_alarm ( void * rd_struct ) { RADSPY_STRUCT *ptr_rd_struct; ptr_rd_struct = ( RADSPY_STRUCT * ) rd_struct; /* lock the modem_in_use variable to check to dial modem */ pthread_mutex_lock ( &modem_mutex ); if ( modem_in_use++ == 0 ) { /* we need to dial out the modem */ printf ( "Dialing the modem: %d\n", modem_in_use ); modem_pid = fork(); if ( 0 == modem_pid ) { int ret; /* we are the child so dial out the modem */ ret = execl ( "/usr/sbin/pppd", "pppd", "call", "ac555qnc", NULL ); if ( -1 == ret ) printf ( "Problem dialing modem: %s\n", strerror ( errno ) ); printf ( "Got here.\n" ); exit ( 0 ); } /* hack to wait enough time to let the modem dial */ sleep ( 10 ); } pthread_mutex_unlock ( &modem_mutex ); /* perform the sending of the data */ printf ( "Sounding the alarm: %d.\n", modem_in_use ); sleep ( 1 ); /* code to send away alarms will go here, sleep for now */ /* release the modem in use */ pthread_mutex_lock ( &modem_mutex ); if ( --modem_in_use == 0 ) { /* we need to hangup the modem */ printf ("Hanging up the modem: %d\n", modem_in_use ); kill ( SIGINT, modem_pid ); } pthread_mutex_unlock ( &modem_mutex );
pthread_exit ( (void *) 0 ); }
This function is a thread that is spawned by the main loop when an event occurs. This event can occur multiple times, which is why I have the shared variable of how many events are currently occuring (modem_in_use). When I run this program, I'm always getting an error about the modem being locked by pid XXX, so it's never being closed. Anyone have any experience with this kinda thing?
Chuck
-- Chuck Haines chaines@gmail.com ------------------------------------------- Tau Kappa Epsilon Fraternity WPI Class of 2005 ------------------------------------------- AIM: CyberGrex YIM: CyberGrex_27 ICQ: 3707881 ------------------------------------------- _______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
What does the parent process look like? How do you spawn the child? If I remember correctly you need to either do a pthread_join() or detach the child from the parent using pthread_attr_init() before spawning the thread to completely clean up the child thread. Thanks Brian
participants (2)
-
Brian Waite
-
Chuck Haines