8000 Base port to Windows by SeanCampbell · Pull Request #2810 · collectd/collectd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 30 commits into from
Jul 27, 2018
Merged

Base port to Windows #2810

merged 30 commits into from
Jul 27, 2018

Conversation

SeanCampbell
Copy link
Contributor

No description provided.

8000
@SeanCampbell SeanCampbell changed the title Base port to Windows [WiP] Base port to Windows Jun 8, 2018
@SeanCampbell SeanCampbell force-pushed the campbellsean-winport branch from a7afc59 to 36647db Compare June 8, 2018 00:23
@SeanCampbell
Copy link
Contributor Author

@igorpeshansky FYI
@tokkee Can you take a look? I tried to keep it small, but let me know if I should break this into smaller PRs.

@SeanCampbell SeanCampbell force-pushed the campbellsean-winport branch from 36647db to 6440b58 Compare June 8, 2018 02:56
@SeanCampbell SeanCampbell changed the title [WiP] Base port to Windows Base port to Windows Jun 8, 2018
@SeanCampbell SeanCampbell force-pushed the campbellsean-winport branch 3 times, most recently from 26baff2 to 0a726c9 Compare June 11, 2018 14:05
@SeanCampbell SeanCampbell force-pushed the campbellsean-winport branch from 0a726c9 to aab3f3f Compare June 11, 2018 14:06
Makefile.am Outdated
@@ -228,7 +254,7 @@ collectd_SOURCES = \


collectd_CFLAGS = $(AM_CFLAGS)
collectd_CPPFLAGS = $(AM_CPPFLAGS)
collectd_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
Copy link
Contributor

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.

10000

Copy link
Contributor Author

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.

if (recv(fd, buffer, sizeof(buffer),
MSG_PEEK
#ifndef WIN32
| MSG_DONTWAIT
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#include <pthread.h>

#ifdef WIN32
#undef ERROR
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#include <winsock2.h>
#else
#include <sys/socket.h>
#include <sys/un.h>
Copy link
Contributor

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.

Copy link
Contributor Author

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.

struct addrinfo ai_hints = {
.ai_family = AF_UNSPEC, .ai_flags = 0, .ai_socktype = SOCK_STREAM};
#ifdef AI_ADDRCONFIG
ai_hints.ai_flags = AI_ADDRCONFIG;
Copy link
Contributor

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.

Copy link
Contributor Author

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_);
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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 :)

Copy link
Contributor

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])
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

int err;
wVersionRequested = MAKEWORD(2, 2);

err = WSAStartup(wVersionRequested, &wsaData);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


err = WSAStartup(wVersionRequested, &wsaData); 10000
if (err != 0) {
printf("WSAStartup failed with error: %d\n", err);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@SeanCampbell
Copy link
Contributor Author

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.

@rubenk
Copy link
Contributor
rubenk commented Jun 13, 2018

Perhaps @mfournier has some ideas as well, he's more familiar with our CI infra.

@rubenk
Copy link
Contributor
rubenk commented Jun 13, 2018

Just curious, did you manage to build these changes with something like mingw on Fedora, or only on cygwin?

@SeanCampbell
Copy link
Contributor Author

I've only built it on Cygwin at this point.

build.sh Outdated
net_if \
poll \
recv \
regex \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is off

Copy link
Contributor Author

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,
Copy link
Contributor

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 []

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rubenk
Copy link
Contributor
rubenk commented Jun 14, 2018

@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.

@SeanCampbell
Copy link
Contributor Author

Sure thing, added that in.

Copy link
Member
@tokkee tokkee left a 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.
Copy link
Member

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.

Copy link
Contributor Author

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"
Copy link
Member

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?

Copy link
Contributor Author

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"],
Copy link
Member

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?

Copy link
Contributor Author

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.

#define MSG_DONTWAIT MSG_NONBLOCK
#endif

#if !HAVE_GETPWNAM_R
#ifdef WIN32
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@tokkee
Copy link
Member
tokkee commented Jun 29, 2018

👍 from me. @rubenk do you want to merge once you're happy?

@SeanCampbell
Copy link
Contributor Author

@rubenk Do you think any other changes are needed?

@tokkee
Copy link
Member
tokkee commented Jul 27, 2018

Since there were no further comments, I'll merge now.

Thank you for your work @SeanCampbell!

@tokkee tokkee merged commit df13592 into collectd:master Jul 27, 2018
@SeanCampbell SeanCampbell deleted the campbellsean-winport branch July 27, 2018 19:33
@rpv-tomsk
Copy link
Contributor

Hi!

Can you please fix the following warnings:

+ automake --add-missing --copy
Makefile.am:5: warning: pkgdatadir was already defined in condition TRUE, which includes condition BUILD_WIN32 ...
/usr/share/automake-1.15/am/header-vars.am: ... 'pkgdatadir' previously defined here
Makefile.am:6: warning: pkglibdir was already defined in condition TRUE, which includes condition BUILD_WIN32 ...
/usr/share/automake-1.15/am/header-vars.am: ... 'pkglibdir' previously defined here
+ autoconf

?

@SeanCampbell
Copy link
Contributor Author

Hi Pavel,

I opened a PR with the fix here: #2907

rpv-tomsk added a commit that referenced this pull request Oct 14, 2018
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
rpv-tomsk added a commit that referenced this pull request Oct 14, 2018
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.
@rpv-tomsk
Copy link
Contributor
rpv-tomsk commented Oct 14, 2018

@SeanCampbell

Hi, Sean!
I added some commits to fix some build issues, they revert some changes which was added in this PR.
Please check them and propose other solutions if they are needed.

Thanks!

make clean && ./build.sh && ./configure && make dist-gzip && ./version-gen.sh && make -s distcheck -j 5

rpv-tomsk added a commit that referenced this pull request Oct 14, 2018
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.
nmdayton pushed a commit to Stackdriver/collectd that referenced this pull request Jan 17, 2019
* 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.
nmdayton pushed a commit to Stackdriver/collectd that referenced this pull request Jan 18, 2019
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0