Code cleanup and memory optimisation
This commit is contained in:
parent
84e003f13a
commit
3ae9d86019
@ -32,6 +32,9 @@ v0.71.6 02-Sep-2005
|
||||
Removed Italian default record. Rewrote code to create default
|
||||
language records.
|
||||
|
||||
mbtask:
|
||||
Code cleanup and memory optimisation.
|
||||
|
||||
|
||||
v0.71.5 18-Aug-2005 - 02-Sep-2005
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Purpose ...............: mbtask - calllist
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2004
|
||||
* Copyright (C) 1997-2005
|
||||
*
|
||||
* Michiel Broek FIDO: 2:280/2802
|
||||
* Beekmansbos 10
|
||||
@ -125,7 +125,6 @@ int check_calllist(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
Syslog('o', "%d system%s to call", call_work, (call_work == 1)?"":"s");
|
||||
} else {
|
||||
if (s_scanout)
|
||||
sem_set((char *)"scanout", FALSE);
|
||||
|
@ -1397,7 +1397,8 @@ void *scheduler(void)
|
||||
calllist[call_entry].addr.node, calllist[call_entry].addr.net,
|
||||
calllist[call_entry].addr.zone, calllist[call_entry].addr.domain);
|
||||
} else {
|
||||
snprintf(opts, 41, "%sf%u.n%u.z%u.%s", port, calllist[call_entry].addr.node, calllist[call_entry].addr.net,
|
||||
snprintf(opts, 41, "%sf%u.n%u.z%u.%s", port, calllist[call_entry].addr.node,
|
||||
calllist[call_entry].addr.net,
|
||||
calllist[call_entry].addr.zone, calllist[call_entry].addr.domain);
|
||||
}
|
||||
calllist[call_entry].taskpid = launch(cmd, opts, (char *)"mbcico", calllist[call_entry].callmode);
|
||||
@ -1446,8 +1447,6 @@ int main(int argc, char **argv)
|
||||
signal(i, (void (*))start_shutdown);
|
||||
else if (i == SIGCHLD)
|
||||
signal(i, SIG_DFL);
|
||||
// else if ((i != SIGKILL) && (i != SIGSTOP))
|
||||
// signal(i, SIG_IGN);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -74,6 +74,7 @@ int load_node(fidoaddr n)
|
||||
memset(&nodes, 0, sizeof(nodes));
|
||||
return FALSE;
|
||||
}
|
||||
free(temp);
|
||||
|
||||
fread(&nodeshdr, sizeof(nodeshdr), 1, fp);
|
||||
while (fread(&nodes, nodeshdr.recsize, 1, fp) == 1) {
|
||||
@ -83,7 +84,6 @@ int load_node(fidoaddr n)
|
||||
if ((n.zone == nodes.Aka[i].zone) && (n.net == nodes.Aka[i].net) &&
|
||||
(n.node == nodes.Aka[i].node) && (n.point == nodes.Aka[i].point)) {
|
||||
fclose(fp);
|
||||
free(temp);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@ -91,7 +91,6 @@ int load_node(fidoaddr n)
|
||||
|
||||
fclose(fp);
|
||||
memset(&nodes, 0, sizeof(nodes));
|
||||
free(temp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -457,8 +456,6 @@ int outstat()
|
||||
}
|
||||
|
||||
rc = load_node(tmp->addr);
|
||||
// Syslog('o', "Load node %s rc=%s, NoCall=%s, NoTCP=%s", fido2str(tmp->addr, 0x0f), rc?"true":"false",
|
||||
// nodes.NoCall?"True":"False", (itnmask + ibnmask + ifcmask)?"False":"True");
|
||||
|
||||
/*
|
||||
* Zone Mail Hours, only use Fidonet Hours.
|
||||
@ -533,7 +530,6 @@ int outstat()
|
||||
T_window = TRUE;
|
||||
}
|
||||
}
|
||||
// Syslog('o', "T_window=%s, iszmh=%s", T_window?"true":"false", iszmh?"true":"false");
|
||||
strcpy(flstr,"...... .... ..");
|
||||
|
||||
/*
|
||||
|
@ -262,7 +262,6 @@ int ping_receive(struct in_addr addr)
|
||||
Syslog('?', "$poll/select failed");
|
||||
return -3;
|
||||
}
|
||||
// Syslog('p', "poll_thread: poll interrupted rc=%d events=%04x", rc, pfd.revents);
|
||||
|
||||
if (pfd.revents & POLLIN || pfd.revents & POLLERR || pfd.revents & POLLHUP || pfd.revents & POLLNVAL) {
|
||||
sl = sizeof(ffrom);
|
||||
@ -337,8 +336,6 @@ void *ping_thread(void *dummy)
|
||||
static time_t pingsend;
|
||||
time_t now;
|
||||
|
||||
printf("Start ping thread\n");
|
||||
|
||||
Syslog('+', "Starting ping thread");
|
||||
pingresult[1] = pingresult[2] = FALSE;
|
||||
pingnr = 2;
|
||||
@ -455,7 +452,6 @@ printf("Start ping thread\n");
|
||||
}
|
||||
}
|
||||
|
||||
Syslog('p', "Ping thread closing socket %d", ping_isocket);
|
||||
if ((rc = close(ping_isocket))) {
|
||||
WriteError("$ping thread error socket close");
|
||||
}
|
||||
|
@ -183,15 +183,16 @@ void load_ports()
|
||||
void check_ports(void)
|
||||
{
|
||||
pp_list *tpl;
|
||||
char lckname[256];
|
||||
char *lckname;
|
||||
FILE *lf;
|
||||
int tmppid, changed = FALSE;
|
||||
pid_t rempid = 0;
|
||||
|
||||
pots_free = isdn_free = 0;
|
||||
lckname = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
for (tpl = pl; tpl; tpl = tpl->next) {
|
||||
snprintf(lckname, 256, "%s%s", LCKPREFIX, tpl->tty);
|
||||
snprintf(lckname, PATH_MAX, "%s%s", LCKPREFIX, tpl->tty);
|
||||
if ((lf = fopen(lckname, "r")) == NULL) {
|
||||
if (tpl->locked) {
|
||||
tpl->locked = 0;
|
||||
@ -241,6 +242,7 @@ void check_ports(void)
|
||||
Syslog('p', "Free ports: pots=%d isdn=%d", pots_free, isdn_free);
|
||||
}
|
||||
}
|
||||
free(lckname);
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,13 +54,14 @@ extern struct _fidonet fidonet;
|
||||
static int scan_dir(int (*)(faddr*, char, int, char *), char *, int);
|
||||
static int scan_dir(int (*fn)(faddr *, char, int, char *), char *dname, int ispoint)
|
||||
{
|
||||
char fname[PATH_MAX], flavor = '?';
|
||||
char *fname, flavor = '?';
|
||||
DIR *dp = NULL;
|
||||
struct dirent *de;
|
||||
int rc = 0, isflo, fage;
|
||||
time_t t_start;
|
||||
|
||||
t_start = time(NULL);
|
||||
fname = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
if ((dp = opendir(dname)) == NULL) {
|
||||
Syslog('-', "Creating directory %s", dname);
|
||||
@ -71,6 +72,7 @@ static int scan_dir(int (*fn)(faddr *, char, int, char *), char *dname, int ispo
|
||||
(void)mkdirs(fname, 0770);
|
||||
if ((dp = opendir(dname)) == NULL) {
|
||||
Syslog('o' ,"\"%s\" cannot be opened, proceed",MBSE_SS(dname));
|
||||
free(fname);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -164,6 +166,7 @@ static int scan_dir(int (*fn)(faddr *, char, int, char *), char *dname, int ispo
|
||||
|
||||
exout:
|
||||
closedir(dp);
|
||||
free(fname);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -131,10 +131,11 @@ void system_msg(pid_t pid, char *msg)
|
||||
*/
|
||||
void system_shout(const char *format, ...)
|
||||
{
|
||||
char buf[512];
|
||||
char *buf;
|
||||
va_list va_ptr;
|
||||
usr_list *tmpu;
|
||||
|
||||
buf = calloc(512, sizeof(char));
|
||||
va_start(va_ptr, format);
|
||||
vsnprintf(buf, 512, format, va_ptr);
|
||||
va_end(va_ptr);
|
||||
@ -143,6 +144,8 @@ void system_shout(const char *format, ...)
|
||||
if (tmpu->pid) {
|
||||
system_msg(tmpu->pid, buf);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
|
||||
@ -350,13 +353,13 @@ void chat_cleanuser(pid_t pid)
|
||||
*/
|
||||
void chat_msg(char *channel, char *nick, char *msg)
|
||||
{
|
||||
char buf[128], *logm;
|
||||
char buf[79], *logm;
|
||||
usr_list *tmpu;
|
||||
|
||||
if (nick == NULL)
|
||||
snprintf(buf, 128, "%s", msg);
|
||||
snprintf(buf, 79, "%s", msg);
|
||||
else
|
||||
snprintf(buf, 128, "<%s> %s", nick, msg);
|
||||
snprintf(buf, 79, "<%s> %s", nick, msg);
|
||||
|
||||
if (CFG.iAutoLog && strlen(CFG.chat_log)) {
|
||||
logm = calloc(PATH_MAX, sizeof(char));
|
||||
@ -364,7 +367,6 @@ void chat_msg(char *channel, char *nick, char *msg)
|
||||
ulog(logm, (char *)"+", channel, (char *)"-1", buf);
|
||||
free(logm);
|
||||
}
|
||||
buf[79] = '\0';
|
||||
|
||||
for (tmpu = users; tmpu; tmpu = tmpu->next) {
|
||||
if (strlen(tmpu->channel) && (strcmp(tmpu->channel, channel) == 0)) {
|
||||
@ -457,7 +459,7 @@ char *chat_connect(char *data)
|
||||
|
||||
char *chat_close(char *data)
|
||||
{
|
||||
static char buf[200];
|
||||
static char buf[81];
|
||||
char *pid;
|
||||
usr_list *tmpu;
|
||||
|
||||
@ -474,12 +476,12 @@ char *chat_close(char *data)
|
||||
send_all("QUIT %s@%s Leaving chat\r\n", tmpu->name, CFG.myfqdn);
|
||||
del_user(&users, CFG.myfqdn, tmpu->name);
|
||||
Syslog('-', "Closing chat for pid %s", pid);
|
||||
snprintf(buf, 200, "100:0;");
|
||||
snprintf(buf, 81, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
Syslog('-', "Pid %s was not connected to chatserver");
|
||||
snprintf(buf, 200, "100:1,*** ERROR - Not connected to server;");
|
||||
snprintf(buf, 81, "100:1,*** ERROR - Not connected to server;");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -483,7 +483,7 @@ void add_path(char *lpath)
|
||||
void *disk_thread(void)
|
||||
{
|
||||
FILE *fp;
|
||||
char *temp;
|
||||
char *temp = NULL;
|
||||
mfs_list *tmp;
|
||||
int rc;
|
||||
|
||||
@ -654,6 +654,7 @@ void *disk_thread(void)
|
||||
fclose(fp);
|
||||
}
|
||||
free(temp);
|
||||
temp = NULL;
|
||||
Syslog('d', "All directories added");
|
||||
|
||||
/*
|
||||
@ -682,6 +683,9 @@ void *disk_thread(void)
|
||||
}
|
||||
|
||||
tidy_mfslist(&mfs);
|
||||
if (temp)
|
||||
free(temp);
|
||||
temp = NULL;
|
||||
disk_run = FALSE;
|
||||
Syslog('+', "Disk thread stopped");
|
||||
pthread_exit(NULL);
|
||||
|
@ -70,20 +70,21 @@ char *get_sysinfo(void)
|
||||
|
||||
char *get_lastcallercount(void)
|
||||
{
|
||||
static char buf[SS_BUFSIZE];
|
||||
static char buf[41];
|
||||
char *temp;
|
||||
FILE *fp;
|
||||
|
||||
snprintf(buf, SS_BUFSIZE, "201:1,16;");
|
||||
snprintf(buf, 41, "100:1,0;");
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(temp, PATH_MAX, "%s/etc/lastcall.data", getenv("MBSE_ROOT"));
|
||||
if ((fp = fopen(temp, "r")) == NULL) {
|
||||
free(temp);
|
||||
return buf;
|
||||
}
|
||||
|
||||
fread(&LCALLhdr, sizeof(LCALLhdr), 1, fp);
|
||||
fseek(fp, 0, SEEK_END);
|
||||
snprintf(buf, SS_BUFSIZE, "100:1,%ld;", ((ftell(fp) - LCALLhdr.hdrsize) / LCALLhdr.recsize));
|
||||
snprintf(buf, 41, "100:1,%ld;", ((ftell(fp) - LCALLhdr.hdrsize) / LCALLhdr.recsize));
|
||||
fclose(fp);
|
||||
free(temp);
|
||||
return buf;
|
||||
|
@ -283,18 +283,22 @@ char *xstrcat(char *src, char *add)
|
||||
|
||||
void CreateSema(char *sem)
|
||||
{
|
||||
char temp[PATH_MAX];
|
||||
char *temp;
|
||||
FILE *fp;
|
||||
int oldmask;
|
||||
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
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;
|
||||
}
|
||||
oldmask = umask(002);
|
||||
if ((fp = fopen(temp, "w")))
|
||||
fclose(fp);
|
||||
else
|
||||
Syslog('?', "Can't create semafore %s", temp);
|
||||
free(temp);
|
||||
umask(oldmask);
|
||||
}
|
||||
|
||||
@ -302,16 +306,18 @@ void CreateSema(char *sem)
|
||||
|
||||
void TouchSema(char *sem)
|
||||
{
|
||||
char temp[PATH_MAX];
|
||||
char *temp;
|
||||
FILE *fp;
|
||||
int oldmask;
|
||||
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem);
|
||||
oldmask = umask(002);
|
||||
if ((fp = fopen(temp, "w")))
|
||||
if ((fp = fopen(temp, "w"))) {
|
||||
fclose(fp);
|
||||
else
|
||||
} else
|
||||
Syslog('?', "Can't touch semafore %s", temp);
|
||||
free(temp);
|
||||
umask(oldmask);
|
||||
}
|
||||
|
||||
@ -319,23 +325,31 @@ void TouchSema(char *sem)
|
||||
|
||||
void RemoveSema(char *sem)
|
||||
{
|
||||
char temp[PATH_MAX];
|
||||
char *temp;
|
||||
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
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;
|
||||
}
|
||||
if (unlink(temp) == -1)
|
||||
Syslog('?', "Can't remove semafore %s", temp);
|
||||
free(temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int IsSema(char *sem)
|
||||
{
|
||||
char temp[PATH_MAX];
|
||||
char *temp;
|
||||
int rc;
|
||||
|
||||
temp = calloc(PATH_MAX, sizeof(temp));
|
||||
snprintf(temp, PATH_MAX, "%s/var/sema/%s", getenv("MBSE_ROOT"), sem);
|
||||
return (access(temp, F_OK) == 0);
|
||||
rc = (access(temp, F_OK) == 0);
|
||||
free(temp);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user