A lot of fixes found with valgrind
This commit is contained in:
103
mbmon/common.c
103
mbmon/common.c
@@ -4,7 +4,7 @@
|
||||
* Purpose ...............: Common utilities
|
||||
*
|
||||
*****************************************************************************
|
||||
* Copyright (C) 1997-2001
|
||||
* Copyright (C) 1997-2003
|
||||
*
|
||||
* Michiel Broek FIDO: 2:280/2802
|
||||
* Beekmansbos 10
|
||||
@@ -207,65 +207,64 @@ void Nopper(void)
|
||||
|
||||
int socket_connect(char *user)
|
||||
{
|
||||
int s;
|
||||
static char buf[SS_BUFSIZE];
|
||||
char tty[18];
|
||||
int s;
|
||||
static char buf[SS_BUFSIZE], tty[18];
|
||||
|
||||
if ((s = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
|
||||
perror("mbmon");
|
||||
printf("Unable to create Unix Datagram socket\n");
|
||||
return -1;
|
||||
}
|
||||
if ((s = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {
|
||||
perror("mbmon");
|
||||
printf("Unable to create Unix Datagram socket\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&clntaddr, 0, sizeof(clntaddr));
|
||||
clntaddr.sun_family = AF_UNIX;
|
||||
strcpy(clntaddr.sun_path, cpath);
|
||||
memset(&clntaddr, 0, sizeof(clntaddr));
|
||||
clntaddr.sun_family = AF_UNIX;
|
||||
strcpy(clntaddr.sun_path, cpath);
|
||||
|
||||
if (bind(s, (struct sockaddr *)&clntaddr, sizeof(clntaddr)) < 0) {
|
||||
close(s);
|
||||
perror("mbmon");
|
||||
printf("Can't bind socket %s\n", cpath);
|
||||
return -1;
|
||||
}
|
||||
if (bind(s, (struct sockaddr *)&clntaddr, sizeof(clntaddr)) < 0) {
|
||||
close(s);
|
||||
perror("mbmon");
|
||||
printf("Can't bind socket %s\n", cpath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&servaddr, 0, sizeof(servaddr));
|
||||
servaddr.sun_family = AF_UNIX;
|
||||
sprintf(servaddr.sun_path, "%s", (char *)spath);
|
||||
memset(&servaddr, 0, sizeof(servaddr));
|
||||
servaddr.sun_family = AF_UNIX;
|
||||
sprintf(servaddr.sun_path, "%s", (char *)spath);
|
||||
|
||||
/*
|
||||
* Now that we have an connection, we gather
|
||||
* information to tell the server who we are.
|
||||
*/
|
||||
if (isatty(1) && (ttyname(1) != NULL)) {
|
||||
strcpy(tty, ttyname(1));
|
||||
if (strchr(tty, 'p'))
|
||||
strcpy(tty, index(tty, 'p'));
|
||||
else if (strchr(tty, 't'))
|
||||
strcpy(tty, index(tty, 't'));
|
||||
else if (strchr(tty, 'c'))
|
||||
strcpy(tty, index(tty, 'c'));
|
||||
} else {
|
||||
strcpy(tty, "-");
|
||||
}
|
||||
sock = s;
|
||||
/*
|
||||
* Now that we have an connection, we gather
|
||||
* information to tell the server who we are.
|
||||
*/
|
||||
if (isatty(1) && (ttyname(1) != NULL)) {
|
||||
strcpy(tty, ttyname(1));
|
||||
if (strchr(tty, 'p'))
|
||||
memccpy(tty, index(tty, 'p'), '\0', strlen(tty));
|
||||
else if (strchr(tty, 't'))
|
||||
memccpy(tty, index(tty, 't'), '\0', strlen(tty));
|
||||
else if (strchr(tty, 'c'))
|
||||
memccpy(tty, index(tty, 'c'), '\0', strlen(tty));
|
||||
} else {
|
||||
strcpy(tty, "-");
|
||||
}
|
||||
sock = s;
|
||||
|
||||
/*
|
||||
* Send the information to the server.
|
||||
*/
|
||||
sprintf(buf, "AINI:5,%d,%s,%s,mbmon,localhost;", getpid(), tty, user);
|
||||
if (socket_send(buf) != 0) {
|
||||
sock = -1;
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* Send the information to the server.
|
||||
*/
|
||||
sprintf(buf, "AINI:5,%d,%s,%s,mbmon,localhost;", getpid(), tty, user);
|
||||
if (socket_send(buf) != 0) {
|
||||
sock = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(buf, socket_receive());
|
||||
if (strncmp(buf, "100:0;", 6) != 0) {
|
||||
printf("AINI not acknowledged by the server\n");
|
||||
sock = -1;
|
||||
return -1;
|
||||
}
|
||||
strcpy(buf, socket_receive());
|
||||
if (strncmp(buf, "100:0;", 6) != 0) {
|
||||
printf("AINI not acknowledged by the server\n");
|
||||
sock = -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return s;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
120
mbmon/mbmon.c
120
mbmon/mbmon.c
@@ -318,72 +318,70 @@ void system_stat(void)
|
||||
|
||||
void disk_stat(void)
|
||||
{
|
||||
int ch, i;
|
||||
char buf[1024];
|
||||
char *cnt, *type, *fs, *p;
|
||||
unsigned long last[10];
|
||||
unsigned long size, used, perc;
|
||||
char sign;
|
||||
int ch, i;
|
||||
char buf[1024], *cnt, *type, *fs, *p, sign;
|
||||
unsigned long last[10], size, used, perc;
|
||||
|
||||
clr_index();
|
||||
set_color(WHITE, BLACK);
|
||||
mvprintw( 5, 6, "3. FILESYSTEM USAGE");
|
||||
set_color(YELLOW, RED);
|
||||
mvprintw( 7, 1, " Size MB Used MB Perc. FS-Type Mountpoint ");
|
||||
set_color(CYAN, BLACK);
|
||||
mvprintw(lines - 2, 6, "Press any key");
|
||||
IsDoing("Filesystem Usage");
|
||||
clr_index();
|
||||
set_color(WHITE, BLACK);
|
||||
mvprintw( 5, 6, "3. FILESYSTEM USAGE");
|
||||
set_color(YELLOW, RED);
|
||||
mvprintw( 7, 1, " Size MB Used MB Perc. FS-Type Mountpoint ");
|
||||
set_color(CYAN, BLACK);
|
||||
mvprintw(lines - 2, 6, "Press any key");
|
||||
IsDoing("Filesystem Usage");
|
||||
for (i = 0; i < 10; i++)
|
||||
last[i] = 0;
|
||||
|
||||
do {
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
do {
|
||||
show_date(LIGHTGRAY, BLACK, 0, 0);
|
||||
|
||||
sprintf(buf, "GDST:1,%d;", getpid());
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
cnt = strtok(buf, ":");
|
||||
cnt = strtok(NULL, ",;");
|
||||
if (atoi(cnt)) {
|
||||
for (i = 0; i < atoi(cnt); i++) {
|
||||
p = strtok(NULL, " ");
|
||||
size = atoi(p);
|
||||
p = strtok(NULL, " ");
|
||||
used = size - atoi(p);
|
||||
perc = (used * 100) / size;
|
||||
sign = ' ';
|
||||
fs = strtok(NULL, " ");
|
||||
type = strtok(NULL, ",;");
|
||||
if (used > last[i])
|
||||
sign = '^';
|
||||
if (used < last[i])
|
||||
sign = 'v';
|
||||
if (last[i] == 0)
|
||||
sign = ' ';
|
||||
last[i] = used;
|
||||
set_color(CYAN, BLACK);
|
||||
mvprintw(i+8, 1, "%8lu %8lu ",
|
||||
size, used);
|
||||
set_color(WHITE, BLACK);
|
||||
printf("%c ", sign);
|
||||
set_color(CYAN, BLACK);
|
||||
if (strstr(type, "iso") == NULL) {
|
||||
if (perc >= 95)
|
||||
set_color(LIGHTRED, BLACK);
|
||||
else if (perc >= 80)
|
||||
set_color(YELLOW, BLACK);
|
||||
}
|
||||
printf("%3lu", perc);
|
||||
putchar('%');
|
||||
set_color(CYAN, BLACK);
|
||||
printf(" %-8s %-40s", type, fs);
|
||||
}
|
||||
locate(i+8, 1);
|
||||
clrtoeol();
|
||||
}
|
||||
sprintf(buf, "GDST:1,%d;", getpid());
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
cnt = strtok(buf, ":");
|
||||
cnt = strtok(NULL, ",;");
|
||||
if (atoi(cnt)) {
|
||||
for (i = 0; i < atoi(cnt); i++) {
|
||||
p = strtok(NULL, " ");
|
||||
size = atoi(p);
|
||||
p = strtok(NULL, " ");
|
||||
used = size - atoi(p);
|
||||
perc = (used * 100) / size;
|
||||
sign = ' ';
|
||||
fs = strtok(NULL, " ");
|
||||
type = strtok(NULL, ",;");
|
||||
if (used > last[i])
|
||||
sign = '^';
|
||||
if (used < last[i])
|
||||
sign = 'v';
|
||||
if (last[i] == 0)
|
||||
sign = ' ';
|
||||
last[i] = used;
|
||||
set_color(CYAN, BLACK);
|
||||
mvprintw(i+8, 1, "%8lu %8lu ", size, used);
|
||||
set_color(WHITE, BLACK);
|
||||
printf("%c ", sign);
|
||||
set_color(CYAN, BLACK);
|
||||
if (strstr(type, "iso") == NULL) {
|
||||
if (perc >= 95)
|
||||
set_color(LIGHTRED, BLACK);
|
||||
else if (perc >= 80)
|
||||
set_color(YELLOW, BLACK);
|
||||
}
|
||||
printf("%3lu", perc);
|
||||
putchar('%');
|
||||
set_color(CYAN, BLACK);
|
||||
printf(" %-8s %-40s", type, fs);
|
||||
}
|
||||
locate(i+8, 1);
|
||||
clrtoeol();
|
||||
}
|
||||
}
|
||||
|
||||
ch = testkey(lines - 2, 20);
|
||||
} while (ch == '\0');
|
||||
ch = testkey(lines - 2, 20);
|
||||
} while (ch == '\0');
|
||||
}
|
||||
|
||||
|
||||
|
@@ -130,6 +130,7 @@ void ulockprogram(char *progname)
|
||||
free(lockfile);
|
||||
return;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
if (oldpid == getpid()) {
|
||||
(void)unlink(lockfile);
|
||||
|
Reference in New Issue
Block a user