Added some errorlogging
This commit is contained in:
parent
88c453808e
commit
bc8e96ed4d
@ -4,7 +4,7 @@
|
||||
* Purpose ...............: mbtask - chat server
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2005
|
||||
* Copyright (C) 1997-2006
|
||||
*
|
||||
* Michiel Broek FIDO: 2:280/2802
|
||||
* Beekmansbos 10
|
||||
@ -198,6 +198,7 @@ int join(pid_t pid, char *channel, int sysop)
|
||||
char buf[81];
|
||||
chn_list *tmp;
|
||||
usr_list *tmpu;
|
||||
int rc;
|
||||
|
||||
Syslog('c', "Join pid %d to channel %s", pid, channel);
|
||||
|
||||
@ -207,10 +208,13 @@ int join(pid_t pid, char *channel, int sysop)
|
||||
for (tmpu = users; tmpu; tmpu = tmpu->next) {
|
||||
if (tmpu->pid == pid) {
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
strncpy(tmpu->channel, channel, 20);
|
||||
tmp->users++;
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
||||
strncpy(tmpu->channel, channel, 20);
|
||||
tmp->users++;
|
||||
rc = pthread_mutex_unlock(&b_mutex);
|
||||
} else {
|
||||
WriteError("$join 1 mutex lock");
|
||||
}
|
||||
Syslog('+', "IBC: user %s has joined channel %s", tmpu->nick, channel);
|
||||
usrchg = TRUE;
|
||||
srvchg = TRUE;
|
||||
@ -248,9 +252,12 @@ int join(pid_t pid, char *channel, int sysop)
|
||||
if (tmpu->pid == pid) {
|
||||
if (add_channel(&channels, channel, tmpu->nick, CFG.myfqdn) == 0) {
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
strncpy(tmpu->channel, channel, 20);
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
||||
strncpy(tmpu->channel, channel, 20);
|
||||
rc = pthread_mutex_unlock(&b_mutex);
|
||||
} else {
|
||||
WriteError("$join 2 mutex lock");
|
||||
}
|
||||
Syslog('+', "IBC: user %s created and joined channel %s", tmpu->nick, channel);
|
||||
usrchg = TRUE;
|
||||
chnchg = TRUE;
|
||||
@ -286,6 +293,7 @@ int part(pid_t pid, char *reason)
|
||||
char buf[81];
|
||||
chn_list *tmp;
|
||||
usr_list *tmpu;
|
||||
int rc;
|
||||
|
||||
if (strlen(reason) > 54)
|
||||
reason[54] = '\0';
|
||||
@ -314,9 +322,12 @@ int part(pid_t pid, char *reason)
|
||||
/*
|
||||
* Clean channel
|
||||
*/
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
tmp->users--;
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
||||
tmp->users--;
|
||||
rc = pthread_mutex_unlock(&b_mutex);
|
||||
} else {
|
||||
WriteError("$part 1 mutex lock");
|
||||
}
|
||||
Syslog('+', "IBC: nick %s leaves channel %s", tmpu->nick, tmp->name);
|
||||
if (tmp->users == 0) {
|
||||
/*
|
||||
@ -330,9 +341,12 @@ int part(pid_t pid, char *reason)
|
||||
/*
|
||||
* Update user data
|
||||
*/
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
tmpu->channel[0] = '\0';
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
||||
tmpu->channel[0] = '\0';
|
||||
rc = pthread_mutex_unlock(&b_mutex);
|
||||
} else {
|
||||
WriteError("$part 2 mutex lock");
|
||||
}
|
||||
usrchg = TRUE;
|
||||
chnchg = TRUE;
|
||||
srvchg = TRUE;
|
||||
@ -393,7 +407,7 @@ char *chat_connect(char *data)
|
||||
{
|
||||
char *pid, *realname, *nick;
|
||||
static char buf[200];
|
||||
int count = 0, sys = FALSE;
|
||||
int count = 0, sys = FALSE, rc;
|
||||
srv_list *sl;
|
||||
usr_list *tmpu;
|
||||
|
||||
@ -430,11 +444,14 @@ char *chat_connect(char *data)
|
||||
/*
|
||||
* Oke, found
|
||||
*/
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
tmpu->pid = atoi(pid);
|
||||
tmpu->pointer = buffer_head;
|
||||
tmpu->sysop = sys;
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
||||
tmpu->pid = atoi(pid);
|
||||
tmpu->pointer = buffer_head;
|
||||
tmpu->sysop = sys;
|
||||
rc = pthread_mutex_unlock(&b_mutex);
|
||||
} else {
|
||||
WriteError("$chat_connect mutex lock");
|
||||
}
|
||||
usrchg = TRUE;
|
||||
srvchg = TRUE;
|
||||
Syslog('c', "Connected user %s (%s) with chatserver, sysop %s", realname, pid, sys ? "True":"False");
|
||||
|
142
mbtask/taskibc.c
142
mbtask/taskibc.c
@ -111,8 +111,12 @@ void receiver(struct servent *);
|
||||
void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int dyndns, unsigned int crc)
|
||||
{
|
||||
ncs_list *tmp, *ta;
|
||||
int rc;
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$fill_ncslist mutex lock");
|
||||
return;
|
||||
}
|
||||
|
||||
tmp = (ncs_list *)malloc(sizeof(ncs_list));
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
@ -145,7 +149,8 @@ void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$fill_ncslist mutex unlock");
|
||||
}
|
||||
|
||||
|
||||
@ -251,7 +256,7 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
||||
{
|
||||
usr_list *tmp, *ta;
|
||||
srv_list *sl;
|
||||
int Found = FALSE;
|
||||
int rc, Found = FALSE;
|
||||
|
||||
Syslog('r', "IBC: add_user (%s, %s, %s)", server, name, realname);
|
||||
|
||||
@ -273,7 +278,10 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
||||
return 1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$add_user() mutex lock");
|
||||
return 1;
|
||||
}
|
||||
|
||||
tmp = (usr_list *)malloc(sizeof(usr_list));
|
||||
memset(tmp, 0, sizeof(usr_list));
|
||||
@ -302,7 +310,8 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$add_user() mutex unlock");
|
||||
|
||||
usrchg = TRUE;
|
||||
return 0;
|
||||
@ -317,14 +326,17 @@ void del_user(usr_list **fap, char *server, char *name)
|
||||
{
|
||||
usr_list **tmp, *tmpa;
|
||||
srv_list *sl;
|
||||
int count = 0;
|
||||
int rc, count = 0;
|
||||
|
||||
Syslog('r', "IBC: deluser (%s, %s)", server, printable(name, 0));
|
||||
|
||||
if (*fap == NULL)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$del_user() mutex lock");
|
||||
return;
|
||||
}
|
||||
|
||||
tmp = fap;
|
||||
while (*tmp) {
|
||||
@ -356,7 +368,8 @@ void del_user(usr_list **fap, char *server, char *name)
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$del_user() mutex unlock");
|
||||
}
|
||||
|
||||
|
||||
@ -367,6 +380,7 @@ void del_user(usr_list **fap, char *server, char *name)
|
||||
int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
||||
{
|
||||
chn_list *tmp, *ta;
|
||||
int rc;
|
||||
|
||||
Syslog('r', "IBC: add_channel (%s, %s, %s)", name, owner, server);
|
||||
|
||||
@ -377,7 +391,10 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$add_channel() mutex lock");
|
||||
return 1;
|
||||
}
|
||||
|
||||
tmp = (chn_list *)malloc(sizeof(chn_list));
|
||||
memset(tmp, 0, sizeof(chn_list));
|
||||
@ -399,7 +416,8 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$add_channel() mutex unlock");
|
||||
|
||||
chnchg = TRUE;
|
||||
return 0;
|
||||
@ -410,13 +428,17 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
||||
void del_channel(chn_list **fap, char *name)
|
||||
{
|
||||
chn_list **tmp, *tmpa;
|
||||
int rc;
|
||||
|
||||
Syslog('r', "IBC: del_channel %s", name);
|
||||
|
||||
if (*fap == NULL)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$del_channel mutex lock");
|
||||
return;
|
||||
}
|
||||
|
||||
tmp = fap;
|
||||
while (*tmp) {
|
||||
@ -430,7 +452,8 @@ void del_channel(chn_list **fap, char *name)
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$del_channel mutex unlock");
|
||||
}
|
||||
|
||||
|
||||
@ -438,7 +461,7 @@ void del_channel(chn_list **fap, char *name)
|
||||
int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, char *fullname, char *router)
|
||||
{
|
||||
srv_list *tmp, *ta;
|
||||
int haverouter = FALSE;
|
||||
int rc, haverouter = FALSE;
|
||||
|
||||
Syslog('r', "IBC: add_server %s %d %s %s \"%s\" %s", name, hops, prod, vers, fullname, router);
|
||||
|
||||
@ -465,7 +488,10 @@ int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$add_server mutex lock");
|
||||
return 0;
|
||||
}
|
||||
|
||||
tmp = (srv_list *)malloc(sizeof(srv_list));
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
@ -490,7 +516,8 @@ int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$add_server mutex unlock");
|
||||
srvchg = TRUE;
|
||||
return 1;
|
||||
}
|
||||
@ -503,13 +530,17 @@ int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
|
||||
void del_server(srv_list **fap, char *name)
|
||||
{
|
||||
srv_list *ta, *tan;
|
||||
int rc;
|
||||
|
||||
Syslog('r', "IBC: delserver %s", name);
|
||||
|
||||
if (*fap == NULL)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$del_server mutex lock");
|
||||
return;
|
||||
}
|
||||
|
||||
for (ta = *fap; ta; ta = ta->next) {
|
||||
while ((tan = ta->next) && (strcmp(tan->server, name) == 0)) {
|
||||
@ -520,7 +551,8 @@ void del_server(srv_list **fap, char *name)
|
||||
ta->next = tan;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$del_server mutex unlock");
|
||||
}
|
||||
|
||||
|
||||
@ -531,13 +563,18 @@ void del_server(srv_list **fap, char *name)
|
||||
void del_router(srv_list **fap, char *name)
|
||||
{
|
||||
srv_list *ta, *tan;
|
||||
int rc;
|
||||
|
||||
Syslog('r', "IBC: delrouter %s", name);
|
||||
|
||||
if (*fap == NULL)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$del_router mutex lock");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (ta = *fap; ta; ta = ta->next) {
|
||||
while ((tan = ta->next) && (strcmp(tan->router, name) == 0)) {
|
||||
@ -549,7 +586,8 @@ void del_router(srv_list **fap, char *name)
|
||||
ta->next = tan;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$del_router mutex unlock");
|
||||
}
|
||||
|
||||
|
||||
@ -631,7 +669,7 @@ void check_servers(void)
|
||||
ncs_list *tnsl, **tmp;
|
||||
srv_list *srv;
|
||||
int j, inlist, Remove, local_reset;
|
||||
int a1, a2, a3, a4;
|
||||
int a1, a2, a3, a4, rc;
|
||||
unsigned int crc;
|
||||
struct servent *se;
|
||||
struct hostent *he;
|
||||
@ -672,10 +710,14 @@ void check_servers(void)
|
||||
* Local reset, make all crc's invalid so the connections will restart.
|
||||
*/
|
||||
if (local_reset) {
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
for (tnsl = ncsl; tnsl; tnsl = tnsl->next)
|
||||
tnsl->crc--;
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$check_servers 1 mutex lock");
|
||||
} else {
|
||||
for (tnsl = ncsl; tnsl; tnsl = tnsl->next)
|
||||
tnsl->crc--;
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$check_servers 1 mutex unlock");
|
||||
}
|
||||
}
|
||||
|
||||
if ((fp = fopen(scfgfn, "r"))) {
|
||||
@ -699,10 +741,14 @@ void check_servers(void)
|
||||
Syslog('+', "IBC: server %s connection reset", tnsl->server);
|
||||
else
|
||||
Syslog('+', "IBC: server %s configuration changed or removed", tnsl->server);
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
tnsl->remove = TRUE;
|
||||
tnsl->action = now;
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$check_servers 2 mutex lock");
|
||||
} else {
|
||||
tnsl->remove = TRUE;
|
||||
tnsl->action = now;
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$check_servers 2 mutex unlock");
|
||||
}
|
||||
srvchg = TRUE;
|
||||
callchg = TRUE;
|
||||
}
|
||||
@ -743,20 +789,24 @@ void check_servers(void)
|
||||
*/
|
||||
if (Remove) {
|
||||
Syslog('r', "IBC: Starting remove list");
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
tmp = &ncsl;
|
||||
while (*tmp) {
|
||||
if ((*tmp)->remove) {
|
||||
Syslog('r', "do %s", (*tmp)->server);
|
||||
tnsl = *tmp;
|
||||
*tmp = (*tmp)->next;
|
||||
free(tnsl);
|
||||
callchg = TRUE;
|
||||
} else {
|
||||
tmp = &((*tmp)->next);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||
WriteError("$check_servers 3 mutex lock");
|
||||
} else {
|
||||
tmp = &ncsl;
|
||||
while (*tmp) {
|
||||
if ((*tmp)->remove) {
|
||||
Syslog('r', "do %s", (*tmp)->server);
|
||||
tnsl = *tmp;
|
||||
*tmp = (*tmp)->next;
|
||||
free(tnsl);
|
||||
callchg = TRUE;
|
||||
} else {
|
||||
tmp = &((*tmp)->next);
|
||||
}
|
||||
}
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$check_servers 3 mutex unlock");
|
||||
}
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
}
|
||||
dump_ncslist();
|
||||
|
||||
@ -914,14 +964,16 @@ void check_servers(void)
|
||||
* Reset our side of the connection.
|
||||
*/
|
||||
Syslog('+', "IBC: server %s connection is half dead", tnsl->server);
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
||||
WriteError("$check_servers 4 mutex lock");
|
||||
tnsl->state = NCS_DEAD;
|
||||
tnsl->action = now + (time_t)60; // 1 minute delay before calling again.
|
||||
tnsl->gotpass = FALSE;
|
||||
tnsl->gotserver = FALSE;
|
||||
tnsl->token = 0;
|
||||
tnsl->halfdead = 0;
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$check_servers 4 mutex unlock");
|
||||
broadcast(tnsl->server, "SQUIT %s Connection died\r\n", tnsl->server);
|
||||
callchg = TRUE;
|
||||
srvchg = TRUE;
|
||||
@ -934,14 +986,16 @@ void check_servers(void)
|
||||
* Missed 3 PING replies
|
||||
*/
|
||||
Syslog('+', "IBC: server %s connection is dead", tnsl->server);
|
||||
pthread_mutex_lock(&b_mutex);
|
||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
||||
WriteError("$check_servers 5 mutex lock");
|
||||
tnsl->state = NCS_DEAD;
|
||||
tnsl->action = now + (time_t)120; // 2 minutes delay before calling again.
|
||||
tnsl->gotpass = FALSE;
|
||||
tnsl->gotserver = FALSE;
|
||||
tnsl->token = 0;
|
||||
tnsl->halfdead = 0;
|
||||
pthread_mutex_unlock(&b_mutex);
|
||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||
WriteError("$check_servers 5 mutex unlock");
|
||||
broadcast(tnsl->server, "SQUIT %s Connection died\r\n", tnsl->server);
|
||||
callchg = TRUE;
|
||||
srvchg = TRUE;
|
||||
|
Reference in New Issue
Block a user