]> jfr.im git - irc/ircd-hybrid/bopm.git/commitdiff
Added code to config.c to close the config file.
authorstrtok <redacted>
Sun, 12 Jan 2003 22:22:49 +0000 (22:22 +0000)
committerstrtok <redacted>
Sun, 12 Jan 2003 22:22:49 +0000 (22:22 +0000)
Added start of 'fdstat' command. Right now it counts the tototal open fds the process has

src/config.c
src/opercmd.c
src/stats.c
src/stats.h

index 9299ee62b27fcca31e17499fd820890569f9122b..c2a86a2119f55e1916f3783e0a0eba1503dbb512 100644 (file)
@@ -67,6 +67,8 @@ void config_load(const char *filename)
    command_init();    /* Initialize the command queue */
    stats_init();      /* Initialize stats (UPTIME) */
    firedns_init();    /* Initialize adns */
+
+   fclose(yyin);
 }
 
 /* Malloc and initialize configuration data to NULL */
index 72390f3542774937cae1e271d4cc8a87f3c7f704..db10046190e2a5bef09eb0bf144d076c776eafaf 100644 (file)
@@ -52,14 +52,16 @@ static void command_free(struct Command *);
 
 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 },
    };
 
 
@@ -348,3 +350,18 @@ static void cmd_stat(char *param, char *source, struct ChannelConf *target)
    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);
+}
index 885bd9a459ed8d433bcb7ca7b463df2497be9bc8..ef6caba4c044e2a2e95127378b988590ff5bd9cb 100644 (file)
@@ -28,6 +28,10 @@ along with this program; if not, write to the Free Software
 #include <arpa/inet.h>
 #include <netdb.h>
 
+#include <sys/resource.h> /* getrlimit */
+#include <errno.h>
+#include <fcntl.h>
+
 #include <stdio.h>
 #include <time.h>
 
@@ -182,5 +186,43 @@ void stats_output(char *target)
             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);
 }
index 3311065f05c40362a78121adfebf0b0bd65762aa..8bb9427d209fa18fbc66b6c4526d81adbac7a7de 100644 (file)
@@ -17,4 +17,6 @@ extern void stats_dnsblrecv();
 extern void stats_dnsblsend();
 extern void stats_output(char *);
 
+extern void fdstats_output(char *);
+
 #endif /* STATS_H */