Rewrote mbtask as a single process

This commit is contained in:
Michiel Broek 2006-02-13 19:26:30 +00:00
parent 88453c9c55
commit cd8c6a00db
21 changed files with 667 additions and 1098 deletions

View File

@ -2,10 +2,20 @@ $Id$
v0.83.12 06-Feb-2006 v0.83.12 06-Feb-2006
mbselib.a:
On socket send error 2, abort the client program.
mbsebbs: mbsebbs:
Added screen rows detection using ANSI sequences needed for Added screen rows detection using ANSI sequences needed for
some terminal programs like minicom. some terminal programs like minicom.
mbtask:
On shutdown also send PART and QUIT messages to all our links
for our own users if they are still online so that the network
will keep the correct state.
Removed all thread programming so that mbtask is now a single
process again. This should fix the crash problem during chat.
v0.83.11 28-Jan-2006 - 06-Feb-2006 v0.83.11 28-Jan-2006 - 06-Feb-2006

3
TODO
View File

@ -50,6 +50,9 @@ mbsebbs:
N: Joe 3.3 doesn't work with mbsebbs, some locking problem. N: Joe 3.3 doesn't work with mbsebbs, some locking problem.
N: Implement kermit protocol, external versions don't work right.
mbfido: mbfido:
W: Check all .flo files for dead attachments. W: Check all .flo files for dead attachments.

81
configure vendored
View File

