diff --git a/ChangeLog b/ChangeLog index 82cc984f..6105863a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,16 +8,33 @@ v0.39.7 14-Jan-2004 that mbtask didn't exist. It is possible that something is broken now, please report such situations. + general: + In all sources replaced the usleep function with the msleep + function. The usleep function will become obsolete someday. + libcommon.a: In execute and execsh on Linux systems sync() is called before and after running the external program to make sure diskbuffers are committed. + Added a milliseconds timer. + Before and after execute and execsh a 100 ms pause is inserted + to prevent (un)archiver and other errors. mbcico: Removed the check to disable calling points. Added a check to see if we get a URL to call other systems. If nodelist info fails, increase error counter in steps of 10. Merged tmail patches from Przemyslaw Kwiatkowski. + Fixed nodelocks during session handshake after many years. The + problem showed only when mbcico was used together with a mailer + on a different OS. When a aka is busy, the aka is now dropped. + When all akas are busy, a session is impossible and the session + is refused. Thanks to Przemyslaw Kwiatkowski for finding and + documenting this bug. + The total session avg cps is now corrected with the two seconds + session close delay time. + During binkp handshake increased the timer of the receiver to + avoid handshake timeouts. mbfido: Removed sync calls that are now in execute. diff --git a/TODO b/TODO index be698b79..4e4d564b 100644 --- a/TODO +++ b/TODO @@ -121,7 +121,9 @@ mbcico: U: Fix binkp file resume when mbcico silently dies. Check with the new driver. - U: Check node locking results for EMSI, YooHoo and FTS-0001 sessions. + L: Implement binkp option ND. + + L: Implement binkp zlib compression. mbfile: L: Add a check to see if the magic filenames are (still) valid. diff --git a/html/misc/usleep.html b/html/misc/usleep.html index 3d7b05a6..936ba1c6 100644 --- a/html/misc/usleep.html +++ b/html/misc/usleep.html @@ -13,51 +13,58 @@ -
-		usleep.doc
-
+
+
Last update 23-Jan-2004
+

System load and the usleep() call.

At some time when developping MBSE BBS I decided that background utilities did't need full speed to do their jobs. BBS utilities under DOS needed to run as fast as possible because you needed to bring the bbs down to run these programs and users couldn't login during that time. - +

Starting with mball, the allfiles creator, I inserted code that does usleep(1) after each 5 processed files. The 1 microsecond is not really the time the program pauses, it's probably a lot longer. I think this depends on the hardware type, (Intel, Sparc, Alpha etc) how long GNU/Linux will really suspends executing the utility. - +

The program speed downgrade at the development machine that mball needed was 3 times the original exection time, while system loading stayed under 30%. At that time the development machine is an 486DX2-66 with a Seagate ST32151N SCSI harddisk. - +

The extra usleep code is only active if you run these utils with the -quiet switch and when this is set in mbsetup. See menu 1->5. With this switch, the program is mostly run by cron. If you onmit this switch, this is probably when you start the program manually, it will then always run at full speed, no matter what the setting in mbsetup is. - +

If you have a fast system or don't care that the performance of your system drops because of background processing, you can turn this future off with mbsetup in the global section. (menu 1->5). - +

Remember, if you have a PII-400 MMX or so with IDE disks, you may still have performance problems and need to set that switch to yes. There is only one way to find out if you need it. - +

Well, actually, I tested this on a Dell Latitude PII-266, setting the switch to yes gave better performance then no. Why? The CPU has more time for the slow IDE disk. With the slow switch on programs runs even faster then with the switch -off. - +off. Modern hardware (PIII and later) may run fine with the slow switch turned +off. +

+In januari 2004 the usleep code is replaced by a milliseconds timer written +around the nanosleep system call. This call conforms to POSIX.1b and is written +so that if the timer is interrupted it will resume with the time left to do. +The real minimum time the timer runs is 10 ms on Intel systems, see also man +nanosleep All usleep(1) calls are now msleep(1) calls, in practice these are +pauses of 10 ms. +

Michiel. - -

+

BackGo Back - + diff --git a/lib/Makefile b/lib/Makefile index e6019730..6173b422 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -40,7 +40,7 @@ OBJS = ${CLCOMM_OBJS} ${COMMON_OBJS} ${DBASE_OBJS} ${MSGBASE_OBJS} ${MBINET_OBJ ${DIESEL_OBJS} ${NODELIST_OBJS} HDRS = ${CLCOMM_HDRS} ${COMMON_HDRS} ${DBASE_HDRS} ${MSGBASE_HDRS} ${MBINET_HDRS} \ ${DIESEL_HDRS} ${NODELIST_HDRS} ${OTHER_HDRS} -OTHER = Makefile README ftscprod.007 mkprod.awk \ +OTHER = Makefile README ftscprod.008 mkprod.awk \ README.diesel README.macro Diesel.doc nodelist.conf TARGET = libclcomm.a libcommon.a libdbase.a libmsgbase.a libmbinet.a libdiesel.a \ libnodelist.a @@ -137,7 +137,7 @@ proglock.o: ../config.h ../lib/libs.h ../lib/structs.h ../lib/users.h ../lib/rec dostran.o: ../config.h libs.h structs.h users.h records.h common.h ftnmsg.o: ../config.h libs.h structs.h common.h clcomm.h mbfile.o: ../config.h libs.h structs.h clcomm.h common.h -nodelock.o: ../config.h libs.h structs.h clcomm.h common.h +nodelock.o: ../config.h libs.h structs.h users.h records.h clcomm.h common.h rawio.o: ../config.h libs.h structs.h common.h mberrors.h strcasestr.o: ../config.h libs.h execute.o: ../config.h libs.h structs.h clcomm.h mberrors.h common.h @@ -160,7 +160,7 @@ dbmsgs.o: ../config.h libs.h structs.h users.h records.h clcomm.h dbcfg.h dbmsgs dbnode.o: ../config.h libs.h structs.h common.h users.h records.h clcomm.h dbcfg.h dbnode.h dbtic.o: ../config.h libs.h structs.h users.h records.h clcomm.h dbcfg.h dbtic.h dbuser.o: ../config.h libs.h structs.h users.h records.h dbcfg.h dbuser.h -jammsg.o: ../config.h libs.h clcomm.h msgtext.h msg.h jam.h jammsg.h +jammsg.o: ../config.h libs.h clcomm.h msgtext.h structs.h common.h msg.h jam.h jammsg.h msg.o: ../config.h libs.h msgtext.h msg.h clcomm.h structs.h common.h jammsg.h msgtext.o: ../config.h libs.h msgtext.h msg.h nntp.o: ../config.h libs.h structs.h users.h records.h clcomm.h mbinet.h diff --git a/lib/common.h b/lib/common.h index d816cfe6..adad5322 100644 --- a/lib/common.h +++ b/lib/common.h @@ -512,6 +512,8 @@ void gpt_resettimers(void); /* Reset all timers */ int gpt_settimer(int, int); /* Set timer no to time */ int gpt_expired(int); /* Is timer expired */ int gpt_running(int); /* Is timer running */ +int msleep(int); /* Milliseconds timer */ + #endif diff --git a/lib/execute.c b/lib/execute.c index a4addcda..6b091f45 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -140,7 +140,9 @@ int execute(char *cmd, char *file, char *pkt, char *in, char *out, char *err) #ifdef __linux__ sync(); #endif + msleep(100); rc = _execute(cmd, file, pkt, in, out, err); + msleep(100); #ifdef __linux sync(); #endif @@ -215,7 +217,9 @@ int execsh(char *cmd, char *in, char *out, char *err) #ifdef __linux__ sync(); #endif + msleep(100); rc = _execsh(cmd, in, out, err); + msleep(100); #ifdef __linux__ sync(); #endif diff --git a/lib/jammsg.c b/lib/jammsg.c index 0e86b8f7..96c2ad84 100644 --- a/lib/jammsg.c +++ b/lib/jammsg.c @@ -10,7 +10,7 @@ * MBSE BBS and utilities. * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -38,10 +38,13 @@ #include "libs.h" #include "clcomm.h" #include "msgtext.h" +#include "structs.h" +#include "common.h" #include "msg.h" #include "jam.h" #include "jammsg.h" + #define MAX_TEXT 2048 int fdHdr = -1; @@ -400,7 +403,7 @@ int JAM_Lock(unsigned long ulTimeout) WriteError("JAM messagebase is locked by pid %d", fl.l_pid); return FALSE; } - usleep(250000); + msleep(250); Syslog('m', "JAM messagebase lock attempt %d", Tries); } diff --git a/lib/mbfile.c b/lib/mbfile.c index edfa2dc4..7725330c 100644 --- a/lib/mbfile.c +++ b/lib/mbfile.c @@ -4,7 +4,7 @@ * Purpose ...............: Basic File I/O * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -193,8 +193,6 @@ long file_crc(char *path, int slow) do { bread = fread(line, 1, 32768, fp); crc = upd_crc32(line, crc, bread); - if (slow) - usleep(1); Nopper(); // For large files on slow systems. } while (bread > 0); diff --git a/lib/msg.c b/lib/msg.c index 5d497af6..ee7741e7 100644 --- a/lib/msg.c +++ b/lib/msg.c @@ -381,7 +381,7 @@ int Msg_Link(char *Path, int do_quiet, int slow_util) i++; if (slow_util && do_quiet && ((i % 5) == 0)) - usleep(1); + msleep(1); if (((i % 10) == 0) && (!do_quiet)) { printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); @@ -414,7 +414,7 @@ int Msg_Link(char *Path, int do_quiet, int slow_util) } if (slow_util && do_quiet && ((i % 5) == 0)) - usleep(1); + msleep(1); if (((i % 10) == 0) && (!do_quiet)) { printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); diff --git a/lib/rawio.c b/lib/rawio.c index 72da3eb5..ffb1295d 100644 --- a/lib/rawio.c +++ b/lib/rawio.c @@ -4,7 +4,7 @@ * Purpose ...............: Raw I/O routines. * ***************************************************************************** - * Copyright (C) 1997-2001 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -238,7 +238,7 @@ int Waitchar(unsigned char *ch, int wtime) rc = read(ttyfd, ch, 1); if (rc == 1) return rc; - usleep(10000); + msleep(10); } return rc; } diff --git a/lib/timers.c b/lib/timers.c index 365de5df..b98f4760 100644 --- a/lib/timers.c +++ b/lib/timers.c @@ -4,7 +4,7 @@ * Purpose ...............: General Purpose Timers * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -127,3 +127,40 @@ int gpt_running(int tno) } + +/* + * Milliseconds timer, returns 0 on success. + */ +int msleep(int msecs) +{ + int rc; + struct timespec req, rem; + + rem.tv_sec = 0; + rem.tv_nsec = 0; + req.tv_sec = msecs / 1000; + req.tv_nsec = (msecs % 1000) * 1000000; + + while (TRUE) { + + rc = nanosleep(&req, &rem); + if (rc == 0) + break; + if ((errno == EINVAL) || (errno == EFAULT)) { + WriteError("$msleep(%d)", msecs); + break; + } + + /* + * Error was EINTR, run timer again to complete. + */ + req.tv_sec = rem.tv_sec; + req.tv_nsec = rem.tv_nsec; + rem.tv_sec = 0; + rem.tv_nsec = 0; + } + + return rc; +} + + diff --git a/mbcico/binkp.c b/mbcico/binkp.c index eaf0ea14..0a8d7326 100644 --- a/mbcico/binkp.c +++ b/mbcico/binkp.c @@ -306,7 +306,7 @@ SM_NAMES SM_EDECL faddr *primary; char *p, *q, *pwd; - int i, rc = 0, bufl, cmd, dupe, SendPass = FALSE; + int i, rc = 0, bufl, cmd, dupe, SendPass = FALSE, akas = 0; fa_list **tmp, *tmpa; faddr *fa, ra; @@ -409,22 +409,35 @@ SM_STATE(WaitAddr) } } free(p); - for (tmpa = remote; tmpa; tmpa = tmpa->next) { - Syslog('+', "Address : %s", ascfnode(tmpa->addr, 0x1f)); - if (nodelock(tmpa->addr, mypid)) { - binkp_send_command(MM_BSY, "Address %s locked", ascfnode(tmpa->addr, 0x1f)); - SM_ERROR; - } - /* - * With the loaded flag we prevent removing the noderecord - * when the remote presents us an address we don't know about. - */ - if (!Loaded) { - if (noderecord(tmpa->addr)) - Loaded = TRUE; + + tmp = &remote; + while (*tmp) { + if (nodelock((*tmp)->addr, mypid)) { + Syslog('+', "address : %s is locked, removed from aka list",ascfnode((*tmp)->addr,0x1f)); + tmpa=*tmp; + *tmp=(*tmp)->next; + free(tmpa); + } else { + /* + * With the loaded flag we prevent removing the noderecord + * when the remote presents us an address we don't know about. + */ + akas++; + Syslog('+', "address : %s",ascfnode((*tmp)->addr,0x1f)); + if (!Loaded) { + if (noderecord((*tmp)->addr)) + Loaded = TRUE; + } + tmp = &((*tmp)->next); } } + if (akas == 0) { + binkp_send_command(MM_BSY, "All aka's busy"); + Syslog('+', "Binkp: abort, all aka's are busy"); + SM_ERROR; + } + history.aka.zone = remote->addr->zone; history.aka.net = remote->addr->net; history.aka.node = remote->addr->node; @@ -578,7 +591,7 @@ SM_NAMES (char *)"Opts" SM_EDECL char *p, *q, *pw; - int i, rc, bufl, cmd, dupe, we_have_pwd = FALSE; + int i, rc, bufl, cmd, dupe, we_have_pwd = FALSE, akas = 0; fa_list **tmp, *tmpa; faddr *fa; @@ -666,23 +679,35 @@ SM_STATE(WaitAddr) SM_ERROR; } } - - for (tmpa = remote; tmpa; tmpa = tmpa->next) { - Syslog('+', "Address : %s", ascfnode(tmpa->addr, 0x1f)); - if (nodelock(tmpa->addr, mypid)) { - binkp_send_command(MM_BSY, "Address %s locked", ascfnode(tmpa->addr, 0x1f)); - SM_ERROR; - } - /* - * With the loaded flag we prevent removing the noderecord - * when the remote presents us an address we don't know about. - */ - if (!Loaded) { - if (noderecord(tmpa->addr)) - Loaded = TRUE; + + tmp = &remote; + while (*tmp) { + if (nodelock((*tmp)->addr, mypid)) { + Syslog('+', "address : %s is locked, removed from aka list",ascfnode((*tmp)->addr,0x1f)); + tmpa=*tmp; + *tmp=(*tmp)->next; + free(tmpa); + } else { + /* + * With the loaded flag we prevent removing the noderecord + * when the remote presents us an address we don't know about. + */ + akas++; + Syslog('+', "address : %s",ascfnode((*tmp)->addr,0x1f)); + if (!Loaded) { + if (noderecord((*tmp)->addr)) + Loaded = TRUE; + } + tmp = &((*tmp)->next); } } + if (akas == 0) { + binkp_send_command(MM_BSY, "All aka's busy"); + Syslog('+', "Binkp: abort, all aka's are busy"); + SM_ERROR; + } + for (tmpa = remote; tmpa; tmpa = tmpa->next) { if (((nlent = getnlent(tmpa->addr))) && (nlent->pflag != NL_DUMMY)) { Syslog('+', "Binkp: remote is a listed system"); @@ -874,7 +899,7 @@ int file_transfer(void) * Nothing done, release */ Syslog('b', "Binkp: NOTHING DONE"); - usleep(1); + msleep(1); break; case Receive: Trc = binkp_receiver(); @@ -1626,7 +1651,7 @@ int binkp_recv_command(char *buf, int *len, int *cmd) if (b0 & 0x80) *cmd = 1; - b1 = GETCHAR(1); + b1 = GETCHAR(BINKP_TIMEOUT / 2); if (tty_status) goto to; @@ -1725,7 +1750,7 @@ int binkp_poll_frame(void) if (c < 0) { c = -c; if (c == STAT_TIMEOUT) { - usleep(1); + msleep(1); rc = 0; break; } diff --git a/mbcico/chat.c b/mbcico/chat.c index 84af3c04..ff07d837 100644 --- a/mbcico/chat.c +++ b/mbcico/chat.c @@ -4,7 +4,7 @@ * Purpose ...............: Fidonet mailer - modem chat * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -104,7 +104,7 @@ int send_str(char *str, char *Phone) case 's': PUTCHAR(' '); *q++ = ' '; break; case ' ': PUTCHAR(' '); *q++ = ' '; break; case 'd': sleep(1); *q++ = '\\'; *q++ = 'd'; break; - case 'p': usleep(250000L); *q++ = '\\'; *q++ = 'p'; break; + case 'p': msleep(250); *q++ = '\\'; *q++ = 'p'; break; case 'D': if (Phone) { PUTSTR(Phone); sprintf(q, "%s", Phone); diff --git a/mbcico/emsi.c b/mbcico/emsi.c index 6485401a..fdf95970 100644 --- a/mbcico/emsi.c +++ b/mbcico/emsi.c @@ -4,7 +4,7 @@ * Purpose ...............: Fidonet mailer * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -70,7 +70,7 @@ int emsi_remote_opts; char *emsi_local_password = NULL; char *emsi_remote_password = NULL; char emsi_remote_comm[4]="8N1"; - +int emsi_akas = 0; int rx_emsi(char *data) @@ -448,6 +448,10 @@ SM_STATE(checkdat) Syslog('+', "Got EMSI_DAT packet \"%s\" with bad crc: %04x/%04x", printable(databuf, 0), lcrc, rcrc); SM_PROCEED(sendnak); } if (scanemsidat(databuf + 12) == 0) { + if (emsi_akas == 0) { + Syslog('+', "All akas busy, abort"); + SM_ERROR; + } SM_PROCEED(sendack); } else { Syslog('+', "Could not parse EMSI_DAT packet \"%s\"",databuf); diff --git a/mbcico/emsidat.c b/mbcico/emsidat.c index be066bec..ab1000cb 100644 --- a/mbcico/emsidat.c +++ b/mbcico/emsidat.c @@ -47,6 +47,7 @@ extern int Loaded; extern int mypid; +extern int emsi_akas; @@ -334,7 +335,7 @@ exit: int scanemsidat(char *buf) { - fa_list **tmp,*tmpa; + fa_list **tmp, *tmpa; faddr *fa; char *p, *q, *mailer_prod, *mailer_name, *mailer_version, *mailer_serial; int dupe; @@ -375,24 +376,35 @@ int scanemsidat(char *buf) } } - for (tmpa = remote; tmpa; tmpa = tmpa->next) { - Syslog('+', "address : %s",ascfnode(tmpa->addr,0x1f)); - (void)nodelock(tmpa->addr, mypid); - /* - * With the loaded flag we prevent removing the noderecord - * when the remote presents us an address we don't know about. - */ - if (!Loaded) { - if (noderecord(tmpa->addr)) - Loaded = TRUE; + tmp = &remote; + while (*tmp) { + if (nodelock((*tmp)->addr, mypid)) { + Syslog('+', "address : %s is locked, removed from aka list",ascfnode((*tmp)->addr,0x1f)); + tmpa=*tmp; + *tmp=(*tmp)->next; + free(tmpa); + } else { + /* + * With the loaded flag we prevent removing the noderecord + * when the remote presents us an address we don't know about. + */ + emsi_akas++; + Syslog('+', "address : %s",ascfnode((*tmp)->addr,0x1f)); + if (!Loaded) { + if (noderecord((*tmp)->addr)) + Loaded = TRUE; + } + tmp = &((*tmp)->next); } } - history.aka.zone = remote->addr->zone; - history.aka.net = remote->addr->net; - history.aka.node = remote->addr->node; - history.aka.point = remote->addr->point; - sprintf(history.aka.domain, "%s", remote->addr->domain); + if (emsi_akas) { /* Only if any aka's left */ + history.aka.zone = remote->addr->zone; + history.aka.net = remote->addr->net; + history.aka.node = remote->addr->node; + history.aka.point = remote->addr->point; + sprintf(history.aka.domain, "%s", remote->addr->domain); + } if (emsi_remote_password) free(emsi_remote_password); diff --git a/mbcico/ftsc.c b/mbcico/ftsc.c index 3be6ebd5..451f3051 100644 --- a/mbcico/ftsc.c +++ b/mbcico/ftsc.c @@ -4,7 +4,7 @@ * Purpose ...............: Fidonet mailer * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -116,95 +116,89 @@ int tx_ftsc(void) SM_DECL(txftsc,(char *)"txftsc") SM_STATES - wait_command, - recv_mail, - send_req, - recv_req + wait_command, + recv_mail, + send_req, + recv_req SM_NAMES - (char *)"wait_command", - (char *)"recv_mail", - (char *)"send_req", - (char *)"recv_req" + (char *)"wait_command", + (char *)"recv_mail", + (char *)"send_req", + (char *)"recv_req" SM_EDECL - int c,rc; - char *nonhold_mail; - int mailsent = FALSE, mailrcvd = FALSE; + int c,rc, mailsent = FALSE, mailrcvd = FALSE; + char *nonhold_mail; - nonhold_mail = (char *)ALL_MAIL; - tosend = create_filelist(remote,nonhold_mail,2); + nonhold_mail = (char *)ALL_MAIL; + tosend = create_filelist(remote,nonhold_mail,2); - Syslog('s', "txftsc SEND_MAIL"); - if ((rc = xmsndfiles(tosend))) - return rc; - mailsent = TRUE; + if ((rc = xmsndfiles(tosend))) + return rc; + mailsent = TRUE; SM_START(wait_command) SM_STATE(wait_command) - Syslog('s', "txftsc WAIT_COMMAND"); - c = GETCHAR(30); - if (c == TIMEOUT) { - Syslog('+', "timeout waiting for remote action, try receive"); - SM_PROCEED(recv_mail); - } else if (c < 0) { - if (mailrcvd && mailsent) { - /* - * Some systems hangup after sending mail, so if we did - * send and receive mail we consider the session OK. - */ - Syslog('+', "Lost carrier, FTS-0001 session looks complete"); - SM_SUCCESS; - } else { - Syslog('+', "got error waiting for TSYNC: received %d",c); - SM_ERROR; - } - } else switch (c) { - case TSYNC: SM_PROCEED(recv_mail); - break; - case SYN: SM_PROCEED(recv_req); - break; - case ENQ: SM_PROCEED(send_req); - break; - case 'C': - case NAK: PUTCHAR(EOT); - SM_PROCEED(wait_command); - break; - case CAN: SM_SUCCESS; /* this is not in BT */ - break; - default: Syslog('s', "got '%s' waiting command", printablec(c)); - PUTCHAR(SUB); - SM_PROCEED(wait_command); - break; + c = GETCHAR(30); + if (c == TIMEOUT) { + Syslog('+', "timeout waiting for remote action, try receive"); + SM_PROCEED(recv_mail); + } else if (c < 0) { + if (mailrcvd && mailsent) { + /* + * Some systems hangup after sending mail, so if we did + * send and receive mail we consider the session OK. + */ + Syslog('+', "Lost carrier, FTS-0001 session looks complete"); + SM_SUCCESS; + } else { + Syslog('+', "got error waiting for TSYNC: received %d",c); + SM_ERROR; } + } else switch (c) { + case TSYNC: SM_PROCEED(recv_mail); + break; + case SYN: SM_PROCEED(recv_req); + break; + case ENQ: SM_PROCEED(send_req); + break; + case 'C': + case NAK: PUTCHAR(EOT); + SM_PROCEED(wait_command); + break; + case CAN: SM_SUCCESS; /* this is not in BT */ + break; + default: Syslog('s', "got '%s' waiting command", printablec(c)); + PUTCHAR(SUB); + SM_PROCEED(wait_command); + break; + } SM_STATE(recv_mail) - Syslog('s', "txftsc RECV_MAIL"); - if (recvfiles()) { - SM_ERROR; - } else { - mailrcvd = TRUE; - SM_PROCEED(wait_command); - } + if (recvfiles()) { + SM_ERROR; + } else { + mailrcvd = TRUE; + SM_PROCEED(wait_command); + } SM_STATE(send_req) - Syslog('s', "txftsc SEND_BARK"); - if (sendbark()) { - SM_ERROR; - } else { - SM_SUCCESS; - } + if (sendbark()) { + SM_ERROR; + } else { + SM_SUCCESS; + } SM_STATE(recv_req) - Syslog('s', "txftsc RECV_BARK"); - if (recvbark()) { - SM_ERROR; - } else { - SM_PROCEED(wait_command); - } + if (recvbark()) { + SM_ERROR; + } else { + SM_PROCEED(wait_command); + } SM_END SM_RETURN @@ -213,148 +207,145 @@ SM_RETURN SM_DECL(rxftsc,(char *)"rxftsc") SM_STATES - recv_mail, - send_mail, - send_req, - recv_req + recv_mail, + send_mail, + send_req, + recv_req SM_NAMES - (char *)"recv_mail", - (char *)"send_mail", - (char *)"send_req", - (char *)"recv_req" + (char *)"recv_mail", + (char *)"send_mail", + (char *)"send_req", + (char *)"recv_req" SM_EDECL - int c, count = 0, didwazoo = FALSE; - int sentmail = FALSE, rcvdmail = FALSE; - file_list *request = NULL, *tmpfl; + int c, count = 0, didwazoo = FALSE, sentmail = FALSE, rcvdmail = FALSE; + file_list *request = NULL, *tmpfl; SM_START(recv_mail) SM_STATE(recv_mail) - Syslog('s', "rxftsc RECV_MAIL"); - if (recvfiles()) { - SM_ERROR; - } else { - rcvdmail = TRUE; - SM_PROCEED(send_mail); - } + if (recvfiles()) { + SM_ERROR; + } else { + rcvdmail = TRUE; + SM_PROCEED(send_mail); + } SM_STATE(send_mail) - Syslog('s', "rxftsc SEND_MAIL count=%d", count); - if (count++ > 45) { - SM_ERROR; - } + Syslog('x', "rxftsc SEND_MAIL count=%d", count); + if (count++ > 45) { + SM_ERROR; + } - /* - * If we got a wazoo request, add files now. - */ - request = respond_wazoo(); - if (request != NULL) { - didwazoo = TRUE; - tmpfl = tosend; - tosend = request; - for (; request->next; request = request->next); - request->next = tmpfl; + /* + * If we got a wazoo request, add files now. + */ + request = respond_wazoo(); + if (request != NULL) { + didwazoo = TRUE; + tmpfl = tosend; + tosend = request; + for (; request->next; request = request->next); + request->next = tmpfl; - request = NULL; - } + request = NULL; + } - if (tosend == NULL) { - count = 0; - SM_PROCEED(send_req); - } + if (tosend == NULL) { + count = 0; + SM_PROCEED(send_req); + } - PUTCHAR(TSYNC); - c = GETCHAR(1); - Syslog('x', "Got char 0x%02x", c); - if (c == TIMEOUT) { - Syslog('x', " timeout"); - SM_PROCEED(send_mail); - } else if (c < 0) { - Syslog('+', "got error waiting for NAK: received %d",c); - SM_ERROR; - } else switch (c) { - case 'C': - case NAK: if (xmsndfiles(tosend)) { - SM_ERROR; - } else { - sentmail = TRUE; - count = 0; - SM_PROCEED(send_req); - } - break; - case CAN: Syslog('+', "Remote refused to pickup mail"); - SM_SUCCESS; - break; - case EOT: PUTCHAR(ACK); - SM_PROCEED(send_mail); - break; - default: Syslog('s', "Got '%s' waiting NAK", printablec(c)); - SM_PROCEED(send_mail); - break; - } + PUTCHAR(TSYNC); + c = GETCHAR(1); + Syslog('x', "Got char 0x%02x", c); + if (c == TIMEOUT) { + Syslog('x', " timeout"); + SM_PROCEED(send_mail); + } else if (c < 0) { + Syslog('+', "got error waiting for NAK: received %d",c); + SM_ERROR; + } else switch (c) { + case 'C': + case NAK: if (xmsndfiles(tosend)) { + SM_ERROR; + } else { + sentmail = TRUE; + count = 0; + SM_PROCEED(send_req); + } + break; + case CAN: Syslog('+', "Remote refused to pickup mail"); + SM_SUCCESS; + break; + case EOT: PUTCHAR(ACK); + SM_PROCEED(send_mail); + break; + default: Syslog('s', "Got '%s' waiting NAK", printablec(c)); + SM_PROCEED(send_mail); + break; + } SM_STATE(send_req) - Syslog('s', "rxftsc SEND_REQ count=%d", count); + Syslog('x', "rxftsc SEND_REQ count=%d", count); - if (didwazoo) { - SM_SUCCESS; - } + if (didwazoo) { + SM_SUCCESS; + } - if (count > 15) { - SM_ERROR; - } + if (count > 15) { + SM_ERROR; + } - if (!made_request) { - SM_PROCEED(recv_req); - } + if (!made_request) { + SM_PROCEED(recv_req); + } - PUTCHAR(SYN); - c = GETCHAR(5); - Syslog('x', "Got char 0x%02x", c); - count++; - if (c == TIMEOUT) { - Syslog('x', " timeout"); - SM_PROCEED(send_req); - } else if (c < 0) { - Syslog('+', "got error waiting for ENQ: received %d",c); - SM_ERROR; - } else switch (c) { - case ENQ: if (sendbark()) { - SM_ERROR; - } else { - SM_PROCEED(recv_req); - } - break; - case CAN: Syslog('+', "Remote refused to accept request"); - SM_PROCEED(recv_req); - break; - case 'C': - case NAK: PUTCHAR(EOT); - SM_PROCEED(send_req); - break; - case SUB: SM_PROCEED(send_req); - break; - default: Syslog('s', "got '%s' waiting ENQ", printablec(c)); - SM_PROCEED(send_req); - break; - } + PUTCHAR(SYN); + c = GETCHAR(5); + Syslog('x', "Got char 0x%02x", c); + count++; + if (c == TIMEOUT) { + Syslog('x', " timeout"); + SM_PROCEED(send_req); + } else if (c < 0) { + Syslog('+', "got error waiting for ENQ: received %d",c); + SM_ERROR; + } else switch (c) { + case ENQ: if (sendbark()) { + SM_ERROR; + } else { + SM_PROCEED(recv_req); + } + break; + case CAN: Syslog('+', "Remote refused to accept request"); + SM_PROCEED(recv_req); + break; + case 'C': + case NAK: PUTCHAR(EOT); + SM_PROCEED(send_req); + break; + case SUB: SM_PROCEED(send_req); + break; + default: Syslog('s', "got '%s' waiting ENQ", printablec(c)); + SM_PROCEED(send_req); + break; + } SM_STATE(recv_req) - Syslog('s', "rxftsc RECV_REQ"); - if (recvbark()) { - if (sentmail && rcvdmail) { - Syslog('+', "Consider session OK"); - SM_SUCCESS; - } else { - SM_ERROR; - } + if (recvbark()) { + if (sentmail && rcvdmail) { + Syslog('+', "Consider session OK"); + SM_SUCCESS; } else { - SM_SUCCESS; + SM_ERROR; } + } else { + SM_SUCCESS; + } SM_END SM_RETURN @@ -420,8 +411,18 @@ SM_STATE(scan_packet) free(fpath); SM_ERROR; case 0: - case 5: Syslog('+', "accepting session"); - fclose(fp); + case 5: fclose(fp); + if (nodelock(&f, mypid)) { + /* + * Lock failed, FTSC-0001 allowes only one aka, so abort session. + */ + Syslog('+', "address : %s is locked, abort", ascfnode(&f, 0x1f)); + Syslog('s', "Unlink %s rc=%d", fpath, unlink(fpath)); + free(fpath); + SM_ERROR; + } + + Syslog('+', "accepting session"); for (tmpl = &remote; *tmpl; tmpl = &((*tmpl)->next)); (*tmpl)=(fa_list*)malloc(sizeof(fa_list)); (*tmpl)->next=NULL; @@ -432,12 +433,15 @@ SM_STATE(scan_packet) (*tmpl)->addr->point=f.point; (*tmpl)->addr->name=NULL; (*tmpl)->addr->domain=NULL; - for (tmpl=&remote;*tmpl;tmpl=&((*tmpl)->next)) { - (void)nodelock((*tmpl)->addr, mypid); - /* try lock all remotes, ignore locking result */ - if (!Loaded) - if (noderecord((*tmpl)->addr)) - Loaded = TRUE; + Syslog('+', "address : %s",ascfnode((*tmpl)->addr,0x1f)); + + /* + * With the loaded flag we prevent removing the noderecord + * when the remote presents us an address we don't know about. + */ + if (!Loaded) { + if (noderecord((*tmpl)->addr)) + Loaded = TRUE; } history.aka.zone = remote->addr->zone; diff --git a/mbcico/mbcico.c b/mbcico/mbcico.c index 77d84925..39d7e2d9 100644 --- a/mbcico/mbcico.c +++ b/mbcico/mbcico.c @@ -126,8 +126,8 @@ void die(int onsig) } if (sentbytes || rcvdbytes) { - total = (int)(c_end - c_start); - if (!total) + total = (int)(c_end - c_start -2); + if (total < 1) total = 1; Syslog('+', "Sent %lu bytes, received %lu bytes, avg %d cps", sentbytes, rcvdbytes, (sentbytes + rcvdbytes) / total); } diff --git a/mbcico/statetbl.h b/mbcico/statetbl.h index ea39b7da..9fb74155 100644 --- a/mbcico/statetbl.h +++ b/mbcico/statetbl.h @@ -19,7 +19,7 @@ int proc(void)\ #define SM_START(x) \ sm_state=x;\ - Syslog('S', "SM (%s): Start => %s", sm_name, sm_sname[sm_state]); \ + Syslog('s', "SM (%s): Start => %s", sm_name, sm_sname[sm_state]); \ while (!sm_success) switch (sm_state)\ {\ default: WriteError("Statemachine %s error: state=%d",sm_name,sm_state);\ @@ -38,16 +38,16 @@ int proc(void)\ #define SM_PROCEED(x) \ if (x != sm_state) {\ - Syslog('S', "SM (%s): %s => %s", sm_name, sm_sname[sm_state], sm_sname[x]);\ + Syslog('s', "SM (%s): %s => %s", sm_name, sm_sname[sm_state], sm_sname[x]);\ }\ sm_state=x; break; #define SM_SUCCESS \ - Syslog('S', "SM (%s): %s => Success", sm_name, sm_sname[sm_state]);\ + Syslog('s', "SM (%s): %s => Success", sm_name, sm_sname[sm_state]);\ sm_success=1; break; #define SM_ERROR \ - Syslog('S', "SM (%s): %s => Error", sm_name, sm_sname[sm_state]);\ + Syslog('s', "SM (%s): %s => Error", sm_name, sm_sname[sm_state]);\ sm_success=-1; break; #endif diff --git a/mbcico/yoohoo.c b/mbcico/yoohoo.c index 01998f1f..63ecc2e0 100644 --- a/mbcico/yoohoo.c +++ b/mbcico/yoohoo.c @@ -87,7 +87,9 @@ static int txyoohoo(void); static void fillhello(unsigned short,char*); static int checkhello(void); -static int iscaller; +static int y_akas; +static int iscaller; + static struct _hello { unsigned char data[128]; unsigned char crc[2]; @@ -129,6 +131,7 @@ int rx_yoohoo(void) char *pwd = NULL; pwd = NULL; + y_akas = 0; localcaps = LOCALCAPS; if (localoptions & NOZMODEM) localcaps &= ~(ZED_ZAPPER|ZED_ZIPPER); if (localoptions & NOZEDZAP) localcaps &= ~ZED_ZAPPER; @@ -139,6 +142,12 @@ int rx_yoohoo(void) if ((rc = rxyoohoo()) == 0) { Loaded = checkhello(); + + if (y_akas == 0) { + Syslog('+', "All akas busy, abort"); + return MBERR_SESSION_ERROR; + } + capabilities = hello2.capabilities; if (capabilities & WZ_FREQ) session_flags |= SESSION_WAZOO; @@ -226,6 +235,7 @@ int tx_yoohoo(void) unsigned short capabilities; char *pwd; + y_akas = 0; if (strlen(nodes.Spasswd)) pwd = xstrcpy(nodes.Spasswd); else @@ -256,6 +266,10 @@ int tx_yoohoo(void) session_flags &= ~SESSION_WAZOO; } + if (y_akas == 0) { + Syslog('+', "All akas busy, abort"); + return MBERR_SESSION_ERROR; + } if ((rc == 0) && ((capabilities & LOCALCAPS) == 0)) { Syslog('+', "No common protocols"); return MBERR_SESSION_ERROR; @@ -286,84 +300,78 @@ int tx_yoohoo(void) SM_DECL(rxyoohoo,(char *)"rxyoohoo") SM_STATES - sendenq, - waitchar, - getpacket, - sendnak, - sendack + sendenq, + waitchar, + getpacket, + sendnak, + sendack SM_NAMES - (char *)"sendenq", - (char *)"waitchar", - (char *)"getpacket", - (char *)"sendnak", - (char *)"sendack" + (char *)"sendenq", + (char *)"waitchar", + (char *)"getpacket", + (char *)"sendnak", + (char *)"sendack" SM_EDECL - int c; - int count=0; - unsigned short lcrc,rcrc; + int c, count=0; + unsigned short lcrc, rcrc; SM_START(sendenq) SM_STATE(sendenq) - Syslog('S', "rxyoohoo SENDENQ"); - if (count++ > 12) { - Syslog('+', "Too many tries to get hello packet"); - SM_ERROR; - } - PUTCHAR(ENQ); - SM_PROCEED(waitchar) + if (count++ > 12) { + Syslog('+', "Too many tries to get YooHoo hello packet"); + SM_ERROR; + } + PUTCHAR(ENQ); + SM_PROCEED(waitchar) SM_STATE(waitchar) - Syslog('S', "rxyoohoo WAITCHAR"); - c=GETCHAR(10); - if (c == TIMEOUT) { - SM_PROCEED(sendenq); - } else if (c < 0) { - SM_ERROR; - } else switch (c) { - case 0x1f: SM_PROCEED(getpacket); - break; - case YOOHOO: SM_PROCEED(sendenq); - break; - default: SM_PROCEED(waitchar); - break; - } + c=GETCHAR(10); + if (c == TIMEOUT) { + SM_PROCEED(sendenq); + } else if (c < 0) { + SM_ERROR; + } else switch (c) { + case 0x1f: SM_PROCEED(getpacket); + break; + case YOOHOO: SM_PROCEED(sendenq); + break; + default: SM_PROCEED(waitchar); + break; + } SM_STATE(getpacket) - Syslog('S', "rxyoohoo GETPACKET"); - GET((char*)&hello, sizeof(hello), 30); - if (STATUS) { - SM_ERROR; - } + GET((char*)&hello, sizeof(hello), 30); + if (STATUS) { + SM_ERROR; + } - lcrc = crc16xmodem((char*)hello.data, sizeof(hello.data)); - rcrc = (hello.crc[0] << 8) + hello.crc[1]; - if (lcrc != rcrc) { - Syslog('+',"crc does not match in hello packet: %04xh/%04xh", rcrc,lcrc); - SM_PROCEED(sendnak); - } else { - SM_PROCEED(sendack); - } + lcrc = crc16xmodem((char*)hello.data, sizeof(hello.data)); + rcrc = (hello.crc[0] << 8) + hello.crc[1]; + if (lcrc != rcrc) { + Syslog('+',"crc does not match in YooHoo hello packet: %04xh/%04xh", rcrc,lcrc); + SM_PROCEED(sendnak); + } else { + SM_PROCEED(sendack); + } SM_STATE(sendnak) - Syslog('S', "rxyoohoo SENDNAK"); - if (count++ > 9) { - Syslog('+', "Too many tries to get hello packet"); - SM_ERROR; - } - PUTCHAR('?'); - SM_PROCEED(waitchar); + if (count++ > 9) { + Syslog('+', "Too many tries to get YooHoo hello packet"); + SM_ERROR; + } + PUTCHAR('?'); + SM_PROCEED(waitchar); SM_STATE(sendack) - Syslog('S', "rxyoohoo SENDACK"); - PUTCHAR(ACK); - SM_SUCCESS; + PUTCHAR(ACK); + SM_SUCCESS; SM_END SM_RETURN @@ -372,268 +380,269 @@ SM_RETURN SM_DECL(txyoohoo,(char *)"txyoohoo") SM_STATES - sendyoohoo, - waitenq, - sendpkt, - waitchar + sendyoohoo, + waitenq, + sendpkt, + waitchar SM_NAMES - (char *)"sendyoohoo", - (char *)"waitenq", - (char *)"sendpkt", - (char *)"waitchar" + (char *)"sendyoohoo", + (char *)"waitenq", + (char *)"sendpkt", + (char *)"waitchar" SM_EDECL - int c; - int count=0; - int startstate; - unsigned short lcrc; + int c, count = 0, startstate; + unsigned short lcrc; - if (iscaller) - startstate = sendpkt; - else - startstate = sendyoohoo; + if (iscaller) + startstate = sendpkt; + else + startstate = sendyoohoo; - lcrc = crc16xmodem((char*)hello.data, sizeof(hello.data)); - hello.crc[0] = lcrc >> 8; - hello.crc[1] = lcrc & 0xff; - Syslog('S', "txyoohoo INIT"); + lcrc = crc16xmodem((char*)hello.data, sizeof(hello.data)); + hello.crc[0] = lcrc >> 8; + hello.crc[1] = lcrc & 0xff; SM_START(startstate) SM_STATE(sendyoohoo) - Syslog('S', "txyoohoo SENDYOOHOO"); - PUTCHAR(YOOHOO); - SM_PROCEED(waitenq); + PUTCHAR(YOOHOO); + SM_PROCEED(waitenq); SM_STATE(waitenq) - Syslog('S', "txyoohoo WAITENQ"); - c=GETCHAR(10); - if (c == TIMEOUT) { - if (count++ > 9) { - Syslog('+', "Timeout waiting ENQ"); - SM_ERROR; - } else { - SM_PROCEED(sendyoohoo); - } - } else if (c < 0) { - SM_ERROR; - } else switch (c) { - case ENQ: SM_PROCEED(sendpkt); - case YOOHOO: SM_PROCEED(waitenq); - default: Syslog('+',"Got '%s' waiting hello ACK", printablec(c)); - SM_PROCEED(waitchar); - break; + c=GETCHAR(10); + if (c == TIMEOUT) { + if (count++ > 9) { + Syslog('+', "Timeout waiting ENQ"); + SM_ERROR; + } else { + SM_PROCEED(sendyoohoo); } + } else if (c < 0) { + SM_ERROR; + } else switch (c) { + case ENQ: SM_PROCEED(sendpkt); + case YOOHOO: SM_PROCEED(waitenq); + default: Syslog('+',"Got '%s' waiting hello ACK", printablec(c)); + SM_PROCEED(waitchar); + break; + } SM_STATE(sendpkt) - Syslog('S', "txyoohoo SENDPKT"); - if (count++ > 9) { - Syslog('+', "Too many tries to send hello packet"); - SM_ERROR; - } + if (count++ > 9) { + Syslog('+', "Too many tries to send YooHoo hello packet"); + SM_ERROR; + } - PUTCHAR(0x1f); - PUT((char*)&hello, sizeof(hello)); - if (STATUS) { - SM_ERROR; - } - SM_PROCEED(waitchar); + PUTCHAR(0x1f); + PUT((char*)&hello, sizeof(hello)); + if (STATUS) { + SM_ERROR; + } + SM_PROCEED(waitchar); SM_STATE(waitchar) - Syslog('S', "txyoohoo WAITCHAR"); - c=GETCHAR(30); - if (c == TIMEOUT) { - Syslog('+', "Timeout waiting hello ACK"); - SM_ERROR; - } else if (c < 0) { - SM_ERROR; - } else switch (c) { - case ACK: Syslog('S', "Handshake successfull"); - SM_SUCCESS; - break; - case '?': SM_PROCEED(sendpkt); - break; - case ENQ: SM_PROCEED(sendpkt); - break; - default: SM_PROCEED(waitchar); - break; - } + c=GETCHAR(30); + if (c == TIMEOUT) { + Syslog('+', "Timeout waiting hello ACK"); + SM_ERROR; + } else if (c < 0) { + SM_ERROR; + } else switch (c) { + case ACK: SM_SUCCESS; + break; + case '?': SM_PROCEED(sendpkt); + break; + case ENQ: SM_PROCEED(sendpkt); + break; + default: SM_PROCEED(waitchar); + break; + } SM_END SM_RETURN - void fillhello(unsigned short capabilities, char *password) { - faddr *best; - unsigned short majver, minver; + faddr *best; + unsigned short majver, minver; - Syslog('S',"fillhello(0x%04hx)",capabilities); + best = bestaka_s(remote->addr); + sscanf(VERSION,"%hd.%hd", &majver, &minver); + memset(&hello, 0, sizeof(hello)); - best = bestaka_s(remote->addr); + hello.data[0] = 'o'; /* signal */ + hello.data[2] = 1; /* hello-version */ + hello.data[4] = (PRODCODE & 0x00ff); /* product code */ + hello.data[5] = (PRODCODE & 0xff00) >> 8; /* product code */ + hello.data[6] = (VERSION_MAJOR & 0x00ff); /* prod-ver-major */ + hello.data[7] = (VERSION_MAJOR & 0xff00) >> 8; /* prod-ver-major */ + hello.data[8] = (VERSION_MINOR & 0x00ff); /* prod-ver-minor */ + hello.data[9] = (VERSION_MINOR & 0xff00) >> 8; /* prod-ver-minor */ + strncpy((char*)hello.data+10, name?name:"Unavailable",59); /* name */ + if (name) { + hello.data[10+strlen(name)] = '\0'; + strncpy((char*)hello.data+11 + strlen(name), + best->domain, 58-strlen(name)); /* domain */ + } else + strncpy((char*)hello.data + 22, best->domain, 47); /* domain */ + strncpy((char*)hello.data+70, CFG.sysop_name,19); /* sysop */ + hello.data[90] = best->zone&0xff; /* zone */ + hello.data[91] = best->zone>>8; /* zone */ + hello.data[92] = best->net&0xff; /* net */ + hello.data[93] = best->net>>8; /* net */ + hello.data[94] = best->node&0xff; /* node */ + hello.data[95] = best->node>>8; /* node */ + hello.data[96] = best->point&0xff; /* point */ + hello.data[97] = best->point>>8; /* point */ - sscanf(VERSION,"%hd.%hd", &majver, &minver); - memset(&hello, 0, sizeof(hello)); - hello.data[0] = 'o'; /* signal */ - hello.data[2] = 1; /* hello-version */ - hello.data[4] = (PRODCODE & 0x00ff); /* product code */ - hello.data[5] = (PRODCODE & 0xff00) >> 8; /* product code */ - hello.data[6] = (VERSION_MAJOR & 0x00ff); /* prod-ver-major */ - hello.data[7] = (VERSION_MAJOR & 0xff00) >> 8; /* prod-ver-major */ - hello.data[8] = (VERSION_MINOR & 0x00ff); /* prod-ver-minor */ - hello.data[9] = (VERSION_MINOR & 0xff00) >> 8; /* prod-ver-minor */ - strncpy((char*)hello.data+10, name?name:"Unavailable",59); /* name */ - if (name) { - hello.data[10+strlen(name)] = '\0'; - strncpy((char*)hello.data+11 + strlen(name), - best->domain, 58-strlen(name)); /* domain */ - } else - strncpy((char*)hello.data + 22, best->domain, 47); /* domain */ - strncpy((char*)hello.data+70, CFG.sysop_name,19); /* sysop */ - hello.data[90] = best->zone&0xff; /* zone */ - hello.data[91] = best->zone>>8; /* zone */ - hello.data[92] = best->net&0xff; /* net */ - hello.data[93] = best->net>>8; /* net */ - hello.data[94] = best->node&0xff; /* node */ - hello.data[95] = best->node>>8; /* node */ - hello.data[96] = best->point&0xff; /* point */ - hello.data[97] = best->point>>8; /* point */ + if (password) + strncpy((char*)hello.data + 98, password, 8); - if (password) - strncpy((char*)hello.data + 98, password, 8); - - hello.data[114] = capabilities & 0xff; /* capabilities */ - hello.data[115] = capabilities >> 8; /* capabilities */ - tidy_faddr(best); - Syslog('S',"filled hello \"%s\"",printable((char*)hello.data,128)); + hello.data[114] = capabilities & 0xff; /* capabilities */ + hello.data[115] = capabilities >> 8; /* capabilities */ + tidy_faddr(best); } int checkhello(void) { - unsigned short i, majver = 0, minver = 0; - fa_list **tmpl,*tmpn; - faddr remaddr; - char *prodnm, *q; - int loaded = FALSE; + unsigned short i, majver = 0, minver = 0; + fa_list **tmpl, *tmpa; + faddr remaddr; + char *prodnm, *q; + int loaded = FALSE; - Syslog('S',"check hello \"%s\"",printable((char*)hello.data,128)); + Syslog('s',"check hello \"%s\"",printable((char*)hello.data,128)); + hello2 = gethello2(hello.data); - hello2 = gethello2(hello.data); + if ((hello2.signal != 0x6f) || (hello2.hello_version != 0x01)) { + Syslog('+', "Got \"%s\" instead of \"o\\000\\001\000\"", printable((char*)hello.data,3)); + } - if ((hello2.signal != 0x6f) || - (hello2.hello_version != 0x01)) { - Syslog('+', "Got \"%s\" instead of \"o\\000\\001\000\"", printable((char*)hello.data,3)); + prodnm = xstrcpy((char *)""); + for (i = 0; ftscprod[i].name; i++) { + if (ftscprod[i].code == hello2.product) { + free(prodnm); + prodnm = xstrcpy(ftscprod[i].name); + majver = hello2.product_maj; + minver = hello2.product_min; + break; } + } - prodnm = xstrcpy((char *)""); - for (i = 0; ftscprod[i].name; i++) - if (ftscprod[i].code == hello2.product) { - free(prodnm); - prodnm = xstrcpy(ftscprod[i].name); - majver = hello2.product_maj; - minver = hello2.product_min; - break; - } - - remaddr.zone = hello2.my_zone; - remaddr.net = hello2.my_net; - remaddr.node = hello2.my_node; - remaddr.point = hello2.my_point; - remaddr.name = NULL; + remaddr.zone = hello2.my_zone; + remaddr.net = hello2.my_net; + remaddr.node = hello2.my_node; + remaddr.point = hello2.my_point; + remaddr.name = NULL; + remaddr.domain = NULL; + if (hello2.my_name[0]) + remaddr.domain = hello2.my_name + (strlen(hello2.my_name)) + 1; + if (remaddr.domain[0]) { + if ((q = strchr(remaddr.domain, '.'))) + *q = '\0'; + } else { remaddr.domain = NULL; - if (hello2.my_name[0]) - remaddr.domain = hello2.my_name + (strlen(hello2.my_name)) + 1; - if (remaddr.domain[0]) { - if ((q = strchr(remaddr.domain, '.'))) - *q = '\0'; + } + if (remote) + Syslog('s',"Remote known address: %s",ascfnode(remote->addr,0x1f)); + + for (tmpl = &remote; *tmpl; tmpl = &((*tmpl)->next)); + if ((remote == NULL) || (metric(remote->addr, &remaddr) != 0)) { + (*tmpl) = (fa_list*)malloc(sizeof(fa_list)); + (*tmpl)->next = NULL; + (*tmpl)->addr = (faddr*)malloc(sizeof(faddr)); + (*tmpl)->addr->zone = remaddr.zone; + (*tmpl)->addr->net = remaddr.net; + (*tmpl)->addr->node = remaddr.node; + (*tmpl)->addr->point = remaddr.point; + (*tmpl)->addr->domain = xstrcpy(remaddr.domain); + (*tmpl)->addr->name = NULL; /* Added 15-Dec-1998 */ + } else { + tmpl=&remote; + Syslog('s',"Using single remote address"); + } + + tmpl = &remote; + while (*tmpl) { + if (nodelock((*tmpl)->addr, mypid)) { + Syslog('+', " address: %s is locked, removed from aka list",ascfnode((*tmpl)->addr,0x1f)); + tmpa = *tmpl; + *tmpl = (*tmpl)->next; + tidy_faddr(tmpa->addr); + free(tmpa); } else { - remaddr.domain = NULL; + Syslog('+', " address: %s",ascfnode((*tmpl)->addr,0x1f)); + y_akas++; + /* + * With the loaded flag we prevent removing the noderecord + * when the remote presents us an address we don't know about. + */ + if (!Loaded) { + if (noderecord((*tmpl)->addr)) + Loaded = TRUE; + } + tmpl = &((*tmpl)->next); } - if (remote) - Syslog('S',"Remote known address: %s",ascfnode(remote->addr,0x1f)); + } - for (tmpl = &remote; *tmpl; tmpl = &((*tmpl)->next)); - if ((remote == NULL) || (metric(remote->addr, &remaddr) != 0)) { - (*tmpl) = (fa_list*)malloc(sizeof(fa_list)); - (*tmpl)->next = NULL; - (*tmpl)->addr = (faddr*)malloc(sizeof(faddr)); - (*tmpl)->addr->zone = remaddr.zone; - (*tmpl)->addr->net = remaddr.net; - (*tmpl)->addr->node = remaddr.node; - (*tmpl)->addr->point = remaddr.point; - (*tmpl)->addr->domain = xstrcpy(remaddr.domain); - (*tmpl)->addr->name = NULL; /* Added 15-Dec-1998 */ - } else { - tmpl=&remote; - Syslog('S',"Using single remote address"); - } - - for (tmpn = remote; tmpn; tmpn = tmpn->next) { - (void)nodelock(tmpn->addr, mypid); - /* - * lock all remotes, ignore locking result - */ - if (!loaded) - if (noderecord(tmpn->addr)) - loaded = TRUE; - } - - Syslog('+', " address: %s",ascfnode(remote->addr,0x1f)); + if (y_akas) { /* Only set if we have aka's left */ history.aka.zone = remote->addr->zone; history.aka.net = remote->addr->net; history.aka.node = remote->addr->node; history.aka.point = remote->addr->point; - Syslog('S', "password: %s",(char*)hello2.my_password); - if (hello2.product < 0x0100) - Syslog('+', " uses: %s [%02X] version %d.%d", prodnm, hello2.product, majver, minver); - else - Syslog('+', " uses: %s [%04X] version %d.%d", prodnm, hello2.product, majver, minver); - Syslog('+', " system: %s",(char*)hello2.my_name); - strncpy(history.system_name, hello2.my_name, 35); - Syslog('+', " sysop: %s",(char*)hello2.sysop); - strncpy(history.sysop, hello2.sysop, 35); - sprintf(history.location, "Somewhere"); + } - free(prodnm); - return loaded; + if (hello2.product < 0x0100) + Syslog('+', " uses: %s [%02X] version %d.%d", prodnm, hello2.product, majver, minver); + else + Syslog('+', " uses: %s [%04X] version %d.%d", prodnm, hello2.product, majver, minver); + Syslog('+', " system: %s",(char*)hello2.my_name); + strncpy(history.system_name, hello2.my_name, 35); + Syslog('+', " sysop: %s",(char*)hello2.sysop); + strncpy(history.sysop, hello2.sysop, 35); + sprintf(history.location, "Somewhere"); + + free(prodnm); + return loaded; } Hello gethello2(unsigned char Hellop[]) { - int i; - Hello p; + int i; + Hello p; - p.signal=Hellop[0]+(Hellop[1]<<8); - p.hello_version=Hellop[2]+(Hellop[3]<<8); - p.product=Hellop[4]+(Hellop[5]<<8); - p.product_maj=Hellop[6]+(Hellop[7]<<8); - p.product_min=Hellop[8]+(Hellop[9]<<8); - for (i=0;i<60;i++) - p.my_name[i]=Hellop[10+i]; - for (i=0;i<20;i++) - p.sysop[i]=Hellop[70+i]; - p.my_zone=Hellop[90]+(Hellop[91]<<8); - p.my_net=Hellop[92]+(Hellop[93]<<8); - p.my_node=Hellop[94]+(Hellop[95]<<8); - p.my_point=Hellop[96]+(Hellop[97]<<8); - for (i=0;i<8;i++) - p.my_password[i]=Hellop[98+i]; - for (i=0;i<8;i++) - p.reserved2[i]=Hellop[106+i]; - p.capabilities=Hellop[114]+(Hellop[115]<<8); - for (i=0;i<12;i++) - p.reserved3[i]=Hellop[116+i]; + p.signal=Hellop[0]+(Hellop[1]<<8); + p.hello_version=Hellop[2]+(Hellop[3]<<8); + p.product=Hellop[4]+(Hellop[5]<<8); + p.product_maj=Hellop[6]+(Hellop[7]<<8); + p.product_min=Hellop[8]+(Hellop[9]<<8); + for (i=0;i<60;i++) + p.my_name[i]=Hellop[10+i]; + for (i=0;i<20;i++) + p.sysop[i]=Hellop[70+i]; + p.my_zone=Hellop[90]+(Hellop[91]<<8); + p.my_net=Hellop[92]+(Hellop[93]<<8); + p.my_node=Hellop[94]+(Hellop[95]<<8); + p.my_point=Hellop[96]+(Hellop[97]<<8); + for (i=0;i<8;i++) + p.my_password[i]=Hellop[98+i]; + for (i=0;i<8;i++) + p.reserved2[i]=Hellop[106+i]; + p.capabilities=Hellop[114]+(Hellop[115]<<8); + for (i=0;i<12;i++) + p.reserved3[i]=Hellop[116+i]; - return p; + return p; } diff --git a/mbfido/aliasdb.c b/mbfido/aliasdb.c index 5ca032e7..dd771e91 100644 --- a/mbfido/aliasdb.c +++ b/mbfido/aliasdb.c @@ -89,7 +89,7 @@ static int alias_db_init(void) while (fcntl(fileno(afp), F_SETLK, &txflock) != 0) { if (tries > 4) Syslog('+', "Alias database locked %d errno=%d %s", tries +1, errno, strerror(errno)); - usleep(250000); + msleep(250); if (++tries >= 60) { fclose(afp); afp = NULL; diff --git a/mbfido/announce.c b/mbfido/announce.c index 5293b0fd..bf73d7e1 100644 --- a/mbfido/announce.c +++ b/mbfido/announce.c @@ -4,7 +4,7 @@ * Purpose ...............: Announce new files and FileFind * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -127,7 +127,7 @@ void Uploads() i++; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); if ((area.Available) && strlen(area.NewGroup)) { @@ -321,7 +321,7 @@ long Report(gr_list *ta, long filepos) if ((!strcmp(T_File.Echo, ta->echo)) && (!strcmp(T_File.Group, ta->group))) { if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); /* * Report one newfile, first line. diff --git a/mbfido/filefind.c b/mbfido/filefind.c index 60412251..968ad373 100644 --- a/mbfido/filefind.c +++ b/mbfido/filefind.c @@ -4,7 +4,7 @@ * Purpose ...............: Announce new files and FileFind * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -117,7 +117,7 @@ void ScanArea(ff_list **ffl) } if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); if (Msg_ReadHeader(Number) == TRUE) { if (((!strcasecmp(Msg.To, "allfix")) || (!strcasecmp(Msg.To, "filefind"))) && (!Msg.Received)) { @@ -288,7 +288,7 @@ void ScanFiles(ff_list *tmp) Nopper(); if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); if (!do_quiet) { printf("%6lu / %6lu", areanr, found); diff --git a/mbfido/mbfindex.c b/mbfido/mbfindex.c index 88198f25..62402247 100644 --- a/mbfido/mbfindex.c +++ b/mbfido/mbfindex.c @@ -4,7 +4,7 @@ * Purpose: File Database Maintenance - Build index for request processor * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -478,7 +478,7 @@ void ReqIndex(void) */ x++; if (CFG.slow_util && do_quiet && ((x % 3) == 0)) - usleep(1); + msleep(1); for (z = 0; z <= 25; z++) { if (strlen(file.Desc[z])) { @@ -658,7 +658,7 @@ void HtmlIndex(char *Lang) TotalHtml++; aTotal++; if (CFG.slow_util && do_quiet && ((x % 3) == 0)) - usleep(1); + msleep(1); MacroVars("efghijklm", "ddsssssds", 0, 0, "", "", "", "", "", 0, ""); MacroVars("e", "d", aTotal); diff --git a/mbfido/mbfutil.c b/mbfido/mbfutil.c index 178211be..30cea500 100644 --- a/mbfido/mbfutil.c +++ b/mbfido/mbfutil.c @@ -152,7 +152,7 @@ void Marker(void) * Release system resources when running in the background */ if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); if (do_quiet) return; diff --git a/mbfido/mbindex.c b/mbfido/mbindex.c index a02b51e3..c63de8d8 100644 --- a/mbfido/mbindex.c +++ b/mbfido/mbindex.c @@ -4,7 +4,7 @@ * Purpose ...............: Nodelist Compiler * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -374,10 +374,10 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n if (CFG.slow_util && do_quiet) { if (zo) { - usleep(1); + msleep(1); } else { if ((lineno % 40) == 0) - usleep(1); + msleep(1); } } diff --git a/mbfido/mbmsg.c b/mbfido/mbmsg.c index f0746503..4c75086a 100644 --- a/mbfido/mbmsg.c +++ b/mbfido/mbmsg.c @@ -4,7 +4,7 @@ * Purpose ...............: Message Base Maintenance * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -475,7 +475,7 @@ void KillArea(char *Path, char *Name, int DaysOld, int MaxMsgs, long Areanr) do { if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); if ((!do_quiet) && ((Counter % 10L) == 0)) { printf("%6lu / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", Counter, TotalMsgs); @@ -587,7 +587,7 @@ void PackArea(char *Path, long Areanr) } if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } diff --git a/mbfido/mgrutil.c b/mbfido/mgrutil.c index 71e954ff..b3ebb205 100644 --- a/mbfido/mgrutil.c +++ b/mbfido/mgrutil.c @@ -4,7 +4,7 @@ * Purpose ...............: AreaMgr and FileMgr utilities. * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -589,7 +589,7 @@ int Areas(void) for (tmp = alist; tmp; tmp = tmp->next) { fseek(fp, msgshdr.hdrsize, SEEK_SET); if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); while (fread(&msgs, msgshdr.recsize, 1, fp) == 1) { if (msgs.Active && !strcmp(msgs.Group, mgroup.Name) && !strcmp(msgs.Tag, tmp->Name)) tmp->IsPresent = TRUE; @@ -639,7 +639,7 @@ int Areas(void) } cmd = xstrcat(cmd, tmp->Name); if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } } @@ -658,7 +658,7 @@ int Areas(void) fseek(fp, msgshdr.hdrsize, SEEK_SET); Syslog('m', "Delete %s", tmp->Name); if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); while (fread(&msgs, msgshdr.recsize, 1, fp) == 1) { if (msgs.Active && !strcmp(msgs.Group, mgroup.Name) && !strcmp(msgs.Tag, tmp->Name)) { fseek(fp, - msgshdr.recsize, SEEK_CUR); @@ -828,7 +828,7 @@ int Areas(void) for (tmp = alist; tmp; tmp = tmp->next) { fseek(fp, tichdr.hdrsize, SEEK_SET); if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); while (fread(&tic, tichdr.recsize, 1, fp) == 1) { if (tic.Active && !strcmp(tic.Group, fgroup.Name) && !strcmp(tic.Name, tmp->Name)) tmp->IsPresent = TRUE; @@ -886,7 +886,7 @@ int Areas(void) } cmd = xstrcat(cmd, tmp->Name); if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } } @@ -907,7 +907,7 @@ int Areas(void) fseek(fp, tichdr.hdrsize, SEEK_SET); Syslog('f', "Delete %s", tmp->Name); if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); while (fread(&tic, tichdr.recsize, 1, fp) == 1) { if (tic.Active && !strcmp(tic.Group, fgroup.Name) && !strcmp(tic.Name, tmp->Name)) { fseek(fp, - tichdr.recsize, SEEK_CUR); diff --git a/mbfido/rollover.c b/mbfido/rollover.c index 041af065..3670d4de 100644 --- a/mbfido/rollover.c +++ b/mbfido/rollover.c @@ -4,7 +4,7 @@ * Purpose ...............: Statistic rollover util. * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -65,7 +65,7 @@ void RollWeek(statcnt *S) S->tweek = 0L; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } @@ -158,7 +158,7 @@ void Rollover() nodes.MailSent.month[Miy] = 0; nodes.MailRcvd.month[Miy] = 0; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } fseek(fp, - nodeshdr.recsize, SEEK_CUR); fwrite(&nodes, nodeshdr.recsize, 1, fp); @@ -199,7 +199,7 @@ void Rollover() msgs.Received.month[Miy] = 0; msgs.Posted.month[Miy] = 0; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } fseek(fp, - msgshdr.recsize, SEEK_CUR); fwrite(&msgs, msgshdr.recsize, 1, fp); @@ -239,7 +239,7 @@ void Rollover() mgroup.MsgsRcvd.month[Miy] = 0; mgroup.MsgsSent.month[Miy] = 0; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } fseek(fp, - mgrouphdr.recsize, SEEK_CUR); fwrite(&mgroup, mgrouphdr.recsize, 1, fp); @@ -278,7 +278,7 @@ void Rollover() tic.Files.month[Miy] = 0; tic.KBytes.month[Miy] = 0; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } fseek(fp, - tichdr.recsize, SEEK_CUR); fwrite(&tic, tichdr.recsize, 1, fp); @@ -318,7 +318,7 @@ void Rollover() fgroup.Files.month[Miy] = 0; fgroup.KBytes.month[Miy] = 0; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } fseek(fp, - fgrouphdr.recsize, SEEK_CUR); fwrite(&fgroup, fgrouphdr.recsize, 1, fp); @@ -354,7 +354,7 @@ void Rollover() if (do_month) { hatch.Hatched.month[Miy] = 0; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } fseek(fp, - hatchhdr.recsize, SEEK_CUR); fwrite(&hatch, hatchhdr.recsize, 1, fp); diff --git a/mbfido/scan.c b/mbfido/scan.c index 09c6a25a..519333a3 100644 --- a/mbfido/scan.c +++ b/mbfido/scan.c @@ -4,7 +4,7 @@ * Purpose ...............: Scan for outgoing mail. * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -182,7 +182,7 @@ void ScanFull() do { if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); if (((Number % 10) == 0) && (!do_quiet)) { printf("%6lu\b\b\b\b\b\b", Number); @@ -245,7 +245,7 @@ void ScanFull() do { if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); if (((Number % 10) == 0) && (!do_quiet)) { printf("%6lu\b\b\b\b\b\b", Number); diff --git a/mbfido/scannews.c b/mbfido/scannews.c index c3af5cc6..ab92e2dc 100644 --- a/mbfido/scannews.c +++ b/mbfido/scannews.c @@ -464,7 +464,7 @@ int get_xover(char *grpname, long startnr, long endnr, List **art) fill_artlist(art, ptr, nr, dupe); free(p); if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } } } diff --git a/mbfido/tic.c b/mbfido/tic.c index b22506c4..a754eb5b 100644 --- a/mbfido/tic.c +++ b/mbfido/tic.c @@ -4,7 +4,7 @@ * Purpose ...............: Process .tic files * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -169,7 +169,7 @@ int LoadTic(char *inb, char *tfn) fa_list *sbl = NULL; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); memset(&RealName, 0, sizeof(RealName)); memset(&TIC, 0, sizeof(TIC)); diff --git a/mbfido/tosspkt.c b/mbfido/tosspkt.c index 0967d8c6..02155c81 100644 --- a/mbfido/tosspkt.c +++ b/mbfido/tosspkt.c @@ -4,7 +4,7 @@ * Purpose ...............: Toss a single *.pkt file * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -156,7 +156,7 @@ int importmsg(faddr *p_from, faddr *f, faddr *t, char *orig, char *subj, time_t sysconnect Link; if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); memset(&Link, 0, sizeof(Link)); diff --git a/mbmon/common.c b/mbmon/common.c index 63d20669..88f8171f 100644 --- a/mbmon/common.c +++ b/mbmon/common.c @@ -4,7 +4,7 @@ * Purpose ...............: Common utilities * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -514,7 +514,7 @@ int Waitchar(unsigned char *ch, int wtime) rc = read(ttyfd, ch, 1); if (rc == 1) return rc; - usleep(10000); + msleep(10); } return rc; } @@ -862,6 +862,42 @@ void mvprintw(int y, int x, const char *format, ...) +/* + * * Milliseconds timer, returns 0 on success. + * */ +int msleep(int msecs) +{ + int rc; + struct timespec req, rem; + + rem.tv_sec = 0; + rem.tv_nsec = 0; + req.tv_sec = msecs / 1000; + req.tv_nsec = (msecs % 1000) * 1000000; + + while (TRUE) { + + rc = nanosleep(&req, &rem); + if (rc == 0) + break; + if ((errno == EINVAL) || (errno == EFAULT)) { + Syslog('?', "$msleep(%d)", msecs); + break; + } + + /* + * Error was EINTR, run timer again to complete. + */ + req.tv_sec = rem.tv_sec; + req.tv_nsec = rem.tv_nsec; + rem.tv_sec = 0; + rem.tv_nsec = 0; + } + + return rc; +} + + /* * Signal handler signal names. */ diff --git a/mbmon/common.h b/mbmon/common.h index 6919352a..4e1ea8aa 100644 --- a/mbmon/common.h +++ b/mbmon/common.h @@ -86,7 +86,7 @@ void colour(int, int); void clear(void); void locate(int, int); void mvprintw(int, int, const char *, ...); - +int msleep(int); #endif diff --git a/mbmon/mutil.c b/mbmon/mutil.c index 44b933aa..4d6491f1 100644 --- a/mbmon/mutil.c +++ b/mbmon/mutil.c @@ -4,7 +4,7 @@ * Purpose ...............: Utilities * ***************************************************************************** - * Copyright (C) 1997-2001 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -531,9 +531,9 @@ void working(int txno, int y, int x) for (i = 1; i <= 5; i++) { putchar(7); fflush(stdout); - usleep(150000); + msleep(150); } - usleep(550000); + msleep(550); break; case 3: mvprintw(4, columns - 14, (char *)"Form inserted"); putchar(7); diff --git a/mbsebbs/mball.c b/mbsebbs/mball.c index 4c2eebf2..bbffd507 100644 --- a/mbsebbs/mball.c +++ b/mbsebbs/mball.c @@ -4,7 +4,7 @@ * Purpose ...............: Creates allfiles listings * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -350,7 +350,7 @@ void Masterlist() */ x++; if (CFG.slow_util && do_quiet && ((x % 3) == 0)) - usleep(1); + msleep(1); AllFiles++; AllAreaFiles++; AllAreaBytes += file.Size; diff --git a/mbsebbs/mbstat.c b/mbsebbs/mbstat.c index 605295a6..b341772b 100644 --- a/mbsebbs/mbstat.c +++ b/mbsebbs/mbstat.c @@ -4,7 +4,7 @@ * Purpose ...............: Change BBS status * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -153,7 +153,6 @@ int main(int argc, char **argv) pw = getpwuid(getuid()); InitClient(pw->pw_name, (char *)"mbstat", CFG.location, CFG.logfile, CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog); - usleep(1); Syslog(' ', " "); Syslog(' ', "MBSTAT v%s", VERSION); @@ -186,7 +185,6 @@ int main(int argc, char **argv) if (!(do_open || do_close || do_wait || do_sema)) Help(); - usleep(1); die(MBERR_OK); return 0; } diff --git a/mbsebbs/mbuser.c b/mbsebbs/mbuser.c index b5772846..fc31a69f 100644 --- a/mbsebbs/mbuser.c +++ b/mbsebbs/mbuser.c @@ -4,7 +4,7 @@ * Purpose ...............: User Pack Util * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -255,7 +255,7 @@ void UserPack(int days, int level, int pack) fwrite(&usr, sizeof(usr), 1, fout); memset(&usr, 0, sizeof(usr)); if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); Nopper(); } fclose(fin); @@ -300,7 +300,7 @@ void UserPack(int days, int level, int pack) fwrite(&usr, sizeof(usr), 1, fout); } if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); } Syslog('+', "Marked %d users to delete", delete); } @@ -314,7 +314,7 @@ void UserPack(int days, int level, int pack) fseek(fout, sizeof(usrhdr), SEEK_SET); while (fread(&usr, sizeof(usr), 1, fout) == 1) { if (CFG.slow_util && do_quiet) - usleep(1); + msleep(1); Nopper(); if (usr.Deleted) { diff --git a/mbsebbs/offline.c b/mbsebbs/offline.c index 5c5bc4bd..d64c2bec 100644 --- a/mbsebbs/offline.c +++ b/mbsebbs/offline.c @@ -4,7 +4,7 @@ * Purpose ...............: Offline Reader * ***************************************************************************** - * Copyright (C) 1997-2003 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -2693,7 +2693,7 @@ unsigned long QWK_PackArea(unsigned long ulLast, long Area) fwrite(&Qwk, sizeof(Qwk), 1, fdm); fseek(fdm, 0L, SEEK_END); if ((Total % 16L) == 0L) - usleep(1); + msleep(1); } if (BarWidth != (unsigned short)((Total * 61L) / TotalPack)) { @@ -2937,7 +2937,7 @@ unsigned long ASCII_PackArea(unsigned long ulLast, long Area) } if ((Total % 16L) == 0L) - usleep(1); + msleep(1); if (BarWidth != (unsigned short)((Total * 61L) / TotalPack)) { BarWidth = (unsigned short)((Total * 61L) / TotalPack); diff --git a/mbsetup/screen.c b/mbsetup/screen.c index e385e4db..10d48b89 100644 --- a/mbsetup/screen.c +++ b/mbsetup/screen.c @@ -4,7 +4,7 @@ * Purpose ...............: Screen functions for setup. * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2004 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -227,9 +227,9 @@ void working(int txno, int y, int x) for (i = 1; i <= 5; i++) { fputc(7, stdout); fflush(stdout); - usleep(150000); + msleep(150); } - usleep(550000); + msleep(550); break; case 3: mvprintw(4, 66, (char *)"Form inserted"); fputc(7, stdout); diff --git a/script/Makefile b/script/Makefile index 3264f950..a9277169 100644 --- a/script/Makefile +++ b/script/Makefile @@ -3,8 +3,8 @@ include ../Makefile.global -OTHER = Makefile README maint midnight weekly monthly installinit.sh rc rc.shutdown \ - mbse.start mbse.stop bbsdoor.sh rundoor.sh init.Debian init.RedHat \ +OTHER = Makefile README maint midnight weekly monthly installinit.sh setup.mbse \ + bbsdoor.sh rundoor.sh init.Debian init.RedHat init.FreeBSD init.NetBSD \ init.Slackware init.SuSE init.Gentoo hatch editor.in bbsjoerc bbsjmacsrc ####################################################################################################