Added start of 'fdstat' command. Right now it counts the tototal open fds the process has
command_init(); /* Initialize the command queue */
stats_init(); /* Initialize stats (UPTIME) */
firedns_init(); /* Initialize adns */
+
+ fclose(yyin);
}
/* Malloc and initialize configuration data to NULL */
static void cmd_check(char *, char *, struct ChannelConf *);
static void cmd_stat(char *, char *, struct ChannelConf *);
+static void cmd_fdstat(char *, char *, struct ChannelConf *);
static struct OperCommandHash COMMAND_TABLE[] =
{
- {"CHECK", cmd_check},
- {"SCAN", cmd_check},
- {"STAT", cmd_stat },
- {"STATS", cmd_stat },
- {"STATUS", cmd_stat }
+ {"CHECK", cmd_check },
+ {"SCAN", cmd_check },
+ {"STAT", cmd_stat },
+ {"STATS", cmd_stat },
+ {"STATUS", cmd_stat },
+ {"FDSTAT", cmd_fdstat },
};
stats_output(target->name);
}
+
+/* cmd_fdstat
+ *
+ * Send output of stats to channel.
+ *
+ * Parameters:
+ * param: Any parameters to the command
+ * channel: Channel the command was sent to
+ * source_p: Who sent the command
+ */
+
+static void cmd_fdstat(char *param, char *source, struct ChannelConf *target)
+{
+ fdstats_output(target->name);
+}
#include <arpa/inet.h>
#include <netdb.h>
+#include <sys/resource.h> /* getrlimit */
+#include <errno.h>
+#include <fcntl.h>
+
#include <stdio.h>
#include <time.h>
target, STATS_CONNECTIONS, STATS_CONNECTIONS ?
(float)STATS_CONNECTIONS / ((float)uptime / 60.0) : 0.0);
+}
+
+
+
+/* fdstats_output
+ *
+ * Output file descriptor stats to target via privmsg
+ *
+ *
+ * Parameters: NONE
+ * Return: NONE
+ *
+ */
+
+void fdstats_output(char *target)
+{
+ unsigned total_fd_use;
+ struct rlimit rlim;
+ int i;
+
+ /* Get file descriptor ceiling */
+ if(getrlimit(RLIMIT_NOFILE, &rlim) == -1)
+ {
+ log("FDSTAT -> getrlimit() error retrieving RLIMIT_NOFILE (%s)", strerror(errno));
+ irc_send("PRIVMSG %s :FDSTAT -> getrlimit() error retrieving RLIMIT_NOFILE (%s)",
+ target, strerror(errno));
+ return;
+ }
+
+ /* Check which file descriptors are active */
+ total_fd_use = 0;
+ for(i = 0; i < rlim.rlim_cur; i++)
+ {
+ fcntl(i,F_GETFD,0);
+ if(errno != EBADF)
+ total_fd_use++;
+ }
+ irc_send("PRIVMSG %s :Total open FD: %d", target, total_fd_use);
}
extern void stats_dnsblsend();
extern void stats_output(char *);
+extern void fdstats_output(char *);
+
#endif /* STATS_H */