@ -5107,89 +5107,8 @@ done
fi fi
if test "$SYSTEM" = "NetBSD"; then
CFLAGS="$CFLAGS `pthread-config --cflags`"
LDFLAGS="$LDFLAGS `pthread-config --ldflags`"
fi
if test "$SYSTEM" = "FreeBSD" || test "$SYSTEM" = "OpenBSD"; then
CFLAGS="-pthread $CFLAGS"
else
echo "$as_me:$LINENO: checking for pthread_create in -lpthread" >&5
echo $ECHO_N "checking for pthread_create in -lpthread... $ECHO_C" >&6
if test "${ac_cv_lib_pthread_pthread_create+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthread $LIBS"
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
/* Override any gcc2 internal prototype to avoid an error. */
#ifdef __cplusplus
extern "C"
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char pthread_create ();
int
main ()
{
pthread_create ();
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_c_werror_flag"
|| test ! -s conftest.err'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_cv_lib_pthread_pthread_create=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_lib_pthread_pthread_create=no
fi
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
echo "$as_me:$LINENO: result: $ac_cv_lib_pthread_pthread_create" >&5
echo "${ECHO_T}$ac_cv_lib_pthread_pthread_create" >&6
if test $ac_cv_lib_pthread_pthread_create = yes; then
result=yes
else
result=no
fi
if test "$result" = "yes"; then
LIBS="$LIBS -lpthread"
fi
fi

View File

@ -199,23 +199,23 @@ dnl
dnl dnl
dnl On NetBSD we need to add the pkg dirs for posix threads dnl On NetBSD we need to add the pkg dirs for posix threads
dnl dnl
if test "$SYSTEM" = "NetBSD"; then dnl if test "$SYSTEM" = "NetBSD"; then
CFLAGS="$CFLAGS `pthread-config --cflags`" dnl CFLAGS="$CFLAGS `pthread-config --cflags`"
LDFLAGS="$LDFLAGS `pthread-config --ldflags`" dnl LDFLAGS="$LDFLAGS `pthread-config --ldflags`"
fi dnl fi
dnl dnl
dnl For FreeBSD and OpenBSD we need -pthread for gcc and don't need libpthread dnl For FreeBSD and OpenBSD we need -pthread for gcc and don't need libpthread
dnl dnl
if test "$SYSTEM" = "FreeBSD" || test "$SYSTEM" = "OpenBSD"; then dnl if test "$SYSTEM" = "FreeBSD" || test "$SYSTEM" = "OpenBSD"; then
CFLAGS="-pthread $CFLAGS" dnl CFLAGS="-pthread $CFLAGS"
else dnl else
AC_CHECK_LIB(pthread,pthread_create,result=yes,result=no) dnl AC_CHECK_LIB(pthread,pthread_create,result=yes,result=no)
if test "$result" = "yes"; then dnl if test "$result" = "yes"; then
LIBS="$LIBS -lpthread" dnl LIBS="$LIBS -lpthread"
fi dnl fi
fi dnl fi

View File

@ -169,6 +169,7 @@ term.o: ../config.h mbselib.h users.h
endian.o: ../config.h mbselib.h endian.o: ../config.h mbselib.h
timers.o: ../config.h mbselib.h timers.o: ../config.h mbselib.h
pidinfo.o: ../config.h mbselib.h pidinfo.o: ../config.h mbselib.h
tmpwork.o: ../config.h mbselib.h
dbcfg.o: ../config.h mbselib.h mbse.h users.h mbsedb.h dbcfg.o: ../config.h mbselib.h mbse.h users.h mbsedb.h
dbdupe.o: ../config.h mbselib.h mbse.h users.h mbsedb.h dbdupe.o: ../config.h mbselib.h mbse.h users.h mbsedb.h
dbftn.o: ../config.h mbselib.h users.h mbsedb.h dbftn.o: ../config.h mbselib.h users.h mbsedb.h

View File

@ -4,7 +4,7 @@
* Purpose ...............: MBSE Deamon Client * Purpose ...............: MBSE Deamon Client
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1993-2005 * Copyright (C) 1993-2006
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -158,6 +158,9 @@ int socket_send(char *buf)
if (sendto(sock, buf, strlen(buf), 0, (struct sockaddr *)&servaddr, sizeof(servaddr)) != strlen(buf)) { if (sendto(sock, buf, strlen(buf), 0, (struct sockaddr *)&servaddr, sizeof(servaddr)) != strlen(buf)) {
printf("Socket send failed error %d\n", errno); printf("Socket send failed error %d\n", errno);
if (errno == 2) {
abort();
}
return -1; return -1;
} }
return 0; return 0;

View File

@ -112,7 +112,7 @@ timecheck.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h timecheck
change.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h change.h dispfile.h funcs.h input.h language.h misc.h timeout.h exitinfo.h bye.h term.h ttyio.h change.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h change.h dispfile.h funcs.h input.h language.h misc.h timeout.h exitinfo.h bye.h term.h ttyio.h
transfer.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h transfer.h change.h whoson.h funcs.h term.h ttyio.h filesub.h language.h openport.h timeout.h zmmisc.h zmsend.h zmrecv.h ymsend.h ymrecv.h transfer.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h transfer.h change.h whoson.h funcs.h term.h ttyio.h filesub.h language.h openport.h timeout.h zmmisc.h zmsend.h zmrecv.h ymsend.h ymrecv.h
exitinfo.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h input.h language.h oneline.h misc.h bye.h timeout.h timecheck.h exitinfo.h exitinfo.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h funcs.h input.h language.h oneline.h misc.h bye.h timeout.h timecheck.h exitinfo.h
mbsebbs.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h mbsebbs.h user.h dispfile.h language.h menu.h misc.h bye.h timeout.h funcs.h term.h ttyio.h openport.h mbsebbs.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/msg.h mbsebbs.h user.h dispfile.h language.h menu.h misc.h bye.h timeout.h funcs.h term.h ttyio.h openport.h input.h
menu.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h oneline.h mail.h change.h chat.h file.h funcs.h input.h misc.h timeout.h menu.h page.h pinfo.h bye.h timecheck.h whoson.h language.h offline.h email.h door.h dispfile.h userlist.h timestats.h logentry.h morefile.h lastcallers.h signature.h term.h ttyio.h menu.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h oneline.h mail.h change.h chat.h file.h funcs.h input.h misc.h timeout.h menu.h page.h pinfo.h bye.h timecheck.h whoson.h language.h offline.h email.h door.h dispfile.h userlist.h timestats.h logentry.h morefile.h lastcallers.h signature.h term.h ttyio.h
pop3.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbinet.h ../lib/msgtext.h ../lib/msg.h msgutil.h pop3.h term.h ttyio.h pop3.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h ../lib/mbinet.h ../lib/msgtext.h ../lib/msg.h msgutil.h pop3.h term.h ttyio.h
lastcallers.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h lastcallers.h term.h ttyio.h lastcallers.o: ../config.h ../lib/mbselib.h ../lib/mbse.h ../lib/users.h input.h language.h lastcallers.h term.h ttyio.h

View File

@ -70,7 +70,7 @@ depend:
# Dependencies generated by make depend # Dependencies generated by make depend
callstat.o: ../config.h ../lib/mbselib.h taskutil.h callstat.h callstat.o: ../config.h ../lib/mbselib.h taskutil.h callstat.h
scanout.o: ../config.h ../lib/mbselib.h taskutil.h scanout.h scanout.o: ../config.h ../lib/mbselib.h taskutil.h scanout.h
taskcomm.o: ../config.h ../lib/mbselib.h taskstat.h taskregs.h taskdisk.h taskinfo.h taskutil.h taskchat.h taskcomm.h taskcomm.o: ../config.h ../lib/mbselib.h taskstat.h taskregs.h taskdisk.h taskinfo.h taskutil.h taskchat.h taskcomm.h taskibc.h
taskinfo.o: ../config.h ../lib/mbselib.h taskinfo.h taskinfo.o: ../config.h ../lib/mbselib.h taskinfo.h
taskstat.o: ../config.h ../lib/mbselib.h taskstat.h callstat.h outstat.h taskibc.h taskutil.h taskstat.o: ../config.h ../lib/mbselib.h taskstat.h callstat.h outstat.h taskibc.h taskutil.h
taskibc.o: ../config.h ../lib/mbselib.h taskstat.h taskutil.h taskchat.h taskibc.h taskibc.o: ../config.h ../lib/mbselib.h taskstat.h taskutil.h taskchat.h taskibc.h
@ -85,4 +85,5 @@ calllist.o: ../config.h ../lib/mbselib.h taskstat.h taskutil.h callstat.h outsta
ping.o: ../config.h ../lib/mbselib.h taskstat.h taskutil.h ping.h ping.o: ../config.h ../lib/mbselib.h taskstat.h taskutil.h ping.h
taskchat.o: ../config.h ../lib/mbselib.h taskutil.h taskregs.h taskchat.h taskibc.h taskchat.o: ../config.h ../lib/mbselib.h taskutil.h taskregs.h taskchat.h taskibc.h
crc.o: ../config.h ../lib/mbselib.h crc.o: ../config.h ../lib/mbselib.h
pidinfo.o: ../config.h ../lib/mbselib.h
# End of generated dependencies # End of generated dependencies

View File

@ -59,6 +59,9 @@ static pid_t pgrp; /* Pids group */
int sock = -1; /* Datagram socket */ int sock = -1; /* Datagram socket */
struct sockaddr_un servaddr; /* Server address */ struct sockaddr_un servaddr; /* Server address */
struct sockaddr_un from; /* From address */ struct sockaddr_un from; /* From address */
struct sockaddr_in myaddr_in; /* IBC local socket */
struct sockaddr_in clientaddr_in; /* IBC remote socket */
int ibcsock = -1; /* IBC socket */
int fromlen; int fromlen;
char waitmsg[81]; /* Waiting message */ char waitmsg[81]; /* Waiting message */
static char spath[PATH_MAX]; /* Socket path */ static char spath[PATH_MAX]; /* Socket path */
@ -111,10 +114,7 @@ extern pid_t mypid; /* Pid of daemon */
int G_Shutdown = FALSE; /* Global shutdown */ int G_Shutdown = FALSE; /* Global shutdown */
int T_Shutdown = FALSE; /* Shutdown threads */ int T_Shutdown = FALSE; /* Shutdown threads */
int nodaemon = FALSE; /* Run in foreground */ int nodaemon = FALSE; /* Run in foreground */
extern int cmd_run; /* Cmd running */ extern time_t resettime; /* IBC reset time */
extern int ping_run; /* Ping running */
extern int disk_run; /* Disk watch running */
extern int ibc_run; /* IBC thread running */
@ -122,10 +122,6 @@ extern int ibc_run; /* IBC thread running */
* Global thread vaiables * Global thread vaiables
*/ */
pthread_t pt_ping; pthread_t pt_ping;
pthread_t pt_command;
pthread_t pt_disk;
pthread_t pt_scheduler;
pthread_t pt_ibc;
@ -395,38 +391,38 @@ void load_maincfg(void)
*/ */
void load_taskcfg(void) void load_taskcfg(void)
{ {
FILE *fp; FILE *fp;
if ((fp = fopen(tcfgfn, "r")) == NULL) { if ((fp = fopen(tcfgfn, "r")) == NULL) {
memset(&TCFG, 0, sizeof(TCFG)); memset(&TCFG, 0, sizeof(TCFG));
TCFG.maxload = 1.50; TCFG.maxload = 1.50;
snprintf(TCFG.zmh_start, 6, "02:30"); snprintf(TCFG.zmh_start, 6, "02:30");
snprintf(TCFG.zmh_end, 6, "03:30"); snprintf(TCFG.zmh_end, 6, "03:30");
snprintf(TCFG.cmd_mailout, 81, "%s/bin/mbfido scan web -quiet", getenv("MBSE_ROOT")); snprintf(TCFG.cmd_mailout, 81, "%s/bin/mbfido scan web -quiet", getenv("MBSE_ROOT"));
snprintf(TCFG.cmd_mailin, 81, "%s/bin/mbfido tic toss web -quiet", getenv("MBSE_ROOT")); snprintf(TCFG.cmd_mailin, 81, "%s/bin/mbfido tic toss web -quiet", getenv("MBSE_ROOT"));
snprintf(TCFG.cmd_newnews, 81, "%s/bin/mbfido news web -quiet", getenv("MBSE_ROOT")); snprintf(TCFG.cmd_newnews, 81, "%s/bin/mbfido news web -quiet", getenv("MBSE_ROOT"));
snprintf(TCFG.cmd_mbindex1, 81, "%s/bin/mbindex -quiet", getenv("MBSE_ROOT")); snprintf(TCFG.cmd_mbindex1, 81, "%s/bin/mbindex -quiet", getenv("MBSE_ROOT"));
if (strlen(_PATH_GOLDNODE)) if (strlen(_PATH_GOLDNODE))
snprintf(TCFG.cmd_mbindex2, 81, "%s -f -q", _PATH_GOLDNODE); snprintf(TCFG.cmd_mbindex2, 81, "%s -f -q", _PATH_GOLDNODE);
snprintf(TCFG.cmd_msglink, 81, "%s/bin/mbmsg link -quiet", getenv("MBSE_ROOT")); snprintf(TCFG.cmd_msglink, 81, "%s/bin/mbmsg link -quiet", getenv("MBSE_ROOT"));
snprintf(TCFG.cmd_reqindex, 81, "%s/bin/mbfile index -quiet", getenv("MBSE_ROOT")); snprintf(TCFG.cmd_reqindex, 81, "%s/bin/mbfile index -quiet", getenv("MBSE_ROOT"));
TCFG.max_tcp = 0; TCFG.max_tcp = 0;
snprintf(TCFG.isp_ping1, 41, "192.168.1.1"); snprintf(TCFG.isp_ping1, 41, "192.168.1.1");
snprintf(TCFG.isp_ping2, 41, "192.168.1.1"); snprintf(TCFG.isp_ping2, 41, "192.168.1.1");
if ((fp = fopen(tcfgfn, "a+")) == NULL) { if ((fp = fopen(tcfgfn, "a+")) == NULL) {
Syslog('?', "$Can't create %s", tcfgfn); Syslog('?', "$Can't create %s", tcfgfn);
die(MBERR_INIT_ERROR); die(MBERR_INIT_ERROR);
}
fwrite(&TCFG, sizeof(TCFG), 1, fp);
fclose(fp);
chmod(tcfgfn, 0640);
Syslog('+', "Created new %s", tcfgfn);
} else {
fread(&TCFG, sizeof(TCFG), 1, fp);
fclose(fp);
} }
fwrite(&TCFG, sizeof(TCFG), 1, fp);
fclose(fp);
chmod(tcfgfn, 0640);
Syslog('+', "Created new %s", tcfgfn);
} else {
fread(&TCFG, sizeof(TCFG), 1, fp);
fclose(fp);
}
tcfg_time = file_time(tcfgfn); tcfg_time = file_time(tcfgfn);
} }
@ -475,9 +471,10 @@ int msleep(int msecs)
*/ */
pid_t launch(char *cmd, char *opts, char *name, int tasktype) pid_t launch(char *cmd, char *opts, char *name, int tasktype)
{ {
char buf[PATH_MAX], *vector[16]; static char buf[PATH_MAX];
int i, rc = 0; char *vector[16];
pid_t pid = 0, lpgrp; int i, rc = 0;
pid_t pid = 0;
Syslog('r', "launch() entered"); Syslog('r', "launch() entered");
if (checktasks(0) >= MAXTASKS) { if (checktasks(0) >= MAXTASKS) {
@ -500,26 +497,21 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
Syslog('?', "Launch: can't execute %s, command not found", vector[0]); Syslog('?', "Launch: can't execute %s, command not found", vector[0]);
return 0; return 0;
} }
Syslog('r', "launch() step 2");
if ((lpgrp = setpgid(0, 0)) == -1) { Syslog('r', "launch() step 2");
Syslog('?', "$setpgid failed");
return 0;
}
Syslog('r', "launch() step 3, lpgrp=%d", lpgrp);
switch (pid = fork()) { switch (pid = fork()) {
case -1: case -1:
Syslog('?', "$Launch: error, can't fork grandchild"); WriteError("$Launch: error, can't fork grandchild");
return 0; return 0;
case 0: case 0:
/* /*
* A delay in the child process to prevent it returns * A delay in the child process to prevent it returns
* before the main process sess it ever started. * before the main process sees it ever started.
*/ */
msleep(150); msleep(150);
Syslog('r', "launch() step 4"); Syslog('r', "launch() step 3");
/* From Paul Vixies cron: */ /* From Paul Vixies cron: */
rc = setsid(); /* It doesn't seem to help */ rc = setsid(); /* It doesn't seem to help */
if (rc == -1) if (rc == -1)
@ -541,7 +533,7 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
_exit(MBERR_EXEC_FAILED); _exit(MBERR_EXEC_FAILED);
} }
errno = 0; errno = 0;
Syslog('r', "launch() step 5"); Syslog('r', "launch() step 4");
rc = execv(vector[0],vector); rc = execv(vector[0],vector);
Syslog('?', "$Launch: execv \"%s\" failed, returned %d", cmd, rc); Syslog('?', "$Launch: execv \"%s\" failed, returned %d", cmd, rc);
_exit(MBERR_EXEC_FAILED); _exit(MBERR_EXEC_FAILED);
@ -550,7 +542,7 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
break; break;
} }
Syslog('r', "launch() step 6"); Syslog('r', "launch() step 5");
/* /*
* Add it to the tasklist. * Add it to the tasklist.
*/ */
@ -738,7 +730,6 @@ void die(int onsig)
{ {
int i, count; int i, count;
char temp[80]; char temp[80];
time_t now;
signal(onsig, SIG_IGN); signal(onsig, SIG_IGN);
@ -803,37 +794,22 @@ void die(int onsig)
Syslog('?', "Continue shutdown with other programs running"); Syslog('?', "Continue shutdown with other programs running");
} }
/*
* Disconnect chatservers
*/
ibc_shutdown();
/* /*
* Now stop the threads * Now stop the threads
*/ */
T_Shutdown = TRUE; T_Shutdown = TRUE;
Syslog('+', "Signal all threads to stop");
/*
* Wait at most 2 seconds for the threads, internal they are
* build to stop within a second.
*/
now = time(NULL) + 2;
while ((cmd_run || ping_run || disk_run || ibc_run) && (time(NULL) < now)) {
sleep(1);
}
if (cmd_run || ping_run || disk_run || ibc_run)
Syslog('+', "Not all threads stopped! Forced shutdown");
if (cmd_run)
Syslog('+', "Thread cmd_run not responding");
if (ping_run)
Syslog('+', "Thread ping_run not responding");
if (disk_run)
Syslog('+', "Thread disk_run not responding");
if (ibc_run)
Syslog('+', "Thread ibc_run not responding");
else
Syslog('+', "All threads stopped");
/* /*
* Free memory * Free memory
*/ */
deinit_ping();
deinitnl(); deinitnl();
deinit_diskwatch();
unload_ports(); unload_ports();
ulocktask(); ulocktask();
printable(NULL, 0); printable(NULL, 0);
@ -843,8 +819,6 @@ void die(int onsig)
*/ */
if (sock != -1) if (sock != -1)
close(sock); close(sock);
if (ping_isocket != -1)
close(ping_isocket);
if (!file_exist(spath, R_OK)) { if (!file_exist(spath, R_OK)) {
unlink(spath); unlink(spath);
} }
@ -1027,11 +1001,10 @@ void check_sema(void)
void start_scheduler(void) void start_scheduler(int port)
{ {
struct passwd *pw; struct passwd *pw;
char *cmd = NULL; char *cmd = NULL;
int rc;
if (nodaemon) if (nodaemon)
printf("init fidonet\n"); printf("init fidonet\n");
@ -1076,6 +1049,28 @@ void start_scheduler(void)
if (nodaemon) if (nodaemon)
printf("sockets created\n"); printf("sockets created\n");
/*
* Setup IBC socket
*/
myaddr_in.sin_family = AF_INET;
myaddr_in.sin_addr.s_addr = INADDR_ANY;
myaddr_in.sin_port = port;
Syslog('+', "IBC: listen on %s, port %d", inet_ntoa(myaddr_in.sin_addr), ntohs(myaddr_in.sin_port));
ibcsock = socket(AF_INET, SOCK_DGRAM, 0);
if (ibcsock == -1) {
WriteError("$IBC: can't create listen socket");
die(MBERR_INIT_ERROR);
}
if (bind(ibcsock, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) {
WriteError("$IBC: can't bind listen socket");
die(MBERR_INIT_ERROR);
}
srand(getpid());
resettime = time(NULL) + (time_t)86400;
/* /*
* The flag masterinit is set if a new config.data is created, this * The flag masterinit is set if a new config.data is created, this
* is true if mbtask is started the very first time. Then we run * is true if mbtask is started the very first time. Then we run
@ -1100,29 +1095,6 @@ void start_scheduler(void)
Syslog('?', "WARNING: this system cannot connect to other systems, check setup"); Syslog('?', "WARNING: this system cannot connect to other systems, check setup");
} }
if (nodaemon)
printf("creating threads\n");
/*
* Install the threads that do the real work.
*/
if ((rc = pthread_create(&pt_ping, NULL, /* (void (*)) */ ping_thread, NULL))) {
WriteError("$pthread_create ping_thread rc=%d", rc);
die(SIGTERM);
} else if ((rc = pthread_create(&pt_command, NULL, (void (*))cmd_thread, NULL))) {
WriteError("$pthread_create cmd_thread rc=%d", rc);
die(SIGTERM);
} else if ((rc = pthread_create(&pt_disk, NULL, (void (*))disk_thread, NULL))) {
WriteError("$pthread_create disk_thread rc=%d", rc);
die(SIGTERM);
} else if ((rc = pthread_create(&pt_ibc, NULL, (void (*))ibc_thread, NULL))) {
WriteError("$pthread_create ibc rc=%d", rc);
die(SIGTERM);
} else {
Syslog('+', "All threads installed");
}
if (nodaemon)
printf("threads installed\n");
/* /*
* Run the scheduler * Run the scheduler
*/ */
@ -1137,20 +1109,21 @@ void start_scheduler(void)
*/ */
void scheduler(void) void scheduler(void)
{ {
struct passwd *pw; struct passwd *pw;
int running = 0, i, found; int rlen, rc, running = 0, i, found, call_work = 0, len;
static int LOADhi = FALSE, oldmin = 70, olddo = 70, oldsec = 70; static int LOADhi = FALSE, oldmin = 70, olddo = 70, oldsec = 70, call_entry = MAXTASKS;
char *cmd = NULL, opts[41], port[21]; char *cmd = NULL, opts[41], port[21], crbuf[512];
static char doing[32]; static char doing[32], buf[2048];
time_t now; time_t now;
struct tm tm, utm; struct tm tm, utm;
#if defined(__linux__) #if defined(__linux__)
FILE *fp; FILE *fp;
#endif #endif
int call_work = 0; double loadavg[3];
static int call_entry = MAXTASKS; pp_list *tpl;
double loadavg[3]; struct pollfd pfd[3];
pp_list *tpl; socklen_t sl;
struct sockaddr_in ffrom;
Syslog('+', "Starting scheduler thread"); Syslog('+', "Starting scheduler thread");
pw = getpwuid(getuid()); pw = getpwuid(getuid());
@ -1159,16 +1132,79 @@ void scheduler(void)
* Enter the mainloop (forever) * Enter the mainloop (forever)
*/ */
do { do {
sleep(1); /*
* Poll UNIX Datagram socket and IBC UDP socket until the defined
* timeout of one second.
* This means we listen of a MBSE BBS client program has something
* to tell. Timeout is one second, after the timeout the rest of the
* mainloop is executed.
*/
pfd[0].fd = sock;
pfd[0].events = POLLIN;
pfd[0].revents = 0;
pfd[1].fd = ibcsock;
pfd[1].events = POLLIN;
pfd[1].revents = 0;
pfd[2].fd = ping_isocket;
pfd[2].events = POLLIN;
pfd[2].revents = 0;
rc = poll(pfd, 3, 1000);
// Syslog('s', "poll() rc=%d", rc);
if (rc == -1) {
/*
* Poll can be interrupted by a finished child so that's not a real error.
*/
if (errno != EINTR) {
Syslog('?', "$poll() rc=%d sock=%d, events=%04x", rc, sock, pfd[0].revents);
Syslog('?', "$poll() rc=%d sock=%d, events=%04x", rc, ibcsock, pfd[1].revents);
}
} else if (rc) {
if (pfd[0].revents & POLLIN) {
/*
* Process the clients request
*/
memset(&buf, 0, sizeof(buf));
fromlen = sizeof(from);
rlen = recvfrom(sock, buf, sizeof(buf) -1, 0, (struct sockaddr *)&from, &fromlen);
if (rlen == -1) {
Syslog('?', "$recvfrom() for command receiver");
} else {
do_cmd(buf);
}
}
if (pfd[1].revents & POLLIN || pfd[1].revents & POLLERR || pfd[1].revents & POLLHUP || pfd[1].revents & POLLNVAL) {
sl = sizeof(myaddr_in);
memset(&clientaddr_in, 0, sizeof(struct sockaddr_in));
memset(&crbuf, 0, sizeof(crbuf));
if ((len = recvfrom(ibcsock, &crbuf, sizeof(crbuf)-1, 0,(struct sockaddr *)&clientaddr_in, &sl)) != -1) {
ibc_receiver(crbuf);
} else {
WriteError("$recvfrom() for IBC receiver");
}
}
if (pfd[2].revents & POLLIN || pfd[2].revents & POLLERR || pfd[2].revents & POLLHUP || pfd[2].revents & POLLNVAL) {
sl = sizeof(ffrom);
if ((len = recvfrom(ping_isocket, &buf, sizeof(buf)-1, 0,(struct sockaddr *)&ffrom, &sl)) != -1) {
ping_receive(buf, len);
} else {
WriteError("$recvfrom() for ping receiver");
}
}
}
if (G_Shutdown) if (G_Shutdown)
break; break;
/* /*
* Check all registered connections and semafore's * Check all registered connections and semafore's
*/ */
check_servers();
reg_check(); reg_check();
check_sema(); check_sema();
check_ports(); check_ports();
diskwatch();
check_ping();
/* /*
* Check the systems load average. * Check the systems load average.
@ -1303,12 +1339,9 @@ void scheduler(void)
running = checktasks(0); running = checktasks(0);
if (s_mailout && (!ptimer) && (!runtasktype(MBFIDO))) { if (s_mailout && (!ptimer) && (!runtasktype(MBFIDO))) {
if (! lock_ibc((char *)"scheduler 1")) { launch(TCFG.cmd_mailout, NULL, (char *)"mailout", MBFIDO);
launch(TCFG.cmd_mailout, NULL, (char *)"mailout", MBFIDO); running = checktasks(0);
unlock_ibc((char *)"scheduler 1"); s_mailout = FALSE;
running = checktasks(0);
s_mailout = FALSE;
}
} }
if (s_mailin && (!ptimer) && (!runtasktype(MBFIDO))) { if (s_mailin && (!ptimer) && (!runtasktype(MBFIDO))) {
@ -1322,32 +1355,23 @@ void scheduler(void)
if ((ipmailers + runtasktype(CM_ISDN) + runtasktype(CM_POTS)) == 0) { if ((ipmailers + runtasktype(CM_ISDN) + runtasktype(CM_POTS)) == 0) {
Syslog('i', "Mailin, no mailers running, start direct"); Syslog('i', "Mailin, no mailers running, start direct");
tosswait = TOSSWAIT_TIME; tosswait = TOSSWAIT_TIME;
if (! lock_ibc((char *)"scheduler 2")) { launch(TCFG.cmd_mailin, NULL, (char *)"mailin", MBFIDO);
launch(TCFG.cmd_mailin, NULL, (char *)"mailin", MBFIDO); running = checktasks(0);
unlock_ibc((char *)"scheduler 2"); s_mailin = FALSE;
running = checktasks(0);
s_mailin = FALSE;
}
} else { } else {
Syslog('i', "Mailin, tosswait=%d", tosswait); Syslog('i', "Mailin, tosswait=%d", tosswait);
if (tosswait == 0) { if (tosswait == 0) {
if (! lock_ibc((char *)"scheduler 3")) { launch(TCFG.cmd_mailin, NULL, (char *)"mailin", MBFIDO);
launch(TCFG.cmd_mailin, NULL, (char *)"mailin", MBFIDO); running = checktasks(0);
unlock_ibc((char *)"scheduler 3"); s_mailin = FALSE;
running = checktasks(0);
s_mailin = FALSE;
}
} }
} }
} }
if (s_newnews && (!ptimer) && (!runtasktype(MBFIDO))) { if (s_newnews && (!ptimer) && (!runtasktype(MBFIDO))) {
if (! lock_ibc((char *)"scheduler 4")) { launch(TCFG.cmd_newnews, NULL, (char *)"newnews", MBFIDO);
launch(TCFG.cmd_newnews, NULL, (char *)"newnews", MBFIDO); running = checktasks(0);
unlock_ibc((char *)"scheduler 4"); s_newnews = FALSE;
running = checktasks(0);
s_newnews = FALSE;
}
} }
/* /*
@ -1358,22 +1382,13 @@ void scheduler(void)
*/ */
if (s_index && (!ptimer) && (!running)) { if (s_index && (!ptimer) && (!running)) {
if (strlen(TCFG.cmd_mbindex1)) { if (strlen(TCFG.cmd_mbindex1)) {
if (! lock_ibc((char *)"scheduler 5")) { launch(TCFG.cmd_mbindex1, NULL, (char *)"compiler 1", MBINDEX);
launch(TCFG.cmd_mbindex1, NULL, (char *)"compiler 1", MBINDEX);
unlock_ibc((char *)"scheduler 5");
}
} }
if (strlen(TCFG.cmd_mbindex2)) { if (strlen(TCFG.cmd_mbindex2)) {
if (! lock_ibc((char *)"scheduler 6")) { launch(TCFG.cmd_mbindex2, NULL, (char *)"compiler 2", MBINDEX);
launch(TCFG.cmd_mbindex2, NULL, (char *)"compiler 2", MBINDEX);
unlock_ibc((char *)"scheduler 6");
}
} }
if (strlen(TCFG.cmd_mbindex3)) { if (strlen(TCFG.cmd_mbindex3)) {
if (! lock_ibc((char *)"scheduler 7")) { launch(TCFG.cmd_mbindex3, NULL, (char *)"compiler 3", MBINDEX);
launch(TCFG.cmd_mbindex3, NULL, (char *)"compiler 3", MBINDEX);
unlock_ibc((char *)"scheduler 7");
}
} }
running = checktasks(0); running = checktasks(0);
s_index = FALSE; s_index = FALSE;
@ -1384,10 +1399,7 @@ void scheduler(void)
* nothing else to do. * nothing else to do.
*/ */
if (s_msglink && (!ptimer) && (!running)) { if (s_msglink && (!ptimer) && (!running)) {
if (! lock_ibc((char *)"scheduler 8")) { launch(TCFG.cmd_msglink, NULL, (char *)"msglink", MBFIDO);
launch(TCFG.cmd_msglink, NULL, (char *)"msglink", MBFIDO);
unlock_ibc((char *)"scheduler 8");
}
running = checktasks(0); running = checktasks(0);
s_msglink = FALSE; s_msglink = FALSE;
} }
@ -1396,10 +1408,7 @@ void scheduler(void)
* Creating filerequest indexes, also only if nothing to do. * Creating filerequest indexes, also only if nothing to do.
*/ */
if (s_reqindex && (!ptimer) && (!running)) { if (s_reqindex && (!ptimer) && (!running)) {
if (! lock_ibc((char *)"scheduler 9")) { launch(TCFG.cmd_reqindex, NULL, (char *)"reqindex", MBFILE);
launch(TCFG.cmd_reqindex, NULL, (char *)"reqindex", MBFILE);
unlock_ibc((char *)"scheduler 9");
}
running = checktasks(0); running = checktasks(0);
s_reqindex = FALSE; s_reqindex = FALSE;
} }
@ -1503,10 +1512,7 @@ void scheduler(void)
calllist[call_entry].addr.net, calllist[call_entry].addr.net,
calllist[call_entry].addr.zone, calllist[call_entry].addr.domain); calllist[call_entry].addr.zone, calllist[call_entry].addr.domain);
} }
if (! lock_ibc((char *)"scheduler 10")) { calllist[call_entry].taskpid = launch(cmd, opts, (char *)"mbcico", calllist[call_entry].callmode);
calllist[call_entry].taskpid = launch(cmd, opts, (char *)"mbcico", calllist[call_entry].callmode);
unlock_ibc((char *)"scheduler 10");
}
if (calllist[call_entry].taskpid) if (calllist[call_entry].taskpid)
calllist[call_entry].calling = TRUE; calllist[call_entry].calling = TRUE;
running = checktasks(0); running = checktasks(0);
@ -1532,6 +1538,7 @@ int main(int argc, char **argv)
int i; int i;
pid_t frk; pid_t frk;
FILE *fp; FILE *fp;
struct servent *se;
/* /*
* Print copyright notices and setup logging. * Print copyright notices and setup logging.
@ -1598,6 +1605,24 @@ int main(int argc, char **argv)
if (nodaemon) if (nodaemon)
printf("main config loaded\n"); printf("main config loaded\n");
if ((se = getservbyname("fido", "udp")) == NULL) {
fprintf(stderr, "IBC: no fido udp entry in /etc/services, cannot start Internet BBS Chat\n");
close(ping_isocket);
exit(MBERR_INIT_ERROR);
}
if (strlen(CFG.bbs_name) == 0) {
fprintf(stderr, "IBC: mbsetup 1.2.1 is empty, cannot start Internet BBS Chat\n");
close(ping_isocket);
exit(MBERR_INIT_ERROR);
}
if (strlen(CFG.myfqdn) == 0) {
fprintf(stderr, "IBC: mbsetup 1.2.10 is empty, cannot start Internet BBS Chat\n");
close(ping_isocket);
exit(MBERR_INIT_ERROR);
}
mypid = getpid(); mypid = getpid();
if (nodaemon) if (nodaemon)
printf("my pid is %d\n", mypid); printf("my pid is %d\n", mypid);
@ -1636,7 +1661,7 @@ int main(int argc, char **argv)
*/ */
mypid = getpid(); mypid = getpid();
printf("init complete, starting scheduler ...\n"); printf("init complete, starting scheduler ...\n");
start_scheduler(); start_scheduler(se->s_port);
} else { } else {
/* /*
* Server initialization is complete. Now we can fork the * Server initialization is complete. Now we can fork the
@ -1677,7 +1702,7 @@ int main(int argc, char **argv)
_exit(MBERR_EXEC_FAILED); _exit(MBERR_EXEC_FAILED);
} }
mypid = getpid(); mypid = getpid();
start_scheduler(); start_scheduler(se->s_port);
/* Not reached */ /* Not reached */
default: default:
/* /*

View File

@ -47,7 +47,7 @@ pid_t launch(char *, char *, char *, int);
int runtasktype(int); int runtasktype(int);
int checktasks(int); int checktasks(int);
void die(int); void die(int);
void start_scheduler(void); void start_scheduler(int);
void scheduler(void); void scheduler(void);
int locktask(char *); int locktask(char *);
void ulocktask(void); void ulocktask(void);

View File

@ -4,7 +4,7 @@
* Purpose ...............: mbtask - ping functions * Purpose ...............: mbtask - ping functions
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2005 * Copyright (C) 1997-2006
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -45,8 +45,12 @@ int icmp_errs = 0; /* ICMP error counter */
extern int internet; /* Internet is down */ extern int internet; /* Internet is down */
extern int rescan; /* Master rescan flag */ extern int rescan; /* Master rescan flag */
struct in_addr paddr; /* Current ping address */ struct in_addr paddr; /* Current ping address */
extern int T_Shutdown; /* Program shutdown */ int pingnr = 2; /* Ping number */
int ping_run = FALSE; /* Thread runnning */ int pingresult[2]; /* Results of pings */
time_t ping_rcvd; /* Time ping received */
time_t ping_sent; /* Time ping sent */
time_t ping_next; /* Time to sent next */
char pingaddress[41]; /* Last pingaddress */
@ -56,7 +60,6 @@ int ping_run = FALSE; /* Thread runnning */
static int icmp4_errcmp(char *, int, struct in_addr *, char *, int, int); static int icmp4_errcmp(char *, int, struct in_addr *, char *, int, int);
unsigned short get_rand16(void); unsigned short get_rand16(void);
int ping_send(struct in_addr); int ping_send(struct in_addr);
int ping_receive(struct in_addr);
/* /*
@ -231,71 +234,50 @@ int ping_send(struct in_addr addr)
/* /*
* 0 = reply received Ok. * Process received data on ping socket
* -1 = reply packet not for us, this is Ok.
* -2 = destination unreachable.
* -3 = poll/select error.
* -4 = time exceeded.
* -5 = wrong packetlen received.
* -6 = no data received, this is Ok.
* -7 = icmp parameter problem.
*/ */
int ping_receive(struct in_addr addr) void ping_receive(char *buf, int len)
{ {
char buf[1024];
int rc, len;
struct sockaddr_in ffrom;
struct icmphdr icmpp; struct icmphdr icmpp;
struct iphdr iph; struct iphdr iph;
socklen_t sl; int reply;
struct pollfd pfd;
pfd.fd = ping_isocket; memcpy(&iph, buf, sizeof(iph));
pfd.events = POLLIN; if (len - iph.ip_hl * 4 >= ICMP_BASEHDR_LEN) {
pfd.revents = 0; memcpy(&icmpp, ((uint32_t *)buf)+iph.ip_hl, sizeof(icmpp));
if (iph.ip_saddr == paddr.s_addr && icmpp.icmp_type == ICMP_ECHOREPLY &&
/* ntohs(icmpp.icmp_id) == id && ntohs(icmpp.icmp_seq) == p_sequence) {
* 100 mSec is enough, this function is called at regular intervals. /*
*/ * Good reply
if ((rc = poll(&pfd, 1, 100) < 0)) { */
if (icmp_errs < ICMP_MAX_ERRS) ping_rcvd = time(NULL);
Syslog('?', "$poll/select failed"); pingresult[pingnr - 1] = TRUE;
return -3; reply = ((int)ping_rcvd - (int)ping_sent);
} if (reply > 10)
Syslog('p', "Ping: got slow reply pingnr=%d to %s in %d seconds", pingnr, pingaddress, reply);
if (pfd.revents & POLLIN || pfd.revents & POLLERR || pfd.revents & POLLHUP || pfd.revents & POLLNVAL) { return;
sl = sizeof(ffrom);
if ((len = recvfrom(ping_isocket, &buf, sizeof(buf)-1, 0,(struct sockaddr *)&ffrom, &sl)) != -1) {
if (len > sizeof(struct iphdr)) {
memcpy(&iph, buf, sizeof(iph));
if (len - iph.ip_hl * 4 >= ICMP_BASEHDR_LEN) {
memcpy(&icmpp, ((uint32_t *)buf)+iph.ip_hl, sizeof(icmpp));
if (iph.ip_saddr == addr.s_addr && icmpp.icmp_type == ICMP_ECHOREPLY &&
ntohs(icmpp.icmp_id) == id && ntohs(icmpp.icmp_seq) == p_sequence) {
return 0;
} else {
/* No regular echo reply. Maybe an error? */
if (icmp4_errcmp((char *)&icmpd, ICMP4_ECHO_LEN, &to.sin_addr, buf, len, ICMP_DEST_UNREACH))
return -2;
if (icmp4_errcmp((char *)&icmpd, ICMP4_ECHO_LEN, &to.sin_addr, buf, len, ICMP_TIME_EXCEEDED))
return -4;
#ifdef __linux__
if (icmp4_errcmp((char *)&icmpd, ICMP4_ECHO_LEN, &to.sin_addr, buf, len, ICMP_PARAMETERPROB))
return -7;
#endif
/*
* No fatal problem, the return code will be -1 caused by other
* icmp trafic on the network (packets not for us).
*/
return -1;
}
}
}
} else { } else {
return -5; /* error */ /* No regular echo reply. Maybe an error? */
if (icmp4_errcmp((char *)&icmpd, ICMP4_ECHO_LEN, &to.sin_addr, buf, len, ICMP_DEST_UNREACH)) {
Syslog('p', "Ping: got destination unreachable");
return;
}
if (icmp4_errcmp((char *)&icmpd, ICMP4_ECHO_LEN, &to.sin_addr, buf, len, ICMP_TIME_EXCEEDED)) {
Syslog('p', "Ping: got time exceeded");
return;
}
#ifdef __linux__
if (icmp4_errcmp((char *)&icmpd, ICMP4_ECHO_LEN, &to.sin_addr, buf, len, ICMP_PARAMETERPROB)) {
Syslog('p', "Ping: got parameter problem");
return;
}
#endif
/*
* Received packet was not for us.
*/
return;
} }
} }
return -6; /* no answer */
} }
@ -321,28 +303,32 @@ void init_pingsocket(void)
if (ping_isocket == STDIN_FILENO || ping_isocket == STDOUT_FILENO || ping_isocket == STDERR_FILENO) { if (ping_isocket == STDIN_FILENO || ping_isocket == STDOUT_FILENO || ping_isocket == STDERR_FILENO) {
exit(MBERR_GENERAL); exit(MBERR_GENERAL);
} }
pingresult[0] = pingresult[1] = FALSE;
ping_next = ping_sent = ping_rcvd = time(NULL);
snprintf(pingaddress, 41, "N/A");
} }
/* /*
* Ping thread * Called regular, but at least each second
*/ */
void *ping_thread(void *dummy) void check_ping(void)
{ {
int rc = 0; int rc = 0;
static int pingnr, pingresult[2];
static char pingaddress[41];
static time_t pingsend;
time_t now; time_t now;
Syslog('+', "Starting ping thread"); // Syslog('p', "Ping: 1=%s 2=%s nr=%d", pingresult[0] ? "TRUE":"FALSE", pingresult[1] ? "TRUE":"FALSE", pingnr);
pingresult[1] = pingresult[2] = FALSE; now = time(NULL);
pingnr = 2; if ((int)now >= (int)ping_next) {
internet = FALSE; // Syslog('p', "Ping: time for next");
ping_run = TRUE; /*
* Was previous ping received?
while (! T_Shutdown) { */
if (pingresult[pingnr - 1] == FALSE) {
Syslog('p', "Ping: timeout to %s", pingaddress);
}
/* /*
* Select new address to ping * Select new address to ping
@ -352,114 +338,74 @@ void *ping_thread(void *dummy)
if (strlen(TCFG.isp_ping2)) { if (strlen(TCFG.isp_ping2)) {
snprintf(pingaddress, 41, "%s", TCFG.isp_ping2); snprintf(pingaddress, 41, "%s", TCFG.isp_ping2);
} else { } else {
pingresult[2] = FALSE; pingresult[1] = TRUE;
} }
} else { } else {
pingnr = 1; pingnr = 1;
if (strlen(TCFG.isp_ping1)) { if (strlen(TCFG.isp_ping1)) {
snprintf(pingaddress, 41, "%s", TCFG.isp_ping1); snprintf(pingaddress, 41, "%s", TCFG.isp_ping1);
} else { } else {
pingresult[1] = FALSE; pingresult[0] = TRUE;
} }
} }
// Syslog('p', "Ping: 1=%s 2=%s nr=%d", pingresult[0] ? "TRUE":"FALSE", pingresult[1] ? "TRUE":"FALSE", pingnr);
ping_next = (time_t)(now + 20);
if (inet_aton(pingaddress, &paddr)) { if (inet_aton(pingaddress, &paddr)) {
pingresult[pingnr - 1] = FALSE;
rc = ping_send(paddr); rc = ping_send(paddr);
// Syslog('p', "Ping: %d sent to %s rc=%d", pingnr, pingaddress, rc);
if (rc) { if (rc) {
if (icmp_errs++ < ICMP_MAX_ERRS) if (icmp_errs++ < ICMP_MAX_ERRS)
Syslog('?', "ping: to %s rc=%d", pingaddress, rc); Syslog('?', "ping: to %s rc=%d", pingaddress, rc);
pingresult[pingnr] = FALSE;
now = time(NULL) + 10;
while ((! T_Shutdown) && (time(NULL) < now)) {
sleep(1);
}
if (T_Shutdown)
break;
} else { } else {
pingsend = time(NULL); ping_sent = now;
pingresult[pingnr - 1] = FALSE;
while (TRUE) { // Syslog('p', "Ping: 1=%s 2=%s nr=%d", pingresult[0] ? "TRUE":"FALSE", pingresult[1] ? "TRUE":"FALSE", pingnr);
if (T_Shutdown) return; // Don't check right after send
break;
if (time(NULL) >= (pingsend + 20)) {
pingresult[pingnr] = FALSE;
if (icmp_errs < ICMP_MAX_ERRS)
Syslog('?', "ping: to %s timeout", pingaddress);
break;
} else {
/*
* Quickly eat all packets not for us, we only want our
* packets and empty results (packet still underway).
*/
while ((rc = ping_receive(paddr)) == -1);
if (!rc) {
/*
* Reply received.
*/
rc = time(NULL) - pingsend;
if (rc > 10)
Syslog('+', "Ping: slow reply after %d seconds", rc);
pingresult[pingnr] = TRUE;
now = time(NULL) + 20 - rc;
while ((! T_Shutdown) && (time(NULL) < now)) {
sleep(1);
}
break;
} else {
if (rc != -6) {
Syslog('p', "ping: recv %s id=%d rc=%d", pingaddress, id, rc);
pingresult[pingnr] = FALSE;
}
}
}
} /* while TRUE */
}
} else {
if (icmp_errs++ < ICMP_MAX_ERRS)
Syslog('?', "Ping address %d is invalid \"%s\"", pingnr, pingaddress);
now = time(NULL) + 10;
while ((! T_Shutdown) && (time(NULL) < now)) {
sleep(1);
}
}
if (T_Shutdown)
break;
/*
* Evaluate the result of the ping test
*/
if (pingresult[1] == FALSE && pingresult[2] == FALSE) {
icmp_errs++;
if (internet) {
Syslog('!', "Internet connection is down");
internet = FALSE;
sem_set((char *)"scanout", TRUE);
RemoveSema((char *)"is_inet");
rescan = TRUE;
}
} else {
icmp_errs = 0;
if (!internet) {
Syslog('!', "Internet connection is up");
internet = TRUE;
sem_set((char *)"scanout", TRUE);
CreateSema((char *)"is_inet");
rescan = TRUE;
} }
} }
} }
// Syslog('p', "Ping: 1=%s 2=%s nr=%d", pingresult[0] ? "TRUE":"FALSE", pingresult[1] ? "TRUE":"FALSE", pingnr);
/*
* Evaluate the result of the ping test
*/
if ((pingresult[0] == FALSE) && (pingresult[1] == FALSE)) {
icmp_errs++;
if (internet) {
Syslog('!', "Internet connection is down");
internet = FALSE;
sem_set((char *)"scanout", TRUE);
RemoveSema((char *)"is_inet");
rescan = TRUE;
}
} else {
icmp_errs = 0;
if (!internet) {
Syslog('!', "Internet connection is up");
internet = TRUE;
sem_set((char *)"scanout", TRUE);
CreateSema((char *)"is_inet");
rescan = TRUE;
}
}
}
void deinit_ping(void)
{
int rc;
if ((rc = close(ping_isocket))) { if ((rc = close(ping_isocket))) {
WriteError("$ping thread error socket close"); WriteError("$ping thread error socket close");
} }
ping_isocket = -1; ping_isocket = -1;
ping_run = FALSE;
Syslog('+', "Ping thread stopped"); Syslog('+', "Ping thread stopped");
pthread_exit(NULL);
} }

