Imported Upstream version 2.6.0
This commit is contained in:
parent
26fb71b504
commit
459aaf9392
510 changed files with 40508 additions and 18859 deletions
|
@ -1,9 +1,9 @@
|
|||
# Network UPS Tools: clients
|
||||
|
||||
# by default, link programs in this directory with libcommon.a
|
||||
LDADD = ../common/libcommon.a libupsclient.la $(NETLIBS)
|
||||
LDADD = ../common/libcommon.la libupsclient.la $(NETLIBS)
|
||||
if WITH_SSL
|
||||
LDADD += $(LIBSSL_LDFLAGS)
|
||||
LDADD += $(LIBSSL_LIBS)
|
||||
endif
|
||||
|
||||
# Avoid per-target CFLAGS, because this will prevent re-use of object
|
||||
|
@ -35,7 +35,7 @@ upslog_SOURCES = upslog.c upsclient.h upslog.h
|
|||
upsmon_SOURCES = upsmon.c upsmon.h upsclient.h
|
||||
|
||||
upssched_SOURCES = upssched.c upssched.h
|
||||
upssched_LDADD = ../common/libcommon.a ../common/libparseconf.la $(NETLIBS)
|
||||
upssched_LDADD = ../common/libcommon.la ../common/libparseconf.la $(NETLIBS)
|
||||
|
||||
upsimage_cgi_SOURCES = upsimage.c upsclient.h upsimagearg.h cgilib.c cgilib.h
|
||||
upsimage_cgi_LDADD = $(LDADD) $(LIBGD_LDFLAGS)
|
||||
|
@ -48,6 +48,6 @@ upsstats_cgi_SOURCES = upsstats.c upsclient.h status.h upsstats.h \
|
|||
libupsclient_la_SOURCES = upsclient.c upsclient.h
|
||||
libupsclient_la_LIBADD = ../common/libparseconf.la
|
||||
if WITH_SSL
|
||||
libupsclient_la_LIBADD += $(LIBSSL_LDFLAGS)
|
||||
libupsclient_la_LIBADD += $(LIBSSL_LIBS)
|
||||
endif
|
||||
libupsclient_la_LDFLAGS = -version-info 1:0:0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Makefile.in generated by automake 1.11 from Makefile.am.
|
||||
# Makefile.in generated by automake 1.11.1 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
|
@ -40,7 +40,7 @@ POST_UNINSTALL = :
|
|||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
target_triplet = @target@
|
||||
@WITH_SSL_TRUE@am__append_1 = $(LIBSSL_LDFLAGS)
|
||||
@WITH_SSL_TRUE@am__append_1 = $(LIBSSL_LIBS)
|
||||
@WITH_SSL_TRUE@am__append_2 = $(LIBSSL_CFLAGS)
|
||||
@WITH_CGI_TRUE@am__append_3 = $(LIBGD_CFLAGS)
|
||||
bin_PROGRAMS = upsc$(EXEEXT) upslog$(EXEEXT) upsrw$(EXEEXT) \
|
||||
|
@ -48,17 +48,18 @@ bin_PROGRAMS = upsc$(EXEEXT) upslog$(EXEEXT) upsrw$(EXEEXT) \
|
|||
sbin_PROGRAMS = upsmon$(EXEEXT) upssched$(EXEEXT)
|
||||
@WITH_CGI_TRUE@cgiexec_PROGRAMS = upsstats.cgi$(EXEEXT) \
|
||||
@WITH_CGI_TRUE@ upsimage.cgi$(EXEEXT) upsset.cgi$(EXEEXT)
|
||||
@WITH_SSL_TRUE@am__append_4 = $(LIBSSL_LDFLAGS)
|
||||
@WITH_SSL_TRUE@am__append_4 = $(LIBSSL_LIBS)
|
||||
subdir = clients
|
||||
DIST_COMMON = $(am__include_HEADERS_DIST) $(dist_bin_SCRIPTS) \
|
||||
$(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_create_stdint_h.m4 \
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \
|
||||
$(top_srcdir)/m4/ax_create_stdint_h.m4 \
|
||||
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
|
||||
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
|
||||
$(top_srcdir)/m4/lt~obsolete.m4 \
|
||||
$(top_srcdir)/m4/nut_arg_with.m4 \
|
||||
$(top_srcdir)/m4/nut_check_ipv6.m4 \
|
||||
$(top_srcdir)/m4/nut_check_asciidoc.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libgd.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libhal.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libneon.m4 \
|
||||
|
@ -68,6 +69,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_create_stdint_h.m4 \
|
|||
$(top_srcdir)/m4/nut_check_libusb.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libwrap.m4 \
|
||||
$(top_srcdir)/m4/nut_check_os.m4 \
|
||||
$(top_srcdir)/m4/nut_config_libhal.m4 \
|
||||
$(top_srcdir)/m4/nut_report_feature.m4 \
|
||||
$(top_srcdir)/m4/nut_type_socklen_t.m4 \
|
||||
$(top_srcdir)/configure.in
|
||||
|
@ -115,47 +117,47 @@ PROGRAMS = $(bin_PROGRAMS) $(cgiexec_PROGRAMS) $(sbin_PROGRAMS)
|
|||
am_upsc_OBJECTS = upsc.$(OBJEXT)
|
||||
upsc_OBJECTS = $(am_upsc_OBJECTS)
|
||||
upsc_LDADD = $(LDADD)
|
||||
upsc_DEPENDENCIES = ../common/libcommon.a libupsclient.la \
|
||||
upsc_DEPENDENCIES = ../common/libcommon.la libupsclient.la \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
am_upscmd_OBJECTS = upscmd.$(OBJEXT)
|
||||
upscmd_OBJECTS = $(am_upscmd_OBJECTS)
|
||||
upscmd_LDADD = $(LDADD)
|
||||
upscmd_DEPENDENCIES = ../common/libcommon.a libupsclient.la \
|
||||
upscmd_DEPENDENCIES = ../common/libcommon.la libupsclient.la \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
am_upsimage_cgi_OBJECTS = upsimage.$(OBJEXT) cgilib.$(OBJEXT)
|
||||
upsimage_cgi_OBJECTS = $(am_upsimage_cgi_OBJECTS)
|
||||
am__DEPENDENCIES_3 = ../common/libcommon.a libupsclient.la \
|
||||
am__DEPENDENCIES_3 = ../common/libcommon.la libupsclient.la \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
upsimage_cgi_DEPENDENCIES = $(am__DEPENDENCIES_3) \
|
||||
$(am__DEPENDENCIES_1)
|
||||
am_upslog_OBJECTS = upslog.$(OBJEXT)
|
||||
upslog_OBJECTS = $(am_upslog_OBJECTS)
|
||||
upslog_LDADD = $(LDADD)
|
||||
upslog_DEPENDENCIES = ../common/libcommon.a libupsclient.la \
|
||||
upslog_DEPENDENCIES = ../common/libcommon.la libupsclient.la \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
am_upsmon_OBJECTS = upsmon.$(OBJEXT)
|
||||
upsmon_OBJECTS = $(am_upsmon_OBJECTS)
|
||||
upsmon_LDADD = $(LDADD)
|
||||
upsmon_DEPENDENCIES = ../common/libcommon.a libupsclient.la \
|
||||
upsmon_DEPENDENCIES = ../common/libcommon.la libupsclient.la \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
am_upsrw_OBJECTS = upsrw.$(OBJEXT)
|
||||
upsrw_OBJECTS = $(am_upsrw_OBJECTS)
|
||||
upsrw_LDADD = $(LDADD)
|
||||
upsrw_DEPENDENCIES = ../common/libcommon.a libupsclient.la \
|
||||
upsrw_DEPENDENCIES = ../common/libcommon.la libupsclient.la \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
am_upssched_OBJECTS = upssched.$(OBJEXT)
|
||||
upssched_OBJECTS = $(am_upssched_OBJECTS)
|
||||
upssched_DEPENDENCIES = ../common/libcommon.a \
|
||||
upssched_DEPENDENCIES = ../common/libcommon.la \
|
||||
../common/libparseconf.la $(am__DEPENDENCIES_1)
|
||||
am_upsset_cgi_OBJECTS = upsset.$(OBJEXT) cgilib.$(OBJEXT)
|
||||
upsset_cgi_OBJECTS = $(am_upsset_cgi_OBJECTS)
|
||||
upsset_cgi_LDADD = $(LDADD)
|
||||
upsset_cgi_DEPENDENCIES = ../common/libcommon.a libupsclient.la \
|
||||
upsset_cgi_DEPENDENCIES = ../common/libcommon.la libupsclient.la \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
am_upsstats_cgi_OBJECTS = upsstats.$(OBJEXT) cgilib.$(OBJEXT)
|
||||
upsstats_cgi_OBJECTS = $(am_upsstats_cgi_OBJECTS)
|
||||
upsstats_cgi_LDADD = $(LDADD)
|
||||
upsstats_cgi_DEPENDENCIES = ../common/libcommon.a libupsclient.la \
|
||||
upsstats_cgi_DEPENDENCIES = ../common/libcommon.la libupsclient.la \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
|
||||
SCRIPTS = $(dist_bin_SCRIPTS)
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include
|
||||
|
@ -184,9 +186,11 @@ HEADERS = $(include_HEADERS)
|
|||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
A2X = @A2X@
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
ASCIIDOC = @ASCIIDOC@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
|
@ -199,8 +203,10 @@ CONFPATH = @CONFPATH@
|
|||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DBLATEX = @DBLATEX@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DOC_BUILD_LIST = @DOC_BUILD_LIST@
|
||||
DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@
|
||||
DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@
|
||||
DRIVER_MAN_LIST = @DRIVER_MAN_LIST@
|
||||
|
@ -217,7 +223,6 @@ HAL_CALLOUTS_PATH = @HAL_CALLOUTS_PATH@
|
|||
HAL_DEVICE_MATCH_KEY = @HAL_DEVICE_MATCH_KEY@
|
||||
HAL_FDI_PATH = @HAL_FDI_PATH@
|
||||
HAL_USER = @HAL_USER@
|
||||
HAVE_GLIB_2_14 = @HAVE_GLIB_2_14@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
|
@ -228,22 +233,22 @@ LDFLAGS = @LDFLAGS@
|
|||
LIBGD_CFLAGS = @LIBGD_CFLAGS@
|
||||
LIBGD_LDFLAGS = @LIBGD_LDFLAGS@
|
||||
LIBHAL_CFLAGS = @LIBHAL_CFLAGS@
|
||||
LIBHAL_LDFLAGS = @LIBHAL_LDFLAGS@
|
||||
LIBHAL_LIBS = @LIBHAL_LIBS@
|
||||
LIBNEON_CFLAGS = @LIBNEON_CFLAGS@
|
||||
LIBNEON_LDFLAGS = @LIBNEON_LDFLAGS@
|
||||
LIBNEON_LIBS = @LIBNEON_LIBS@
|
||||
LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@
|
||||
LIBNETSNMP_LDFLAGS = @LIBNETSNMP_LDFLAGS@
|
||||
LIBNETSNMP_LIBS = @LIBNETSNMP_LIBS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBPOWERMAN_CFLAGS = @LIBPOWERMAN_CFLAGS@
|
||||
LIBPOWERMAN_LDFLAGS = @LIBPOWERMAN_LDFLAGS@
|
||||
LIBPOWERMAN_LIBS = @LIBPOWERMAN_LIBS@
|
||||
LIBS = @LIBS@
|
||||
LIBSSL_CFLAGS = @LIBSSL_CFLAGS@
|
||||
LIBSSL_LDFLAGS = @LIBSSL_LDFLAGS@
|
||||
LIBSSL_LIBS = @LIBSSL_LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
|
||||
LIBUSB_LDFLAGS = @LIBUSB_LDFLAGS@
|
||||
LIBUSB_LIBS = @LIBUSB_LIBS@
|
||||
LIBWRAP_CFLAGS = @LIBWRAP_CFLAGS@
|
||||
LIBWRAP_LDFLAGS = @LIBWRAP_LDFLAGS@
|
||||
LIBWRAP_LIBS = @LIBWRAP_LIBS@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
|
@ -341,7 +346,7 @@ top_srcdir = @top_srcdir@
|
|||
udevdir = @udevdir@
|
||||
|
||||
# by default, link programs in this directory with libcommon.a
|
||||
LDADD = ../common/libcommon.a libupsclient.la $(NETLIBS) \
|
||||
LDADD = ../common/libcommon.la libupsclient.la $(NETLIBS) \
|
||||
$(am__append_1)
|
||||
|
||||
# Avoid per-target CFLAGS, because this will prevent re-use of object
|
||||
|
@ -357,7 +362,7 @@ upsrw_SOURCES = upsrw.c upsclient.h
|
|||
upslog_SOURCES = upslog.c upsclient.h upslog.h
|
||||
upsmon_SOURCES = upsmon.c upsmon.h upsclient.h
|
||||
upssched_SOURCES = upssched.c upssched.h
|
||||
upssched_LDADD = ../common/libcommon.a ../common/libparseconf.la $(NETLIBS)
|
||||
upssched_LDADD = ../common/libcommon.la ../common/libparseconf.la $(NETLIBS)
|
||||
upsimage_cgi_SOURCES = upsimage.c upsclient.h upsimagearg.h cgilib.c cgilib.h
|
||||
upsimage_cgi_LDADD = $(LDADD) $(LIBGD_LDFLAGS)
|
||||
upsset_cgi_SOURCES = upsset.c upsclient.h cgilib.c cgilib.h
|
||||
|
|
|
@ -298,6 +298,11 @@ int upscli_sslcert(UPSCONN_t *ups, const char *dir, const char *file, int verify
|
|||
|
||||
static int upscli_sslinit(UPSCONN_t *ups)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10000000L
|
||||
const SSL_METHOD *ssl_method;
|
||||
#else
|
||||
SSL_METHOD *ssl_method;
|
||||
#endif
|
||||
char buf[UPSCLI_NETBUF_LEN];
|
||||
|
||||
/* see if upsd even talks SSL/TLS */
|
||||
|
@ -317,10 +322,16 @@ static int upscli_sslinit(UPSCONN_t *ups)
|
|||
|
||||
/* upsd is happy, so let's crank up the client */
|
||||
|
||||
SSL_library_init();
|
||||
SSL_load_error_strings();
|
||||
SSL_library_init();
|
||||
|
||||
ups->ssl_ctx = SSL_CTX_new(TLSv1_client_method());
|
||||
ssl_method = TLSv1_client_method();
|
||||
|
||||
if (!ssl_method) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ups->ssl_ctx = SSL_CTX_new(ssl_method);
|
||||
|
||||
if (!ups->ssl_ctx) {
|
||||
return 0;
|
||||
|
@ -385,14 +396,9 @@ int upscli_sslcert(UPSCONN_t *ups, const char *file, const char *path, int verif
|
|||
int upscli_connect(UPSCONN_t *ups, const char *host, int port, int flags)
|
||||
{
|
||||
int sock_fd;
|
||||
#ifndef HAVE_IPV6
|
||||
struct sockaddr_in local, server;
|
||||
struct hostent *serv;
|
||||
#else
|
||||
struct addrinfo hints, *res, *ai;
|
||||
char sport[NI_MAXSERV];
|
||||
int v;
|
||||
#endif
|
||||
|
||||
if (!ups) {
|
||||
return -1;
|
||||
|
@ -408,58 +414,6 @@ int upscli_connect(UPSCONN_t *ups, const char *host, int port, int flags)
|
|||
return -1;
|
||||
}
|
||||
|
||||
#ifndef HAVE_IPV6
|
||||
serv = gethostbyname(host);
|
||||
|
||||
if (!serv) {
|
||||
struct in_addr listenaddr;
|
||||
|
||||
if (!inet_aton(host, &listenaddr)) {
|
||||
ups->upserror = UPSCLI_ERR_NOSUCHHOST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
serv = gethostbyaddr(&listenaddr, sizeof(listenaddr), AF_INET);
|
||||
|
||||
if (!serv) {
|
||||
ups->upserror = UPSCLI_ERR_NOSUCHHOST;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
ups->upserror = UPSCLI_ERR_SOCKFAILURE;
|
||||
ups->syserrno = errno;
|
||||
close(sock_fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&local, '\0', sizeof(local));
|
||||
local.sin_family = AF_INET;
|
||||
local.sin_port = htons(INADDR_ANY);
|
||||
|
||||
memset(&server, '\0', sizeof(server));
|
||||
server.sin_family = AF_INET;
|
||||
server.sin_port = htons(port);
|
||||
|
||||
memcpy(&server.sin_addr, serv->h_addr, serv->h_length);
|
||||
|
||||
if (bind(sock_fd, (struct sockaddr *) &local, sizeof(local)) < 0) {
|
||||
ups->upserror = UPSCLI_ERR_BINDFAILURE;
|
||||
ups->syserrno = errno;
|
||||
close(sock_fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (connect(sock_fd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) < 0) {
|
||||
ups->upserror = UPSCLI_ERR_CONNFAILURE;
|
||||
ups->syserrno = errno;
|
||||
close(sock_fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ups->fd = sock_fd;
|
||||
#else
|
||||
snprintf(sport, sizeof(sport), "%hu", (unsigned short int)port);
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
|
@ -543,7 +497,7 @@ int upscli_connect(UPSCONN_t *ups, const char *host, int port, int flags)
|
|||
if (ups->fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
pconf_init(&ups->pc_ctx, NULL);
|
||||
|
||||
ups->host = strdup(host);
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
extern "C" {
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
#define UPSCLI_ERRBUF_LEN 256
|
||||
|
@ -154,13 +156,12 @@ int upscli_ssl(UPSCONN_t *ups);
|
|||
|
||||
#define UPSCLI_CONN_TRYSSL 0x0001 /* try SSL, OK if not supported */
|
||||
#define UPSCLI_CONN_REQSSL 0x0002 /* try SSL, fail if not supported */
|
||||
#ifdef HAVE_IPV6
|
||||
#define UPSCLI_CONN_INET 0x0004 /* IPv4 only */
|
||||
#define UPSCLI_CONN_INET6 0x0008 /* IPv6 only */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* *INDENT-OFF* */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
#endif
|
||||
|
||||
#endif /* UPSCLIENT_H_SEEN */
|
||||
|
|
|
@ -152,6 +152,13 @@ static void do_cmd(char **argv, const int argc)
|
|||
if (upscli_readline(ups, buf, sizeof(buf)) < 0) {
|
||||
fatalx(EXIT_FAILURE, "Instant command failed: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
/* FUTURE: status cookies will tie in here */
|
||||
if (strncmp(buf, "OK", 2) != 0) {
|
||||
fatalx(EXIT_FAILURE, "Unexpected response from upsd: %s", buf);
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
}
|
||||
|
||||
static void clean_exit(void)
|
||||
|
|
|
@ -620,7 +620,7 @@ int main(int argc, char **argv)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
struct imgvar_t imgvar[] = {
|
||||
imgvar_t imgvar[] = {
|
||||
{ "input.voltage", "input.transfer.low", "input.voltage.nominal",
|
||||
"input.transfer.high", 0,
|
||||
"%.1f VAC", draw_utility },
|
||||
|
|
|
@ -44,7 +44,7 @@ struct {
|
|||
{ NULL, 0, 0, 0 }
|
||||
};
|
||||
|
||||
struct imgvar_t {
|
||||
typedef struct {
|
||||
char *name; /* name of the UPS variable */
|
||||
char *minimum; /* name of minimum value UPS variable
|
||||
or variable in imgarg table */
|
||||
|
@ -55,6 +55,6 @@ struct imgvar_t {
|
|||
|
||||
/* pointer to drawing function */
|
||||
void (*drawfunc)(double, int, int, int, int, const char*);
|
||||
};
|
||||
} imgvar_t;
|
||||
|
||||
extern struct imgvar_t imgvar[];
|
||||
extern imgvar_t imgvar[];
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
static sigset_t nut_upslog_sigmask;
|
||||
static char logbuffer[LARGEBUF], *logformat;
|
||||
|
||||
static struct flist_t *fhead = NULL;
|
||||
static flist_t *fhead = NULL;
|
||||
|
||||
#define DEFAULT_LOGFORMAT "%TIME @Y@m@d @H@M@S% %VAR battery.charge% " \
|
||||
"%VAR input.voltage% %VAR ups.load% [%VAR ups.status%] " \
|
||||
|
@ -109,7 +109,7 @@ static void help(const char *prog)
|
|||
printf(" - Use -f \"<format>\" so your shell doesn't break it up.\n");
|
||||
printf(" -i <interval> - Time between updates, in seconds\n");
|
||||
printf(" -l <logfile> - Log file name, or - for stdout\n");
|
||||
printf(" -p <pidbase> - Base name for PID file (defaults to \"upslog\")\n");
|
||||
printf(" -p <pidbase> - Base name for PID file (defaults to \"%s\")\n", prog);
|
||||
printf(" -s <ups> - Monitor UPS <ups> - <upsname>@<host>[:<port>]\n");
|
||||
printf(" - Example: -s myups@server\n");
|
||||
printf(" -u <user> - Switch to <user> if started as root\n");
|
||||
|
@ -238,7 +238,7 @@ static void print_literal(const char *arg)
|
|||
/* register another parsing function to be called later */
|
||||
static void add_call(void (*fptr)(const char *arg), const char *arg)
|
||||
{
|
||||
struct flist_t *tmp, *last;
|
||||
flist_t *tmp, *last;
|
||||
|
||||
tmp = last = fhead;
|
||||
|
||||
|
@ -247,7 +247,7 @@ static void add_call(void (*fptr)(const char *arg), const char *arg)
|
|||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
tmp = xmalloc(sizeof(struct flist_t));
|
||||
tmp = xmalloc(sizeof(flist_t));
|
||||
|
||||
tmp->fptr = fptr;
|
||||
|
||||
|
@ -343,7 +343,7 @@ static void compile_format(void)
|
|||
/* go through the list of functions and call them in order */
|
||||
static void run_flist(void)
|
||||
{
|
||||
struct flist_t *tmp;
|
||||
flist_t *tmp;
|
||||
|
||||
tmp = fhead;
|
||||
|
||||
|
@ -369,18 +369,16 @@ static void run_flist(void)
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
int interval = 30, i;
|
||||
char *prog = NULL;
|
||||
const char *prog = xbasename(argv[0]);
|
||||
time_t now, nextpoll = 0;
|
||||
const char *user = NULL;
|
||||
struct passwd *new_uid = NULL;
|
||||
const char *pidfilebase = "upslog";
|
||||
const char *user = NULL;
|
||||
struct passwd *new_uid = NULL;
|
||||
const char *pidfilebase = prog;
|
||||
|
||||
logformat = DEFAULT_LOGFORMAT;
|
||||
user = RUN_AS_USER;
|
||||
|
||||
printf("Network UPS Tools upslog %s\n", UPS_VERSION);
|
||||
|
||||
prog = argv[0];
|
||||
printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
|
||||
|
||||
while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:")) != -1) {
|
||||
switch(i) {
|
||||
|
@ -476,7 +474,7 @@ int main(int argc, char **argv)
|
|||
/* now drop root if we have it */
|
||||
new_uid = get_user_pwent(user);
|
||||
|
||||
openlog("upslog", LOG_PID, LOG_FACILITY);
|
||||
open_syslog(prog);
|
||||
|
||||
if (logfile != stdout)
|
||||
background();
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/* upslog.h - table of functions for handling various logging functions */
|
||||
|
||||
/* function list */
|
||||
struct flist_t {
|
||||
typedef struct flist_s {
|
||||
void (*fptr)(const char *arg);
|
||||
const char *arg;
|
||||
struct flist_t *next;
|
||||
};
|
||||
struct flist_s *next;
|
||||
} flist_t;
|
||||
|
||||
static void do_host(const char *arg);
|
||||
static void do_upshost(const char *arg);
|
||||
|
|
|
@ -73,9 +73,7 @@ static int userfsd = 0, use_pipe = 1, pipefd[2];
|
|||
|
||||
static utype_t *firstups = NULL;
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
static int opt_af = AF_UNSPEC;
|
||||
#endif
|
||||
|
||||
/* signal handling things */
|
||||
static struct sigaction sa;
|
||||
|
@ -89,12 +87,12 @@ static sigset_t nut_upsmon_sigmask;
|
|||
|
||||
static void setflag(int *val, int flag)
|
||||
{
|
||||
*val = (*val |= flag);
|
||||
*val |= flag;
|
||||
}
|
||||
|
||||
static void clearflag(int *val, int flag)
|
||||
{
|
||||
*val = (*val ^= (*val & flag));
|
||||
*val ^= (*val & flag);
|
||||
}
|
||||
|
||||
static int flag_isset(int num, int flag)
|
||||
|
@ -1431,13 +1429,11 @@ static int try_connect(utype_t *ups)
|
|||
else
|
||||
flags |= UPSCLI_CONN_TRYSSL;
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
if (opt_af == AF_INET)
|
||||
flags |= UPSCLI_CONN_INET;
|
||||
|
||||
if (opt_af == AF_INET6)
|
||||
flags |= UPSCLI_CONN_INET6;
|
||||
#endif
|
||||
|
||||
ret = upscli_connect(&ups->conn, ups->hostname, ups->port, flags);
|
||||
|
||||
|
@ -1674,10 +1670,8 @@ static void help(const char *progname)
|
|||
printf(" -K checks POWERDOWNFLAG, sets exit code to 0 if set\n");
|
||||
printf(" -p always run privileged (disable privileged parent)\n");
|
||||
printf(" -u <user> run child as user <user> (ignored when using -p)\n");
|
||||
#ifdef HAVE_IPV6
|
||||
printf(" -4 IPv4 only\n");
|
||||
printf(" -6 IPv6 only\n");
|
||||
#endif
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -1718,16 +1712,9 @@ static void runparent(int fd)
|
|||
}
|
||||
|
||||
/* fire up the split parent/child scheme */
|
||||
static void start_pipe(const char *user)
|
||||
static void start_pipe(void)
|
||||
{
|
||||
int ret;
|
||||
struct passwd *new_uid = NULL;
|
||||
|
||||
/* default user = the --with-user value from configure */
|
||||
if (user)
|
||||
new_uid = get_user_pwent(user);
|
||||
else
|
||||
new_uid = get_user_pwent(RUN_AS_USER);
|
||||
|
||||
ret = pipe(pipefd);
|
||||
|
||||
|
@ -1748,11 +1735,6 @@ static void start_pipe(const char *user)
|
|||
}
|
||||
|
||||
close(pipefd[0]);
|
||||
|
||||
/* write the pid file now, as we will soon lose root */
|
||||
writepid("upsmon");
|
||||
|
||||
become_user(new_uid);
|
||||
}
|
||||
|
||||
static void delete_ups(utype_t *target)
|
||||
|
@ -1897,11 +1879,17 @@ static void check_parent(void)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, cmd, checking_flag = 0;
|
||||
const char *prog = xbasename(argv[0]);
|
||||
int i, cmd = 0, checking_flag = 0;
|
||||
|
||||
cmd = 0;
|
||||
printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
|
||||
|
||||
printf("Network UPS Tools upsmon %s\n", UPS_VERSION);
|
||||
/* if no configuration file is specified on the command line, use default */
|
||||
configfile = xmalloc(SMALLBUF);
|
||||
snprintf(configfile, SMALLBUF, "%s/upsmon.conf", confpath());
|
||||
configfile = xrealloc(configfile, strlen(configfile) + 1);
|
||||
|
||||
run_as_user = xstrdup(RUN_AS_USER);
|
||||
|
||||
while ((i = getopt(argc, argv, "+Dhic:f:pu:VK46")) != -1) {
|
||||
switch (i) {
|
||||
|
@ -1921,6 +1909,7 @@ int main(int argc, char *argv[])
|
|||
nut_debug_level++;
|
||||
break;
|
||||
case 'f':
|
||||
free(configfile);
|
||||
configfile = xstrdup(optarg);
|
||||
break;
|
||||
case 'h':
|
||||
|
@ -1933,19 +1922,18 @@ int main(int argc, char *argv[])
|
|||
use_pipe = 0;
|
||||
break;
|
||||
case 'u':
|
||||
free(run_as_user);
|
||||
run_as_user = xstrdup(optarg);
|
||||
break;
|
||||
case 'V':
|
||||
/* just show the banner */
|
||||
exit(EXIT_SUCCESS);
|
||||
#ifdef HAVE_IPV6
|
||||
case '4':
|
||||
opt_af = AF_INET;
|
||||
break;
|
||||
case '6':
|
||||
opt_af = AF_INET6;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
help(argv[0]);
|
||||
break;
|
||||
|
@ -1953,21 +1941,14 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (cmd) {
|
||||
sendsignal("upsmon", cmd);
|
||||
sendsignal(prog, cmd);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
openlog("upsmon", LOG_PID, LOG_FACILITY);
|
||||
|
||||
/* if no configuration file was specified on the command line, use default */
|
||||
if (!configfile) {
|
||||
configfile = xmalloc(SMALLBUF);
|
||||
snprintf(configfile, SMALLBUF, "%s/upsmon.conf", confpath());
|
||||
configfile = xrealloc(configfile, strlen(configfile) + 1);
|
||||
}
|
||||
open_syslog(prog);
|
||||
|
||||
loadconfig();
|
||||
|
||||
|
@ -1997,14 +1978,21 @@ int main(int argc, char *argv[])
|
|||
upsdebugx(1, "debug level is '%d'", nut_debug_level);
|
||||
}
|
||||
|
||||
/* === root parent and unprivileged child split here === */
|
||||
|
||||
/* only do the pipe stuff if the user hasn't disabled it */
|
||||
if (use_pipe)
|
||||
start_pipe(run_as_user);
|
||||
else {
|
||||
if (use_pipe) {
|
||||
struct passwd *new_uid = get_user_pwent(run_as_user);
|
||||
|
||||
/* === root parent and unprivileged child split here === */
|
||||
start_pipe();
|
||||
|
||||
/* write the pid file now, as we will soon lose root */
|
||||
writepid(prog);
|
||||
|
||||
become_user(new_uid);
|
||||
} else {
|
||||
upslogx(LOG_INFO, "Warning: running as one big root process by request (upsmon -p)");
|
||||
writepid("upsmon");
|
||||
|
||||
writepid(prog);
|
||||
}
|
||||
|
||||
/* prep our signal handlers */
|
||||
|
@ -2012,7 +2000,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* reopen the log for the child process */
|
||||
closelog();
|
||||
openlog("upsmon", LOG_PID, LOG_FACILITY);
|
||||
open_syslog(prog);
|
||||
|
||||
while (exit_flag == 0) {
|
||||
utype_t *ups;
|
||||
|
|
255
clients/upsrw.c
255
clients/upsrw.c
|
@ -26,6 +26,9 @@
|
|||
|
||||
#include "upsclient.h"
|
||||
|
||||
static char *upsname = NULL, *hostname = NULL;
|
||||
static UPSCONN_t *ups = NULL;
|
||||
|
||||
struct list_t {
|
||||
char *name;
|
||||
struct list_t *next;
|
||||
|
@ -33,7 +36,7 @@ struct list_t {
|
|||
|
||||
static void usage(const char *prog)
|
||||
{
|
||||
printf("Network UPS Tools upsrw %s\n\n", UPS_VERSION);
|
||||
printf("Network UPS Tools %s %s\n\n", prog, UPS_VERSION);
|
||||
printf("usage: %s [-h]\n", prog);
|
||||
printf(" %s [-s <variable>] [-u <username>] [-p <password>] <ups>\n\n", prog);
|
||||
printf("Demo program to set variables within UPS hardware.\n");
|
||||
|
@ -47,56 +50,45 @@ static void usage(const char *prog)
|
|||
printf(" <ups> UPS identifier - <upsname>[@<hostname>[:<port>]]\n");
|
||||
printf("\n");
|
||||
printf("Call without -s to show all possible read/write variables.\n");
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void clean_exit(UPSCONN_t *ups, char *upsname, char *hostname, int code)
|
||||
static void clean_exit(void)
|
||||
{
|
||||
if (ups) {
|
||||
upscli_disconnect(ups);
|
||||
}
|
||||
|
||||
free(upsname);
|
||||
free(hostname);
|
||||
|
||||
upscli_disconnect(ups);
|
||||
|
||||
exit(code);
|
||||
free(ups);
|
||||
}
|
||||
|
||||
static int do_set(UPSCONN_t *ups, const char *upsname, const char *varname,
|
||||
const char *newval)
|
||||
static void do_set(const char *varname, const char *newval)
|
||||
{
|
||||
char buf[SMALLBUF], enc[SMALLBUF];
|
||||
|
||||
snprintf(buf, sizeof(buf), "SET VAR %s %s \"%s\"\n",
|
||||
upsname, varname, pconf_encode(newval, enc, sizeof(enc)));
|
||||
snprintf(buf, sizeof(buf), "SET VAR %s %s \"%s\"\n", upsname, varname, pconf_encode(newval, enc, sizeof(enc)));
|
||||
|
||||
if (upscli_sendline(ups, buf, strlen(buf)) < 0) {
|
||||
fprintf(stderr, "Can't set variable: %s\n",
|
||||
upscli_strerror(ups));
|
||||
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Can't set variable: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
if (upscli_readline(ups, buf, sizeof(buf)) < 0) {
|
||||
fprintf(stderr, "Set variable failed: %s\n",
|
||||
upscli_strerror(ups));
|
||||
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Set variable failed: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
/* FUTURE: status cookies will tie in here */
|
||||
if (strncmp(buf, "OK", 2) != 0) {
|
||||
printf("Unexpected response from upsd: %s\n", buf);
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Unexpected response from upsd: %s", buf);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
}
|
||||
|
||||
static int do_setvar(UPSCONN_t *ups, const char *varname, char *uin,
|
||||
const char *pass, char *upsname, char *hostname)
|
||||
static void do_setvar(const char *varname, char *uin, const char *pass)
|
||||
{
|
||||
char newval[SMALLBUF], temp[SMALLBUF], user[SMALLBUF], *ptr;
|
||||
struct passwd *pw;
|
||||
struct passwd *pw;
|
||||
|
||||
if (uin) {
|
||||
snprintf(user, sizeof(user), "%s", uin);
|
||||
|
@ -105,22 +97,24 @@ static int do_setvar(UPSCONN_t *ups, const char *varname, char *uin,
|
|||
|
||||
pw = getpwuid(getuid());
|
||||
|
||||
if (pw)
|
||||
if (pw) {
|
||||
printf("Username (%s): ", pw->pw_name);
|
||||
else
|
||||
} else {
|
||||
printf("Username: ");
|
||||
}
|
||||
|
||||
if (fgets(user, sizeof(user), stdin) == NULL) {
|
||||
upsdebug_with_errno(LOG_INFO, "%s", __func__);
|
||||
}
|
||||
|
||||
/* deal with that pesky newline */
|
||||
if (strlen(user) > 1)
|
||||
if (strlen(user) > 1) {
|
||||
user[strlen(user) - 1] = '\0';
|
||||
else {
|
||||
if (!pw)
|
||||
} else {
|
||||
if (!pw) {
|
||||
fatalx(EXIT_FAILURE, "No username available - even tried getpwuid");
|
||||
|
||||
}
|
||||
|
||||
snprintf(user, sizeof(user), "%s", pw->pw_name);
|
||||
}
|
||||
}
|
||||
|
@ -130,10 +124,7 @@ static int do_setvar(UPSCONN_t *ups, const char *varname, char *uin,
|
|||
pass = GETPASS("Password: " );
|
||||
|
||||
if (!pass) {
|
||||
fprintf(stderr, "getpass failed: %s\n",
|
||||
strerror(errno));
|
||||
|
||||
return EXIT_FAILURE;
|
||||
fatal_with_errno(EXIT_FAILURE, "getpass failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,116 +144,93 @@ static int do_setvar(UPSCONN_t *ups, const char *varname, char *uin,
|
|||
snprintf(temp, sizeof(temp), "USERNAME %s\n", user);
|
||||
|
||||
if (upscli_sendline(ups, temp, strlen(temp)) < 0) {
|
||||
fprintf(stderr, "Can't set username: %s\n",
|
||||
upscli_strerror(ups));
|
||||
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Can't set username: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
if (upscli_readline(ups, temp, sizeof(temp)) < 0) {
|
||||
|
||||
if (upscli_upserror(ups) == UPSCLI_ERR_UNKCOMMAND) {
|
||||
fprintf(stderr, "Set username failed due to an "
|
||||
"unknown command.\n");
|
||||
|
||||
fprintf(stderr, "You probably need to upgrade upsd.\n");
|
||||
|
||||
clean_exit(ups, upsname, hostname, EXIT_FAILURE);
|
||||
fatalx(EXIT_FAILURE, "Set username failed due to an unknown command. You probably need to upgrade upsd.");
|
||||
}
|
||||
|
||||
fprintf(stderr, "Set username failed: %s\n",
|
||||
upscli_strerror(ups));
|
||||
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Set username failed: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
snprintf(temp, sizeof(temp), "PASSWORD %s\n", pass);
|
||||
|
||||
if (upscli_sendline(ups, temp, strlen(temp)) < 0) {
|
||||
fprintf(stderr, "Can't set password: %s\n",
|
||||
upscli_strerror(ups));
|
||||
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Can't set password: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
if (upscli_readline(ups, temp, sizeof(temp)) < 0) {
|
||||
fprintf(stderr, "Set password failed: %s\n",
|
||||
upscli_strerror(ups));
|
||||
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Set password failed: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
/* no upsname means die */
|
||||
if (!upsname) {
|
||||
fprintf(stderr, "Error: a UPS name must be specified (upsname[@hostname[:port]])\n");
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Error: a UPS name must be specified (upsname[@hostname[:port]])");
|
||||
}
|
||||
|
||||
/* old variable names are no longer supported */
|
||||
if (!strchr(varname, '.')) {
|
||||
fprintf(stderr, "Error: old variable names are not supported\n");
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Error: old variable names are not supported");
|
||||
}
|
||||
|
||||
return do_set(ups, upsname, varname, newval);
|
||||
}
|
||||
do_set(varname, newval);
|
||||
}
|
||||
|
||||
static const char *get_data(const char *type, UPSCONN_t *ups,
|
||||
const char *upsname, const char *varname)
|
||||
static const char *get_data(const char *type, const char *varname)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
char **answer;
|
||||
const char *query[4];
|
||||
const char *query[4];
|
||||
|
||||
query[0] = type;
|
||||
query[1] = upsname;
|
||||
query[2] = varname;
|
||||
|
||||
numq = 3;
|
||||
|
||||
ret = upscli_get(ups, numq, query, &numa, &answer);
|
||||
|
||||
if ((ret < 0) || (numa < numq))
|
||||
if ((ret < 0) || (numa < numq)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* <type> <upsname> <varname> <desc> */
|
||||
return answer[3];
|
||||
}
|
||||
|
||||
static void do_string(UPSCONN_t *ups, const char *upsname, const char *varname)
|
||||
static void do_string(const char *varname)
|
||||
{
|
||||
const char *val;
|
||||
const char *val;
|
||||
|
||||
val = get_data("VAR", ups, upsname, varname);
|
||||
val = get_data("VAR", varname);
|
||||
|
||||
if (!val) {
|
||||
fprintf(stderr, "do_string: can't get current value of %s\n",
|
||||
varname);
|
||||
return;
|
||||
fatalx(EXIT_FAILURE, "do_string: can't get current value of %s", varname);
|
||||
}
|
||||
|
||||
printf("Type: STRING\n");
|
||||
printf("Value: %s\n", val);
|
||||
}
|
||||
|
||||
static void do_enum(UPSCONN_t *ups, const char *upsname, const char *varname)
|
||||
static void do_enum(const char *varname)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
char **answer, *val;
|
||||
const char *query[4], *tmp;
|
||||
char **answer, buf[SMALLBUF];
|
||||
const char *query[4], *val;
|
||||
|
||||
/* get current value */
|
||||
tmp = get_data("VAR", ups, upsname, varname);
|
||||
val = get_data("VAR", varname);
|
||||
|
||||
if (!tmp) {
|
||||
fprintf(stderr, "do_enum: can't get current value of %s\n",
|
||||
varname);
|
||||
return;
|
||||
if (!val) {
|
||||
fatalx(EXIT_FAILURE, "do_enum: can't get current value of %s", varname);
|
||||
}
|
||||
|
||||
/* tmp is a pointer into answer - have to save it somewhere else */
|
||||
val = xstrdup(tmp);
|
||||
snprintf(buf, sizeof(buf), "%s", val);
|
||||
|
||||
query[0] = "ENUM";
|
||||
query[1] = upsname;
|
||||
|
@ -272,8 +240,7 @@ static void do_enum(UPSCONN_t *ups, const char *upsname, const char *varname)
|
|||
ret = upscli_list_start(ups, numq, query);
|
||||
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Error: %s\n", upscli_strerror(ups));
|
||||
return;
|
||||
fatalx(EXIT_FAILURE, "Error: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
ret = upscli_list_next(ups, numq, query, &numa, &answer);
|
||||
|
@ -285,32 +252,27 @@ static void do_enum(UPSCONN_t *ups, const char *upsname, const char *varname)
|
|||
/* ENUM <upsname> <varname> <value> */
|
||||
|
||||
if (numa < 4) {
|
||||
fprintf(stderr, "Error: insufficient data "
|
||||
"(got %d args, need at least 4)\n", numa);
|
||||
|
||||
free(val);
|
||||
return;
|
||||
fatalx(EXIT_FAILURE, "Error: insufficient data (got %d args, need at least 4)", numa);
|
||||
}
|
||||
|
||||
printf("Option: \"%s\"", answer[3]);
|
||||
|
||||
if (!strcmp(answer[3], val))
|
||||
if (!strcmp(answer[3], buf)) {
|
||||
printf(" SELECTED");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
ret = upscli_list_next(ups, numq, query, &numa, &answer);
|
||||
}
|
||||
|
||||
free(val);
|
||||
}
|
||||
|
||||
static void do_type(UPSCONN_t *ups, const char *upsname, const char *varname)
|
||||
static void do_type(const char *varname)
|
||||
{
|
||||
int ret;
|
||||
unsigned int i, numq, numa;
|
||||
char **answer;
|
||||
const char *query[4];
|
||||
const char *query[4];
|
||||
|
||||
query[0] = "TYPE";
|
||||
query[1] = upsname;
|
||||
|
@ -328,54 +290,54 @@ static void do_type(UPSCONN_t *ups, const char *upsname, const char *varname)
|
|||
for (i = 3; i < numa; i++) {
|
||||
|
||||
if (!strcasecmp(answer[i], "ENUM")) {
|
||||
do_enum(ups, upsname, varname);
|
||||
do_enum(varname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!strncasecmp(answer[i], "STRING:", 7)) {
|
||||
do_string(ups, upsname, varname);
|
||||
do_string(varname);
|
||||
return;
|
||||
}
|
||||
|
||||
/* ignore this one */
|
||||
if (!strcasecmp(answer[i], "RW"))
|
||||
if (!strcasecmp(answer[i], "RW")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("Type: %s (unrecognized)\n", answer[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void print_rw(UPSCONN_t *ups, const char *upsname, const char *varname)
|
||||
static void print_rw(const char *varname)
|
||||
{
|
||||
const char *tmp;
|
||||
const char *tmp;
|
||||
|
||||
printf("[%s]\n", varname);
|
||||
|
||||
tmp = get_data("DESC", ups, upsname, varname);
|
||||
tmp = get_data("DESC", varname);
|
||||
|
||||
if (tmp)
|
||||
if (tmp) {
|
||||
printf("%s\n", tmp);
|
||||
else
|
||||
} else {
|
||||
printf("Description unavailable\n");
|
||||
}
|
||||
|
||||
do_type(ups, upsname, varname);
|
||||
do_type(varname);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
static int print_rwlist(UPSCONN_t *ups, const char *upsname)
|
||||
static void print_rwlist(void)
|
||||
{
|
||||
int ret;
|
||||
unsigned int numq, numa;
|
||||
const char *query[2];
|
||||
const char *query[2];
|
||||
char **answer;
|
||||
struct list_t *lhead, *llast, *ltmp, *lnext;
|
||||
|
||||
/* the upsname is now required */
|
||||
if (!upsname) {
|
||||
fprintf(stderr, "Error: a UPS name must be specified (upsname[@hostname[:port]])\n");
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Error: a UPS name must be specified (upsname[@hostname[:port]])");
|
||||
}
|
||||
|
||||
llast = lhead = NULL;
|
||||
|
@ -390,12 +352,10 @@ static int print_rwlist(UPSCONN_t *ups, const char *upsname)
|
|||
|
||||
/* old upsd --> fall back on old LISTRW technique */
|
||||
if (upscli_upserror(ups) == UPSCLI_ERR_UNKCOMMAND) {
|
||||
fprintf(stderr, "Error: upsd is too old to support this query\n");
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Error: upsd is too old to support this query");
|
||||
}
|
||||
|
||||
fprintf(stderr, "Error: %s\n", upscli_strerror(ups));
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Error: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
ret = upscli_list_next(ups, numq, query, &numa, &answer);
|
||||
|
@ -404,9 +364,7 @@ static int print_rwlist(UPSCONN_t *ups, const char *upsname)
|
|||
|
||||
/* RW <upsname> <varname> <value> */
|
||||
if (numa < 4) {
|
||||
fprintf(stderr, "Error: insufficient data "
|
||||
"(got %d args, need at least 4)\n", numa);
|
||||
return EXIT_FAILURE;
|
||||
fatalx(EXIT_FAILURE, "Error: insufficient data (got %d args, need at least 4)", numa);
|
||||
}
|
||||
|
||||
/* sock this entry away for later */
|
||||
|
@ -415,10 +373,11 @@ static int print_rwlist(UPSCONN_t *ups, const char *upsname)
|
|||
ltmp->name = xstrdup(answer[2]);
|
||||
ltmp->next = NULL;
|
||||
|
||||
if (llast)
|
||||
if (llast) {
|
||||
llast->next = ltmp;
|
||||
else
|
||||
} else {
|
||||
lhead = ltmp;
|
||||
}
|
||||
|
||||
llast = ltmp;
|
||||
|
||||
|
@ -432,28 +391,23 @@ static int print_rwlist(UPSCONN_t *ups, const char *upsname)
|
|||
while (ltmp) {
|
||||
lnext = ltmp->next;
|
||||
|
||||
print_rw(ups, upsname, ltmp->name);
|
||||
print_rw(ltmp->name);
|
||||
|
||||
free(ltmp->name);
|
||||
free(ltmp);
|
||||
ltmp = lnext;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, port, ret;
|
||||
char *upsname, *hostname, *setvar, *prog;
|
||||
char *password = NULL, *username = NULL;
|
||||
UPSCONN_t ups;
|
||||
|
||||
setvar = username = NULL;
|
||||
prog = argv[0];
|
||||
int i, port;
|
||||
const char *prog = xbasename(argv[0]);
|
||||
char *password = NULL, *username = NULL, *setvar = NULL;
|
||||
|
||||
while ((i = getopt(argc, argv, "+s:p:u:V")) != -1) {
|
||||
switch (i) {
|
||||
switch (i)
|
||||
{
|
||||
case 's':
|
||||
setvar = optarg;
|
||||
break;
|
||||
|
@ -464,45 +418,42 @@ int main(int argc, char **argv)
|
|||
username = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
printf("Network UPS Tools upsrw %s\n", UPS_VERSION);
|
||||
printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
default:
|
||||
usage(prog);
|
||||
break;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc < 1)
|
||||
if (argc < 1) {
|
||||
usage(prog);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
upsname = hostname = NULL;
|
||||
/* be a good little client that cleans up after itself */
|
||||
atexit(clean_exit);
|
||||
|
||||
if (upscli_splitname(argv[0], &upsname, &hostname, &port) != 0) {
|
||||
fprintf(stderr, "Error: invalid UPS definition. Required format: upsname[@hostname[:port]]\n");
|
||||
clean_exit(&ups, upsname, hostname, EXIT_FAILURE);
|
||||
fatalx(EXIT_FAILURE, "Error: invalid UPS definition. Required format: upsname[@hostname[:port]]");
|
||||
}
|
||||
|
||||
if (upscli_connect(&ups, hostname, port, 0) < 0) {
|
||||
fprintf(stderr, "Can't connect: %s\n", upscli_strerror(&ups));
|
||||
clean_exit(&ups, upsname, hostname, EXIT_FAILURE);
|
||||
ups = xcalloc(1, sizeof(*ups));
|
||||
|
||||
if (upscli_connect(ups, hostname, port, 0) < 0) {
|
||||
fatalx(EXIT_FAILURE, "Error: %s", upscli_strerror(ups));
|
||||
}
|
||||
|
||||
/* setting a variable? */
|
||||
if (setvar) {
|
||||
ret = do_setvar(&ups, setvar, username, password, upsname,
|
||||
hostname);
|
||||
|
||||
clean_exit(&ups, upsname, hostname, ret);
|
||||
/* setting a variable */
|
||||
do_setvar(setvar, username, password);
|
||||
} else {
|
||||
/* if not, get the list of supported read/write variables */
|
||||
print_rwlist();
|
||||
}
|
||||
|
||||
/* if not, get the list of supported read/write variables */
|
||||
ret = print_rwlist(&ups, upsname);
|
||||
|
||||
clean_exit(&ups, upsname, hostname, ret);
|
||||
|
||||
/* NOTREACHED */
|
||||
exit(EXIT_FAILURE);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -50,14 +50,14 @@
|
|||
#include "upssched.h"
|
||||
#include "timehead.h"
|
||||
|
||||
typedef struct {
|
||||
typedef struct ttype_s {
|
||||
char *name;
|
||||
time_t etime;
|
||||
void *next;
|
||||
} ttype_t;
|
||||
struct ttype_s *next;
|
||||
} ttype_t;
|
||||
|
||||
ttype_t *thead = NULL;
|
||||
static struct conn_t *connhead = NULL;
|
||||
static conn_t *connhead = NULL;
|
||||
char *cmdscript = NULL, *pipefn = NULL, *lockfn = NULL;
|
||||
int verbose = 0; /* use for debugging */
|
||||
|
||||
|
@ -300,9 +300,9 @@ static int open_sock(void)
|
|||
return fd;
|
||||
}
|
||||
|
||||
static void conn_del(struct conn_t *target)
|
||||
static void conn_del(conn_t *target)
|
||||
{
|
||||
struct conn_t *tmp, *last = NULL;
|
||||
conn_t *tmp, *last = NULL;
|
||||
|
||||
tmp = connhead;
|
||||
|
||||
|
@ -327,7 +327,7 @@ static void conn_del(struct conn_t *target)
|
|||
upslogx(LOG_ERR, "Tried to delete a bogus state connection");
|
||||
}
|
||||
|
||||
static int send_to_one(struct conn_t *conn, const char *fmt, ...)
|
||||
static int send_to_one(conn_t *conn, const char *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
@ -354,7 +354,7 @@ static int send_to_one(struct conn_t *conn, const char *fmt, ...)
|
|||
static void conn_add(int sockfd)
|
||||
{
|
||||
int acc, ret;
|
||||
struct conn_t *tmp, *last;
|
||||
conn_t *tmp, *last;
|
||||
struct sockaddr_un saddr;
|
||||
socklen_t salen;
|
||||
|
||||
|
@ -391,7 +391,7 @@ static void conn_add(int sockfd)
|
|||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
tmp = xmalloc(sizeof(struct conn_t));
|
||||
tmp = xmalloc(sizeof(conn_t));
|
||||
tmp->fd = acc;
|
||||
tmp->next = NULL;
|
||||
|
||||
|
@ -405,7 +405,7 @@ static void conn_add(int sockfd)
|
|||
pconf_init(&tmp->ctx, NULL);
|
||||
}
|
||||
|
||||
static int sock_arg(struct conn_t *conn)
|
||||
static int sock_arg(conn_t *conn)
|
||||
{
|
||||
if (conn->ctx.numargs < 1)
|
||||
return 0;
|
||||
|
@ -446,7 +446,7 @@ static void log_unknown(int numarg, char **arg)
|
|||
upslogx(LOG_INFO, "arg %d: %s", i, arg[i]);
|
||||
}
|
||||
|
||||
static int sock_read(struct conn_t *conn)
|
||||
static int sock_read(conn_t *conn)
|
||||
{
|
||||
int i, ret;
|
||||
char ch;
|
||||
|
@ -494,7 +494,7 @@ static void start_daemon(int lockfd)
|
|||
int maxfd, pid, pipefd, ret;
|
||||
struct timeval tv;
|
||||
fd_set rfds;
|
||||
struct conn_t *tmp, *tmpnext;
|
||||
conn_t *tmp, *tmpnext;
|
||||
socklen_t fromlen;
|
||||
|
||||
fromlen = sizeof(struct sockaddr);
|
||||
|
@ -899,10 +899,12 @@ static void checkconf(void)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *prog = xbasename(argv[0]);
|
||||
|
||||
verbose = 1; /* TODO: remove when done testing */
|
||||
|
||||
/* normally we don't have stderr, so get this going to syslog early */
|
||||
openlog("upssched", LOG_PID, LOG_DAEMON);
|
||||
open_syslog(prog);
|
||||
syslogbit_set();
|
||||
|
||||
upsname = getenv("UPSNAME");
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#define SERIALIZE_WAIT 3
|
||||
|
||||
/* track client connections */
|
||||
struct conn_t {
|
||||
typedef struct conn_s {
|
||||
int fd;
|
||||
PCONF_CTX_t ctx;
|
||||
void *next;
|
||||
};
|
||||
struct conn_s *next;
|
||||
} conn_t;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue