Code cleanup and memory optimisation

This commit is contained in:
Michiel Broek 2005-09-11 13:07:42 +00:00
parent 84e003f13a
commit 3ae9d86019
11 changed files with 70 additions and 51 deletions

View File

@ -32,6 +32,9 @@ v0.71.6 02-Sep-2005
Removed Italian default record. Rewrote code to create default Removed Italian default record. Rewrote code to create default
language records. language records.
mbtask:
Code cleanup and memory optimisation.
v0.71.5 18-Aug-2005 - 02-Sep-2005 v0.71.5 18-Aug-2005 - 02-Sep-2005

View File

@ -4,7 +4,7 @@
* Purpose ...............: mbtask - calllist * Purpose ...............: mbtask - calllist
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2004 * Copyright (C) 1997-2005
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -125,7 +125,6 @@ int check_calllist(void)
} }
} }
} }
Syslog('o', "%d system%s to call", call_work, (call_work == 1)?"":"s");
} else { } else {
if (s_scanout) if (s_scanout)
sem_set((char *)"scanout", FALSE); sem_set((char *)"scanout", FALSE);

View File

@ -1397,7 +1397,8 @@ void *scheduler(void)
calllist[call_entry].addr.node, calllist[call_entry].addr.net, calllist[call_entry].addr.node, 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);
} else { } 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].addr.zone, calllist[call_entry].addr.domain);
} }
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);
@ -1446,8 +1447,6 @@ int main(int argc, char **argv)
signal(i, (void (*))start_shutdown); signal(i, (void (*))start_shutdown);
else if (i == SIGCHLD) else if (i == SIGCHLD)
signal(i, SIG_DFL); signal(i, SIG_DFL);
// else if ((i != SIGKILL) && (i != SIGSTOP))
// signal(i, SIG_IGN);
} }
/* /*

View File

@ -74,6 +74,7 @@ int load_node(fidoaddr n)
memset(&nodes, 0, sizeof(nodes)); memset(&nodes, 0, sizeof(nodes));
return FALSE; return FALSE;
} }
free(temp);
fread(&nodeshdr, sizeof(nodeshdr), 1, fp); fread(&nodeshdr, sizeof(nodeshdr), 1, fp);
while (fread(&nodes, nodeshdr.recsize, 1, fp) == 1) { 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) && 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)) { (n.node == nodes.Aka[i].node) && (n.point == nodes.Aka[i].point)) {
fclose(fp); fclose(fp);
free(temp);
return TRUE; return TRUE;
} }
} }
@ -91,7 +91,6 @@ int load_node(fidoaddr n)
fclose(fp); fclose(fp);
memset(&nodes, 0, sizeof(nodes)); memset(&nodes, 0, sizeof(nodes));
free(temp);
return FALSE; return FALSE;
} }
@ -457,8 +456,6 @@ int outstat()
} }
rc = load_node(tmp->addr); 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. * Zone Mail Hours, only use Fidonet Hours.
@ -533,7 +530,6 @@ int outstat()
T_window = TRUE; T_window = TRUE;
} }
} }
// Syslog('o', "T_window=%s, iszmh=%s", T_window?"true":"false", iszmh?"true":"false");
strcpy(flstr,"...... .... .."); strcpy(flstr,"...... .... ..");
/* /*

View File

@ -262,7 +262,6 @@ int ping_receive(struct in_addr addr)
Syslog('?', "$poll/select failed"); Syslog('?', "$poll/select failed");
return -3; 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) { if (pfd.revents & POLLIN || pfd.revents & POLLERR || pfd.revents & POLLHUP || pfd.revents & POLLNVAL) {
sl = sizeof(ffrom); sl = sizeof(ffrom);
@ -337,8 +336,6 @@ void *ping_thread(void *dummy)
static time_t pingsend; static time_t pingsend;
time_t now; time_t now;
printf("Start ping thread\n");
Syslog('+', "Starting ping thread"); Syslog('+', "Starting ping thread");
pingresult[1] = pingresult[2] = FALSE; pingresult[1] = pingresult[2] = FALSE;
pingnr = 2; 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))) { if ((rc = close(ping_isocket))) {
WriteError("$ping thread error socket close"); WriteError("$ping thread error socket close");
} }

View File

@ -183,15 +183,16 @@ void load_ports()
void check_ports(void) void check_ports(void)
{ {
pp_list *tpl; pp_list *tpl;
char lckname[256]; char *lckname;
FILE *lf; FILE *lf;
int tmppid, changed = FALSE; int tmppid, changed = FALSE;
pid_t rempid = 0; pid_t rempid = 0;
pots_free = isdn_free = 0; pots_free = isdn_free = 0;
lckname = calloc(PATH_MAX, sizeof(char));
for (tpl = pl; tpl; tpl = tpl->next) { 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 ((lf = fopen(lckname, "r")) == NULL) {
if (tpl->locked) { if (tpl->locked) {
tpl->locked = 0; tpl->locked = 0;
@ -241,6 +242,7 @@ void check_ports(void)
Syslog('p', "Free ports: pots=%d isdn=%d", pots_free, isdn_free); Syslog('p', "Free ports: pots=%d isdn=%d", pots_free, isdn_free);
} }
} }
free(lckname);
} }

View File

@ -54,13 +54,14 @@ extern struct _fidonet fidonet;
static int scan_dir(int (*)(faddr*, char, int, char *), char *, int); 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) 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; DIR *dp = NULL;
struct dirent *de; struct dirent *de;
int rc = 0, isflo, fage; int rc = 0, isflo, fage;
time_t t_start; time_t t_start;
t_start = time(NULL); t_start = time(NULL);
fname = calloc(PATH_MAX, sizeof(char));
if ((dp = opendir(dname)) == NULL) { if ((dp = opendir(dname)) == NULL) {
Syslog('-', "Creating directory %s", dname); 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); (void)mkdirs(fname, 0770);
if ((dp = opendir(dname)) == NULL) { if ((dp = opendir(dname)) == NULL) {
Syslog('o' ,"\"%s\" cannot be opened, proceed",MBSE_SS(dname)); Syslog('o' ,"\"%s\" cannot be opened, proceed",MBSE_SS(dname));
free(fname);
return 0; return 0;
} }
} }
@ -164,6 +166,7 @@ static int scan_dir(int (*fn)(faddr *, char, int, char *), char *dname, int ispo
exout: exout:
closedir(dp); closedir(dp);
free(fname);
return rc; return rc;
} }

View File

@ -131,10 +131,11 @@ void system_msg(pid_t pid, char *msg)
*/ */
void system_shout(const char *format, ...) void system_shout(const char *format, ...)
{ {
char buf[512]; char *buf;
va_list va_ptr; va_list va_ptr;
usr_list *tmpu; usr_list *tmpu;
buf = calloc(512, sizeof(char));
va_start(va_ptr, format); va_start(va_ptr, format);
vsnprintf(buf, 512, format, va_ptr); vsnprintf(buf, 512, format, va_ptr);
va_end(va_ptr); va_end(va_ptr);
@ -143,6 +144,8 @@ void system_shout(const char *format, ...)
if (tmpu->pid) { if (tmpu->pid) {
system_msg(tmpu->pid, buf); 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) void chat_msg(char *channel, char *nick, char *msg)
{ {
char buf[128], *logm; char buf[79], *logm;
usr_list *tmpu; usr_list *tmpu;
if (nick == NULL) if (nick == NULL)
snprintf(buf, 128, "%s", msg); snprintf(buf, 79, "%s", msg);
else else
snprintf(buf, 128, "<%s> %s", nick, msg); snprintf(buf, 79, "<%s> %s", nick, msg);
if (CFG.iAutoLog && strlen(CFG.chat_log)) { if (CFG.iAutoLog && strlen(CFG.chat_log)) {
logm = calloc(PATH_MAX, sizeof(char)); 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); ulog(logm, (char *)"+", channel, (char *)"-1", buf);
free(logm); free(logm);
} }
buf[79] = '\0';
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
if (strlen(tmpu->channel) && (strcmp(tmpu->channel, channel) == 0)) { if (strlen(tmpu->channel) && (strcmp(tmpu->channel, channel) == 0)) {
@ -457,7 +459,7 @@ char *chat_connect(char *data)
char *chat_close(char *data) char *chat_close(char *data)
{ {
static char buf[200]; static char buf[81];
char *pid; char *pid;
usr_list *tmpu; 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); send_all("QUIT %s@%s Leaving chat\r\n", tmpu->name, CFG.myfqdn);
del_user(&users, CFG.myfqdn, tmpu->name); del_user(&users, CFG.myfqdn, tmpu->name);
Syslog('-', "Closing chat for pid %s", pid); Syslog('-', "Closing chat for pid %s", pid);
snprintf(buf, 200, "100:0;"); snprintf(buf, 81, "100:0;");
return buf; return buf;
} }
} }
Syslog('-', "Pid %s was not connected to chatserver"); 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; return buf;
} }

View File

@ -483,7 +483,7 @@ void add_path(char *lpath)
void *disk_thread(void) void *disk_thread(void)
{ {
FILE *fp; FILE *fp;
char *temp; char *temp = NULL;
mfs_list *tmp; mfs_list *tmp;
int rc; int rc;
@ -654,6 +654,7 @@ void *disk_thread(void)
fclose(fp); fclose(fp);
} }
free(temp); free(temp);
temp = NULL;
Syslog('d', "All directories added"); Syslog('d', "All directories added");
/* /*
@ -682,6 +683,9 @@ void *disk_thread(void)
} }
tidy_mfslist(&mfs); tidy_mfslist(&mfs);
if (temp)
free(temp);
temp = NULL;
disk_run = FALSE; disk_run = FALSE;
Syslog('+', "Disk thread stopped"); Syslog('+', "Disk thread stopped");
pthread_exit(NULL); pthread_exit(NULL);

View File

@ -70,20 +70,21 @@ char *get_sysinfo(void)
char *get_lastcallercount(void) char *get_lastcallercount(void)
{ {
static char buf[SS_BUFSIZE]; static char buf[41];
char *temp; char *temp;
FILE *fp; FILE *fp;
snprintf(buf, SS_BUFSIZE, "201:1,16;"); snprintf(buf, 41, "100:1,0;");
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
snprintf(temp, PATH_MAX, "%s/etc/lastcall.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/lastcall.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) == NULL) { if ((fp = fopen(temp, "r")) == NULL) {
free(temp); free(temp);
return buf; return buf;
} }
fread(&LCALLhdr, sizeof(LCALLhdr), 1, fp); fread(&LCALLhdr, sizeof(LCALLhdr), 1, fp);
fseek(fp, 0, SEEK_END); 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); fclose(fp);
free(temp); free(temp);
return buf; return buf;

View File

@ -283,18 +283,22 @@ char *xstrcat(char *src, char *add)
void CreateSema(char *sem) void CreateSema(char *sem)
{ {
char temp[PATH_MAX]; char *temp;
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);
if ((fp = fopen(temp, "w"))) if ((fp = fopen(temp, "w")))
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);
} }
@ -302,16 +306,18 @@ void CreateSema(char *sem)
void TouchSema(char *sem) void TouchSema(char *sem)
{ {
char temp[PATH_MAX]; char *temp;
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);
} }
@ -319,23 +325,31 @@ void TouchSema(char *sem)
void RemoveSema(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); 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[PATH_MAX]; char *temp;
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);
return (access(temp, F_OK) == 0); rc = (access(temp, F_OK) == 0);
free(temp);
return rc;
} }