-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Base port to Windows #2810
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
Base port to Windows #2810
Conversation
a7afc59
to
36647db
Compare
@igorpeshansky FYI |
36647db
to
6440b58
Compare
26baff2
to
0a726c9
Compare
0a726c9
to
aab3f3f
Compare
Makefile.am
Outdated
@@ -228,7 +254,7 @@ collectd_SOURCES = \ | |||
|
|||
|
|||
collectd_CFLAGS = $(AM_CFLAGS) | |||
collectd_CPPFLAGS = $(AM_CPPFLAGS) | |||
collectd_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this variable do? if it's for libltdl, we don't use that anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I copied this over from an old commit and didn't realize it wasn't needed anymore. Removed.
src/daemon/common.c
Outdated
if (recv(fd, buffer, sizeof(buffer), | ||
MSG_PEEK | ||
#ifndef WIN32 | ||
| MSG_DONTWAIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks a bit ugly, how about defining MSG_DONTWAIT to 0 for win32 like
#ifdef WIN32
#define MSG_DONTWAIT 0
#endif
and then keeping the recv call unchanged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/daemon/plugin.h
Outdated
#include <pthread.h> | ||
|
||
#ifdef WIN32 | ||
#undef ERROR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment as to why you do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/libcollectdclient/client.c
Outdated
#include <winsock2.h> | ||
#else | ||
#include <sys/socket.h> | ||
#include <sys/un.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving these includes up will probably break some platform like OpenBSD. See 34471c0 for an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. Moved them down. gnulib_config.h needs to be before config.h, so I left the Windows includes at the top.
src/libcollectdclient/client.c
Outdated
struct addrinfo ai_hints = { | ||
.ai_family = AF_UNSPEC, .ai_flags = 0, .ai_socktype = SOCK_STREAM}; | ||
#ifdef AI_ADDRCONFIG | ||
ai_hints.ai_flags = AI_ADDRCONFIG; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you define AI_ADDRCONFIG to 0 if not previously defined? that would clean this up nicely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -60,7 +64,7 @@ int lcc_server_destroy(lcc_network_t *net, lcc_server_t *srv); | |||
|
|||
/* Configure servers */ | |||
int lcc_server_set_ttl(lcc_server_t *srv, uint8_t ttl); | |||
int lcc_server_set_interface(lcc_server_t *srv, char const *interface); | |||
int lcc_server_set_interface(lcc_server_t *srv, char const *interface_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it interface
shadows something? How about calling it iface instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
build.sh
Outdated
if [ -d "_gnulib" ]; then | ||
echo "Assuming that gnulib is already built, because _gnulib exists." | ||
else | ||
git clone git://git.savannah.gnu.org/gnulib.git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch, cloning a git repo into a git repo, I'm not sure how I feel about this yet ;-) Won't git submodules work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I hadn't heard of that before. I'll check this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works really nicely here; updated. Thanks for pointing this out.
build.sh
Outdated
strtok_r \ | ||
poll \ | ||
recv \ | ||
net_if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you sort this list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
build.sh
Outdated
&& aclocal -I /usr/share/aclocal \ | ||
&& $libtoolize --copy --force \ | ||
&& automake --add-missing --copy \ | ||
&& autoconf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there no autoreconf on cygwin that can replace the above 5 lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following how it builds it for other platforms, but autoreconf seems to work just as well and is simpler :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah indeed! We should probably just do that for all platforms then. Care to do a separate PR for that?
@@ -99,6 +99,10 @@ case $host_os in | |||
AC_DEFINE([KERNEL_SOLARIS], [1], [True if program is to be compiled for a Solaris kernel]) | |||
ac_system="Solaris" | |||
;; | |||
*mingw32*) | |||
AC_DEFINE([KERNEL_WIN32], [1], [True if program is to be compiled for a Windows kernel]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this define looks unused in this PR, is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it's not used in this PR, but I use it in some plugins I ported (in follow-up PRs). Would you prefer I wait to define it until it's used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. No problem, just leave it in.
src/daemon/cmd_windows.c
Outdated
int err; | ||
wVersionRequested = MAKEWORD(2, 2); | ||
|
||
err = WSAStartup(wVersionRequested, &wsaData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you combine this with line 31? We generally prefer C99-style declarations for newer code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/daemon/cmd_windows.c
Outdated
|
||
err = WSAStartup(wVersionRequested, &wsaData); 10000 | ||
if (err != 0) { | ||
printf("WSAStartup failed with error: %d\n", err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does windows have a stderr to log this to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this seems to work fine using ERROR as is the case with other platforms.
Thanks for checking this out and for all your suggestions. As far as CI, I'm not very familiar with the space, but I saw a few places that recommended AppVeyor as the Travis alternative for Windows, and it looks like it also has free CI for open source projects. |
Perhaps @mfournier has some ideas as well, he's more familiar with our CI infra. |
Just curious, did you manage to build these changes with something like mingw on Fedora, or only on cygwin? |
I've only built it on Cygwin at this point. |
build.sh
Outdated
net_if \ | ||
poll \ | ||
recv \ | ||
regex \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
configure.ac
Outdated
@@ -848,11 +854,17 @@ AC_CHECK_FUNCS([socket], | |||
[ | |||
AC_CHECK_LIB([socket], [socket], | |||
[socket_needs_socket="yes"], | |||
[AC_MSG_ERROR([cannot find socket() in libsocket])] | |||
[ | |||
AC_CHECK_LIB(gnu, rpl_socket, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please quote the arguments with []
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@SeanCampbell could you add a few lines of documentation on how to build this for Windows? Not sure what's the best location, probably the README. |
Sure thing, added that in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me but see a few comments.
I'm not super-happy about all the added conditionals but this is C, so what can you do? ;-)
README
Outdated
|
||
$ INSTALL_DIR="C:/some/other/install/directory" ./build.sh | ||
|
||
As of now, the only plugin tested to work on Windows is the `logfile' plugin. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is useful information but can easily go out of sync. We're also not yet tracking it for other OSes, but maybe we should. I'm wondering if we can have a good way to track and manage this information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
build.sh
Outdated
set -x | ||
echo "Installing collectd to ${INSTALL_DIR}." | ||
TOP_SRCDIR=$(pwd) | ||
MINGW_ROOT="/usr/x86_64-w64-mingw32/sys-root/mingw" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this path name valid universally? If not, can it be auto-detected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, looks like you can detect it.
configure.ac
Outdated
[AC_MSG_ERROR([cannot find nanosleep])] | ||
[ | ||
AC_CHECK_FUNCS([rpl_nanosleep], | ||
[nanosleep_needs_gnulib="yes"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be unused. Do we need it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is leftover from changes I patched in from kele's port, so it's not needed anymore.
src/daemon/common.c
Outdated
#define MSG_DONTWAIT MSG_NONBLOCK | ||
#endif | ||
|
||
#if !HAVE_GETPWNAM_R | ||
#ifdef WIN32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Putting this into an else branch seems cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
👍 from me. @rubenk do you want to merge once you're happy? |
@rubenk Do you think any other changes are needed? |
Since there were no further comments, I'll merge now. Thank you for your work @SeanCampbell! |
Hi! Can you please fix the following warnings:
? |
Hi Pavel, I opened a PR with the fix here: #2907 |
Change introduced in df13592 (#2810) This change causes error in 'master-aggregation' hook: ERROR: files left in build directory after distclean: ./liboconfig.la ./libcommon.la ./libmount.la ./libformat_json.la ./libheap.la ./libignorelist.la ./libavltree.la ./libformat_graphite.la ./liblatency.la ./liblookup.la ./libmetadata.la ./libcmds.la
Change introduced in df13592 (#2810) causes build failure on Solaris: src/libcollectdclient/server.c: In function ‘server_multicast_join’: src/libcollectdclient/server.c:103:9: error: unknown field ‘imr_address’ specified in initializer .imr_address.s_addr = INADDR_ANY, .imr_multiaddr.s_addr = sa->s_addr, ^ src/libcollectdclient/server.c:103:69: error: ‘struct sockaddr_in’ has no member named ‘S_un’ .imr_address.s_addr = INADDR_ANY, .imr_multiaddr.s_addr = sa->s_addr, ^ src/libcollectdclient/server.c:102:27: error: missing braces around initializer [-Werror=missing-braces] struct ip_mreq mreq = { ^ src/libcollectdclient/server.c:102:27: note: (near initialization for ‘mreq’) Removed this change as not related to WIN32 platform.
Hi, Sean! Thanks!
|
Change introduced in df13592 (#2810) causes build failure on Solaris: src/libcollectdclient/server.c: In function ‘server_multicast_join’: src/libcollectdclient/server.c:103:9: error: unknown field ‘imr_address’ specified in initializer .imr_address.s_addr = INADDR_ANY, .imr_multiaddr.s_addr = sa->s_addr, ^ src/libcollectdclient/server.c:103:69: error: ‘struct sockaddr_in’ has no member named ‘S_un’ .imr_address.s_addr = INADDR_ANY, .imr_multiaddr.s_addr = sa->s_addr, ^ src/libcollectdclient/server.c:102:27: error: missing braces around initializer [-Werror=missing-braces] struct ip_mreq mreq = { ^ src/libcollectdclient/server.c:102:27: note: (near initialization for ‘mreq’) Removed this change as not related to WIN32 platform.
* Update configure.ac / Makefile.am to build for Windows using Cygwin. * Update build.sh to build for Windows. * Base port of the daemon. * Include gnulib as a submodule.
* Update configure.ac / Makefile.am to build for Windows using Cygwin. * Update build.sh to build for Windows. * Base port of the daemon. * Include gnulib as a submodule.
No description provided.