Imported Upstream version 2.6.4
This commit is contained in:
parent
fad6ced6f6
commit
fefe62b2bd
257 changed files with 6020 additions and 1394 deletions
|
@ -268,6 +268,7 @@ MKDIR_P = @MKDIR_P@
|
|||
NETLIBS = @NETLIBS@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
NUT_NETVERSION = @NUT_NETVERSION@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OS_NAME = @OS_NAME@
|
||||
|
@ -281,6 +282,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
|||
PACKAGE_URL = @PACKAGE_URL@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
PIDPATH = @PIDPATH@
|
||||
PKG_CONFIG = @PKG_CONFIG@
|
||||
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
|
||||
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
|
||||
|
@ -288,6 +290,7 @@ PORT = @PORT@
|
|||
RANLIB = @RANLIB@
|
||||
RUN_AS_GROUP = @RUN_AS_GROUP@
|
||||
RUN_AS_USER = @RUN_AS_USER@
|
||||
SBINDIR = @SBINDIR@
|
||||
SED = @SED@
|
||||
SERLIBS = @SERLIBS@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* upsc - simple "client" to test communications
|
||||
|
||||
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
|
||||
Copyright (C) 2012 Arnaud Quette <arnaud.quette@free.fr>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -34,6 +35,7 @@ static void usage(const char *prog)
|
|||
|
||||
printf("usage: %s -l | -L [<hostname>[:port]]\n", prog);
|
||||
printf(" %s <ups> [<variable>]\n", prog);
|
||||
printf(" %s -c <ups>\n", prog);
|
||||
|
||||
printf("\nDemo program to display UPS variables.\n\n");
|
||||
|
||||
|
@ -46,6 +48,10 @@ static void usage(const char *prog)
|
|||
printf(" <ups> - upsd server, <upsname>[@<hostname>[:<port>]] form\n");
|
||||
printf(" <variable> - optional, display this variable only.\n");
|
||||
printf(" Default: list all variables for <host>\n");
|
||||
|
||||
printf("\nThird form (lists clients connected to a device):\n");
|
||||
printf(" -c - lists each client connected on <ups>, one per line.\n");
|
||||
printf(" <ups> - upsd server, <upsname>[@<hostname>[:<port>]] form\n");
|
||||
}
|
||||
|
||||
static void printvar(const char *var)
|
||||
|
@ -155,6 +161,39 @@ static void list_upses(int verbose)
|
|||
}
|
||||
}
|
||||
|
||||
static void list_clients(const char *devname)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
const char *query[4];
|
||||
char **answer;
|
||||
|
||||
query[0] = "CLIENT";
|
||||
query[1] = devname;
|
||||
numq = 2;
|
||||
|
||||
ret = upscli_list_start(ups, numq, query);
|
||||
|
||||
if (ret < 0) {
|
||||
/* check for an old upsd */
|
||||
if (upscli_upserror(ups) == UPSCLI_ERR_UNKCOMMAND) {
|
||||
fatalx(EXIT_FAILURE, "Error: upsd is too old to support this query");
|
||||
}
|
||||
|
||||
fatalx(EXIT_FAILURE, "Error: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
while ((ret=upscli_list_next(ups, numq, query, &numa, &answer)) == 1) {
|
||||
|
||||
/* CLIENT <upsname> <address> */
|
||||
if (numa < 3) {
|
||||
fatalx(EXIT_FAILURE, "Error: insufficient data (got %d args, need at least 3)", numa);
|
||||
}
|
||||
|
||||
printf("%s\n", answer[2]);
|
||||
}
|
||||
}
|
||||
|
||||
static void clean_exit(void)
|
||||
{
|
||||
if (ups) {
|
||||
|
@ -169,10 +208,10 @@ static void clean_exit(void)
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, port;
|
||||
int varlist = 0, verbose = 0;
|
||||
int varlist = 0, clientlist = 0, verbose = 0;
|
||||
const char *prog = xbasename(argv[0]);
|
||||
|
||||
while ((i = getopt(argc, argv, "+hlLV")) != -1) {
|
||||
while ((i = getopt(argc, argv, "+hlLcV")) != -1) {
|
||||
|
||||
switch (i)
|
||||
{
|
||||
|
@ -181,6 +220,9 @@ int main(int argc, char **argv)
|
|||
case 'l':
|
||||
varlist = 1;
|
||||
break;
|
||||
case 'c':
|
||||
clientlist = 1;
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
fatalx(EXIT_SUCCESS, "Network UPS Tools upscmd %s", UPS_VERSION);
|
||||
|
@ -219,6 +261,11 @@ int main(int argc, char **argv)
|
|||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (clientlist) {
|
||||
list_clients(upsname);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
printvar(argv[1]);
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* upsmon - monitor power status over the 'net (talks to upsd via TCP)
|
||||
|
||||
Copyright (C) 1998 Russell Kroll <rkroll@exploits.org>
|
||||
Copyright (C)
|
||||
1998 Russell Kroll <rkroll@exploits.org>
|
||||
2012 Arnaud Quette <arnaud.quette.free.fr>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -79,12 +81,6 @@ static int opt_af = AF_UNSPEC;
|
|||
static struct sigaction sa;
|
||||
static sigset_t nut_upsmon_sigmask;
|
||||
|
||||
#ifdef SHUT_RDWR
|
||||
#define shutdown_how SHUT_RDWR
|
||||
#else
|
||||
#define shutdown_how 2
|
||||
#endif
|
||||
|
||||
static void setflag(int *val, int flag)
|
||||
{
|
||||
*val |= flag;
|
||||
|
@ -696,7 +692,7 @@ static void recalc(void)
|
|||
}
|
||||
|
||||
/* note: we assume that a UPS that isn't critical must be OK *
|
||||
* *
|
||||
* *
|
||||
* this means a UPS we've never heard from is assumed OL *
|
||||
* whether this is really the best thing to do is undecided */
|
||||
|
||||
|
@ -709,12 +705,12 @@ static void recalc(void)
|
|||
ups = ups->next;
|
||||
}
|
||||
|
||||
/* upsdebugx(3, "Current power value: %d", val_ol);
|
||||
upsdebugx(3, "Minimum power value: %d", minsupplies); */
|
||||
upsdebugx(3, "Current power value: %d", val_ol);
|
||||
upsdebugx(3, "Minimum power value: %d", minsupplies);
|
||||
|
||||
if (val_ol < minsupplies)
|
||||
forceshutdown();
|
||||
}
|
||||
}
|
||||
|
||||
static void ups_low_batt(utype_t *ups)
|
||||
{
|
||||
|
@ -792,10 +788,7 @@ static void redefine_ups(utype_t *ups, int pv, const char *un,
|
|||
|
||||
free(ups->un);
|
||||
|
||||
if (un)
|
||||
ups->un = xstrdup(un);
|
||||
else
|
||||
ups->un = NULL;
|
||||
ups->un = xstrdup(un);
|
||||
|
||||
/*
|
||||
* if not logged in force a reconnection since this
|
||||
|
@ -954,7 +947,7 @@ static void addups(int reloading, const char *sys, const char *pvs,
|
|||
else
|
||||
upslogx(LOG_INFO, "UPS: %s (monitoring only)", tmp->sys);
|
||||
|
||||
tmp->upsname = tmp->hostname = NULL;
|
||||
tmp->upsname = tmp->hostname = NULL;
|
||||
|
||||
if (upscli_splitname(tmp->sys, &tmp->upsname, &tmp->hostname,
|
||||
&tmp->port) != 0) {
|
||||
|
@ -1945,6 +1938,15 @@ int main(int argc, char *argv[])
|
|||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* otherwise, we are being asked to start.
|
||||
* so check if a previous instance is running by sending signal '0'
|
||||
* (Ie 'kill <pid> 0') */
|
||||
if (sendsignal(prog, 0) == 0) {
|
||||
printf("Fatal error: A previous upsmon instance is already running!\n");
|
||||
printf("Either stop the previous instance first, or use the 'reload' command.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
|
@ -1961,6 +1963,8 @@ int main(int argc, char *argv[])
|
|||
/* we may need to get rid of a flag from a previous shutdown */
|
||||
if (powerdownflag != NULL)
|
||||
clear_pdflag();
|
||||
/* FIXME (else): POWERDOWNFLAG is not defined!!
|
||||
* => fallback to a default value */
|
||||
|
||||
if (totalpv < minsupplies) {
|
||||
printf("\nFatal error: insufficient power configured!\n\n");
|
||||
|
|
|
@ -19,15 +19,13 @@
|
|||
|
||||
/* flags for ups->status */
|
||||
|
||||
#define ST_ONLINE 0x001 /* UPS is on line (OL) */
|
||||
#define ST_ONBATT 0x002 /* UPS is on battery (OB) */
|
||||
#define ST_LOWBATT 0x004 /* UPS has a low battery (LB) */
|
||||
#define ST_FSD 0x008 /* master has set forced shutdown flag */
|
||||
#define ST_MASTER 0x010 /* we are the master on this UPS */
|
||||
/* was ST_ALIVE 0x020 */
|
||||
#define ST_LOGIN 0x040 /* we are logged into this UPS */
|
||||
/* was ST_FIRST 0x080 */
|
||||
#define ST_CONNECTED 0x100 /* upscli_connect returned OK */
|
||||
#define ST_ONLINE (1 << 0) /* UPS is on line (OL) */
|
||||
#define ST_ONBATT (1 << 1) /* UPS is on battery (OB) */
|
||||
#define ST_LOWBATT (1 << 2) /* UPS has a low battery (LB) */
|
||||
#define ST_FSD (1 << 3) /* master has set forced shutdown flag */
|
||||
#define ST_MASTER (1 << 4) /* we are the master on this UPS */
|
||||
#define ST_LOGIN (1 << 5) /* we are logged into this UPS */
|
||||
#define ST_CONNECTED (1 << 6) /* upscli_connect returned OK */
|
||||
|
||||
/* required contents of flag file */
|
||||
#define SDMAGIC "upsmon-shutdown-file"
|
||||
|
@ -74,10 +72,10 @@ typedef struct {
|
|||
|
||||
/* notify flag values */
|
||||
|
||||
#define NOTIFY_IGNORE 1 /* don't do anything */
|
||||
#define NOTIFY_SYSLOG 2 /* send the msg to the syslog */
|
||||
#define NOTIFY_WALL 4 /* send the msg to all users */
|
||||
#define NOTIFY_EXEC 8 /* send the msg to NOTIFYCMD script */
|
||||
#define NOTIFY_IGNORE (1 << 0) /* don't do anything */
|
||||
#define NOTIFY_SYSLOG (1 << 1) /* send the msg to the syslog */
|
||||
#define NOTIFY_WALL (1 << 2) /* send the msg to all users */
|
||||
#define NOTIFY_EXEC (1 << 3) /* send the msg to NOTIFYCMD script */
|
||||
|
||||
/* flags are set to NOTIFY_SYSLOG | NOTIFY_WALL at program init */
|
||||
/* the user can override with NOTIFYFLAGS in the upsmon.conf */
|
||||
|
|
|
@ -267,6 +267,61 @@ static void do_enum(const char *varname)
|
|||
}
|
||||
}
|
||||
|
||||
static void do_range(const char *varname)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
char **answer;
|
||||
const char *query[4], *val;
|
||||
int ival, min, max;
|
||||
|
||||
/* get current value */
|
||||
val = get_data("VAR", varname);
|
||||
|
||||
if (!val) {
|
||||
fatalx(EXIT_FAILURE, "do_range: can't get current value of %s", varname);
|
||||
}
|
||||
|
||||
ival = atoi(val);
|
||||
|
||||
query[0] = "RANGE";
|
||||
query[1] = upsname;
|
||||
query[2] = varname;
|
||||
numq = 3;
|
||||
|
||||
ret = upscli_list_start(ups, numq, query);
|
||||
|
||||
if (ret < 0) {
|
||||
fatalx(EXIT_FAILURE, "Error: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
ret = upscli_list_next(ups, numq, query, &numa, &answer);
|
||||
|
||||
printf("Type: RANGE\n");
|
||||
|
||||
while (ret == 1) {
|
||||
|
||||
/* RANGE <upsname> <varname> <min> <max> */
|
||||
|
||||
if (numa < 5) {
|
||||
fatalx(EXIT_FAILURE, "Error: insufficient data (got %d args, need at least 4)", numa);
|
||||
}
|
||||
|
||||
min = atoi(answer[3]);
|
||||
max = atoi(answer[4]);
|
||||
|
||||
printf("Option: \"%i-%i\"", min, max);
|
||||
|
||||
if ((ival >= min) && (ival <= max)) {
|
||||
printf(" SELECTED");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
ret = upscli_list_next(ups, numq, query, &numa, &answer);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_type(const char *varname)
|
||||
{
|
||||
int ret;
|
||||
|
@ -294,6 +349,11 @@ static void do_type(const char *varname)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!strcasecmp(answer[i], "RANGE")) {
|
||||
do_range(varname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strncasecmp(answer[i], "STRING:", 7)) {
|
||||
do_string(varname);
|
||||
return;
|
||||
|
|
|
@ -694,7 +694,7 @@ static void sendcmd(const char *cmd, const char *arg1, const char *arg2)
|
|||
snprintfcat(buf, sizeof(buf), " \"%s\"",
|
||||
pconf_encode(arg2, enc, sizeof(enc)));
|
||||
|
||||
snprintfcat(buf, sizeof(buf), "\n");
|
||||
snprintfcat(enc, sizeof(enc), "%s\n", buf);
|
||||
|
||||
/* see if the parent needs to be started (and maybe start it) */
|
||||
|
||||
|
@ -715,10 +715,10 @@ static void sendcmd(const char *cmd, const char *arg1, const char *arg2)
|
|||
|
||||
/* we're connected now */
|
||||
|
||||
ret = write(pipefd, buf, strlen(buf));
|
||||
ret = write(pipefd, enc, strlen(enc));
|
||||
|
||||
/* if we can't send the whole thing, loop back and try again */
|
||||
if ((ret < 1) || (ret != (int) strlen(buf))) {
|
||||
if ((ret < 1) || (ret != (int) strlen(enc))) {
|
||||
upslogx(LOG_ERR, "write failed, trying again");
|
||||
close(pipefd);
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue