Commit 2633b602 authored by Kirk Webb's avatar Kirk Webb

The file descriptor leak is still present. Note that closing the socket

used for the SIOCGIFHWADDR ioctl in Linux did NOT deallocate the descriptor,
nor was an error returned by close!  I changed the code to use a statically
allocated socket - better anyway.
parent 5385adfd
......@@ -93,8 +93,11 @@ int main(int argc, char **argv) {
for (;;) {
if (!opts->first) {
sleep(mopts.interval);
}
do_update();
}
get_load();
get_min_tty_idle();
get_packet_counts();
send_pkt();
if (opts->once) {
break;
}
......@@ -107,13 +110,6 @@ int main(int argc, char **argv) {
return exitcode;
}
void do_update (void) {
get_load();
get_min_tty_idle();
get_packet_counts();
send_pkt();
}
int parse_args(int argc, char **argv) {
char ch;
......@@ -227,6 +223,9 @@ int init_slothd(void) {
*/
opts->ttys[opts->numttys] = strdup("/dev/ptmx");
opts->numttys++;
/* Open socket for SIOCGHWADDR ioctl */
pkt->ifd = socket(PF_INET, SOCK_DGRAM, 0);
#endif
while (opts->numttys < MAXTTYS && (dptr = readdir(devs))) {
if (strstr(dptr->d_name, "tty") || strstr(dptr->d_name, "pty")) {
......@@ -440,35 +439,11 @@ void get_packet_counts(void) {
return;
}
#ifdef comment
int get_macaddrs(char *buf, void *data) {
int i=-1, j;
char *maddr;
SLOTHD_PACKET *pkt = (SLOTHD_PACKET*)data;
if ((maddr = strstr(buf, "MAC="))) {
maddr += 4;
++i;
for (j = 0; j < MACADDRLEN; j+=3, maddr+=2) {
pkt->ifaces[i].macaddr[j] = *maddr;
pkt->ifaces[i].macaddr[j+1] = *(maddr+1);
pkt->ifaces[i].macaddr[j+2] = ':';
}
pkt->ifaces[i].macaddr[MACADDRLEN-1] = '\0';
}
pkt->numaddrs = i+1;
return 0;
}
#endif /* comment */
int get_counters(char *buf, void *data) {
SLOTHD_PACKET *pkt = (SLOTHD_PACKET*)data;
#ifdef __linux__
int sfd = socket(PF_INET, SOCK_DGRAM, 0);
struct ifreq ifr;
bzero(&ifr, sizeof(struct ifreq));
#endif
......@@ -494,7 +469,7 @@ int get_counters(char *buf, void *data) {
}
#ifdef __linux__
strcpy(ifr.ifr_name, pkt->ifaces[pkt->ifcnt].ifname);
if (ioctl(sfd, SIOCGIFHWADDR, &ifr) < 0) {
if (ioctl(pkt->ifd, SIOCGIFHWADDR, &ifr) < 0) {
perror("error getting HWADDR");
return -1;
}
......@@ -505,7 +480,6 @@ int get_counters(char *buf, void *data) {
if (opts->debug) {
printf("macaddr: %s\n", pkt->ifaces[pkt->ifcnt].addr);
}
close(sfd);
#endif
pkt->ifcnt++;
}
......
......@@ -68,6 +68,9 @@ typedef struct {
double loadavg[3];
int ifcnt;
int sd;
#ifdef __linux__
int ifd; /* IOCTL file descriptor */
#endif
struct sockaddr_in servaddr;
struct {
u_long ipkts;
......@@ -91,7 +94,6 @@ typedef struct {
int parse_args(int, char**);
int init_slothd(void);
void do_update(void);
void get_min_tty_idle(void);
void utmp_enum_terms(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment