Imported Upstream version 2.6.2
This commit is contained in:
parent
a367d9bc54
commit
45043b58d0
246 changed files with 18228 additions and 1415 deletions
|
@ -59,6 +59,8 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \
|
|||
$(top_srcdir)/m4/lt~obsolete.m4 \
|
||||
$(top_srcdir)/m4/nut_arg_with.m4 \
|
||||
$(top_srcdir)/m4/nut_check_asciidoc.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libavahi.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libfreeipmi.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libgd.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libhal.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libneon.m4 \
|
||||
|
@ -229,10 +231,14 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
|||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LD = @LD@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBAVAHI_CFLAGS = @LIBAVAHI_CFLAGS@
|
||||
LIBAVAHI_LIBS = @LIBAVAHI_LIBS@
|
||||
LIBGD_CFLAGS = @LIBGD_CFLAGS@
|
||||
LIBGD_LDFLAGS = @LIBGD_LDFLAGS@
|
||||
LIBHAL_CFLAGS = @LIBHAL_CFLAGS@
|
||||
LIBHAL_LIBS = @LIBHAL_LIBS@
|
||||
LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@
|
||||
LIBIPMI_LIBS = @LIBIPMI_LIBS@
|
||||
LIBNEON_CFLAGS = @LIBNEON_CFLAGS@
|
||||
LIBNEON_LIBS = @LIBNEON_LIBS@
|
||||
LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@
|
||||
|
@ -270,6 +276,10 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
|||
PACKAGE_URL = @PACKAGE_URL@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
PKG_CONFIG = @PKG_CONFIG@
|
||||
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
|
||||
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
|
||||
PORT = @PORT@
|
||||
RANLIB = @RANLIB@
|
||||
RUN_AS_GROUP = @RUN_AS_GROUP@
|
||||
RUN_AS_USER = @RUN_AS_USER@
|
||||
|
@ -334,6 +344,8 @@ sbindir = @sbindir@
|
|||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
systemdsystemshutdowndir = @systemdsystemshutdowndir@
|
||||
systemdsystemunitdir = @systemdsystemunitdir@
|
||||
target = @target@
|
||||
target_alias = @target_alias@
|
||||
target_cpu = @target_cpu@
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "upsclient.h"
|
||||
#include "timehead.h"
|
||||
|
@ -393,12 +394,17 @@ int upscli_sslcert(UPSCONN_t *ups, const char *file, const char *path, int verif
|
|||
|
||||
#endif /* HAVE_SSL */
|
||||
|
||||
int upscli_connect(UPSCONN_t *ups, const char *host, int port, int flags)
|
||||
int upscli_tryconnect(UPSCONN_t *ups, const char *host, int port, int flags,struct timeval * timeout)
|
||||
{
|
||||
int sock_fd;
|
||||
struct addrinfo hints, *res, *ai;
|
||||
char sport[NI_MAXSERV];
|
||||
int v;
|
||||
fd_set wfds;
|
||||
int ret;
|
||||
int error;
|
||||
socklen_t error_size;
|
||||
long fd_flags;
|
||||
|
||||
if (!ups) {
|
||||
return -1;
|
||||
|
@ -466,7 +472,37 @@ int upscli_connect(UPSCONN_t *ups, const char *host, int port, int flags)
|
|||
continue;
|
||||
}
|
||||
|
||||
/* non blocking connect */
|
||||
if(timeout != NULL) {
|
||||
fd_flags = fcntl(sock_fd, F_GETFL);
|
||||
fd_flags |= O_NONBLOCK;
|
||||
fcntl(sock_fd, F_SETFL, fd_flags);
|
||||
}
|
||||
|
||||
while ((v = connect(sock_fd, ai->ai_addr, ai->ai_addrlen)) < 0) {
|
||||
if(errno == EINPROGRESS) {
|
||||
FD_ZERO(&wfds);
|
||||
FD_SET(sock_fd, &wfds);
|
||||
ret = select(sock_fd+1,NULL,&wfds,NULL,
|
||||
timeout);
|
||||
if (FD_ISSET(sock_fd, &wfds)) {
|
||||
error_size = sizeof(error);
|
||||
getsockopt(sock_fd,SOL_SOCKET,SO_ERROR,
|
||||
&error,&error_size);
|
||||
if( error == 0) {
|
||||
/* connect successful */
|
||||
v = 0;
|
||||
break;
|
||||
}
|
||||
errno = error;
|
||||
}
|
||||
else {
|
||||
/* Timeout */
|
||||
v = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (errno)
|
||||
{
|
||||
case EAFNOSUPPORT:
|
||||
|
@ -486,6 +522,13 @@ int upscli_connect(UPSCONN_t *ups, const char *host, int port, int flags)
|
|||
continue;
|
||||
}
|
||||
|
||||
/* switch back to blocking operation */
|
||||
if(timeout != NULL) {
|
||||
fd_flags = fcntl(sock_fd, F_GETFL);
|
||||
fd_flags &= ~O_NONBLOCK;
|
||||
fcntl(sock_fd, F_SETFL, fd_flags);
|
||||
}
|
||||
|
||||
ups->fd = sock_fd;
|
||||
ups->upserror = 0;
|
||||
ups->syserrno = 0;
|
||||
|
@ -529,6 +572,11 @@ int upscli_connect(UPSCONN_t *ups, const char *host, int port, int flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int upscli_connect(UPSCONN_t *ups, const char *host, int port, int flags)
|
||||
{
|
||||
return upscli_tryconnect(ups,host,port,flags,NULL);
|
||||
}
|
||||
|
||||
/* map upsd error strings back to upsclient internal numbers */
|
||||
static struct {
|
||||
int errnum;
|
||||
|
|
|
@ -65,6 +65,8 @@ typedef struct {
|
|||
|
||||
const char *upscli_strerror(UPSCONN_t *ups);
|
||||
|
||||
int upscli_tryconnect(UPSCONN_t *ups, const char *host, int port, int flags, struct timeval *tv);
|
||||
|
||||
int upscli_connect(UPSCONN_t *ups, const char *host, int port, int flags);
|
||||
|
||||
/* --- functions that only use the new names --- */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue