Hello!!
I'm a sysadmin at La Laguna University in Spain. We are using NUT to manage
our UPS with great success, but we miss a feature and we would like to send
this patch to you.
If you apply this patch running upsd -c info you'll get information about
client connections in syslog. This is very simple and helpfull if you have
hundreds of servers connected to the same upsd.
Thank you for your nice work!!
Index: server/upsd.c
===================================================================
--- server/upsd.c (revisión: 3411)
+++ server/upsd.c (copia de trabajo)
@@ -92,7 +92,7 @@
static char pidfn[SMALLBUF];
/* set by signal handlers */
-static int reload_flag = 0, exit_flag = 0;
+static int reload_flag = 0, exit_flag = 0, info_flag = 0;
static const char *inet_ntopW (struct sockaddr_storage *s)
{
@@ -664,6 +664,21 @@
handler = xrealloc(handler, maxconn * sizeof(*handler));
}
+/* log client info */
+static void client_info(void)
+{
+ nut_ctype_t *client, *cnext;
+
+ if (firstclient) {
+ /* show connected clients */
+ for (client = firstclient; client; client = cnext) {
+ cnext = client->next;
+ upslogx(LOG_INFO, "Client %s connected to UPS [%s]\n", client->addr, client->loginups);
+ }
+ } else
+ upslogx(LOG_INFO, "There isn't any connected client\n");
+}
+
/* service requests and check on new data */
static void mainloop(void)
{
@@ -682,6 +697,11 @@
reload_flag = 0;
}
+ if (info_flag) {
+ client_info();
+ info_flag = 0;
+ }
+
/* scan through driver sockets */
for (ups = firstups; ups && (nfds < maxconn); ups = ups->next) {
@@ -818,6 +838,7 @@
printf(" commands:\n");
printf(" - reload: reread configuration files\n");
printf(" - stop: stop process and exit\n");
+ printf(" - info: print client information via syslog and exit\n");
printf(" -D raise debugging level\n");
printf(" -h display this help\n");
printf(" -r <dir> chroots to <dir>\n");
@@ -840,6 +861,11 @@
exit_flag = sig;
}
+static void set_info_flag(int sig)
+{
+ info_flag = 1;
+}
+
static void setup_signals(void)
{
struct sigaction sa;
@@ -861,6 +887,10 @@
/* handle reloading */
sa.sa_handler = set_reload_flag;
sigaction(SIGHUP, &sa, NULL);
+
+ /* Show connectd clients */
+ sa.sa_handler = set_info_flag;
+ sigaction(SIGCMD_INFO, &sa, NULL);
}
void check_perms(const char *fn)
@@ -926,6 +956,8 @@
cmd = SIGCMD_RELOAD;
if (!strncmp(optarg, "stop", strlen(optarg)))
cmd = SIGCMD_STOP;
+ if (!strncmp(optarg, "info", strlen(optarg)))
+ cmd = SIGCMD_INFO;
/* bad command given */
if (cmd == 0)
Index: server/upsd.h
===================================================================
--- server/upsd.h (revisión: 3411)
+++ server/upsd.h (copia de trabajo)
@@ -72,6 +72,7 @@
#define SIGCMD_STOP SIGTERM
#define SIGCMD_RELOAD SIGHUP
+#define SIGCMD_INFO SIGUSR1
/* awkward way to make a string out of a numeric constant */
_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsdev