+#define WANT_DECLARATIONS 1
#include "config.h"
#ifndef lint
static char rcsid[] ATTR_UNUSED = "$Id$";
#include "getopt.h"
#endif
+
+/* Always override possible system defintions as it is safe (used by glib) */
+#undef MAX
+#define MAX(a,b) ((a)>(b)?(a):(b))
+#undef MIN
+#define MIN(a,b) ((a)<(b)?(a):(b))
+
#define NELEM(x) (sizeof((x))/sizeof(*(x)))
#ifndef DEBUG
readbody++;
break;
case 'v':
+#ifndef DEBUG /* prevent suppositious overflow */
verbose++;
+#endif
break;
case 'V':
fprintf(stderr,version);
error(_("Error closing lockfile \"%s\""),lockreal);
}
-static inline int lockdevice(int attempt)
+static int lockdevice(int attempt)
{
int fd=-1;
char buf[64];
static char *catchdata;
static size_t catchdatal,catchdatasiz;
-static char *reform(const char *s,int slot);
+static const char *reform(const char *s,int slot);
static void catched(const char *end,char edata)
{
size_t len;
if (verbose>=2) error(_(".Retrying phase, %d out of %ld.."),retrycnt,maxretryn);
}
-static char *reform(const char *s,int slot)
+static const char *reform(const char *s,int slot)
{
static struct formslot {
char *s;
static char *check_format(const char *fmt,const char *string)
{
static char err[LINE_MAX],sub[50];
-char *subp,cf,cs;
-const char *sf,*ss;
+char cf,cs;
+const char *sf,*ss,*subp;
for (sf=fmt,ss=string;(cf=*sf) && (cs=*ss);sf++,ss++) {
subp=NULL;
memset(&tm,0,sizeof(tm)); /* may be redundant */
for (i=0;i<NELEM(timeparse);i++)
GETTIME(i)=DIGIT2ASC(s+timeparse[i].strpos);
- if (tm.tm_year<70) tm.tm_year+=100;
- tm.tm_mon--;
maketime(s+2);
return(1);
#undef DIGIT2ASC
int status;
pid_t pid;
+ signal(SIGCHLD,(RETSIGTYPE (*)(int))signal_chld);
+ /* we don't care about siginterrupt(3) as it doesn't matter how it is set */
+
d2("signal_chld: signo=%d\n",signo);
while (0<(pid=waitpid(-1 /* ANY process */,&status,WNOHANG /* options */))) {
if (verbose>=2)
FILE *f;
d2("receive_text: %s\n",bodyline);
- signal(SIGCHLD,signal_chld);
+ signal(SIGCHLD,(RETSIGTYPE (*)(int))signal_chld);
#if RECEIVE_TEST
pid=0;
#else
if ((end-=start)>LOCKREPORT)
logmsg(_("Device lock succeeded after %ld seconds"),(long)end);
}
+
+retryopen:
+
if (verbose>=1) error(_(".Opening device \"%s\".."),device);
if ((devfd=open(device,O_RDWR|O_NDELAY))<0)
error(_("^!Cannot open device \"%s\" for r/w access"),device);
- if (tcgetattr(devfd,&restios))
- error(_("^Unable to get termios settings"));
- else {
- restios.c_cflag=(restios.c_cflag&~(CBAUD|CBAUDEX))|B0|HUPCL;
- restios_yes=1;
- }
- tios.c_iflag=IGNBRK|IGNPAR|(handshake_rtscts ? 0 : IXON|IXOFF);
- tios.c_oflag=0;
- tios.c_cflag=CS8|CREAD|CLOCAL|HUPCL|portbaud|(handshake_rtscts ? CRTSCTS : 0);
- tios.c_lflag=IEXTEN|NOFLSH;
- memset(tios.c_cc,_POSIX_VDISABLE,sizeof(tios.c_cc));
- tios.c_cc[VTIME]=0;
- tios.c_cc[VMIN ]=1;
- cfsetispeed(&tios,portbaud);
- if (cfsetospeed(&tios,portbaud)|cfsetispeed(&tios,portbaud))
- error(_("^Error setting termios baudrate on device"));
- if (tcflush(devfd,TCIOFLUSH))
- error(_("^Error flushing termios (TCIOFLUSH) on device"));
- if (tcsetattr(devfd,TCSANOW,&tios))
- error(_("^!Unable to set initial termios device settings"));
+retryall:
- setalarm();
+ if (tcgetattr(devfd,&restios))
+ error(_("^Unable to get termios settings"));
+ else {
+ restios.c_cflag=(restios.c_cflag&~(CBAUD|CBAUDEX))|B0|HUPCL;
+ restios_yes=1;
+ }
+ tios.c_iflag=IGNBRK|IGNPAR|(handshake_rtscts ? 0 : IXON|IXOFF);
+ tios.c_oflag=0;
+ tios.c_cflag=CS8|CREAD|CLOCAL|HUPCL|portbaud|(handshake_rtscts ? CRTSCTS : 0);
+ tios.c_lflag=IEXTEN|NOFLSH;
+ memset(tios.c_cc,_POSIX_VDISABLE,sizeof(tios.c_cc));
+ tios.c_cc[VTIME]=0;
+ tios.c_cc[VMIN ]=1;
+ cfsetispeed(&tios,portbaud);
+ if (cfsetospeed(&tios,portbaud)|cfsetispeed(&tios,portbaud))
+ error(_("^Error setting termios baudrate on device"));
+ if (tcflush(devfd,TCIOFLUSH))
+ error(_("^Error flushing termios (TCIOFLUSH) on device"));
+ if (tcsetattr(devfd,TCSANOW,&tios))
+ error(_("^!Unable to set initial termios device settings"));
+
+ setalarm();
-retryall:
devcmd("",NULL,"\r\nAT\033\032"); /* ESCAPE, CTRL-Z */
devcmd(NULL,NULL,"\r\nAT");
smscset();
if (!lockdevice(1)) {
if (verbose>=1)
error(_(".Dialout detected, waiting for lock.."));
+ if (verbose>=1) error(_(".Closing device \"%s\".."),device);
+ if (close(devfd))
+ error(_("Error closing device \"%s\""),device);
lockdevice(0);
- goto retryall;
+ goto retryopen;
}
d1("Lock-device succeeded\n");
do {