Changed mutex locking
This commit is contained in:
parent
bc8e96ed4d
commit
e2312db257
@ -116,7 +116,6 @@ extern int ping_run; /* Ping running */
|
|||||||
int sched_run = FALSE; /* Scheduler running */
|
int sched_run = FALSE; /* Scheduler running */
|
||||||
extern int disk_run; /* Disk watch running */
|
extern int disk_run; /* Disk watch running */
|
||||||
extern int ibc_run; /* IBC thread running */
|
extern int ibc_run; /* IBC thread running */
|
||||||
extern pthread_mutex_t b_mutex; /* IBC mutex lock */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -466,9 +465,7 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = pthread_mutex_lock(&b_mutex);
|
if (lock_ibc((char *)"launch")) {
|
||||||
if (rc) {
|
|
||||||
WriteError("$launch mutex lock");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Syslog('r', "launch() mutex locked");
|
Syslog('r', "launch() mutex locked");
|
||||||
@ -523,10 +520,7 @@ pid_t launch(char *cmd, char *opts, char *name, int tasktype)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = pthread_mutex_unlock(&b_mutex);
|
unlock_ibc((char *)"launch");
|
||||||
if (rc) {
|
|
||||||
WriteError("$launch mutex unlock");
|
|
||||||
}
|
|
||||||
Syslog('r', "launch() mutex unlocked");
|
Syslog('r', "launch() mutex unlocked");
|
||||||
|
|
||||||
ptimer = PAUSETIME;
|
ptimer = PAUSETIME;
|
||||||
|
@ -71,7 +71,6 @@ extern chn_list *channels; /* Connected channels */
|
|||||||
extern int usrchg;
|
extern int usrchg;
|
||||||
extern int chnchg;
|
extern int chnchg;
|
||||||
extern int srvchg;
|
extern int srvchg;
|
||||||
extern pthread_mutex_t b_mutex;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -198,7 +197,6 @@ int join(pid_t pid, char *channel, int sysop)
|
|||||||
char buf[81];
|
char buf[81];
|
||||||
chn_list *tmp;
|
chn_list *tmp;
|
||||||
usr_list *tmpu;
|
usr_list *tmpu;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('c', "Join pid %d to channel %s", pid, channel);
|
Syslog('c', "Join pid %d to channel %s", pid, channel);
|
||||||
|
|
||||||
@ -208,12 +206,10 @@ 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 ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
if (! lock_ibc((char *)"join 1")) {
|
||||||
strncpy(tmpu->channel, channel, 20);
|
strncpy(tmpu->channel, channel, 20);
|
||||||
tmp->users++;
|
tmp->users++;
|
||||||
rc = pthread_mutex_unlock(&b_mutex);
|
unlock_ibc((char *)"join 1");
|
||||||
} else {
|
|
||||||
WriteError("$join 1 mutex lock");
|
|
||||||
}
|
}
|
||||||
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;
|
||||||
@ -252,11 +248,9 @@ 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 ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
if (! lock_ibc((char *)"join 2")) {
|
||||||
strncpy(tmpu->channel, channel, 20);
|
strncpy(tmpu->channel, channel, 20);
|
||||||
rc = pthread_mutex_unlock(&b_mutex);
|
unlock_ibc((char *)"join 2");
|
||||||
} else {
|
|
||||||
WriteError("$join 2 mutex lock");
|
|
||||||
}
|
}
|
||||||
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;
|
||||||
@ -293,7 +287,6 @@ int part(pid_t pid, char *reason)
|
|||||||
char buf[81];
|
char buf[81];
|
||||||
chn_list *tmp;
|
chn_list *tmp;
|
||||||
usr_list *tmpu;
|
usr_list *tmpu;
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (strlen(reason) > 54)
|
if (strlen(reason) > 54)
|
||||||
reason[54] = '\0';
|
reason[54] = '\0';
|
||||||
@ -322,11 +315,9 @@ int part(pid_t pid, char *reason)
|
|||||||
/*
|
/*
|
||||||
* Clean channel
|
* Clean channel
|
||||||
*/
|
*/
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
if (! lock_ibc((char *)"part 1")) {
|
||||||
tmp->users--;
|
tmp->users--;
|
||||||
rc = pthread_mutex_unlock(&b_mutex);
|
unlock_ibc((char *)"part 1");
|
||||||
} else {
|
|
||||||
WriteError("$part 1 mutex lock");
|
|
||||||
}
|
}
|
||||||
Syslog('+', "IBC: nick %s leaves channel %s", tmpu->nick, tmp->name);
|
Syslog('+', "IBC: nick %s leaves channel %s", tmpu->nick, tmp->name);
|
||||||
if (tmp->users == 0) {
|
if (tmp->users == 0) {
|
||||||
@ -341,11 +332,9 @@ int part(pid_t pid, char *reason)
|
|||||||
/*
|
/*
|
||||||
* Update user data
|
* Update user data
|
||||||
*/
|
*/
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
if (! lock_ibc((char *)"part 2")) {
|
||||||
tmpu->channel[0] = '\0';
|
tmpu->channel[0] = '\0';
|
||||||
rc = pthread_mutex_unlock(&b_mutex);
|
unlock_ibc((char *)"part 2");
|
||||||
} else {
|
|
||||||
WriteError("$part 2 mutex lock");
|
|
||||||
}
|
}
|
||||||
usrchg = TRUE;
|
usrchg = TRUE;
|
||||||
chnchg = TRUE;
|
chnchg = TRUE;
|
||||||
@ -407,7 +396,7 @@ char *chat_connect(char *data)
|
|||||||
{
|
{
|
||||||
char *pid, *realname, *nick;
|
char *pid, *realname, *nick;
|
||||||
static char buf[200];
|
static char buf[200];
|
||||||
int count = 0, sys = FALSE, rc;
|
int count = 0, sys = FALSE;
|
||||||
srv_list *sl;
|
srv_list *sl;
|
||||||
usr_list *tmpu;
|
usr_list *tmpu;
|
||||||
|
|
||||||
@ -444,13 +433,11 @@ char *chat_connect(char *data)
|
|||||||
/*
|
/*
|
||||||
* Oke, found
|
* Oke, found
|
||||||
*/
|
*/
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)) == 0) {
|
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;
|
||||||
rc = pthread_mutex_unlock(&b_mutex);
|
unlock_ibc((char *)"chat_connect");
|
||||||
} else {
|
|
||||||
WriteError("$chat_connect mutex lock");
|
|
||||||
}
|
}
|
||||||
usrchg = TRUE;
|
usrchg = TRUE;
|
||||||
srvchg = TRUE;
|
srvchg = TRUE;
|
||||||
|
168
mbtask/taskibc.c
168
mbtask/taskibc.c
@ -61,6 +61,7 @@ int banchg = FALSE; /* Is banned users changed */
|
|||||||
int nickchg = FALSE; /* Is nicknames changed */
|
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 is_locked = FALSE; /* Is mutex locked */
|
||||||
|
|
||||||
|
|
||||||
#define PING_PONG_LOG 1
|
#define PING_PONG_LOG 1
|
||||||
@ -69,6 +70,7 @@ int do_reset = FALSE; /* Reset init */
|
|||||||
pthread_mutex_t b_mutex = PTHREAD_MUTEX_INITIALIZER;
|
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;
|
||||||
|
|
||||||
|
|
||||||
@ -105,18 +107,51 @@ void receiver(struct servent *);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int lock_ibc(char *func)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (is_locked) {
|
||||||
|
WriteError("%s() mutex already locked", func);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
||||||
|
WriteError("$%s() mutex lock", func);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
is_locked = TRUE;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void unlock_ibc(char *func)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (!is_locked) {
|
||||||
|
WriteError("%s() mutex unlock, was not locked", func);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
is_locked = FALSE;
|
||||||
|
|
||||||
|
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
||||||
|
WriteError("$%s() mutex unlock", func);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a server to the serverlist
|
* Add a server to the serverlist
|
||||||
*/
|
*/
|
||||||
void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int dyndns, unsigned int crc)
|
void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int dyndns, unsigned int crc)
|
||||||
{
|
{
|
||||||
ncs_list *tmp, *ta;
|
ncs_list *tmp, *ta;
|
||||||
int rc;
|
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (lock_ibc((char *)"fill_ncslist"))
|
||||||
WriteError("$fill_ncslist mutex lock");
|
|
||||||
return;
|
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));
|
||||||
@ -149,8 +184,7 @@ void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"fill_ncslist");
|
||||||
WriteError("$fill_ncslist mutex unlock");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -256,7 +290,7 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
|||||||
{
|
{
|
||||||
usr_list *tmp, *ta;
|
usr_list *tmp, *ta;
|
||||||
srv_list *sl;
|
srv_list *sl;
|
||||||
int rc, Found = FALSE;
|
int Found = FALSE;
|
||||||
|
|
||||||
Syslog('r', "IBC: add_user (%s, %s, %s)", server, name, realname);
|
Syslog('r', "IBC: add_user (%s, %s, %s)", server, name, realname);
|
||||||
|
|
||||||
@ -278,8 +312,7 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (lock_ibc((char *)"add_user")) {
|
||||||
WriteError("$add_user() mutex lock");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,9 +343,7 @@ int add_user(usr_list **fap, char *server, char *name, char *realname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"add_user");
|
||||||
WriteError("$add_user() mutex unlock");
|
|
||||||
|
|
||||||
usrchg = TRUE;
|
usrchg = TRUE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -326,16 +357,17 @@ void del_user(usr_list **fap, char *server, char *name)
|
|||||||
{
|
{
|
||||||
usr_list **tmp, *tmpa;
|
usr_list **tmp, *tmpa;
|
||||||
srv_list *sl;
|
srv_list *sl;
|
||||||
int rc, count = 0;
|
int count = 0;
|
||||||
|
|
||||||
Syslog('r', "IBC: deluser (%s, %s)", server, printable(name, 0));
|
Syslog('r', "IBC: deluser (%s, %s)", server, printable(name, 0));
|
||||||
|
|
||||||
if (*fap == NULL)
|
if (*fap == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (name) {
|
||||||
WriteError("$del_user() mutex lock");
|
if (lock_ibc((char *)"del_user")) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = fap;
|
tmp = fap;
|
||||||
@ -368,8 +400,8 @@ void del_user(usr_list **fap, char *server, char *name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
if (name)
|
||||||
WriteError("$del_user() mutex unlock");
|
unlock_ibc((char *)"del_user");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -380,7 +412,6 @@ void del_user(usr_list **fap, char *server, char *name)
|
|||||||
int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
||||||
{
|
{
|
||||||
chn_list *tmp, *ta;
|
chn_list *tmp, *ta;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "IBC: add_channel (%s, %s, %s)", name, owner, server);
|
Syslog('r', "IBC: add_channel (%s, %s, %s)", name, owner, server);
|
||||||
|
|
||||||
@ -391,8 +422,7 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (lock_ibc((char *)"add_channel")) {
|
||||||
WriteError("$add_channel() mutex lock");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,9 +446,7 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"add_channel");
|
||||||
WriteError("$add_channel() mutex unlock");
|
|
||||||
|
|
||||||
chnchg = TRUE;
|
chnchg = TRUE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -428,15 +456,13 @@ int add_channel(chn_list **fap, char *name, char *owner, char *server)
|
|||||||
void del_channel(chn_list **fap, char *name)
|
void del_channel(chn_list **fap, char *name)
|
||||||
{
|
{
|
||||||
chn_list **tmp, *tmpa;
|
chn_list **tmp, *tmpa;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "IBC: del_channel %s", name);
|
Syslog('r', "IBC: del_channel %s", name);
|
||||||
|
|
||||||
if (*fap == NULL)
|
if (*fap == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (lock_ibc((char *)"del_channel")) {
|
||||||
WriteError("$del_channel mutex lock");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,8 +478,7 @@ void del_channel(chn_list **fap, char *name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"del_channel");
|
||||||
WriteError("$del_channel mutex unlock");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -461,7 +486,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)
|
int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, char *fullname, char *router)
|
||||||
{
|
{
|
||||||
srv_list *tmp, *ta;
|
srv_list *tmp, *ta;
|
||||||
int rc, haverouter = FALSE;
|
int haverouter = FALSE;
|
||||||
|
|
||||||
Syslog('r', "IBC: add_server %s %d %s %s \"%s\" %s", name, hops, prod, vers, fullname, router);
|
Syslog('r', "IBC: add_server %s %d %s %s \"%s\" %s", name, hops, prod, vers, fullname, router);
|
||||||
|
|
||||||
@ -488,8 +513,7 @@ int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (lock_ibc((char *)"add_server")) {
|
||||||
WriteError("$add_server mutex lock");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,8 +540,7 @@ int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"add_server");
|
||||||
WriteError("$add_server mutex unlock");
|
|
||||||
srvchg = TRUE;
|
srvchg = TRUE;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -530,15 +553,13 @@ int add_server(srv_list **fdp, char *name, int hops, char *prod, char *vers, ch
|
|||||||
void del_server(srv_list **fap, char *name)
|
void del_server(srv_list **fap, char *name)
|
||||||
{
|
{
|
||||||
srv_list *ta, *tan;
|
srv_list *ta, *tan;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "IBC: delserver %s", name);
|
Syslog('r', "IBC: delserver %s", name);
|
||||||
|
|
||||||
if (*fap == NULL)
|
if (*fap == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (lock_ibc((char *)"del_server")) {
|
||||||
WriteError("$del_server mutex lock");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,8 +572,7 @@ void del_server(srv_list **fap, char *name)
|
|||||||
ta->next = tan;
|
ta->next = tan;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"del_server");
|
||||||
WriteError("$del_server mutex unlock");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -563,15 +583,13 @@ void del_server(srv_list **fap, char *name)
|
|||||||
void del_router(srv_list **fap, char *name)
|
void del_router(srv_list **fap, char *name)
|
||||||
{
|
{
|
||||||
srv_list *ta, *tan;
|
srv_list *ta, *tan;
|
||||||
int rc;
|
|
||||||
|
|
||||||
Syslog('r', "IBC: delrouter %s", name);
|
Syslog('r', "IBC: delrouter %s", name);
|
||||||
|
|
||||||
if (*fap == NULL)
|
if (*fap == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (lock_ibc((char *)"del_router")) {
|
||||||
WriteError("$del_router mutex lock");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,8 +604,7 @@ void del_router(srv_list **fap, char *name)
|
|||||||
ta->next = tan;
|
ta->next = tan;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"del_router");
|
||||||
WriteError("$del_router mutex unlock");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -669,7 +686,7 @@ void check_servers(void)
|
|||||||
ncs_list *tnsl, **tmp;
|
ncs_list *tnsl, **tmp;
|
||||||
srv_list *srv;
|
srv_list *srv;
|
||||||
int j, inlist, Remove, local_reset;
|
int j, inlist, Remove, local_reset;
|
||||||
int a1, a2, a3, a4, rc;
|
int a1, a2, a3, a4;
|
||||||
unsigned int crc;
|
unsigned int crc;
|
||||||
struct servent *se;
|
struct servent *se;
|
||||||
struct hostent *he;
|
struct hostent *he;
|
||||||
@ -710,13 +727,10 @@ 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 ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (! lock_ibc((char *)"check_servers 1")) {
|
||||||
WriteError("$check_servers 1 mutex lock");
|
|
||||||
} else {
|
|
||||||
for (tnsl = ncsl; tnsl; tnsl = tnsl->next)
|
for (tnsl = ncsl; tnsl; tnsl = tnsl->next)
|
||||||
tnsl->crc--;
|
tnsl->crc--;
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"check_servers 1");
|
||||||
WriteError("$check_servers 1 mutex unlock");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,13 +755,10 @@ 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 ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (! lock_ibc((char *)"check_servers 2")) {
|
||||||
WriteError("$check_servers 2 mutex lock");
|
|
||||||
} else {
|
|
||||||
tnsl->remove = TRUE;
|
tnsl->remove = TRUE;
|
||||||
tnsl->action = now;
|
tnsl->action = now;
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"check_servers 2");
|
||||||
WriteError("$check_servers 2 mutex unlock");
|
|
||||||
}
|
}
|
||||||
srvchg = TRUE;
|
srvchg = TRUE;
|
||||||
callchg = TRUE;
|
callchg = TRUE;
|
||||||
@ -789,9 +800,7 @@ void check_servers(void)
|
|||||||
*/
|
*/
|
||||||
if (Remove) {
|
if (Remove) {
|
||||||
Syslog('r', "IBC: Starting remove list");
|
Syslog('r', "IBC: Starting remove list");
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex))) {
|
if (! lock_ibc((char *)"check_servers 3")) {
|
||||||
WriteError("$check_servers 3 mutex lock");
|
|
||||||
} else {
|
|
||||||
tmp = &ncsl;
|
tmp = &ncsl;
|
||||||
while (*tmp) {
|
while (*tmp) {
|
||||||
if ((*tmp)->remove) {
|
if ((*tmp)->remove) {
|
||||||
@ -804,8 +813,7 @@ void check_servers(void)
|
|||||||
tmp = &((*tmp)->next);
|
tmp = &((*tmp)->next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"check_servers 3");
|
||||||
WriteError("$check_servers 3 mutex unlock");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dump_ncslist();
|
dump_ncslist();
|
||||||
@ -964,16 +972,14 @@ 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);
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
lock_ibc((char *)"check_servers 4");
|
||||||
WriteError("$check_servers 4 mutex lock");
|
|
||||||
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;
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"check_servers 4");
|
||||||
WriteError("$check_servers 4 mutex unlock");
|
|
||||||
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;
|
||||||
@ -986,16 +992,14 @@ 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);
|
||||||
if ((rc = pthread_mutex_lock(&b_mutex)))
|
lock_ibc((char *)"check_servers 5");
|
||||||
WriteError("$check_servers 5 mutex lock");
|
|
||||||
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;
|
||||||
if ((rc = pthread_mutex_unlock(&b_mutex)))
|
unlock_ibc((char *)"check_servers 5");
|
||||||
WriteError("$check_servers 5 mutex unlock");
|
|
||||||
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;
|
||||||
@ -1135,13 +1139,13 @@ 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);
|
||||||
pthread_mutex_lock(&b_mutex);
|
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;
|
||||||
pthread_mutex_unlock(&b_mutex);
|
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
|
||||||
@ -1187,11 +1191,11 @@ 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);
|
||||||
pthread_mutex_lock(&b_mutex);
|
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;
|
||||||
pthread_mutex_unlock(&b_mutex);
|
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
|
||||||
@ -1261,13 +1265,13 @@ 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);
|
||||||
pthread_mutex_lock(&b_mutex);
|
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;
|
||||||
pthread_mutex_unlock(&b_mutex);
|
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);
|
||||||
@ -1387,9 +1391,9 @@ 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)) {
|
||||||
pthread_mutex_lock(&b_mutex);
|
lock_ibc((char *)"command_nick");
|
||||||
strncpy(tmp->nick, nick, 9);
|
strncpy(tmp->nick, nick, 9);
|
||||||
pthread_mutex_unlock(&b_mutex);
|
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;
|
||||||
@ -1455,9 +1459,9 @@ 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))) {
|
||||||
pthread_mutex_lock(&b_mutex);
|
lock_ibc((char *)"command_join");
|
||||||
strncpy(tmpu->channel, channel, 20);
|
strncpy(tmpu->channel, channel, 20);
|
||||||
pthread_mutex_unlock(&b_mutex);
|
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);
|
||||||
@ -1514,9 +1518,9 @@ int command_part(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))) {
|
||||||
pthread_mutex_lock(&b_mutex);
|
lock_ibc((char *)"command_part");
|
||||||
tmpu->channel[0] = '\0';
|
tmpu->channel[0] = '\0';
|
||||||
pthread_mutex_unlock(&b_mutex);
|
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: %s", nick, server, message);
|
||||||
@ -1561,9 +1565,9 @@ 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;
|
||||||
pthread_mutex_lock(&b_mutex);
|
lock_ibc((char *)"command_topic");
|
||||||
strncpy(tmp->topic, topic, 54);
|
strncpy(tmp->topic, topic, 54);
|
||||||
pthread_mutex_unlock(&b_mutex);
|
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);
|
||||||
|
@ -107,6 +107,8 @@ typedef struct _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 *);
|
||||||
|
Reference in New Issue
Block a user