View File

@ -10,7 +10,9 @@
#define ICMP_MAX_ERRS 5 #define ICMP_MAX_ERRS 5
#define SET_SOCKA_LEN4(socka) #define SET_SOCKA_LEN4(socka)
void init_pingsocket(void); void init_pingsocket(void);
void *ping_thread(void*); void ping_receive(char *, int);
void check_ping(void);
void deinit_ping(void);
#endif #endif

View File

@ -76,6 +76,7 @@ extern int srvchg;
/* /*
* Prototypes * Prototypes
*/ */
void Chatlog(char *, char *, char *);
void chat_dump(void); void chat_dump(void);
void system_msg(pid_t, char *); void system_msg(pid_t, char *);
void chat_help(pid_t, int); void chat_help(pid_t, int);
@ -129,7 +130,6 @@ void system_msg(pid_t pid, char *msg)
else else
buffer_head = 0; buffer_head = 0;
// Syslog('c', "system_msg(%d, %s) ptr=%d", pid, msg, buffer_head);
memset(&chat_messages[buffer_head], 0, sizeof(_chat_messages)); memset(&chat_messages[buffer_head], 0, sizeof(_chat_messages));
chat_messages[buffer_head].topid = pid; chat_messages[buffer_head].topid = pid;
snprintf(chat_messages[buffer_head].fromname, 36, "Server"); snprintf(chat_messages[buffer_head].fromname, 36, "Server");
@ -207,11 +207,8 @@ int join(pid_t pid, char *channel, int sysop)
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
if (tmpu->pid == pid) { if (tmpu->pid == pid) {
if (! lock_ibc((char *)"join 1")) { strncpy(tmpu->channel, channel, 20);
strncpy(tmpu->channel, channel, 20); tmp->users++;
tmp->users++;
unlock_ibc((char *)"join 1");
}
Syslog('+', "IBC: user %s has joined channel %s", tmpu->nick, channel); Syslog('+', "IBC: user %s has joined channel %s", tmpu->nick, channel);
usrchg = TRUE; usrchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
@ -249,10 +246,7 @@ int join(pid_t pid, char *channel, int sysop)
if (tmpu->pid == pid) { if (tmpu->pid == pid) {
if (add_channel(&channels, channel, tmpu->nick, CFG.myfqdn) == 0) { if (add_channel(&channels, channel, tmpu->nick, CFG.myfqdn) == 0) {
if (! lock_ibc((char *)"join 2")) { strncpy(tmpu->channel, channel, 20);
strncpy(tmpu->channel, channel, 20);
unlock_ibc((char *)"join 2");
}
Syslog('+', "IBC: user %s created and joined channel %s", tmpu->nick, channel); Syslog('+', "IBC: user %s created and joined channel %s", tmpu->nick, channel);
usrchg = TRUE; usrchg = TRUE;
chnchg = TRUE; chnchg = TRUE;
@ -318,11 +312,8 @@ int part(pid_t pid, char *reason)
/* /*
* Clean channel * Clean channel
*/ */
if (! lock_ibc((char *)"part 1")) { if (tmp->users > 0)
if (tmp->users > 0) tmp->users--;
tmp->users--;
unlock_ibc((char *)"part 1");
}
Syslog('+', "IBC: nick %s leaves channel %s, %d user left", tmpu->nick, tmp->name, tmp->users); Syslog('+', "IBC: nick %s leaves channel %s, %d user left", tmpu->nick, tmp->name, tmp->users);
if (tmp->users == 0) { if (tmp->users == 0) {
/* /*
@ -337,10 +328,7 @@ int part(pid_t pid, char *reason)
/* /*
* Update user data * Update user data
*/ */
if (! lock_ibc((char *)"part 2")) { tmpu->channel[0] = '\0';
tmpu->channel[0] = '\0';
unlock_ibc((char *)"part 2");
}
usrchg = TRUE; usrchg = TRUE;
chnchg = TRUE; chnchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
@ -436,12 +424,9 @@ void chat_connect_r(char *data, char *buf)
/* /*
* Oke, found * Oke, found
*/ */
if (! lock_ibc((char *)"chat_connect")) { tmpu->pid = atoi(pid);
tmpu->pid = atoi(pid); tmpu->pointer = buffer_head;
tmpu->pointer = buffer_head; tmpu->sysop = sys;
tmpu->sysop = sys;
unlock_ibc((char *)"chat_connect");
}
usrchg = TRUE; usrchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
Syslog('c', "Connected user %s (%s) with chatserver, sysop %s", realname, pid, sys ? "True":"False"); Syslog('c', "Connected user %s (%s) with chatserver, sysop %s", realname, pid, sys ? "True":"False");
@ -500,6 +485,7 @@ void chat_close_r(char *data, char *buf)
return; return;
} }
} }
Syslog('c', "Pid %s was not connected to chatserver"); Syslog('c', "Pid %s was not connected to chatserver");
snprintf(buf, 81, "100:1,*** ERROR - Not connected to server;"); snprintf(buf, 81, "100:1,*** ERROR - Not connected to server;");
return; return;
@ -810,15 +796,16 @@ void chat_checksysop_r(char *data, char *buf)
pid = strtok(data, ","); pid = strtok(data, ",");
pid = strtok(NULL, ";"); pid = strtok(NULL, ";");
if (reg_ispaging(pid)) { if (reg_ispaging(pid)) {
Syslog('c', "Check sysopchat for pid %s, user has paged", pid); Syslog('c', "Check sysopchat for pid %s, user has paged", pid);
/* /*
* Now check if sysop is present in the sysop channel * Now check if sysop is present in the sysop channel
*/ */
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
if (atoi(pid) != tmpu->pid) { if (atoi(pid) != tmpu->pid) {
if (strlen(tmpu->channel) && (strcasecmp(tmpu->channel, "#sysop") == 0) && tmpu->sysop) { if (strlen(tmpu->channel) && (strcasecmp(tmpu->channel, "#sysop") == 0) && tmpu->sysop) {
Syslog('c', "Sending ACK on check"); Syslog('c', "Sending ACK on check");
snprintf(buf, 20, "100:1,1;"); snprintf(buf, 20, "100:1,1;");
reg_sysoptalk(pid); reg_sysoptalk(pid);

View File

@ -3,7 +3,6 @@
/* $Id$ */ /* $Id$ */
void Chatlog(char *, char *, char *);
void chat_msg(char *, char *, char *); void chat_msg(char *, char *, char *);
void system_shout(const char *, ...); void system_shout(const char *, ...);
void chat_init(void); void chat_init(void);

View File

@ -37,6 +37,7 @@
#include "taskutil.h" #include "taskutil.h"
#include "taskchat.h" #include "taskchat.h"
#include "taskcomm.h" #include "taskcomm.h"
#include "taskibc.h"
extern int oserr; /* Copy of Unix error */ extern int oserr; /* Copy of Unix error */
@ -45,8 +46,6 @@ extern struct sockaddr_un from; /* From socket address */
extern int fromlen; /* From address length */ extern int fromlen; /* From address length */
extern int logtrans; /* Log transactions */ extern int logtrans; /* Log transactions */
extern int T_Shutdown; /* Program shutdown */ extern int T_Shutdown; /* Program shutdown */
extern int ibc_run; /* Chatserver running */
int cmd_run = FALSE;/* cmd running */
@ -288,12 +287,8 @@ char *exe_cmd(char *in)
* 100:0; Ok * 100:0; Ok
*/ */
if (strncmp(cmd, "CPAG", 4) == 0) { if (strncmp(cmd, "CPAG", 4) == 0) {
if (ibc_run) { if ((result = reg_page(token))) {
if ((result = reg_page(token))) { snprintf(obuf, SS_BUFSIZE, "100:1,%d;", result);
snprintf(obuf, SS_BUFSIZE, "100:1,%d;", result);
}
} else {
snprintf(obuf, SS_BUFSIZE, "100:1,3;");
} }
Syslog('+', "%s", obuf); Syslog('+', "%s", obuf);
return obuf; return obuf;
@ -347,15 +342,11 @@ char *exe_cmd(char *in)
* 100:0; Ok * 100:0; Ok
*/ */
if (strncmp(cmd, "CCON", 4) == 0) { if (strncmp(cmd, "CCON", 4) == 0) {
if (ibc_run) { buf = calloc(SS_BUFSIZE, sizeof(char));
buf = calloc(SS_BUFSIZE, sizeof(char)); chat_connect_r(token, buf);
chat_connect_r(token, buf); snprintf(obuf, SS_BUFSIZE, "%s", buf);
snprintf(obuf, SS_BUFSIZE, "%s", buf); free(buf);
free(buf); return obuf;
return obuf;
} else {
return ebuf;
}
} }
/* /*
@ -668,7 +659,6 @@ char *exe_cmd(char *in)
void do_cmd(char *);
void do_cmd(char *cmd) void do_cmd(char *cmd)
{ {
char buf[SS_BUFSIZE]; char buf[SS_BUFSIZE];
@ -696,58 +686,3 @@ void do_cmd(char *cmd)
} }
/*
* Thread that reads the command socket for new commands.
*/
void *cmd_thread(void)
{
int rlen, rc;
struct pollfd pfd;
static char buf[2048];
Syslog('+', "Starting cmd thread");
cmd_run = TRUE;
while (! T_Shutdown) {
/*
* Poll UNIX Datagram socket until the defined timeout of one second.
* This means we listen of a MBSE BBS client program has something
* to tell.
*/
pfd.fd = sock;
pfd.events = POLLIN;
pfd.revents = 0;
rc = poll(&pfd, 1, 1000);
if (rc == -1) {
/*
* Poll can be interrupted by a finished child so that's not a real error.
*/
if (errno != EINTR) {
Syslog('?', "$poll() rc=%d sock=%d, events=%04x", rc, sock, pfd.revents);
}
} else if (rc) {
if (pfd.revents & POLLIN) {
/*
* Process the clients request
*/
memset(&buf, 0, sizeof(buf));
fromlen = sizeof(from);
rlen = recvfrom(sock, buf, sizeof(buf) -1, 0, (struct sockaddr *)&from, &fromlen);
if (rlen == -1) {
Syslog('?', "$recvfrom()");
} else {
do_cmd(buf);
}
} else {
Syslog('-', "Return poll rc=%d, events=%04x", rc, pfd.revents);
}
}
}
cmd_run = FALSE;
Syslog('+', "Cmd thread stopped");
pthread_exit(NULL);
}

View File

@ -3,7 +3,7 @@
/* $Id$ */ /* $Id$ */
void *cmd_thread(void); void do_cmd(char *);
#endif #endif

View File

@ -44,14 +44,10 @@ typedef struct _mfs_list {
} mfs_list; } mfs_list;
mfs_list *mfs = NULL; /* List of filesystems */ mfs_list *mfs = NULL; /* List of filesystems */
int disk_reread = FALSE; /* Reread tables */ int disk_reread = TRUE; /* Reread tables */
extern int T_Shutdown; /* Program shutdown */
int disk_run = FALSE; /* Thread running */
int recursecount = 0; /* Recurse counter */ int recursecount = 0; /* Recurse counter */
pthread_mutex_t a_mutex = PTHREAD_MUTEX_INITIALIZER;
/* /*
* Internal prototypes * Internal prototypes
@ -250,7 +246,6 @@ void disk_check_r(char *token, char *buf)
{ {
mfs_list *tmp; mfs_list *tmp;
unsigned int needed, lowest = 0xffffffff; unsigned int needed, lowest = 0xffffffff;
int rc;
strtok(token, ","); strtok(token, ",");
needed = atol(strtok(NULL, ";")); needed = atol(strtok(NULL, ";"));
@ -263,17 +258,11 @@ void disk_check_r(char *token, char *buf)
return; return;
} }
if ((rc = pthread_mutex_lock(&a_mutex)))
Syslog('!', "disk_check() mutex_lock failed rc=%d", rc);
for (tmp = mfs; tmp; tmp = tmp->next) { for (tmp = mfs; tmp; tmp = tmp->next) {
if (!tmp->ro && (tmp->avail < lowest)) if (!tmp->ro && (tmp->avail < lowest))
lowest = tmp->avail; lowest = tmp->avail;
} }
if ((rc = pthread_mutex_unlock(&a_mutex)))
Syslog('!', "disk_check() mutex_unlock failed rc=%d", rc);
if (lowest < needed) { if (lowest < needed) {
snprintf(buf, SS_BUFSIZE, "100:2,0,%d;", lowest); snprintf(buf, SS_BUFSIZE, "100:2,0,%d;", lowest);
} else { } else {
@ -292,7 +281,7 @@ void disk_getfs_r(char *buf)
{ {
char tt[80], *ans = NULL; char tt[80], *ans = NULL;
mfs_list *tmp; mfs_list *tmp;
int rc, i = 0; int i = 0;
buf[0] = '\0'; buf[0] = '\0';
if (mfs == NULL) { if (mfs == NULL) {
@ -300,9 +289,6 @@ void disk_getfs_r(char *buf)
return; return;
} }
if ((rc = pthread_mutex_lock(&a_mutex)))
Syslog('!', "disk_getfs() mutex_lock failed rc=%d", rc);
for (tmp = mfs; tmp; tmp = tmp->next) { for (tmp = mfs; tmp; tmp = tmp->next) {
i++; i++;
if (ans == NULL) if (ans == NULL)
@ -315,8 +301,6 @@ void disk_getfs_r(char *buf)
if (i == 10) /* No more then 10 filesystems */ if (i == 10) /* No more then 10 filesystems */
break; break;
} }
if ((rc = pthread_mutex_unlock(&a_mutex)))
Syslog('!', "disk_getfs() mutex_unlock failed rc=%d", rc);
if (strlen(ans) > (SS_BUFSIZE - 8)) if (strlen(ans) > (SS_BUFSIZE - 8))
snprintf(buf, SS_BUFSIZE, "100:0;"); snprintf(buf, SS_BUFSIZE, "100:0;");
@ -333,7 +317,7 @@ void disk_getfs_r(char *buf)
/* /*
* Update disk useage status. The calling function must lock the mutex! * Update disk useage status.
*/ */
void update_diskstat(void) void update_diskstat(void)
{ {
@ -473,221 +457,172 @@ void add_path(char *lpath)
/* /*
* Diskwatch thread * Diskwatch
*/ */
void *disk_thread(void) void diskwatch(void)
{ {
FILE *fp; FILE *fp;
char *temp = NULL; char *temp = NULL;
mfs_list *tmp; mfs_list *tmp;
int rc;
Syslog('+', "Start disk thread"); if (disk_reread) {
disk_run = TRUE; disk_reread = FALSE;
disk_reread = TRUE; Syslog('+', "Reread disk filesystems");
while (! T_Shutdown) { tidy_mfslist(&mfs);
if (disk_reread) { add_path(getenv("MBSE_ROOT"));
disk_reread = FALSE; add_path(CFG.bbs_menus);
Syslog('+', "Reread disk filesystems"); add_path(CFG.bbs_txtfiles);
add_path(CFG.alists_path);
add_path(CFG.req_magic);
add_path(CFG.bbs_usersdir);
add_path(CFG.nodelists);
add_path(CFG.inbound);
add_path(CFG.pinbound);
add_path(CFG.outbound);
add_path(CFG.ftp_base);
add_path(CFG.bbs_macros);
add_path(CFG.out_queue);
add_path(CFG.rulesdir);
add_path(CFG.tmailshort);
add_path(CFG.tmaillong);
if ((rc = pthread_mutex_lock(&a_mutex))) temp = calloc(PATH_MAX, sizeof(char ));
Syslog('!', "disk_thread() mutex_lock failed rc=%d", rc); snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&areahdr, sizeof(areahdr), 1, fp);
fseek(fp, areahdr.hdrsize, SEEK_SET);
tidy_mfslist(&mfs); while (fread(&area, areahdr.recsize, 1, fp)) {
if (area.Available) {
add_path(getenv("MBSE_ROOT")); add_path(area.Path);
add_path(CFG.bbs_menus);
add_path(CFG.bbs_txtfiles);
add_path(CFG.alists_path);
add_path(CFG.req_magic);
add_path(CFG.bbs_usersdir);
add_path(CFG.nodelists);
add_path(CFG.inbound);
add_path(CFG.pinbound);
add_path(CFG.outbound);
add_path(CFG.ftp_base);
add_path(CFG.bbs_macros);
add_path(CFG.out_queue);
add_path(CFG.rulesdir);
add_path(CFG.tmailshort);
add_path(CFG.tmaillong);
temp = calloc(PATH_MAX, sizeof(char ));
snprintf(temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&areahdr, sizeof(areahdr), 1, fp);
fseek(fp, areahdr.hdrsize, SEEK_SET);
while (fread(&area, areahdr.recsize, 1, fp)) {
if (area.Available) {
add_path(area.Path);
}
} }
fclose(fp);
} }
fclose(fp);
if (T_Shutdown)
break;
snprintf(temp, PATH_MAX, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&msgshdr, sizeof(msgshdr), 1, fp);
fseek(fp, msgshdr.hdrsize, SEEK_SET);
while (fread(&msgs, msgshdr.recsize, 1, fp)) {
if (msgs.Active)
add_path(msgs.Base);
fseek(fp, msgshdr.syssize, SEEK_CUR);
}
fclose(fp);
}
if (T_Shutdown)
break;
snprintf(temp, PATH_MAX, "%s/etc/language.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&langhdr, sizeof(langhdr), 1, fp);
fseek(fp, langhdr.hdrsize, SEEK_SET);
while (fread(&lang, langhdr.recsize, 1, fp)) {
if (lang.Available) {
add_path(lang.MenuPath);
add_path(lang.TextPath);
add_path(lang.MacroPath);
}
}
fclose(fp);
}
if (T_Shutdown)
break;
snprintf(temp, PATH_MAX, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&nodeshdr, sizeof(nodeshdr), 1, fp);
fseek(fp, nodeshdr.hdrsize, SEEK_SET);
while (fread(&nodes, nodeshdr.recsize, 1, fp)) {
if (nodes.Session_in == S_DIR)
add_path(nodes.Dir_in_path);
if (nodes.Session_out == S_DIR)
add_path(nodes.Dir_out_path);
add_path(nodes.OutBox);
fseek(fp, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR);
}
fclose(fp);
}
if (T_Shutdown)
break;
snprintf(temp, PATH_MAX, "%s/etc/fgroups.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&fgrouphdr, sizeof(fgrouphdr), 1, fp);
fseek(fp, fgrouphdr.hdrsize, SEEK_SET);
while (fread(&fgroup, fgrouphdr.recsize, 1, fp)) {
if (fgroup.Active)
add_path(fgroup.BasePath);
}
fclose(fp);
}
if (T_Shutdown)
break;
snprintf(temp, PATH_MAX, "%s/etc/mgroups.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&mgrouphdr, sizeof(mgrouphdr), 1, fp);
fseek(fp, mgrouphdr.hdrsize, SEEK_SET);
while (fread(&mgroup, mgrouphdr.recsize, 1, fp)) {
if (mgroup.Active)
add_path(mgroup.BasePath);
}
fclose(fp);
}
if (T_Shutdown)
break;
snprintf(temp, PATH_MAX, "%s/etc/hatch.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&hatchhdr, sizeof(hatchhdr), 1, fp);
fseek(fp, hatchhdr.hdrsize, SEEK_SET);
while (fread(&hatch, hatchhdr.recsize, 1, fp)) {
if (hatch.Active)
add_path(hatch.Spec);
}
fclose(fp);
}
if (T_Shutdown)
break;
snprintf(temp, PATH_MAX, "%s/etc/magic.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&magichdr, sizeof(magichdr), 1, fp);
fseek(fp, magichdr.hdrsize, SEEK_SET);
while (fread(&magic, magichdr.recsize, 1, fp)) {
if (magic.Active && ((magic.Attrib == MG_COPY) || (magic.Attrib == MG_UNPACK)))
add_path(magic.Path);
}
fclose(fp);
}
free(temp);
temp = NULL;
Syslog('d', "All directories added");
/*
* Now update the new table with filesystems information. This must
* be done before we unlock the mutex so that waiting clients get
* usefull information.
*/
update_diskstat();
for (tmp = mfs; tmp; tmp = tmp->next) {
Syslog('+', "Found filesystem: %s type: %s status: %s", tmp->mountpoint, tmp->fstype, tmp->ro ?"RO":"RW");
}
if ((rc = pthread_mutex_unlock(&a_mutex)))
Syslog('!', "disk_thread() mutex_unlock failed rc=%d", rc);
} }
if ((rc = pthread_mutex_lock(&a_mutex))) snprintf(temp, PATH_MAX, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
Syslog('!', "disk_thread() mutex_lock failed rc=%d", rc); if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&msgshdr, sizeof(msgshdr), 1, fp);
fseek(fp, msgshdr.hdrsize, SEEK_SET);
update_diskstat(); while (fread(&msgs, msgshdr.recsize, 1, fp)) {
if (msgs.Active)
add_path(msgs.Base);
fseek(fp, msgshdr.syssize, SEEK_CUR);
}
fclose(fp);
}
if ((rc = pthread_mutex_unlock(&a_mutex))) snprintf(temp, PATH_MAX, "%s/etc/language.data", getenv("MBSE_ROOT"));
Syslog('!', "disk_thread() mutex_unlock failed rc=%d", rc); if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&langhdr, sizeof(langhdr), 1, fp);
fseek(fp, langhdr.hdrsize, SEEK_SET);
sleep(1); while (fread(&lang, langhdr.recsize, 1, fp)) {
if (lang.Available) {
add_path(lang.MenuPath);
add_path(lang.TextPath);
add_path(lang.MacroPath);
}
}
fclose(fp);
}
snprintf(temp, PATH_MAX, "%s/etc/nodes.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&nodeshdr, sizeof(nodeshdr), 1, fp);
fseek(fp, nodeshdr.hdrsize, SEEK_SET);
while (fread(&nodes, nodeshdr.recsize, 1, fp)) {
if (nodes.Session_in == S_DIR)
add_path(nodes.Dir_in_path);
if (nodes.Session_out == S_DIR)
add_path(nodes.Dir_out_path);
add_path(nodes.OutBox);
fseek(fp, nodeshdr.filegrp + nodeshdr.mailgrp, SEEK_CUR);
}
fclose(fp);
}
snprintf(temp, PATH_MAX, "%s/etc/fgroups.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&fgrouphdr, sizeof(fgrouphdr), 1, fp);
fseek(fp, fgrouphdr.hdrsize, SEEK_SET);
while (fread(&fgroup, fgrouphdr.recsize, 1, fp)) {
if (fgroup.Active)
add_path(fgroup.BasePath);
}
fclose(fp);
}
snprintf(temp, PATH_MAX, "%s/etc/mgroups.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&mgrouphdr, sizeof(mgrouphdr), 1, fp);
fseek(fp, mgrouphdr.hdrsize, SEEK_SET);
while (fread(&mgroup, mgrouphdr.recsize, 1, fp)) {
if (mgroup.Active)
add_path(mgroup.BasePath);
}
fclose(fp);
}
snprintf(temp, PATH_MAX, "%s/etc/hatch.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&hatchhdr, sizeof(hatchhdr), 1, fp);
fseek(fp, hatchhdr.hdrsize, SEEK_SET);
while (fread(&hatch, hatchhdr.recsize, 1, fp)) {
if (hatch.Active)
add_path(hatch.Spec);
}
fclose(fp);
}
snprintf(temp, PATH_MAX, "%s/etc/magic.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r"))) {
Syslog('d', "+ %s", temp);
fread(&magichdr, sizeof(magichdr), 1, fp);
fseek(fp, magichdr.hdrsize, SEEK_SET);
while (fread(&magic, magichdr.recsize, 1, fp)) {
if (magic.Active && ((magic.Attrib == MG_COPY) || (magic.Attrib == MG_UNPACK)))
add_path(magic.Path);
}
fclose(fp);
}
free(temp);
temp = NULL;
Syslog('d', "All directories added");
/*
* Now update the new table with filesystems information.
*/
update_diskstat();
for (tmp = mfs; tmp; tmp = tmp->next) {
Syslog('+', "Found filesystem: %s type: %s status: %s", tmp->mountpoint, tmp->fstype, tmp->ro ?"RO":"RW");
}
} }
tidy_mfslist(&mfs); update_diskstat();
if (temp) }
free(temp);
temp = NULL;
disk_run = FALSE;
Syslog('+', "Disk thread stopped"); void deinit_diskwatch()
pthread_exit(NULL); {
Syslog('d', "De-init diskwatch done");
#if defined(__NetBSD__) tidy_mfslist(&mfs);
return NULL;
#endif
} }

View File

@ -6,6 +6,7 @@
char *disk_reset(void); /* Reset disk tables */ char *disk_reset(void); /* Reset disk tables */
void disk_check_r(char *, char *); /* Check space in Megabytes */ void disk_check_r(char *, char *); /* Check space in Megabytes */
void disk_getfs_r(char *); /* Get disk status */ void disk_getfs_r(char *); /* Get disk status */
void *disk_thread(void); /* Disk watch thread */ void diskwatch(void); /* Diskwatch */
void deinit_diskwatch(void); /* Release memory */
#endif #endif

View File

@ -38,8 +38,6 @@
int ibc_run = FALSE; /* Thread running */
extern int T_Shutdown; /* Program shutdown */
extern int internet; /* Internet status */ extern int internet; /* Internet status */
time_t scfg_time = (time_t)0; /* Servers config time */ time_t scfg_time = (time_t)0; /* Servers config time */
time_t now; /* Current time */ time_t now; /* Current time */
@ -49,10 +47,6 @@ usr_list *users = NULL; /* Active users */
chn_list *channels = NULL; /* Active channels */ chn_list *channels = NULL; /* Active channels */
ban_list *banned = NULL; /* Banned users */ ban_list *banned = NULL; /* Banned users */
nick_list *nicknames = NULL; /* Known nicknames */ nick_list *nicknames = NULL; /* Known nicknames */
int ls; /* Listen socket */
struct sockaddr_in myaddr_in; /* Listen socket address */
struct sockaddr_in clientaddr_in; /* Remote socket address */
char crbuf[512]; /* Chat receive buffer */
int callchg = FALSE; /* Is call state changed */ int callchg = FALSE; /* Is call state changed */
int srvchg = FALSE; /* Is serverlist changed */ int srvchg = FALSE; /* Is serverlist changed */
int usrchg = FALSE; /* Is userlist changed */ int usrchg = FALSE; /* Is userlist changed */
@ -62,14 +56,10 @@ int nickchg = FALSE; /* Is nicknames changed */
time_t resettime; /* Time to reset all */ time_t resettime; /* Time to reset all */
int do_reset = FALSE; /* Reset init */ int do_reset = FALSE; /* Reset init */
int link_reset = FALSE; /* Reset one link */ int link_reset = FALSE; /* Reset one link */
int is_locked = FALSE; /* Is mutex locked */ extern struct sockaddr_in clientaddr_in; /* IBC remote socket */
#define PING_PONG_LOG 1 #define PING_PONG_LOG 1
pthread_mutex_t b_mutex = PTHREAD_MUTEX_INITIALIZER;
typedef enum {NCS_INIT, NCS_CALL, NCS_WAITPWD, NCS_CONNECT, NCS_HANGUP, NCS_FAIL, NCS_DEAD} NCSTYPE; typedef enum {NCS_INIT, NCS_CALL, NCS_WAITPWD, NCS_CONNECT, NCS_HANGUP, NCS_FAIL, NCS_DEAD} NCSTYPE;
@ -111,43 +101,6 @@ int command_join(char *, char *);
int command_part(char *, char *); int command_part(char *, char *);
int command_topic(char *, char *); int command_topic(char *, char *);
int command_privmsg(char *, char *); int command_privmsg(char *, char *);
void receiver(struct servent *);
int lock_ibc(char *func)
{
int rc;
if (is_locked) {
WriteError("IBC: %s() mutex lock, already locked", func);
return TRUE;
}
if ((rc = pthread_mutex_lock(&b_mutex))) {
WriteError("$IBC: %s() mutex lock", func);
return TRUE;
}
is_locked = TRUE;
return FALSE;
}
void unlock_ibc(char *func)
{
int rc;
if (!is_locked) {
WriteError("IBC: %s() mutex unlock, was not locked", func);
return;
}
is_locked = FALSE;
if ((rc = pthread_mutex_unlock(&b_mutex)))
WriteError("$IBC: %s() mutex unlock", func);
}
@ -158,9 +111,6 @@ void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int
{ {
ncs_list *tmp, *ta; ncs_list *tmp, *ta;
if (lock_ibc((char *)"fill_ncslist"))
return;
tmp = (ncs_list *)malloc(sizeof(ncs_list)); tmp = (ncs_list *)malloc(sizeof(ncs_list));
memset(tmp, 0, sizeof(tmp)); memset(tmp, 0, sizeof(tmp));
tmp->next = NULL; tmp->next = NULL;
@ -191,8 +141,6 @@ void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int
} }
} }
} }
unlock_ibc((char *)"fill_ncslist");
} }
@ -333,10 +281,6 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
return 1; return 1;
} }
if (lock_ibc((char *)"add_user")) {
return 1;
}
tmp = (usr_list *)malloc(sizeof(usr_list)); tmp = (usr_list *)malloc(sizeof(usr_list));
memset(tmp, 0, sizeof(usr_list)); memset(tmp, 0, sizeof(usr_list));
tmp->next = NULL; tmp->next = NULL;
@ -364,7 +308,6 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
} }
} }
unlock_ibc((char *)"add_user");
usrchg = TRUE; usrchg = TRUE;
return 0; return 0;
} }
@ -385,12 +328,6 @@ void del_user(usr_list **fap, char *server, char *name)
if (*fap == NULL) if (*fap == NULL)
return; return;
if (name) {
if (lock_ibc((char *)"del_user")) {
return;
}
}
tmp = fap; tmp = fap;
while (*tmp) { while (*tmp) {
if (name && (strcmp((*tmp)->server, server) == 0) && (strcmp((*tmp)->name, name) == 0)) { if (name && (strcmp((*tmp)->server, server) == 0) && (strcmp((*tmp)->name, name) == 0)) {
@ -420,9 +357,6 @@ void del_user(usr_list **fap, char *server, char *name)
srvchg = TRUE; srvchg = TRUE;
} }
} }
if (name)
unlock_ibc((char *)"del_user");
} }
@ -443,10 +377,6 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
} }
} }
if (lock_ibc((char *)"add_channel")) {
return 1;
}
tmp = (chn_list *)malloc(sizeof(chn_list)); tmp = (chn_list *)malloc(sizeof(chn_list));
memset(tmp, 0, sizeof(chn_list)); memset(tmp, 0, sizeof(chn_list));
tmp->next = NULL; tmp->next = NULL;
@ -467,7 +397,6 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
} }
} }
unlock_ibc((char *)"add_channel");
chnchg = TRUE; chnchg = TRUE;
return 0; return 0;
} }
@ -483,10 +412,6 @@ void del_channel(chn_list **fap, char *name)
if (*fap == NULL) if (*fap == NULL)
return; return;
if (lock_ibc((char *)"del_channel")) {
return;
}
tmp = fap; tmp = fap;
while (*tmp) { while (*tmp) {
if (strcmp((*tmp)->name, name) == 0) { if (strcmp((*tmp)->name, name) == 0) {
@ -498,8 +423,6 @@ void del_channel(chn_list **fap, char *name)
tmp = &((*tmp)->next); tmp = &((*tmp)->next);
} }
} }
unlock_ibc((char *)"del_channel");
} }
@ -534,10 +457,6 @@ int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
} }
} }
if (lock_ibc((char *)"add_server")) {
return 0;
}
tmp = (srv_list *)malloc(sizeof(srv_list)); tmp = (srv_list *)malloc(sizeof(srv_list));
memset(tmp, 0, sizeof(tmp)); memset(tmp, 0, sizeof(tmp));
tmp->next = NULL; tmp->next = NULL;
@ -561,7 +480,6 @@ int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
} }
} }
unlock_ibc((char *)"add_server");
srvchg = TRUE; srvchg = TRUE;
return 1; return 1;
} }
@ -580,10 +498,6 @@ void del_server(srv_list **fap, char *name)
if (*fap == NULL) if (*fap == NULL)
return; return;
if (lock_ibc((char *)"del_server")) {
return;
}
for (ta = *fap; ta; ta = ta->next) { for (ta = *fap; ta; ta = ta->next) {
while ((tan = ta->next) && (strcmp(tan->server, name) == 0)) { while ((tan = ta->next) && (strcmp(tan->server, name) == 0)) {
ta->next = tan->next; ta->next = tan->next;
@ -592,8 +506,6 @@ void del_server(srv_list **fap, char *name)
} }
ta->next = tan; ta->next = tan;
} }
unlock_ibc((char *)"del_server");
} }
@ -610,11 +522,6 @@ void del_router(srv_list **fap, char *name)
if (*fap == NULL) if (*fap == NULL)
return; return;
if (lock_ibc((char *)"del_router")) {
return;
}
for (ta = *fap; ta; ta = ta->next) { for (ta = *fap; ta; ta = ta->next) {
while ((tan = ta->next) && (strcmp(tan->router, name) == 0)) { while ((tan = ta->next) && (strcmp(tan->router, name) == 0)) {
del_user(&users, tan->server, NULL); del_user(&users, tan->server, NULL);
@ -624,8 +531,6 @@ void del_router(srv_list **fap, char *name)
} }
ta->next = tan; ta->next = tan;
} }
unlock_ibc((char *)"del_router");
} }
@ -745,12 +650,13 @@ void check_servers(void)
struct servent *se; struct servent *se;
struct hostent *he; struct hostent *he;
now = time(NULL);
snprintf(scfgfn, PATH_MAX, "%s/etc/ibcsrv.data", getenv("MBSE_ROOT")); snprintf(scfgfn, PATH_MAX, "%s/etc/ibcsrv.data", getenv("MBSE_ROOT"));
/* /*
* Check if we reached the global reset time * Check if we reached the global reset time
*/ */
if (((int)time(NULL) > (int)resettime) && !do_reset) { if (((int)now > (int)resettime) && !do_reset) {
resettime = time(NULL) + (time_t)86400; resettime = time(NULL) + (time_t)86400;
do_reset = TRUE; do_reset = TRUE;
Syslog('+', "IBC: global reset time reached, preparing reset"); Syslog('+', "IBC: global reset time reached, preparing reset");
@ -784,11 +690,8 @@ void check_servers(void)
* Local reset, make all crc's invalid so the connections will restart. * Local reset, make all crc's invalid so the connections will restart.
*/ */
if (local_reset) { if (local_reset) {
if (! lock_ibc((char *)"check_servers 1")) { for (tnsl = ncsl; tnsl; tnsl = tnsl->next)
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) tnsl->crc--;
tnsl->crc--;
unlock_ibc((char *)"check_servers 1");
}
} }
if (link_reset) { if (link_reset) {
@ -817,11 +720,8 @@ void check_servers(void)
Syslog('+', "IBC: server %s connection reset", tnsl->server); Syslog('+', "IBC: server %s connection reset", tnsl->server);
else else
Syslog('+', "IBC: server %s configuration changed or removed", tnsl->server); Syslog('+', "IBC: server %s configuration changed or removed", tnsl->server);
if (! lock_ibc((char *)"check_servers 2")) { tnsl->remove = TRUE;
tnsl->remove = TRUE; tnsl->action = now;
tnsl->action = now;
unlock_ibc((char *)"check_servers 2");
}
srvchg = TRUE; srvchg = TRUE;
callchg = TRUE; callchg = TRUE;
} }
@ -866,20 +766,17 @@ void check_servers(void)
*/ */
if (Remove) { if (Remove) {
Syslog('r', "IBC: Starting remove list"); Syslog('r', "IBC: Starting remove list");
if (! lock_ibc((char *)"check_servers 3")) { tmp = &ncsl;
tmp = &ncsl; while (*tmp) {
while (*tmp) { if ((*tmp)->remove) {
if ((*tmp)->remove) { Syslog('r', "do %s", (*tmp)->server);
Syslog('r', "do %s", (*tmp)->server); tnsl = *tmp;
tnsl = *tmp; *tmp = (*tmp)->next;
*tmp = (*tmp)->next; free(tnsl);
free(tnsl); callchg = TRUE;
callchg = TRUE; } else {
} else { tmp = &((*tmp)->next);
tmp = &((*tmp)->next);
}
} }
unlock_ibc((char *)"check_servers 3");
} }
} }
dump_ncslist(); dump_ncslist();
@ -1038,14 +935,12 @@ void check_servers(void)
* Reset our side of the connection. * Reset our side of the connection.
*/ */
Syslog('+', "IBC: server %s connection is half dead", tnsl->server); Syslog('+', "IBC: server %s connection is half dead", tnsl->server);
lock_ibc((char *)"check_servers 4");
tnsl->state = NCS_DEAD; tnsl->state = NCS_DEAD;
tnsl->action = now + (time_t)60; // 1 minute delay before calling again. tnsl->action = now + (time_t)60; // 1 minute delay before calling again.
tnsl->gotpass = FALSE; tnsl->gotpass = FALSE;
tnsl->gotserver = FALSE; tnsl->gotserver = FALSE;
tnsl->token = 0; tnsl->token = 0;
tnsl->halfdead = 0; tnsl->halfdead = 0;
unlock_ibc((char *)"check_servers 4");
broadcast(tnsl->server, "SQUIT %s Connection died\r\n", tnsl->server); broadcast(tnsl->server, "SQUIT %s Connection died\r\n", tnsl->server);
callchg = TRUE; callchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
@ -1058,14 +953,12 @@ void check_servers(void)
* Missed 3 PING replies * Missed 3 PING replies
*/ */
Syslog('+', "IBC: server %s connection is dead", tnsl->server); Syslog('+', "IBC: server %s connection is dead", tnsl->server);
lock_ibc((char *)"check_servers 5");
tnsl->state = NCS_DEAD; tnsl->state = NCS_DEAD;
tnsl->action = now + (time_t)120; // 2 minutes delay before calling again. tnsl->action = now + (time_t)120; // 2 minutes delay before calling again.
tnsl->gotpass = FALSE; tnsl->gotpass = FALSE;
tnsl->gotserver = FALSE; tnsl->gotserver = FALSE;
tnsl->token = 0; tnsl->token = 0;
tnsl->halfdead = 0; tnsl->halfdead = 0;
unlock_ibc((char *)"check_servers 5");
broadcast(tnsl->server, "SQUIT %s Connection died\r\n", tnsl->server); broadcast(tnsl->server, "SQUIT %s Connection died\r\n", tnsl->server);
callchg = TRUE; callchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
@ -1205,13 +1098,11 @@ int command_server(char *hostname, char *parameters)
if (tnsl->token == token) { if (tnsl->token == token) {
broadcast(tnsl->server, "SERVER %s %d %s %s %s %s\r\n", name, ihops, id, prod, vers, fullname); broadcast(tnsl->server, "SERVER %s %d %s %s %s %s\r\n", name, ihops, id, prod, vers, fullname);
system_shout("* New server: %s, %s", name, fullname); system_shout("* New server: %s, %s", name, fullname);
lock_ibc((char *)"command_server 1");
tnsl->gotserver = TRUE; tnsl->gotserver = TRUE;
callchg = TRUE; callchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
tnsl->state = NCS_CONNECT; tnsl->state = NCS_CONNECT;
tnsl->action = now + (time_t)10; tnsl->action = now + (time_t)10;
unlock_ibc((char *)"command_server 1");
Syslog('+', "IBC: connected with neighbour server: %s", tnsl->server); Syslog('+', "IBC: connected with neighbour server: %s", tnsl->server);
/* /*
* Send all already known servers * Send all already known servers
@ -1256,11 +1147,9 @@ int command_server(char *hostname, char *parameters)
send_msg(tnsl, "SERVER %s 0 %ld mbsebbs %s %s\r\n", tnsl->myname, token, VERSION, CFG.bbs_name); send_msg(tnsl, "SERVER %s 0 %ld mbsebbs %s %s\r\n", tnsl->myname, token, VERSION, CFG.bbs_name);
broadcast(tnsl->server, "SERVER %s %d %s %s %s %s\r\n", name, ihops, id, prod, vers, fullname); broadcast(tnsl->server, "SERVER %s %d %s %s %s %s\r\n", name, ihops, id, prod, vers, fullname);
system_shout("* New server: %s, %s", name, fullname); system_shout("* New server: %s, %s", name, fullname);
lock_ibc((char *)"command_server 2");
tnsl->gotserver = TRUE; tnsl->gotserver = TRUE;
tnsl->state = NCS_CONNECT; tnsl->state = NCS_CONNECT;
tnsl->action = now + (time_t)10; tnsl->action = now + (time_t)10;
unlock_ibc((char *)"command_server 2");
Syslog('+', "IBC: connected with neighbour server: %s", tnsl->server); Syslog('+', "IBC: connected with neighbour server: %s", tnsl->server);
/* /*
* Send all already known servers * Send all already known servers
@ -1326,13 +1215,11 @@ int command_squit(char *hostname, char *parameters)
if (strcmp(name, tnsl->server) == 0) { if (strcmp(name, tnsl->server) == 0) {
Syslog('+', "IBC: disconnect neighbour server %s: %s", name, message); Syslog('+', "IBC: disconnect neighbour server %s: %s", name, message);
lock_ibc((char *)"command_squit");
tnsl->state = NCS_HANGUP; tnsl->state = NCS_HANGUP;
tnsl->action = now + (time_t)120; // 2 minutes delay before calling again. tnsl->action = now + (time_t)120; // 2 minutes delay before calling again.
tnsl->gotpass = FALSE; tnsl->gotpass = FALSE;
tnsl->gotserver = FALSE; tnsl->gotserver = FALSE;
tnsl->token = 0; tnsl->token = 0;
unlock_ibc((char *)"command_squit");
del_router(&servers, name); del_router(&servers, name);
} else { } else {
Syslog('+', "IBC: disconnect relay server %s: %s", name, message); Syslog('+', "IBC: disconnect relay server %s: %s", name, message);
@ -1452,9 +1339,7 @@ int command_nick(char *hostname, char *parameters)
for (tmp = users; tmp; tmp = tmp->next) { for (tmp = users; tmp; tmp = tmp->next) {
if ((strcmp(tmp->server, server) == 0) && (strcmp(tmp->realname, realname) == 0) && (strcmp(tmp->name, name) == 0)) { if ((strcmp(tmp->server, server) == 0) && (strcmp(tmp->realname, realname) == 0) && (strcmp(tmp->name, name) == 0)) {
lock_ibc((char *)"command_nick");
strncpy(tmp->nick, nick, 9); strncpy(tmp->nick, nick, 9);
unlock_ibc((char *)"command_nick");
found = TRUE; found = TRUE;
Syslog('+', "IBC: user %s set nick to %s", name, nick); Syslog('+', "IBC: user %s set nick to %s", name, nick);
usrchg = TRUE; usrchg = TRUE;
@ -1520,9 +1405,7 @@ int command_join(char *hostname, char *parameters)
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
if ((strcmp(tmpu->server, server) == 0) && ((strcmp(tmpu->nick, nick) == 0) || (strcmp(tmpu->name, nick) == 0))) { if ((strcmp(tmpu->server, server) == 0) && ((strcmp(tmpu->nick, nick) == 0) || (strcmp(tmpu->name, nick) == 0))) {
lock_ibc((char *)"command_join");
strncpy(tmpu->channel, channel, 20); strncpy(tmpu->channel, channel, 20);
unlock_ibc((char *)"command_join");
Syslog('+', "IBC: user %s joined channel %s", nick, channel); Syslog('+', "IBC: user %s joined channel %s", nick, channel);
usrchg = TRUE; usrchg = TRUE;
snprintf(msg, 81, "* %s@%s has joined %s", nick, server, channel); snprintf(msg, 81, "* %s@%s has joined %s", nick, server, channel);
@ -1577,19 +1460,17 @@ int command_part(char *hostname, char *parameters)
} }
} }
Syslog('r', "IBC: part input server=%s nick=%s", server, nick); // Syslog('r', "IBC: part input server=%s nick=%s", server, nick);
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
Syslog('r', "IBC: part test server=%s nick=%s name=%s", tmpu->server, tmpu->nick, tmpu->name); // Syslog('r', "IBC: part test server=%s nick=%s name=%s", tmpu->server, tmpu->nick, tmpu->name);
if ((strcmp(tmpu->server, server) == 0) && ((strcmp(tmpu->nick, nick) == 0) || (strcmp(tmpu->name, nick) == 0))) { if ((strcmp(tmpu->server, server) == 0) && ((strcmp(tmpu->nick, nick) == 0) || (strcmp(tmpu->name, nick) == 0))) {
lock_ibc((char *)"command_part");
tmpu->channel[0] = '\0'; tmpu->channel[0] = '\0';
unlock_ibc((char *)"command_part");
if (message) { if (message) {
Syslog('+', "IBC: user %s left channel %s: %s", nick, channel, message); Syslog('+', "IBC: user %s left channel %s: %s", nick, channel, message);
snprintf(msg, 81, "* %s@%s has left: %s", nick, server, message); snprintf(msg, 81, "* %s@%s has left channel %s: %s", nick, server, channel, message);
} else { } else {
Syslog('+', "IBC: user %s left channel %s", nick, channel); Syslog('+', "IBC: user %s left channel %s", nick, channel);
snprintf(msg, 81, "* %s@%s has silently left this channel", nick, server); snprintf(msg, 81, "* %s@%s has silently left channel %s", nick, server, channel);
} }
chat_msg(channel, NULL, msg); chat_msg(channel, NULL, msg);
usrchg = TRUE; usrchg = TRUE;
@ -1628,9 +1509,7 @@ int command_topic(char *hostname, char *parameters)
for (tmp = channels; tmp; tmp = tmp->next) { for (tmp = channels; tmp; tmp = tmp->next) {
if (strcmp(tmp->name, channel) == 0) { if (strcmp(tmp->name, channel) == 0) {
chnchg = TRUE; chnchg = TRUE;
lock_ibc((char *)"command_topic");
strncpy(tmp->topic, topic, 54); strncpy(tmp->topic, topic, 54);
unlock_ibc((char *)"command_topic");
Syslog('+', "IBC: channel %s topic: %s", channel, topic); Syslog('+', "IBC: channel %s topic: %s", channel, topic);
snprintf(msg, 81, "* Channel topic is now: %s", tmp->topic); snprintf(msg, 81, "* Channel topic is now: %s", tmp->topic);
chat_msg(channel, NULL, msg); chat_msg(channel, NULL, msg);
@ -1758,191 +1637,132 @@ int do_command(char *hostname, char *command, char *parameters)
void receiver(struct servent *se) void ibc_receiver(char *crbuf)
{ {
struct pollfd pfd;
struct hostent *hp, *tp; struct hostent *hp, *tp;
struct in_addr in; struct in_addr in;
int rc, len, inlist; int inlist;
socklen_t sl; ncs_list *tnsl;
ncs_list *tnsl;
char *hostname, *command, *parameters, *ipaddress; char *hostname, *command, *parameters, *ipaddress;
pfd.fd = ls; hp = gethostbyaddr((char *)&clientaddr_in.sin_addr, sizeof(struct in_addr), clientaddr_in.sin_family);
pfd.events = POLLIN; if (hp == NULL)
pfd.revents = 0; hostname = inet_ntoa(clientaddr_in.sin_addr);
else
hostname = hp->h_name;
if ((rc = poll(&pfd, 1, 1000) < 0)) { if ((crbuf[strlen(crbuf) -2] != '\r') && (crbuf[strlen(crbuf) -1] != '\n')) {
Syslog('r', "$IBC: poll/select failed"); Syslog('!', "IBC: got message not terminated with CR-LF, dropped");
return; return;
} }
now = time(NULL); /*
if (pfd.revents & POLLIN || pfd.revents & POLLERR || pfd.revents & POLLHUP || pfd.revents & POLLNVAL) { * First check fr a fixed IP address.
sl = sizeof(myaddr_in); */
memset(&clientaddr_in, 0, sizeof(struct sockaddr_in)); inlist = FALSE;
memset(&crbuf, 0, sizeof(crbuf)); for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
if ((len = recvfrom(ls, &crbuf, sizeof(crbuf)-1, 0,(struct sockaddr *)&clientaddr_in, &sl)) != -1) { if (strcmp(tnsl->server, hostname) == 0) {
hp = gethostbyaddr((char *)&clientaddr_in.sin_addr, sizeof(struct in_addr), clientaddr_in.sin_family); inlist = TRUE;
if (hp == NULL) break;
hostname = inet_ntoa(clientaddr_in.sin_addr); }
else }
hostname = hp->h_name; if (!inlist) {
/*
if ((crbuf[strlen(crbuf) -2] != '\r') && (crbuf[strlen(crbuf) -1] != '\n')) { * Check for dynamic dns address
Syslog('!', "IBC: got message not terminated with CR-LF, dropped"); */
return; ipaddress = xstrcpy(inet_ntoa(clientaddr_in.sin_addr));
} for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
if (tnsl->dyndns) {
/* tp = gethostbyname(tnsl->server);
* First check fr a fixed IP address. if (tp != NULL) {
*/ memcpy(&in, tp->h_addr, tp->h_length);
inlist = FALSE; if (strcmp(inet_ntoa(in), ipaddress) == 0) {
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) { /*
if (strcmp(tnsl->server, hostname) == 0) { * Test if the backresolved dynamic DNS name is changed, but exclude the
inlist = TRUE; * initial value which is the same as the real server name.
break; */
} if (strcmp(tnsl->resolved, hostname) && strcmp(tnsl->resolved, tnsl->server)) {
} Syslog('r', "IBC: GrepThiz old resolved %s new resolved %s state %s",
if (!inlist) { tnsl->resolved, hostname, ncsstate[tnsl->state]);
/* Syslog('+', "IBC: server %s resolved FQDN changed, restarting", tnsl->server);
* Check for dynamic dns address tnsl->crc--;
*/ link_reset = TRUE;
ipaddress = xstrcpy(inet_ntoa(clientaddr_in.sin_addr)); /*
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) { * This would be the moment to reset this neighbour
if (tnsl->dyndns) { * Double check state: waitpwd or call ?
tp = gethostbyname(tnsl->server); */
if (tp != NULL) {
memcpy(&in, tp->h_addr, tp->h_length);
if (strcmp(inet_ntoa(in), ipaddress) == 0) {
/*
* Test if the backresolved dynamic DNS name is changed, but exclude the
* initial value which is the same as the real server name.
*/
if (strcmp(tnsl->resolved, hostname) && strcmp(tnsl->resolved, tnsl->server)) {
Syslog('r', "IBC: GrepThiz old resolved %s new resolved %s state %s",
tnsl->resolved, hostname, ncsstate[tnsl->state]);
Syslog('+', "IBC: server %s resolved FQDN changed, restarting", tnsl->server);
tnsl->crc--;
link_reset = TRUE;
/*
* This would be the moment to reset this neighbour
* Double check state: waitpwd or call ?
*/
}
/*
* Store the back resolved IP fqdn for reference and change the
* FQDN to the one from the setup, so we continue to use the
* dynamic FQDN.
*/
if (strcmp(tnsl->resolved, hostname))
Syslog('r', "IBC: setting '%s' to dynamic dns '%s'", hostname, tnsl->server);
strncpy(tnsl->resolved, hostname, 63);
inlist = TRUE;
hostname = tnsl->server;
break;
}
} }
/*
* Store the back resolved IP fqdn for reference and change the
* FQDN to the one from the setup, so we continue to use the
* dynamic FQDN.
*/
if (strcmp(tnsl->resolved, hostname))
Syslog('r', "IBC: setting '%s' to dynamic dns '%s'", hostname, tnsl->server);
strncpy(tnsl->resolved, hostname, 63);
inlist = TRUE;
hostname = tnsl->server;
break;
} }
} }
free(ipaddress);
} }
if (!inlist) {
Syslog('r', "IBC: message from unknown host (%s), dropped", hostname);
return;
}
if (tnsl->state == NCS_INIT) {
Syslog('r', "IBC: message received from %s while in init state, dropped", hostname);
return;
}
tnsl->last = now;
crbuf[strlen(crbuf) -2] = '\0';
#ifndef PING_PONG_LOG
if (strcmp(crbuf, (char *)"PING") && strcmp(crbuf, (char *)"PONG"))
#endif
Syslog('r', "IBC: < %s: \"%s\"", hostname, printable(crbuf, 0));
/*
* Parse message
*/
command = strtok(crbuf, " \0");
parameters = strtok(NULL, "\0");
if (atoi(command)) {
Syslog('r', "IBC: Got error %d", atoi(command));
} else {
do_command(hostname, command, parameters);
}
} else {
Syslog('r', "IBC: recvfrom returned len=%d", len);
} }
free(ipaddress);
}
if (!inlist) {
Syslog('r', "IBC: message from unknown host (%s), dropped", hostname);
return;
}
if (tnsl->state == NCS_INIT) {
Syslog('r', "IBC: message received from %s while in init state, dropped", hostname);
return;
}
tnsl->last = now;
crbuf[strlen(crbuf) -2] = '\0';
#ifndef PING_PONG_LOG
if (strcmp(crbuf, (char *)"PING") && strcmp(crbuf, (char *)"PONG"))
#endif
Syslog('r', "IBC: < %s: \"%s\"", hostname, printable(crbuf, 0));
/*
* Parse message
*/
command = strtok(crbuf, " \0");
parameters = strtok(NULL, "\0");
if (atoi(command)) {
Syslog('r', "IBC: Got error %d", atoi(command));
} else {
do_command(hostname, command, parameters);
} }
} }
/* void ibc_shutdown(void)
* IBC thread
*/
void *ibc_thread(void *dummy)
{ {
struct servent *se; ncs_list *tnsl;
ncs_list *tnsl; usr_list *usrp;
Syslog('+', "Starting IBC thread");
if ((se = getservbyname("fido", "udp")) == NULL) {
Syslog('!', "IBC: no fido udp entry in /etc/services, cannot start Internet BBS Chat");
goto exit;
}
if (strlen(CFG.bbs_name) == 0) {
Syslog('!', "IBC: mbsetup 1.2.1 is empty, cannot start Internet BBS Chat");
goto exit;
}
if (strlen(CFG.myfqdn) == 0) {
Syslog('!', "IBC: mbsetup 1.2.10 is empty, cannot start Internet BBS Chat");
goto exit;
}
myaddr_in.sin_family = AF_INET;
myaddr_in.sin_addr.s_addr = INADDR_ANY;
myaddr_in.sin_port = se->s_port;
Syslog('+', "IBC: listen on %s, port %d", inet_ntoa(myaddr_in.sin_addr), ntohs(myaddr_in.sin_port));
ls = socket(AF_INET, SOCK_DGRAM, 0);
if (ls == -1) {
Syslog('!', "$IBC: can't create listen socket");
goto exit;
}
if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) {
Syslog('!', "$IBC: can't bind listen socket");
goto exit;
}
ibc_run = TRUE;
srand(getpid());
resettime = time(NULL) + (time_t)86400;
while (! T_Shutdown) {
/*
* Check neighbour servers state
*/
now = time(NULL);
check_servers();
/*
* Get any incoming messages
*/
receiver(se);
}
Syslog('r', "IBC: start shutdown connections"); Syslog('r', "IBC: start shutdown connections");
for (usrp = users; usrp; usrp = usrp->next) {
if (strcmp(usrp->server, CFG.myfqdn) == 0) {
/*
* Our user, still connected
*/
if (strlen(usrp->channel) && strcmp(usrp->channel, "#sysop")) {
/*
* In a channel
*/
broadcast((char *)"foobar", "PART %s@%s %s System shutdown\r\n", usrp->nick, usrp->server, usrp->channel);
}
broadcast((char *)"foobar", "QUIT %s@%s System shutdown\r\n", usrp->nick, usrp->server);
}
}
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) { for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
if (tnsl->state == NCS_CONNECT) { if (tnsl->state == NCS_CONNECT) {
send_msg(tnsl, "SQUIT %s System shutdown\r\n", tnsl->myname); send_msg(tnsl, "SQUIT %s System shutdown\r\n", tnsl->myname);
@ -1950,11 +1770,5 @@ void *ibc_thread(void *dummy)
} }
tidy_servers(&servers); tidy_servers(&servers);
exit:
ibc_run = FALSE;
Syslog('+', "IBC thread stopped");
pthread_exit(NULL);
} }

View File

@ -106,9 +106,6 @@ typedef struct _nick_list {
} nick_list; } nick_list;
int lock_ibc(char *);
void unlock_ibc(char *);
int add_user(usr_list **, char *, char *, char *); int add_user(usr_list **, char *, char *, char *);
void del_user(usr_list **, char *, char *); void del_user(usr_list **, char *, char *);
int add_channel(chn_list **, char *, char *, char *); int add_channel(chn_list **, char *, char *, char *);
@ -118,7 +115,10 @@ int do_command(char *, char *, char *);
void send_all(const char *, ...); void send_all(const char *, ...);
void send_at(char *, char *, char *); void send_at(char *, char *, char *);
void send_nick(char *, char *, char *); void send_nick(char *, char *, char *);
void *ibc_thread(void *); void check_servers(void);
void ibc_receiver(char *);
void ibc_shutdown(void);
#endif #endif

View File

@ -46,6 +46,8 @@ unsigned int lcrc = 0, tcrc = 1;
int lcnt = 0, lchr; int lcnt = 0, lchr;
static char *pbuff = NULL; static char *pbuff = NULL;
pthread_mutex_t l_mutex = PTHREAD_MUTEX_INITIALIZER;
static char *mon[] = { static char *mon[] = {
(char *)"Jan",(char *)"Feb",(char *)"Mar", (char *)"Jan",(char *)"Feb",(char *)"Mar",
@ -62,15 +64,13 @@ static char *mon[] = {
void WriteError(const char *format, ...) void WriteError(const char *format, ...)
{ {
char *outputstr; char outputstr[1024];
va_list va_ptr; va_list va_ptr;
outputstr = calloc(10240, sizeof(char));
va_start(va_ptr, format); va_start(va_ptr, format);
vsnprintf(outputstr, 10240, format, va_ptr); vsnprintf(outputstr, 1024, format, va_ptr);
va_end(va_ptr); va_end(va_ptr);
Syslog('?', outputstr); Syslog('?', outputstr);
free(outputstr);
} }
@ -81,13 +81,18 @@ void WriteError(const char *format, ...)
void Syslog(int grade, const char *format, ...) void Syslog(int grade, const char *format, ...)
{ {
va_list va_ptr; va_list va_ptr;
char outstr[1024], datestr[21]; char outstr[1024], datestr[21], lname[PATH_MAX];
int oldmask, debug; int oldmask, debug;
FILE *logfile = NULL, *debugfile; FILE *logfile = NULL, *debugfile;
char *logname = NULL, *debugname;
time_t now; time_t now;
struct tm ptm; struct tm ptm;
if (pthread_mutex_lock(&l_mutex)) {
perror("");
printf("Syslog mutex_lock l_nutex failed\n");
return;
}
debug = isalpha(grade); debug = isalpha(grade);
va_start(va_ptr, format); va_start(va_ptr, format);
vsnprintf(outstr, 1024, format, va_ptr); vsnprintf(outstr, 1024, format, va_ptr);
@ -96,35 +101,33 @@ void Syslog(int grade, const char *format, ...)
tcrc = StringCRC32(outstr); tcrc = StringCRC32(outstr);
if (tcrc == lcrc) { if (tcrc == lcrc) {
lcnt++; lcnt++;
pthread_mutex_unlock(&l_mutex);
return; return;
} }
lcrc = tcrc; lcrc = tcrc;
if (!debug) { if (!debug) {
logname = calloc(PATH_MAX, sizeof(char));
oldmask=umask(066); oldmask=umask(066);
snprintf(logname, PATH_MAX, "%s/log/mbtask.log", getenv("MBSE_ROOT")); snprintf(lname, PATH_MAX, "%s/log/mbtask.log", getenv("MBSE_ROOT"));
logfile = fopen(logname, "a"); logfile = fopen(lname, "a");
umask(oldmask); umask(oldmask);
if (logfile == NULL) { if (logfile == NULL) {
printf("Cannot open logfile \"%s\"\n", logname); printf("Can't open logfile \"%s\"\n", lname);
free(logname); pthread_mutex_unlock(&l_mutex);
return; return;
} }
} }
debugname = calloc(PATH_MAX, sizeof(char));
oldmask=umask(066); oldmask=umask(066);
snprintf(debugname, PATH_MAX, "%s/log/%s", getenv("MBSE_ROOT"), CFG.debuglog); snprintf(lname, PATH_MAX, "%s/log/%s", getenv("MBSE_ROOT"), CFG.debuglog);
debugfile = fopen(debugname, "a"); debugfile = fopen(lname, "a");
umask(oldmask); umask(oldmask);
if (debugfile == NULL) { if (debugfile == NULL) {
printf("Cannot open logfile \"%s\"\n", debugname); printf("Can't open logfile \"%s\"\n", lname);
free(debugname);
if (!debug) { if (!debug) {
free(logname);
fclose(logfile); fclose(logfile);
} }
pthread_mutex_unlock(&l_mutex);
return; return;
} }
@ -150,10 +153,8 @@ void Syslog(int grade, const char *format, ...)
fprintf(logfile, "\n"); fprintf(logfile, "\n");
fflush(logfile); fflush(logfile);
if (fclose(logfile) != 0) if (fclose(logfile) != 0)
printf("Cannot close logfile \"%s\"\n", logname); printf("Can't close mbtask.log");
free(logname);
} }
fprintf(debugfile, "%c %s mbtask[%d] ", grade, datestr, mypid); fprintf(debugfile, "%c %s mbtask[%d] ", grade, datestr, mypid);
@ -165,11 +166,10 @@ void Syslog(int grade, const char *format, ...)
fflush(debugfile); fflush(debugfile);
if (fclose(debugfile) != 0) if (fclose(debugfile) != 0)
printf("Cannot close logfile \"%s\"\n", debugname); printf("Can't close logfile \"%s\"\n", CFG.debuglog);
lchr = grade; lchr = grade;
free(debugname); pthread_mutex_unlock(&l_mutex);
return; return;
} }
@ -259,14 +259,12 @@ char *xstrcat(char *src, char *add)
void CreateSema(char *sem) void CreateSema(char *sem)
{ {
char *temp; char temp[PATH_MAX];
FILE *fp; FILE *fp;
int oldmask; int oldmask;
temp = calloc(PATH_MAX, sizeof(char));
snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem); snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem);
if (access(temp, F_OK) == 0) { if (access(temp, F_OK) == 0) {
free(temp);
return; return;
} }
oldmask = umask(002); oldmask = umask(002);
@ -274,7 +272,6 @@ void CreateSema(char *sem)
fclose(fp); fclose(fp);
else else
Syslog('?', "Can't create semafore %s", temp); Syslog('?', "Can't create semafore %s", temp);
free(temp);
umask(oldmask); umask(oldmask);
} }
@ -282,18 +279,16 @@ void CreateSema(char *sem)
void TouchSema(char *sem) void TouchSema(char *sem)
{ {
char *temp; char temp[PATH_MAX];
FILE *fp; FILE *fp;
int oldmask; int oldmask;
temp = calloc(PATH_MAX, sizeof(char));
snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem); snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem);
oldmask = umask(002); oldmask = umask(002);
if ((fp = fopen(temp, "w"))) { if ((fp = fopen(temp, "w"))) {
fclose(fp); fclose(fp);
} else } else
Syslog('?', "Can't touch semafore %s", temp); Syslog('?', "Can't touch semafore %s", temp);
free(temp);
umask(oldmask); umask(oldmask);
} }
@ -301,31 +296,24 @@ void TouchSema(char *sem)
void RemoveSema(char *sem) void RemoveSema(char *sem)
{ {
char *temp; char temp[PATH_MAX];
temp = calloc(PATH_MAX, sizeof(char));
snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem); snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem);
if (access(temp, F_OK)) { if (access(temp, F_OK)) {
free(temp);
return; return;
} }
if (unlink(temp) == -1) if (unlink(temp) == -1)
Syslog('?', "Can't remove semafore %s", temp); Syslog('?', "Can't remove semafore %s", temp);
free(temp);
} }
int IsSema(char *sem) int IsSema(char *sem)
{ {
char *temp; char temp[PATH_MAX];
int rc;
temp = calloc(PATH_MAX, sizeof(temp));
snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem); snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem);
rc = (access(temp, F_OK) == 0); return (access(temp, F_OK) == 0);
free(temp);
return rc;
} }
@ -348,7 +336,7 @@ int file_exist(char *path, int mode)
/* /*
* Make directory tree, the name must end with a / * Make directory tree, the name must end with a /
*/ */
int mkdirs(char *name, mode_t mode) int mkdirs(char *name, mode_t mode)
{ {