Hi!

Now when I know how to take the DCD status (thanx to Glynn Clements) I can
write my super-reconnect script started by crond every 5 mins.

I would like to hear your wise comments

the script is

#!/bin/sh

# is the line OK?
#
if [ -e /var/lock/LCK..cua1 ]                   
then
  exit 0
fi

# not reentrant!
#
if [ ! -z `pidof modemtest`] 
then
  exit 0
fi

echo "Connecion failed...Reconnecting" `date +"%a %D %T"`

# sleep until DCD is high
#
/usr/local/sbin/modemtest /dev/cua1             

# do the connection
#
pppd /dev/cua1 115200 defaultroute crtscts lock 

echo "Connection reestablished" `date +%T`      


Where 'modemtest' is as simple as

#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <syslog.h>


#define SLEEP_INTERVAL  3
#define DCD_HIGH        1
#define DCD_LOW         0

extern char* program_invocation_short_name;

int TestDCD(int);

int main(int argc,char** argv)
{
  int fd;
  
  openlog(program_invocation_short_name,0,LOG_DAEMON);  
  
  if (-1 == (fd = open(argv[1],O_RDWR)))
    {
      syslog(LOG_ERR,"Canot open %s\n",argv[1]);
      exit(1);
    };

  while(TestDCD(fd) == DCD_LOW)
    sleep(SLEEP_INTERVAL);
    
  closelog();
        
  return 0;
}



/* reads the DCD state and return 1 (high) or 0 (low) */

int TestDCD(int nDevice)
{
  int nStatus;
  
  if (ioctl(nDevice,TIOCMGET,&nStatus) == -1)
    {
      syslog(LOG_ERR,"ioctl error!\n");
      exit(1);
    }
  else
    return nStatus & TIOCM_CD;   
}


Is there a better/simple/more reliable/etc  approach?

Thanx for your help!

        Marin

          -= Why do we need gates in a world without fences? =-

Reply via email to