Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows port v2.6.5 6 #455

Draft
wants to merge 223 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
223 commits
Select commit Hold shift + click to select a range
ecd42d8
Initial commit (preliminary investigation)
Oct 18, 2010
c9c402c
Set eol-style to native
Oct 18, 2010
b50052f
Fix executable bits
clepple Oct 20, 2010
52358e6
Move wincompat.[ch] to common
Oct 20, 2010
ee3fd34
Remove hard coded path to libws2_32
Oct 20, 2010
06a056b
Fix errors appeared when merging from regular 2.4.3 to svn trunk
Oct 20, 2010
56bae5a
Set again eol property to native
Oct 20, 2010
f4bbae1
Remove hack from confpath function.
Oct 20, 2010
035bcf1
Remove unneeded debug printf
Oct 20, 2010
8bf7767
Better handling of multiple connection on drivers
Oct 20, 2010
ca609ba
Rename DATADIR to NUT_DATADIR to avoid conflict with MinGW objidl.h h…
aquette Oct 20, 2010
5b7d7ad
Map syslog to Windows's event log.
Oct 28, 2010
315995f
Remove C++ style comments
Oct 28, 2010
0572127
upsd behaves like a service by default now
Oct 28, 2010
0f955d1
Add Uninstall facility to upsd
Oct 29, 2010
36ac62d
Factorization of service code
Nov 3, 2010
12b4f4b
MinGW socklen detection (by Arnaud Quette)
Nov 3, 2010
0a70267
Make drivers run as service by default
Nov 3, 2010
a6dd8a6
Add regex library check and flags
aquette Nov 4, 2010
526a248
Checking whether or not we should use the 'regex' library...
arjendekorte Nov 4, 2010
43b986d
Correct integration of WinSock library (by Arnaud Quette)
Nov 5, 2010
d592a68
This 3 lines has been duplicated instead of being removed.
Nov 5, 2010
6dcd454
Finish removing hard-coded paths to winsock2 library (as in [[SVN:267…
clepple Nov 5, 2010
d8ae3f5
More factorization and fix a bug in drivers services stop
Nov 5, 2010
10f11d3
We need to register one driver service per ups in upsd.conf.
Nov 16, 2010
09bf7cd
Better use of NUT framework for previous commit
Nov 16, 2010
dafcbcd
Remove useless header
Nov 19, 2010
d65907b
Change the "full services" approach to a more POSIX one.
Nov 26, 2010
9d9c732
Add regex library for drivers (by Arnaud Quette)
Nov 26, 2010
06af1b8
Reverting useless previous commit: [[SVN:2705]]
Nov 29, 2010
97f9667
Fix upsd clients read
Dec 1, 2010
0827701
upsmon uses a message box instead of wall
Dec 1, 2010
b16539e
Start upsmon as a single process.
Dec 1, 2010
7509599
More work on serial drivers.
Dec 9, 2010
bc95b43
upscmd is now working
Dec 10, 2010
27af8dd
upsrw is now working
Dec 10, 2010
41ba23c
Fix timeout calculation
Dec 10, 2010
72b9807
Update halt.c compilation
Dec 16, 2010
25b4f68
Automatic generation of winevent.h and winevent.dll
Dec 16, 2010
17eca71
Simplify timeout calculation
Dec 17, 2010
1cbacf2
forgot this for automatic winevent.h and winevent.dll generation
Dec 17, 2010
6a55c6a
First implementation of termios functions
Dec 17, 2010
10a1c99
Use paths relative to the .exe file's binary for configuration and PI…
Dec 20, 2010
acbfbdd
Add usleep() implementation for systems that lack it (patch from Paul…
Dec 20, 2010
c6a6795
Do not use an external DLL anymore.
Dec 21, 2010
7f9edce
Forgot to remove now useless winevent.dll reference
Dec 21, 2010
5e72ed9
Fix winevent.h generation on clean compile (by Paul Fertser)
Dec 21, 2010
c2de280
Make datapath relative too
Dec 22, 2010
83c5705
Fix latency bug for mge-utalk.
Jan 7, 2011
df97c4b
code cleanup
Jan 7, 2011
8e8bcb9
Fix client disconnection
Jan 7, 2011
67fddb1
Merge from the trunk -> porting the IPv6 code to Windows
Jan 13, 2011
24c4012
Fix service access to configuration path
Jan 18, 2011
9e8538e
Safer relative path management
Jan 18, 2011
e6445e1
Prefer to use static variables locally over global variables
arjendekorte Jan 18, 2011
b7b8d2f
Compilation fix (from Arjen de Korte)
Jan 19, 2011
bdad5ce
Fix "make install"
Jan 26, 2011
af675f9
upsmon does not fork in WIN32
Jan 26, 2011
be33cab
Clean-up : put compatibility macros in wincompat.h
Jan 26, 2011
65f33eb
Fix a warning
Jan 26, 2011
abba82a
More clean-up of wincompat
Jan 26, 2011
65c0d49
Merge from trunk
Jan 26, 2011
e26253a
Add strtok_r implementation and remove last "#define strtok_r"
Jan 27, 2011
a12d1bc
Cleaner warning fix in common.c
Jan 27, 2011
6be30a6
Disable Hotplug and udev support on Windows (useful when cross-compil…
Jan 27, 2011
a25153a
Fix warning in wincompat.c
Jan 27, 2011
2ab3691
Fix warning in upsmon.h
Jan 27, 2011
65bf10c
Fix possible race in notify.
Jan 27, 2011
4e8fc4f
Fix another race condition in notify.
Jan 27, 2011
162b862
Fix warnings in main.c
Jan 27, 2011
664d782
Porting isbmex driver
Jan 27, 2011
05201f4
Fix warnings in libshut.c.
Jan 28, 2011
90f3a14
Fix warning in mge-xml.c
Jan 28, 2011
493ba7d
upslog_with_errno does not call exit() nor return, ...
Jan 28, 2011
3f1844e
Fix compilation on buildbot
Jan 31, 2011
7084805
Fix "make distckeck-light" in Windows environment
Feb 1, 2011
6b6f05b
Fix "upsdrvctl start" path issue
Feb 2, 2011
21c167b
clean-up printf calls
Feb 2, 2011
412e5e4
Prefer upsdebugx to upslogx for low level output
Feb 7, 2011
f94fe36
small typo
Feb 7, 2011
f0b41e8
Add date to notification
Feb 9, 2011
5786823
Extent print_event capabilities
Feb 14, 2011
9be9876
Let nut.exe calls its children through their relatives paths
Feb 15, 2011
ba6a030
Add a Sleep before running upsmon...
Feb 22, 2011
a15f3f0
Correctly manage time-out in libusb
Feb 24, 2011
97f5a73
Add some console output when running in non-service mode
Mar 16, 2011
bd4f8b5
Fix a crash if configuration files are wrong in non-service mode
Mar 16, 2011
7ed18c1
Handle properly the "none" MODE in nut.conf
Mar 16, 2011
6142ecb
Windows scripts and support files for NUT Windows installer using WIX
Mar 16, 2011
edec90a
small typo
Mar 18, 2011
58d73ab
Remove DLL from the SVN repository.
Mar 18, 2011
0b26e1a
MinGW bin directory and MSYS bin directory are now configurable
Mar 18, 2011
cd63314
Remove regex2.dll dependency.
Mar 18, 2011
109d00f
Removed binary files (DLL & ibd) and Updated with icons and .bmp imag…
Mar 22, 2011
5cc3998
Correctly sized banner for Windows installer
Mar 22, 2011
47943fa
commit again a small typo
Mar 22, 2011
6d8b6b6
Add information on installation
Mar 23, 2011
08f7acd
Merge with trunk
Mar 28, 2011
e219af1
NUT is automatically started during system startup
Apr 6, 2011
408daa2
fix "upsdrvctl shutdown" command
Apr 6, 2011
be0c131
More generic wrong MODE handling + log same message as Linux version.
Apr 7, 2011
6511930
Update NUT version (by Praveen Kumar)
Apr 7, 2011
8dcbc1d
Makes the call to "wall" function non blocking, ...
May 2, 2011
ca40ae3
Add a call to "upsdrvctl shutdown" if POWERDOWNFLAG is set when servi…
May 3, 2011
8f7a019
Using named pipe for a better port of signals.
May 11, 2011
704ac40
forgot to change wait duration.
May 11, 2011
186b80a
[Installer] Include documentation in HTML format
May 16, 2011
eac694e
Add hints to configure SHUTDOWNCMD and POWERDOWNFLAG
May 17, 2011
4f8abbd
Add a check box for launching the automatic libUSB drivers installation
May 17, 2011
9b7c20a
Add source files and a note on how to compile the automatic driver in…
May 17, 2011
e9b33e1
This doesn't make it through the previous merge from trunk
May 20, 2011
62ad0bf
Remove useless empty directories
May 23, 2011
6f88e4d
nut_check_socketlib.m4 has been removed from trunk,
May 24, 2011
ccb488b
Add files in the project's root (README, INSTALL...)
May 24, 2011
604caa5
convert end of line to unix style
May 24, 2011
5de231d
merge from trunk [[SVN:2990]] to [[SVN:2997]]
May 25, 2011
3be1d87
Converting some files to Unix-style line endings
May 25, 2011
2e009f7
Fix Winsock2 testing and result publication
aquette May 25, 2011
9f4d349
Correct configuration value for usb_set_configuration
Jun 24, 2011
a6a1ab1
Merge from trunk [[SVN:3002]] to [[SVN:3057]]
Jun 24, 2011
4d95c13
Fix timeout being in seconds instead of milliseconds
Jun 29, 2011
029d1a5
Add WIN32 specific error case for detecting disconnection
Jun 29, 2011
f4a947d
Change timeout from seconds to milliseconds (from David Bolen)
Jun 30, 2011
0785ad8
Revert [[SVN:3108]]. Correct errno management should be enough
Jun 30, 2011
acfc00c
Make sure errno is set to an actual error code (thanks to David Bolen)
Jun 30, 2011
dcd40a0
Make sure serial functions set errno to an actual error code
Jun 30, 2011
1a72ce8
Add the error message associated with GetLastError to the error string.
Jun 30, 2011
fd32d6a
Add a notification to unplug and re-plug the device...
Jul 4, 2011
0dc2036
Change from libgnurx-0.dll to msys-regex-1.dll for the sake of coherency
Jul 4, 2011
b4c144e
The stock msys-regex-1.dll is crashing.
Aug 8, 2011
c9c39fd
This seems to be the correct way to set and reset DTR and RTS with Wi…
Aug 8, 2011
2940efd
Add some more hints on how to compile wdi-simple.exe
Aug 8, 2011
d38e09b
Print an error message when driver's installation has failed.
Aug 8, 2011
e134eaa
Correct handling of timeout
Aug 11, 2011
40688af
Merge from trunk [[SVN:3060]] to [[SVN:3318]]
Nov 15, 2011
2b86a2b
Don't leave one liner alone after if.
Nov 29, 2011
ebd377f
Fix blazer_ser driver (from Paul Fertser)
Nov 29, 2011
19b5dcf
Fix "make distcheck-light" (by Arnaud Quette)
Jan 5, 2012
fdc4851
Remove useless code
Jan 16, 2012
cecaae7
Fix porting of upssched
Jan 16, 2012
055b526
Fix commands with blank in their path
Jan 16, 2012
0b665ed
Cleaner initialization of variables
Jan 19, 2012
0c5ab76
Add filter_path function
Jan 19, 2012
0d4a0d7
Add getpwuid and getpass functions.
Jan 20, 2012
999c10a
Merge from trunk: [[SVN:3320]] to [[SVN:3435]]
Feb 9, 2012
b6c56d6
Cleaner regex addtion por apcsmart driver (by Arnaud Quette)
Feb 16, 2012
f252fb3
Better handling of ETIMEDOUT
Mar 8, 2012
24cd5ea
typo in comments
Mar 8, 2012
976509a
Add comments about EPROTO and EOVERFLOW
Mar 8, 2012
1fc249e
Clean up
Mar 8, 2012
7ddc2b8
Add #ifdef WIN32 for do_upsconf_args definition
Mar 16, 2012
56d1e01
Fix indentation
Mar 16, 2012
eafc048
Small correction to error messages.
Mar 26, 2012
66fb320
Merge from trunk: [[SVN:3438]] to [[SVN:3508]]
Mar 29, 2012
98ec457
Special case when sending signal 0
Mar 30, 2012
e2c4c42
This is needed for non WIN32 too.
Mar 30, 2012
5b31630
This doesn't make it through past merges.
Apr 3, 2012
7fd7d66
Conditional Makefile for WIN32
Apr 6, 2012
037377d
Fix conditional Makefile for WIN32
Apr 6, 2012
c6717d4
Make the message box of notify non-blocking
Apr 17, 2012
f6e673a
Completely skip termios.h with WIN32
Apr 23, 2012
5750e7a
Merge from trunk [[SVN:3511]] to [[SVN:3539]]
Apr 24, 2012
99cbdb6
echo a comment
Apr 26, 2012
a851d40
Add nut-scanner files and libupsclient-1.dll to the MSI installer
Apr 26, 2012
d0060d1
libupsclient-1.dll is needed in "bin" too
Apr 26, 2012
5dc75eb
Add libneon-27.dll and libnetsnmp-30.dll in bin directory
May 2, 2012
701d0a2
Update comments for IPv6 on Windows platforms
May 2, 2012
2bcf45b
Make sure upssched.conf is DOS compatible
May 2, 2012
6cfa65e
Add more DLLs in bin directory
May 2, 2012
ba5da43
Fix journal event truncation.
May 3, 2012
d84a3fe
Add an external wall-like application.
May 9, 2012
e3aaeb1
Add pipedebug program
May 11, 2012
e60fdb9
Add general Windows conditional (by Arnaud Quette)
May 14, 2012
667e76f
Keep same sockdebug's binary name for all OS.
May 14, 2012
8d77af8
Merge from trunk [[SVN:3541]] to [[SVN:3644]] (upgrade to 2.6.4)
Jun 4, 2012
03c1246
Porting genericups driver
Jul 23, 2012
a685770
Merge from trunk [[SVN:3645]] to [[SVN:3690]]
Jul 23, 2012
bdbdae9
Update installer script with oldmge-shut instead of newmge-shut
Jul 25, 2012
99b4c5d
Adding Windows 2000 and older support
Jul 27, 2012
1889102
Fix w32_setcomm and w32_getcomm for genericups
Jul 27, 2012
90dbbc7
Disconnect named pipe correctly
Aug 2, 2012
c333196
Fix UPS shutdown
Aug 6, 2012
3e5f31a
typo in comments
Aug 6, 2012
24ce9b8
Get rid of console event and PID management
Aug 8, 2012
8362af8
Merge from trunk [[SVN:3692]] to [[SVN:3713]] (upgrade to 2.6.5)
Aug 9, 2012
7c05e83
Fix Event Viewer regression
Sep 17, 2012
1cd81af
Fix upssched regression due to CVE-2012-2944
Sep 17, 2012
0c881ed
Fix communication with named pipe
Sep 18, 2012
a4de451
Typo in installer dialog box
Sep 18, 2012
3ad74f4
update error logs
Sep 18, 2012
7eff2b1
Fix invalid memory allocation (fix a crash at exit time in upsmon)
Oct 15, 2012
7012439
Automated Windows cross compilation
aquette Dec 9, 2012
622ec08
Fix MingGW-w64 compilation
aquette Dec 9, 2012
54cdcfb
Forgotten build and distribution rules
aquette Dec 9, 2012
d9af842
Some fixes after rebase
bohe-eaton Sep 26, 2013
ab80897
More changes after rebase
bohe-eaton Sep 26, 2013
a5aa9b4
Fix upsclient link after rebase
Sep 27, 2013
03e1162
Fix compilation on Windows
bohe-eaton Oct 3, 2013
1adb7fe
Remove useless link to intl which break compilation on Linux
bohe-eaton Oct 3, 2013
471179d
Update gitignore for Windows
bohe-eaton Oct 3, 2013
946c51c
Try to get rid of warnings
bohe-eaton Oct 3, 2013
46796b5
Fix weird difftime behavior
bohe-eaton Oct 4, 2013
119cf4f
Fix Linux compilation
bohe-eaton Oct 4, 2013
7efba41
Fix Linux compilation warning
bohe-eaton Oct 8, 2013
7ccf807
a2x: use --destination-dir
clepple Nov 13, 2013
eb9bd2e
windows_port: distribute win_shut_compat.h
clepple Nov 13, 2013
9519d87
windows_port: remove conflict markers from blazer_ser.c
clepple Nov 13, 2013
03df76f
Add basic Windows wait for launch process.
emilienkia-eaton Jan 13, 2014
8a914ae
Fix Windows driver starting model and add comments.
emilienkia-eaton Jan 13, 2014
c40e90b
Merge branch 'WaitForStartedDriver_WindowsPortWithBlazerCommon' into …
emilienkia-eaton Feb 20, 2014
fc94fc0
Fix "no OFF status in "ups.status" although UPS is switched off" and …
arnaudquette-eaton Feb 20, 2014
ce7f58c
Merge branch 'FixNoOffStatusMgeHid' into v2.6.5-5
emilienkia-eaton Feb 20, 2014
a874a77
Fix Windows Installer file list.
emilienkia-eaton Feb 28, 2014
c153bf9
Merge branch 'FixWindowsDistrib' into v2.6.5-5
emilienkia-eaton Feb 28, 2014
7627947
Use only NOTIFY_SYSLOG as default notify flag in upsmon for Windows.
emilienkia-eaton Mar 4, 2014
f8dd8f7
Update upsmon config to note that Windows only writes to syslog on Wi…
emilienkia-eaton Mar 4, 2014
05a5111
Add upsmon default flag for Windows notice in documentation.
emilienkia-eaton Mar 4, 2014
11b6a58
Merge branch 'WindowsNotifyFlagDefaultSyslogOnly' into WindowsPort-v2…
emilienkia-eaton Mar 4, 2014
3bd5557
Add Windows registry entry for NUT installation path.
emilienkia-eaton Mar 4, 2014
76228c9
Merge branch 'WindowsInstallPathRegistry' into WindowsPort-v2.6.5-6
emilienkia-eaton Mar 4, 2014
72f380c
Update Windows release version in doc.
emilienkia-eaton Mar 4, 2014
6d53cfe
Modify version in Windows installer description file.
emilienkia-eaton Mar 5, 2014
290ce6d
Modify version in configuration descriptor.
emilienkia-eaton Mar 5, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clients/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ upsmon
upsrw
upssched
.libs
*.exe
25 changes: 20 additions & 5 deletions clients/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ endif

bin_PROGRAMS = upsc upslog upsrw upscmd
dist_bin_SCRIPTS = upssched-cmd
if HAVE_WINDOWS_SOCKETS
sbin_PROGRAMS = upsmon upssched message
#TODO : port libnutclient
lib_LTLIBRARIES = libupsclient.la
else !HAVE_WINDOWS_SOCKETS
sbin_PROGRAMS = upsmon upssched
lib_LTLIBRARIES = libupsclient.la libnutclient.la
endif !HAVE_WINDOWS_SOCKETS
if WITH_DEV
include_HEADERS = upsclient.h ../include/parseconf.h nutclient.h
endif
Expand All @@ -33,6 +39,9 @@ upscmd_SOURCES = upscmd.c upsclient.h
upsrw_SOURCES = upsrw.c upsclient.h
upslog_SOURCES = upslog.c upsclient.h upslog.h
upsmon_SOURCES = upsmon.c upsmon.h upsclient.h
if HAVE_WINDOWS_SOCKETS
message_SOURCES = message.c
endif

upssched_SOURCES = upssched.c upssched.h
upssched_LDADD = ../common/libcommon.la ../common/libparseconf.la $(NETLIBS)
Expand All @@ -45,15 +54,21 @@ upsstats_cgi_SOURCES = upsstats.c upsclient.h status.h upsstats.h \
upsimagearg.h cgilib.c cgilib.h

# not LDADD.

# libupsclient version information
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
if HAVE_WINDOWS_SOCKETS
libupsclient_la_SOURCES = upsclient.c upsclient.h ../common/wincompat.c ../common/common.c
libupsclient_la_LIBADD = ../common/libparseconf.la -lws2_32
libupsclient_la_LDFLAGS = -version-info 3:1:0 -no-undefined
else !HAVE_WINDOWS_SOCKETS
libupsclient_la_SOURCES = upsclient.c upsclient.h
libupsclient_la_LIBADD = ../common/libparseconf.la
libupsclient_la_LDFLAGS = -version-info 3:1:0
endif !HAVE_WINDOWS_SOCKETS

if WITH_SSL
libupsclient_la_LIBADD += $(LIBSSL_LIBS)
endif

# libupsclient version information
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
libupsclient_la_LDFLAGS = -version-info 3:1:0

libnutclient_la_SOURCES = nutclient.h nutclient.cpp

10 changes: 10 additions & 0 deletions clients/message.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifdef WIN32
#include <windows.h>

int main(int args,char ** argv)
{
MessageBox(NULL,argv[1],"Network UPS Tools",MB_OK|MB_ICONEXCLAMATION|MB_SERVICE_NOTIFICATION);

return 0;
}
#endif
4 changes: 2 additions & 2 deletions clients/nutclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef WIN32
#include "nutclient.h"

#include <sstream>
Expand Down Expand Up @@ -1723,4 +1723,4 @@ void nutclient_execute_device_command(NUTCLIENT_t client, const char* dev, const

} /* extern "C" */


#endif
2 changes: 2 additions & 0 deletions clients/upsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
#include "common.h"
#include "nut_platform.h"

#ifndef WIN32
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#endif

#include "upsclient.h"

Expand Down
51 changes: 48 additions & 3 deletions clients/upsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,36 @@

#include "config.h" /* safe because it doesn't contain prototypes */

#ifndef WIN32
#ifdef HAVE_PTHREAD
/* this include is needed on AIX to have errno stored in thread local storage */
#include <pthread.h>
#endif
#endif

#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifndef WIN32
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#define SOCK_OPT_CAST
#else
#define SOCK_OPT_CAST (char *)
/* Those 2 files for support of getaddrinfo, getnameinfo and freeaddrinfo
on Windows 2000 and older versions */
#include <ws2tcpip.h>
#include <wspiapi.h>
/* This override network system calls to adapt to Windows specificity */
#define W32_NETWORK_CALL_OVERRIDE
#include "wincompat.h"
#undef W32_NETWORK_CALL_OVERRIDE
#endif

#include "upsclient.h"
#include "common.h"
Expand Down Expand Up @@ -840,8 +855,16 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, int port, int flags,stru
fd_set wfds;
int error;
socklen_t error_size;

#ifndef WIN32
long fd_flags;
#else
HANDLE event = NULL;
unsigned long argp;

WSADATA WSAdata;
WSAStartup(2,&WSAdata);
#endif
if (!ups) {
return -1;
}
Expand Down Expand Up @@ -900,7 +923,7 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, int port, int flags,stru
{
case EAFNOSUPPORT:
case EINVAL:
break;
break;
default:
ups->upserror = UPSCLI_ERR_SOCKFAILURE;
ups->syserrno = errno;
Expand All @@ -910,21 +933,38 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, int port, int flags,stru

/* non blocking connect */
if(timeout != NULL) {
#ifndef WIN32
fd_flags = fcntl(sock_fd, F_GETFL);
fd_flags |= O_NONBLOCK;
fcntl(sock_fd, F_SETFL, fd_flags);
}

#else
event = CreateEvent(NULL, /* Security */
FALSE, /* auto-reset */
FALSE, /* initial state */
NULL); /* no name */

/* Associate socket event to the socket via its Event object */
WSAEventSelect( sock_fd, event, FD_CONNECT );
CloseHandle(event);
}
#endif

while ((v = connect(sock_fd, ai->ai_addr, ai->ai_addrlen)) < 0) {
#ifndef WIN32
if(errno == EINPROGRESS) {
#else
if(errno == WSAEWOULDBLOCK) {
#endif
FD_ZERO(&wfds);
FD_SET(sock_fd, &wfds);
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);
SOCK_OPT_CAST&error,&error_size);
if( error == 0) {
/* connect successful */
v = 0;
Expand Down Expand Up @@ -960,9 +1000,14 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, int port, int flags,stru

/* switch back to blocking operation */
if(timeout != NULL) {
#ifndef WIN32
fd_flags = fcntl(sock_fd, F_GETFL);
fd_flags &= ~O_NONBLOCK;
fcntl(sock_fd, F_SETFL, fd_flags);
#else
argp = 0;
ioctlsocket(sock_fd,FIONBIO,&argp);
#endif
}

ups->fd = sock_fd;
Expand Down
4 changes: 4 additions & 0 deletions clients/upscmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
#include "common.h"
#include "nut_platform.h"

#ifndef WIN32
#include <pwd.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#else
#include "wincompat.h"
#endif

#include "upsclient.h"

Expand Down
16 changes: 16 additions & 0 deletions clients/upslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@
#include "timehead.h"
#include "upslog.h"

#ifdef WIN32
#include "wincompat.h"
#endif

static int port, reopen_flag = 0, exit_flag = 0;
static char *upsname, *hostname;
static UPSCONN_t ups;

static FILE *logfile;
static const char *logfn, *monhost;
#ifndef WIN32
static sigset_t nut_upslog_sigmask;
#endif
static char logbuffer[LARGEBUF], *logformat;

static flist_t *fhead = NULL;
Expand All @@ -67,6 +73,7 @@ static void reopen_log(void)
fatal_with_errno(EXIT_FAILURE, "could not reopen logfile %s", logfn);
}

#ifndef WIN32
static void set_reopen_flag(int sig)
{
reopen_flag = sig;
Expand All @@ -76,10 +83,12 @@ static void set_exit_flag(int sig)
{
exit_flag = sig;
}
#endif

/* handlers: reload on HUP, exit on INT/QUIT/TERM */
static void setup_signals(void)
{
#ifndef WIN32
struct sigaction sa;

sigemptyset(&nut_upslog_sigmask);
Expand All @@ -97,6 +106,7 @@ static void setup_signals(void)
fatal_with_errno(EXIT_FAILURE, "Can't install SIGQUIT handler");
if (sigaction(SIGTERM, &sa, NULL) < 0)
fatal_with_errno(EXIT_FAILURE, "Can't install SIGTERM handler");
#endif
}

static void help(const char *prog)
Expand Down Expand Up @@ -393,6 +403,9 @@ int main(int argc, char **argv)

case 'l':
logfn = optarg;
#ifdef WIN32
logfn = filter_path(optarg);
#endif
break;

case 'i':
Expand Down Expand Up @@ -430,6 +443,9 @@ int main(int argc, char **argv)
if (argc >= 3) {
monhost = argv[0];
logfn = argv[1];
#ifdef WIN32
logfn = filter_path(argv[1]);
#endif
interval = atoi(argv[2]);
}

Expand Down
Loading