[libvirt PATCH 00/32] the gnulib saga: revenge of the gnus

We currently have 25 gnulib modules in bootstrap.conf and after this series we're down to 7. Except this is a lie, because we've been failing to count the indirect dependencies, so after this series, libvirt is actually pulling in 41 modules. Still, that's better than the 115 modules we indirectly use before this series :-) I have actually eliminated the remaining modules too, but I'm having trouble with the event loop impl in the RPC client on Windows that I'm still debugging. I'll poist the remaining patches once I've figured out that problem. Daniel P. Berrangé (32): tests: stop setting $SHELL env variable util: add a virArchFromHost() impl for Windows util: add API for reading password from the console src: remove usage of strchrnul function build: generate configmake.h in root directory util: use getgrouplist() directly instead of mgetgroups tools: replace wcwidth() with g_unichar_* APIs src: remove unused sys/utsname.h includes util: explicitly include windows.h storage: remove use of stat-time.h headers src: implement APIs for passing FDs over UNIX sockets rpc: conditionalize signal handling src: only import sys/uio.h when journald is built src: replace mkdir() with g_mkdir() m4: disable polkit build on Windows util: conditionalize more of virCommand on WIN32 src: remove all traces of Cygwin support util: conditionalize virProcess APIs on Windows src: conditionalize use of net/if.h configure: add check for sys/ioctl.h src: conditionalize use of S_ISSOCK macro configure: request system specific extensions src: stop using O_DIRECTORY in resctrl src: ensure O_CLOEXEC is defined on Windows src: conditionalize use of F_DUPFD_CLOEXEC src: conditionalize use of O_DIRECT src: conditionalize use of O_BINARY src: conditionalize use of chown & stat constants src: convert all code to use virsocket.h tests: conditionalize use of SIGPIPE src: conditionalize EAI_ADDRFAMILY bootstrap: remove 18 more gnulib modules Makefile.am | 44 ++++++++ bootstrap.conf | 36 ------ build-aux/syntax-check.mk | 2 +- configure.ac | 35 +++--- m4/virt-compile-pie.m4 | 2 +- m4/virt-polkit.m4 | 4 + m4/virt-win-common.m4 | 8 +- m4/virt-win-cygwin.m4 | 32 ------ m4/virt-win-symbols.m4 | 4 +- m4/virt-win-windres.m4 | 4 +- m4/virt-xdr.m4 | 9 +- po/POTFILES.in | 1 - src/Makefile.am | 8 +- src/admin/Makefile.inc.am | 1 - src/conf/network_conf.c | 2 - src/esx/esx_util.c | 3 +- src/esx/esx_util.h | 1 - src/internal.h | 10 ++ src/libvirt-domain.c | 2 + src/libvirt.c | 9 +- src/libvirt_private.syms | 6 + src/libxl/libxl_conf.c | 2 - src/locking/Makefile.inc.am | 1 - src/logging/Makefile.inc.am | 1 - src/lxc/lxc_controller.c | 4 +- src/lxc/lxc_driver.c | 4 +- src/nwfilter/nwfilter_dhcpsnoop.c | 3 - src/nwfilter/nwfilter_learnipaddr.c | 4 +- src/openvz/openvz_conf.c | 4 +- src/qemu/qemu_agent.c | 4 +- src/qemu/qemu_conf.c | 3 +- src/qemu/qemu_driver.c | 3 +- src/qemu/qemu_interface.c | 4 +- src/qemu/qemu_migration.c | 3 +- src/qemu/qemu_monitor.c | 3 +- src/qemu/qemu_monitor_json.c | 4 +- src/remote/qemu_protocol.x | 1 - src/remote/remote_protocol.x | 2 +- src/rpc/Makefile.inc.am | 3 - src/rpc/genprotocol.pl | 2 +- src/rpc/virnetclient.c | 33 ++++-- src/rpc/virnetdaemon.c | 35 +++++- src/rpc/virnetdaemon.h | 4 + src/rpc/virnetprotocol.x | 2 +- src/rpc/virnetsocket.c | 42 ++++--- src/security/security_dac.c | 4 + src/security/security_manager.c | 2 + src/security/security_selinux.c | 16 +-- src/storage/storage_util.c | 24 +++- src/util/virarch.c | 52 ++++++++- src/util/virarptable.c | 1 - src/util/vircgroup.c | 10 +- src/util/vircommand.c | 165 +++++++++++++++++----------- src/util/virdnsmasq.c | 9 +- src/util/virfdstream.c | 13 +-- src/util/virfile.c | 58 ++++++++-- src/util/virhostcpu.c | 1 - src/util/virhostmem.c | 1 - src/util/virlog.c | 8 +- src/util/virnetdev.c | 1 - src/util/virnetdev.h | 4 +- src/util/virnetdevbridge.c | 8 +- src/util/virnetdevip.c | 4 +- src/util/virnetdevmacvlan.c | 3 +- src/util/virnetdevtap.c | 4 +- src/util/virnetdevvportprofile.c | 3 +- src/util/virnetlink.c | 3 +- src/util/virprocess.c | 103 +++++++++++++---- src/util/virresctrl.c | 2 +- src/util/virsocket.c | 142 +++++++++++++++++++++++- src/util/virsocket.h | 6 +- src/util/virsocketaddr.c | 2 - src/util/virsocketaddr.h | 20 +--- src/util/virsysinfo.c | 14 ++- src/util/virsystemd.c | 9 +- src/util/virutil.c | 76 +++++++++---- src/util/virutil.h | 2 + src/util/virxdrdefs.h | 12 +- src/vbox/vbox_MSCOMGlue.c | 6 +- tests/Makefile.am | 3 - tests/libxlmock.c | 2 +- tests/nsstest.c | 3 +- tests/testutils.c | 2 +- tests/virauthconfigtest.c | 2 + tests/virkeyfiletest.c | 2 + tests/virlockspacetest.c | 4 +- tests/virnetmessagetest.c | 2 + tests/virnetsockettest.c | 3 +- tests/virnettlscontexttest.c | 3 +- tests/virnettlshelpers.c | 1 - tests/virnettlssessiontest.c | 3 +- tests/virportallocatormock.c | 5 +- tests/virtestmock.c | 9 +- tests/virtimetest.c | 2 + tests/viruritest.c | 2 + tests/vshtabletest.c | 8 +- tools/nss/libvirt_nss.c | 7 +- tools/virsh-domain.c | 46 +++++++- tools/virt-login-shell.c | 6 +- tools/vsh-table.c | 2 +- tools/vsh.c | 12 +- 101 files changed, 859 insertions(+), 452 deletions(-) delete mode 100644 m4/virt-win-cygwin.m4 -- 2.24.1

None of the tests appear to reference a SHELL env variable explicitly and they all succeeed when it is not set. This eliminates the only use of the gnulib posix-shell module. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- tests/Makefile.am | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index f957c7d1ba..19705c6b76 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -16,8 +16,6 @@ ## License along with this library. If not, see ## <http://www.gnu.org/licenses/>. -SHELL = $(PREFERABLY_POSIX_SHELL) - AM_CPPFLAGS = \ -I$(top_builddir) -I$(top_srcdir) \ -I$(top_builddir)/gnulib/lib -I$(top_srcdir)/gnulib/lib \ @@ -484,7 +482,6 @@ TESTS_ENVIRONMENT = \ abs_top_srcdir="$(abs_top_srcdir)" \ abs_builddir="$(abs_builddir)" \ abs_srcdir="$(abs_srcdir)" \ - SHELL="$(SHELL)" \ LIBVIRT_AUTOSTART=0 \ LC_ALL=C \ VIR_TEST_EXPENSIVE=$(VIR_TEST_EXPENSIVE) \ -- 2.24.1

On Thu, Jan 23, 2020 at 11:42:54AM +0000, Daniel P. Berrangé wrote:
None of the tests appear to reference a SHELL env variable explicitly and they all succeeed when it is not set. This eliminates the only use of the gnulib posix-shell module.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- tests/Makefile.am | 3 --- 1 file changed, 3 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Instead of relying on GNULIb's uname() impl, directly use the Windows API for determining CPU architecture. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virarch.c | 52 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/util/virarch.c b/src/util/virarch.c index b132e178c3..553d21c97c 100644 --- a/src/util/virarch.c +++ b/src/util/virarch.c @@ -21,7 +21,12 @@ #include <config.h> -#include <sys/utsname.h> +#ifdef WIN32 +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +#else +# include <sys/utsname.h> +#endif #include "virlog.h" #include "virarch.h" @@ -154,6 +159,50 @@ virArch virArchFromString(const char *archstr) * uname 'machine' field, since this will canonicalize * architecture names like 'amd64' into 'x86_64'. */ +#ifdef WIN32 + +/* + * Missing in ming64 headers 6.0.0, but defined as '12' in: + * + * https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-... + */ +# ifndef PROCESSOR_ARCHITECTURE_ARM64 +# define PROCESSOR_ARCHITECTURE_ARM64 12 +# endif + +virArch virArchFromHost(void) +{ + SYSTEM_INFO info; + + GetSystemInfo(&info); + + switch (info.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: + return VIR_ARCH_X86_64; + case PROCESSOR_ARCHITECTURE_IA64: + return VIR_ARCH_ITANIUM; + case PROCESSOR_ARCHITECTURE_INTEL: + case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64: + return VIR_ARCH_I686; + case PROCESSOR_ARCHITECTURE_MIPS: + return VIR_ARCH_MIPS; + case PROCESSOR_ARCHITECTURE_ALPHA: + return VIR_ARCH_ALPHA; + case PROCESSOR_ARCHITECTURE_PPC: + return VIR_ARCH_PPC; + case PROCESSOR_ARCHITECTURE_SHX: + return VIR_ARCH_SH4; + case PROCESSOR_ARCHITECTURE_ARM: + return VIR_ARCH_ARMV7L; + case PROCESSOR_ARCHITECTURE_ARM64: + return VIR_ARCH_AARCH64; + default: + VIR_WARN("Unknown host arch %d, report to libvir-list@redhat.com", + info.wProcessorArchitecture); + return VIR_ARCH_NONE; + } +} +#else /* !WIN32 */ virArch virArchFromHost(void) { struct utsname ut; @@ -184,3 +233,4 @@ virArch virArchFromHost(void) return arch; } +#endif /* !WIN32 */ -- 2.24.1

On Thu, Jan 23, 2020 at 11:42:55AM +0000, Daniel P. Berrangé wrote:
Instead of relying on GNULIb's uname() impl, directly use the Windows API for determining CPU architecture.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virarch.c | 52 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/src/util/virarch.c b/src/util/virarch.c index b132e178c3..553d21c97c 100644 --- a/src/util/virarch.c +++ b/src/util/virarch.c @@ -154,6 +159,50 @@ virArch virArchFromString(const char *archstr) * uname 'machine' field, since this will canonicalize * architecture names like 'amd64' into 'x86_64'. */ +#ifdef WIN32 + +/* + * Missing in ming64 headers 6.0.0, but defined as '12' in: + * + * https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-... + */ +# ifndef PROCESSOR_ARCHITECTURE_ARM64 +# define PROCESSOR_ARCHITECTURE_ARM64 12 +# endif + +virArch virArchFromHost(void) +{ + SYSTEM_INFO info; + + GetSystemInfo(&info); + + switch (info.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: + return VIR_ARCH_X86_64; + case PROCESSOR_ARCHITECTURE_IA64: + return VIR_ARCH_ITANIUM; + case PROCESSOR_ARCHITECTURE_INTEL: + case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64: + return VIR_ARCH_I686; + case PROCESSOR_ARCHITECTURE_MIPS: + return VIR_ARCH_MIPS; + case PROCESSOR_ARCHITECTURE_ALPHA: + return VIR_ARCH_ALPHA; + case PROCESSOR_ARCHITECTURE_PPC: + return VIR_ARCH_PPC; + case PROCESSOR_ARCHITECTURE_SHX: + return VIR_ARCH_SH4; + case PROCESSOR_ARCHITECTURE_ARM: + return VIR_ARCH_ARMV7L; + case PROCESSOR_ARCHITECTURE_ARM64: + return VIR_ARCH_AARCH64; + default: + VIR_WARN("Unknown host arch %d, report to libvir-list@redhat.com",
Just a tiny nit, I would wrap %d with single quotes to make it obvious it's dynamic part of the error message. Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

This imports a simpler version of GNULIB's getpass() function impl for Windows. Note that GNULIB's impl was buggy as it returned a static string on UNIX, and a heap allocated string on Windows. This new impl always heap allocates. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/libvirt.c | 9 ++++----- src/libvirt_private.syms | 1 + src/util/virutil.c | 29 +++++++++++++++++++++++++++++ src/util/virutil.h | 2 ++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index f1ffc97261..353b3a55d8 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -30,7 +30,6 @@ #include <libxml/parser.h> #include <libxml/xpath.h> -#include "getpass.h" #ifdef WITH_CURL # include <curl/curl.h> @@ -157,9 +156,9 @@ virConnectAuthCallbackDefault(virConnectCredentialPtr cred, if (fflush(stdout) != 0) return -1; - bufptr = getpass(""); - if (!bufptr) - return -1; + bufptr = virGetPassword(); + if (STREQ(bufptr, "")) + VIR_FREE(bufptr); break; default: @@ -167,7 +166,7 @@ virConnectAuthCallbackDefault(virConnectCredentialPtr cred, } if (cred[i].type != VIR_CRED_EXTERNAL) { - cred[i].result = g_strdup(STREQ(bufptr, "") && cred[i].defresult ? cred[i].defresult : bufptr); + cred[i].result = bufptr ? bufptr : g_strdup(cred[i].defresult ? cred[i].defresult : ""); cred[i].resultlen = strlen(cred[i].result); } } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b63feb4054..fa046051a3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3371,6 +3371,7 @@ virGetGroupList; virGetGroupName; virGetHostname; virGetHostnameQuiet; +virGetPassword; virGetSelfLastChanged; virGetSystemPageSize; virGetSystemPageSizeKB; diff --git a/src/util/virutil.c b/src/util/virutil.c index 7c2c5a78f6..87ca16c088 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -28,6 +28,10 @@ #include <poll.h> #include <sys/stat.h> +#ifdef WIN32 +# include <conio.h> +#endif /* WIN32 */ + #ifdef MAJOR_IN_MKDEV # include <sys/mkdev.h> #elif MAJOR_IN_SYSMACROS @@ -1731,3 +1735,28 @@ virHostGetDRMRenderNode(void) VIR_DIR_CLOSE(driDir); return ret; } + +/* + * Get a password from the console input stream. + * The caller must free the returned password. + * + * Returns: the password, or NULL + */ +char *virGetPassword(void) +{ +#ifdef WIN32 + GString *pw = g_string_new(""); + + while (1) { + char c = _getch(); + if (c == '\r') + break; + + g_string_append_c(pw, c); + } + + return g_string_free(pw, FALSE); +#else /* !WIN32 */ + return g_strdup(getpass("")); +#endif /* ! WIN32 */ +} diff --git a/src/util/virutil.h b/src/util/virutil.h index 1a6ae1787a..62a53f34cb 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -159,3 +159,5 @@ char *virHostGetDRMRenderNode(void) G_GNUC_NO_INLINE; */ #define VIR_ASSIGN_IS_OVERFLOW(lvalue, rvalue) \ (((lvalue) = (rvalue)) != (rvalue)) + +char *virGetPassword(void); -- 2.24.1

On Thu, Jan 23, 2020 at 11:42:56AM +0000, Daniel P. Berrangé wrote:
This imports a simpler version of GNULIB's getpass() function impl for Windows. Note that GNULIB's impl was buggy as it returned a static string on UNIX, and a heap allocated string on Windows. This new impl always heap allocates.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/libvirt.c | 9 ++++----- src/libvirt_private.syms | 1 + src/util/virutil.c | 29 +++++++++++++++++++++++++++++ src/util/virutil.h | 2 ++ 4 files changed, 36 insertions(+), 5 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

The strchrnul function doesn't exist on Windows and rather than attempt to implement it, it is simpler to just avoid its usage, as any callers are easily adapted. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/openvz/openvz_conf.c | 4 +++- src/security/security_selinux.c | 16 ++++++++-------- src/util/vircgroup.c | 10 +++++++--- src/util/virdnsmasq.c | 9 +++++++-- src/util/virsysinfo.c | 14 ++++++++------ tests/testutils.c | 2 +- 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index e9ee1a7bf4..1ec42c1d93 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -245,7 +245,9 @@ openvzReadNetworkConf(virDomainDefPtr def, /*parse string*/ do { - char *next = strchrnul(p, ','); + char *next = strchr(p, ','); + if (!next) + next = strchr(p, '\0'); if (STRPREFIX(p, "ifname=")) { /* skip in libvirt */ } else if (STRPREFIX(p, "host_ifname=")) { diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 21279e7622..2fd9c113f3 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -721,14 +721,14 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) goto error; } - ptr = strchrnul(data->domain_context, '\n'); - if (ptr && *ptr == '\n') { + ptr = strchr(data->domain_context, '\n'); + if (ptr) { *ptr = '\0'; ptr++; if (*ptr != '\0') { data->alt_domain_context = g_strdup(ptr); - ptr = strchrnul(data->alt_domain_context, '\n'); - if (ptr && *ptr == '\n') + ptr = strchr(data->alt_domain_context, '\n'); + if (ptr) *ptr = '\0'; } } @@ -743,12 +743,12 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) goto error; } - ptr = strchrnul(data->file_context, '\n'); - if (ptr && *ptr == '\n') { + ptr = strchr(data->file_context, '\n'); + if (ptr) { *ptr = '\0'; data->content_context = g_strdup(ptr + 1); - ptr = strchrnul(data->content_context, '\n'); - if (ptr && *ptr == '\n') + ptr = strchr(data->content_context, '\n'); + if (ptr) *ptr = '\0'; } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 87ed9f4565..4aa1918c1b 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -174,9 +174,13 @@ virCgroupPartitionNeedsEscaping(const char *path) if (STRPREFIX(line, "#subsys_name")) continue; - tmp = strchrnul(line, ' '); - *tmp = '\0'; - len = tmp - line; + tmp = strchr(line, ' '); + if (tmp) { + *tmp = '\0'; + len = tmp - line; + } else { + len = strlen(line); + } if (STRPREFIX(path, line) && path[len] == '.') { diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 2555f3110f..adc6f96bb6 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -640,6 +640,7 @@ dnsmasqCapsSet(dnsmasqCapsPtr caps, static int dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const char *buf) { + int len; const char *p; caps->noRefresh = true; @@ -675,10 +676,14 @@ dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const char *buf) return 0; fail: - p = strchrnul(buf, '\n'); + p = strchr(buf, '\n'); + if (!p) + len = strlen(buf); + else + len = p - buf; virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse %s version number in '%.*s'"), - caps->binaryPath, (int) (p - buf), buf); + caps->binaryPath, len, buf); return -1; } diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index c526c0322f..4cc4523be0 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -460,18 +460,20 @@ virSysinfoReadARM(void) return g_steal_pointer(&ret); } -static char * +static const char * virSysinfoParseS390Delimited(const char *base, const char *name, char **value, char delim1, char delim2) { const char *start; - char *end; + const char *end; if (delim1 != delim2 && (start = strstr(base, name)) && (start = strchr(start, delim1))) { start += 1; - end = strchrnul(start, delim2); + end = strchr(start, delim2); + if (!end) + end = start + strlen(start); virSkipSpaces(&start); *value = g_strndup(start, end - start); virTrimSpaces(*value, NULL); @@ -480,7 +482,7 @@ virSysinfoParseS390Delimited(const char *base, const char *name, char **value, return NULL; } -static char * +static const char * virSysinfoParseS390Line(const char *base, const char *name, char **value) { return virSysinfoParseS390Delimited(base, name, value, ':', '\n'); @@ -521,7 +523,7 @@ virSysinfoParseS390System(const char *base, virSysinfoSystemDefPtr *sysdef) static int virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret) { - char *tmp_base; + const char *tmp_base; char *manufacturer = NULL; char *procline = NULL; char *ncpu = NULL; @@ -555,7 +557,7 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret) } /* now, for each processor found, extract the frequency information */ - tmp_base = (char *) base; + tmp_base = base; while ((tmp_base = strstr(tmp_base, "cpu number")) && (tmp_base = virSysinfoParseS390Line(tmp_base, "cpu number", &ncpu))) { diff --git a/tests/testutils.c b/tests/testutils.c index b490609e36..248f9ee8be 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1200,7 +1200,7 @@ virTestCounterReset(const char *prefix) virtTestCounter = 0; ignore_value(virStrcpyStatic(virtTestCounterStr, prefix)); - virtTestCounterPrefixEndOffset = strchrnul(virtTestCounterStr, '\0'); + virtTestCounterPrefixEndOffset = virtTestCounterStr + strlen(virtTestCounterStr); } -- 2.24.1

On Thu, Jan 23, 2020 at 11:42:57AM +0000, Daniel P. Berrangé wrote:
The strchrnul function doesn't exist on Windows and rather than attempt to implement it, it is simpler to just avoid its usage, as any callers are easily adapted.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/openvz/openvz_conf.c | 4 +++- src/security/security_selinux.c | 16 ++++++++-------- src/util/vircgroup.c | 10 +++++++--- src/util/virdnsmasq.c | 9 +++++++-- src/util/virsysinfo.c | 14 ++++++++------ tests/testutils.c | 2 +- 6 files changed, 34 insertions(+), 21 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Currently we rely on gnulib creating configmake.h, but we can easily create it ourselves instead. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- Makefile.am | 44 ++++++++++++++++++++++++++++++++++++++++ configure.ac | 12 +++++------ tools/nss/libvirt_nss.c | 7 +------ tools/virt-login-shell.c | 6 +----- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/Makefile.am b/Makefile.am index 8a8eecb697..485b281a03 100644 --- a/Makefile.am +++ b/Makefile.am @@ -129,6 +129,9 @@ clean-cov: MAINTAINERCLEANFILES = .git-module-status +BUILT_SOURCES = configmake.h +CLEANFILES = configmake.h + distclean-local: clean-GNUmakefile clean-GNUmakefile: test '$(srcdir)' = . || rm -f $(top_builddir)/GNUmakefile @@ -154,3 +157,44 @@ gen-AUTHORS: ci-%: $(MAKE) -C $(srcdir)/ci/ $@ + +# Listed in the same order as the GNU makefile conventions, and +# provided by autoconf 2.59c+ or 2.70. +# The Automake-defined pkg* macros are appended, in the order +# listed in the Automake 1.10a+ documentation. +configmake.h: Makefile + $(AM_V_GEN)rm -f $@-t && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + echo '#if HAVE_WINSOCK2_H'; \ + echo '# include <winsock2.h> /* avoid mingw pollution on DATADIR */'; \ + echo '#endif'; \ + echo '#define PREFIX "$(prefix)"'; \ + echo '#define EXEC_PREFIX "$(exec_prefix)"'; \ + echo '#define BINDIR "$(bindir)"'; \ + echo '#define SBINDIR "$(sbindir)"'; \ + echo '#define LIBEXECDIR "$(libexecdir)"'; \ + echo '#define DATAROOTDIR "$(datarootdir)"'; \ + echo '#define DATADIR "$(datadir)"'; \ + echo '#define SYSCONFDIR "$(sysconfdir)"'; \ + echo '#define SHAREDSTATEDIR "$(sharedstatedir)"'; \ + echo '#define LOCALSTATEDIR "$(localstatedir)"'; \ + echo '#define RUNSTATEDIR "$(runstatedir)"'; \ + echo '#define INCLUDEDIR "$(includedir)"'; \ + echo '#define OLDINCLUDEDIR "$(oldincludedir)"'; \ + echo '#define DOCDIR "$(docdir)"'; \ + echo '#define INFODIR "$(infodir)"'; \ + echo '#define HTMLDIR "$(htmldir)"'; \ + echo '#define DVIDIR "$(dvidir)"'; \ + echo '#define PDFDIR "$(pdfdir)"'; \ + echo '#define PSDIR "$(psdir)"'; \ + echo '#define LIBDIR "$(libdir)"'; \ + echo '#define LISPDIR "$(lispdir)"'; \ + echo '#define LOCALEDIR "$(localedir)"'; \ + echo '#define MANDIR "$(mandir)"'; \ + echo '#define MANEXT "$(manext)"'; \ + echo '#define PKGDATADIR "$(pkgdatadir)"'; \ + echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \ + echo '#define PKGLIBDIR "$(pkglibdir)"'; \ + echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \ + } | sed '/""/d' > $@-t && \ + mv -f $@-t $@ diff --git a/configure.ac b/configure.ac index 4bdf38ec15..f0d79b95d4 100644 --- a/configure.ac +++ b/configure.ac @@ -132,14 +132,12 @@ AC_PROG_CPP dnl autoconf 2.70 adds a --runstatedir option so that downstreams dnl can point to /run instead of the historic /var/run, but dnl autoconf hasn't had a release since 2012. -dnl -dnl gnulib sets configmake.h to include runstatedir, but sets -dnl it to $localstatedir/run if $runstatedir env var is not set -dnl which is useless for apps that need to use /run without -dnl waiting for autoconf 2.70 -dnl +if test "x$runstatedir" = x; then + AC_SUBST([runstatedir], ['${localstatedir}/run']) +fi + dnl we introduce --with-runstatedir and then overwrite the -dnl value of $runstatedir so gnulib's configmake.h becomes useful +dnl value of $runstatedir so configmake.h is more useful AC_ARG_WITH( [runstatedir], [AS_HELP_STRING( diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index 6e332f7578..3b89f72742 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -41,12 +41,7 @@ # include <nsswitch.h> #endif -/* - * This gnulib files is used for its macros only, - * so doesn't introduce a link time dep, which we - * must avoid - */ -#include "gnulib/lib/configmake.h" +#include "configmake.h" #include "libvirt_nss_leases.h" diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c index cf4a249f0a..25449f972d 100644 --- a/tools/virt-login-shell.c +++ b/tools/virt-login-shell.c @@ -28,11 +28,7 @@ #include <errno.h> #include <string.h> -/* - * These gnulib files are used for their macros only, - * so don't introduce a link time dep, which we must avoid - */ -#include "gnulib/lib/configmake.h" +#include "configmake.h" #define VIR_INT64_STR_BUFLEN 21 -- 2.24.1

On Thu, Jan 23, 2020 at 11:42:58AM +0000, Daniel P. Berrangé wrote:
Currently we rely on gnulib creating configmake.h, but we can easily create it ourselves instead.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- Makefile.am | 44 ++++++++++++++++++++++++++++++++++++++++ configure.ac | 12 +++++------ tools/nss/libvirt_nss.c | 7 +------ tools/virt-login-shell.c | 6 +----- 4 files changed, 51 insertions(+), 18 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

On Thu, Jan 23, 2020 at 11:42:58AM +0000, Daniel P. Berrangé wrote:
Currently we rely on gnulib creating configmake.h, but we can easily create it ourselves instead.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- Makefile.am | 44 ++++++++++++++++++++++++++++++++++++++++ configure.ac | 12 +++++------ tools/nss/libvirt_nss.c | 7 +------ tools/virt-login-shell.c | 6 +----- 4 files changed, 51 insertions(+), 18 deletions(-)
diff --git a/Makefile.am b/Makefile.am index 8a8eecb697..485b281a03 100644 --- a/Makefile.am +++ b/Makefile.am @@ -129,6 +129,9 @@ clean-cov:
MAINTAINERCLEANFILES = .git-module-status
+BUILT_SOURCES = configmake.h +CLEANFILES = configmake.h + distclean-local: clean-GNUmakefile clean-GNUmakefile: test '$(srcdir)' = . || rm -f $(top_builddir)/GNUmakefile @@ -154,3 +157,44 @@ gen-AUTHORS:
ci-%: $(MAKE) -C $(srcdir)/ci/ $@ + +# Listed in the same order as the GNU makefile conventions, and +# provided by autoconf 2.59c+ or 2.70. +# The Automake-defined pkg* macros are appended, in the order +# listed in the Automake 1.10a+ documentation. +configmake.h: Makefile + $(AM_V_GEN)rm -f $@-t && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + echo '#if HAVE_WINSOCK2_H'; \
This needs changing to "#if WIN32" since we're not going to explicitly check for windows headers in configure once we drop gnulib. I'll make this trivial change locally.
+ echo '# include <winsock2.h> /* avoid mingw pollution on DATADIR */'; \ + echo '#endif'; \ + echo '#define PREFIX "$(prefix)"'; \ + echo '#define EXEC_PREFIX "$(exec_prefix)"'; \ + echo '#define BINDIR "$(bindir)"'; \ + echo '#define SBINDIR "$(sbindir)"'; \ + echo '#define LIBEXECDIR "$(libexecdir)"'; \ + echo '#define DATAROOTDIR "$(datarootdir)"'; \ + echo '#define DATADIR "$(datadir)"'; \ + echo '#define SYSCONFDIR "$(sysconfdir)"'; \ + echo '#define SHAREDSTATEDIR "$(sharedstatedir)"'; \ + echo '#define LOCALSTATEDIR "$(localstatedir)"'; \ + echo '#define RUNSTATEDIR "$(runstatedir)"'; \ + echo '#define INCLUDEDIR "$(includedir)"'; \ + echo '#define OLDINCLUDEDIR "$(oldincludedir)"'; \ + echo '#define DOCDIR "$(docdir)"'; \ + echo '#define INFODIR "$(infodir)"'; \ + echo '#define HTMLDIR "$(htmldir)"'; \ + echo '#define DVIDIR "$(dvidir)"'; \ + echo '#define PDFDIR "$(pdfdir)"'; \ + echo '#define PSDIR "$(psdir)"'; \ + echo '#define LIBDIR "$(libdir)"'; \ + echo '#define LISPDIR "$(lispdir)"'; \ + echo '#define LOCALEDIR "$(localedir)"'; \ + echo '#define MANDIR "$(mandir)"'; \ + echo '#define MANEXT "$(manext)"'; \ + echo '#define PKGDATADIR "$(pkgdatadir)"'; \ + echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \ + echo '#define PKGLIBDIR "$(pkglibdir)"'; \ + echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \ + } | sed '/""/d' > $@-t && \ + mv -f $@-t $@ diff --git a/configure.ac b/configure.ac index 4bdf38ec15..f0d79b95d4 100644 --- a/configure.ac +++ b/configure.ac @@ -132,14 +132,12 @@ AC_PROG_CPP dnl autoconf 2.70 adds a --runstatedir option so that downstreams dnl can point to /run instead of the historic /var/run, but dnl autoconf hasn't had a release since 2012. -dnl -dnl gnulib sets configmake.h to include runstatedir, but sets -dnl it to $localstatedir/run if $runstatedir env var is not set -dnl which is useless for apps that need to use /run without -dnl waiting for autoconf 2.70 -dnl +if test "x$runstatedir" = x; then + AC_SUBST([runstatedir], ['${localstatedir}/run']) +fi + dnl we introduce --with-runstatedir and then overwrite the -dnl value of $runstatedir so gnulib's configmake.h becomes useful +dnl value of $runstatedir so configmake.h is more useful AC_ARG_WITH( [runstatedir], [AS_HELP_STRING( diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index 6e332f7578..3b89f72742 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -41,12 +41,7 @@ # include <nsswitch.h> #endif
-/* - * This gnulib files is used for its macros only, - * so doesn't introduce a link time dep, which we - * must avoid - */ -#include "gnulib/lib/configmake.h" +#include "configmake.h"
#include "libvirt_nss_leases.h"
diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c index cf4a249f0a..25449f972d 100644 --- a/tools/virt-login-shell.c +++ b/tools/virt-login-shell.c @@ -28,11 +28,7 @@ #include <errno.h> #include <string.h>
-/* - * These gnulib files are used for their macros only, - * so don't introduce a link time dep, which we must avoid - */ -#include "gnulib/lib/configmake.h" +#include "configmake.h"
#define VIR_INT64_STR_BUFLEN 21
-- 2.24.1
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

The mgetgroups function is a GNULIB custom wrapper around getgrouplist(). This implements a simplified version of that code directly. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/internal.h | 4 ++++ src/util/virutil.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/internal.h b/src/internal.h index 4b0286e237..4a63984cec 100644 --- a/src/internal.h +++ b/src/internal.h @@ -155,6 +155,10 @@ _Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define VIR_WARNINGS_NO_POINTER_SIGN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wpointer-sign\"") + #if HAVE_SUGGEST_ATTRIBUTE_FORMAT # define VIR_WARNINGS_NO_PRINTF \ _Pragma ("GCC diagnostic push") \ diff --git a/src/util/virutil.c b/src/util/virutil.c index 87ca16c088..4bc0aef35f 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -66,7 +66,6 @@ # include <sys/un.h> #endif -#include "mgetgroups.h" #include "virerror.h" #include "virlog.h" #include "virbuffer.h" @@ -980,6 +979,11 @@ virDoesGroupExist(const char *name) } + +/* Work around an incompatibility of OS X 10.11: getgrouplist + accepts int *, not gid_t *, and int and gid_t differ in sign. */ +VIR_WARNINGS_NO_POINTER_SIGN + /* Compute the list of primary and supplementary groups associated * with @uid, and including @gid in the list (unless it is -1), * storing a malloc'd result into @list. If uid is -1 or doesn't exist in the @@ -1000,11 +1004,27 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) /* invalid users have no supplementary groups */ if (uid != (uid_t)-1 && virGetUserEnt(uid, &user, &primary, NULL, NULL, true) >= 0) { - if ((ret = mgetgroups(user, primary, list)) < 0) { - virReportSystemError(errno, - _("cannot get group list for '%s'"), user); - ret = -1; - goto cleanup; + int nallocgrps = 10; + gid_t *grps = g_new(gid_t, nallocgrps); + + while (1) { + int nprevallocgrps = nallocgrps; + int rv; + + rv = getgrouplist(user, primary, grps, &nallocgrps); + + /* Some systems (like Darwin) have a bug where they + never increase max_n_groups. */ + if (rv < 0 && nprevallocgrps == nallocgrps) + nallocgrps *= 2; + + /* either shrinks to actual size, or enlarges tonew size */ + grps = g_renew(gid_t, grps, nallocgrps); + + if (rv >= 0) { + ret = rv; + break; + } } } @@ -1029,6 +1049,8 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) return ret; } +VIR_WARNINGS_RESET + /* Set the real and effective uid and gid to the given values, as well * as all the supplementary groups, so that the process has all the -- 2.24.1

On Thu, Jan 23, 2020 at 11:42:59AM +0000, Daniel P. Berrangé wrote:
The mgetgroups function is a GNULIB custom wrapper around getgrouplist(). This implements a simplified version of that code directly.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/internal.h | 4 ++++ src/util/virutil.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/src/util/virutil.c b/src/util/virutil.c index 87ca16c088..4bc0aef35f 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1000,11 +1004,27 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) /* invalid users have no supplementary groups */ if (uid != (uid_t)-1 && virGetUserEnt(uid, &user, &primary, NULL, NULL, true) >= 0) { - if ((ret = mgetgroups(user, primary, list)) < 0) { - virReportSystemError(errno, - _("cannot get group list for '%s'"), user); - ret = -1; - goto cleanup; + int nallocgrps = 10; + gid_t *grps = g_new(gid_t, nallocgrps);
This is never used anywhere except in the while loop.
+ while (1) { + int nprevallocgrps = nallocgrps; + int rv; + + rv = getgrouplist(user, primary, grps, &nallocgrps); + + /* Some systems (like Darwin) have a bug where they + never increase max_n_groups. */ + if (rv < 0 && nprevallocgrps == nallocgrps) + nallocgrps *= 2; + + /* either shrinks to actual size, or enlarges tonew size */
s/tonew/to new/
+ grps = g_renew(gid_t, grps, nallocgrps); + + if (rv >= 0) { + ret = rv; + break;
Based on the GNULIB implementation here we should set *list = grps. With that fixed: Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

On Mon, Jan 27, 2020 at 12:44:01PM +0100, Pavel Hrdina wrote:
On Thu, Jan 23, 2020 at 11:42:59AM +0000, Daniel P. Berrangé wrote:
The mgetgroups function is a GNULIB custom wrapper around getgrouplist(). This implements a simplified version of that code directly.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/internal.h | 4 ++++ src/util/virutil.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/src/util/virutil.c b/src/util/virutil.c index 87ca16c088..4bc0aef35f 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1000,11 +1004,27 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) /* invalid users have no supplementary groups */ if (uid != (uid_t)-1 && virGetUserEnt(uid, &user, &primary, NULL, NULL, true) >= 0) { - if ((ret = mgetgroups(user, primary, list)) < 0) { - virReportSystemError(errno, - _("cannot get group list for '%s'"), user); - ret = -1; - goto cleanup; + int nallocgrps = 10; + gid_t *grps = g_new(gid_t, nallocgrps);
This is never used anywhere except in the while loop.
The loop relies on the "grps" pointer being persistent across loop iterations though.
+ while (1) { + int nprevallocgrps = nallocgrps; + int rv; + + rv = getgrouplist(user, primary, grps, &nallocgrps); + + /* Some systems (like Darwin) have a bug where they + never increase max_n_groups. */ + if (rv < 0 && nprevallocgrps == nallocgrps) + nallocgrps *= 2; + + /* either shrinks to actual size, or enlarges tonew size */
s/tonew/to new/
+ grps = g_renew(gid_t, grps, nallocgrps); + + if (rv >= 0) { + ret = rv; + break;
Based on the GNULIB implementation here we should set *list = grps.
Yes.
With that fixed:
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Mon, Jan 27, 2020 at 04:42:41PM +0000, Daniel P. Berrangé wrote:
On Mon, Jan 27, 2020 at 12:44:01PM +0100, Pavel Hrdina wrote:
On Thu, Jan 23, 2020 at 11:42:59AM +0000, Daniel P. Berrangé wrote:
The mgetgroups function is a GNULIB custom wrapper around getgrouplist(). This implements a simplified version of that code directly.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/internal.h | 4 ++++ src/util/virutil.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/src/util/virutil.c b/src/util/virutil.c index 87ca16c088..4bc0aef35f 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1000,11 +1004,27 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) /* invalid users have no supplementary groups */ if (uid != (uid_t)-1 && virGetUserEnt(uid, &user, &primary, NULL, NULL, true) >= 0) { - if ((ret = mgetgroups(user, primary, list)) < 0) { - virReportSystemError(errno, - _("cannot get group list for '%s'"), user); - ret = -1; - goto cleanup; + int nallocgrps = 10; + gid_t *grps = g_new(gid_t, nallocgrps);
This is never used anywhere except in the while loop.
The loop relies on the "grps" pointer being persistent across loop iterations though.
Sorry, probably bad wording. I meant that we need to assign the "grps" to *lists otherwise it's used only in the loop.
+ while (1) { + int nprevallocgrps = nallocgrps; + int rv; + + rv = getgrouplist(user, primary, grps, &nallocgrps); + + /* Some systems (like Darwin) have a bug where they + never increase max_n_groups. */ + if (rv < 0 && nprevallocgrps == nallocgrps) + nallocgrps *= 2; + + /* either shrinks to actual size, or enlarges tonew size */
s/tonew/to new/
+ grps = g_renew(gid_t, grps, nallocgrps); + + if (rv >= 0) { + ret = rv; + break;
Based on the GNULIB implementation here we should set *list = grps.
Yes.
With that fixed:
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On Mon, Jan 27, 2020 at 06:05:06PM +0100, Pavel Hrdina wrote:
On Mon, Jan 27, 2020 at 04:42:41PM +0000, Daniel P. Berrangé wrote:
On Mon, Jan 27, 2020 at 12:44:01PM +0100, Pavel Hrdina wrote:
On Thu, Jan 23, 2020 at 11:42:59AM +0000, Daniel P. Berrangé wrote:
The mgetgroups function is a GNULIB custom wrapper around getgrouplist(). This implements a simplified version of that code directly.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/internal.h | 4 ++++ src/util/virutil.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/src/util/virutil.c b/src/util/virutil.c index 87ca16c088..4bc0aef35f 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1000,11 +1004,27 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list) /* invalid users have no supplementary groups */ if (uid != (uid_t)-1 && virGetUserEnt(uid, &user, &primary, NULL, NULL, true) >= 0) { - if ((ret = mgetgroups(user, primary, list)) < 0) { - virReportSystemError(errno, - _("cannot get group list for '%s'"), user); - ret = -1; - goto cleanup; + int nallocgrps = 10; + gid_t *grps = g_new(gid_t, nallocgrps);
This is never used anywhere except in the while loop.
The loop relies on the "grps" pointer being persistent across loop iterations though.
Sorry, probably bad wording. I meant that we need to assign the "grps" to *lists otherwise it's used only in the loop.
Ok, so your later suggestion/comment addresses that.
+ while (1) { + int nprevallocgrps = nallocgrps; + int rv; + + rv = getgrouplist(user, primary, grps, &nallocgrps); + + /* Some systems (like Darwin) have a bug where they + never increase max_n_groups. */ + if (rv < 0 && nprevallocgrps == nallocgrps) + nallocgrps *= 2; + + /* either shrinks to actual size, or enlarges tonew size */
s/tonew/to new/
+ grps = g_renew(gid_t, grps, nallocgrps); + + if (rv >= 0) { + ret = rv; + break;
Based on the GNULIB implementation here we should set *list = grps.
Yes.
With that fixed:
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

The combination of g_unichar_iszerowidth and g_unichar_iswide is sufficient to replicate the logic of wcwidth() for libvirt. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- tests/vshtabletest.c | 8 ++------ tools/vsh-table.c | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/vshtabletest.c b/tests/vshtabletest.c index f2e0554f0a..54498b8a5a 100644 --- a/tests/vshtabletest.c +++ b/tests/vshtabletest.c @@ -155,14 +155,12 @@ testUnicodeArabic(const void *opaque G_GNUC_UNUSED) " 1 ﻉﺪﻴﻟ ﺎﻠﺜﻘﻴﻟ ﻕﺎﻣ ﻊﻧ, ٣٠ ﻎﻴﻨﻳﺍ ﻮﺘﻧﺎﻤﺗ ﺎﻠﺛﺎﻠﺛ، ﺄﺳﺭ, ﺩﻮﻟ ﺩﻮﻟ. ﺄﻣﺎﻣ ﺍ ﺎﻧ ﻲﻜﻧ\n" " ﺺﻔﺣﺓ ﺖﻜﺘﻴﻛﺍً ﻊﻟ, ﺎﻠﺠﻧﻭﺩ ﻭﺎﻠﻌﺗﺍﺩ ﺵﺭ\n"; vshTablePtr table; - wchar_t wc; /* If this char is not classed as printable, the actual * output won't match what this test expects. The code * is still operating correctly, but we have different * layout */ - mbrtowc(&wc, "،", MB_CUR_MAX, NULL); - if (!iswprint(wc)) + if (!g_unichar_isprint(g_utf8_get_char(","))) return EXIT_AM_SKIP; table = vshTableNew("ﻡﺍ ﻢﻣﺍ ﻕﺎﺌﻣﺓ", "ﺓ ﺎﻠﺼﻋ", "ﺍﻸﺜﻧﺎﻧ", NULL); @@ -197,14 +195,12 @@ testUnicodeZeroWidthChar(const void *opaque G_GNUC_UNUSED) " 1\u200B fedora28 run\u200Bning\n" " 2 rhel7.5 running\n"; char *act = NULL; - wchar_t wc; /* If this char is not classed as printable, the actual * output won't match what this test expects. The code * is still operating correctly, but we have different * layout */ - mbrtowc(&wc, "\u200B", MB_CUR_MAX, NULL); - if (!iswprint(wc)) + if (!g_unichar_isprint(g_utf8_get_char("\u200B"))) return EXIT_AM_SKIP; table = vshTableNew("I\u200Bd", "Name", "\u200BStatus", NULL); diff --git a/tools/vsh-table.c b/tools/vsh-table.c index a2365b2c32..e21514e86f 100644 --- a/tools/vsh-table.c +++ b/tools/vsh-table.c @@ -261,7 +261,7 @@ vshTableSafeEncode(const char *s, size_t *width) } else { memcpy(buf, p, len); buf += len; - *width += wcwidth(wc); + *width += g_unichar_iszerowidth(wc) ? 0 : (g_unichar_iswide(wc) ? 2 : 1); } p += len; } -- 2.24.1

On Thu, Jan 23, 2020 at 11:43:00AM +0000, Daniel P. Berrangé wrote:
The combination of g_unichar_iszerowidth and g_unichar_iswide is sufficient to replicate the logic of wcwidth() for libvirt.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- tests/vshtabletest.c | 8 ++------ tools/vsh-table.c | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virhostcpu.c | 1 - src/util/virhostmem.c | 1 - 2 files changed, 2 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 0bde532a0c..81293eea8c 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -22,7 +22,6 @@ #include <config.h> #include <dirent.h> -#include <sys/utsname.h> #include <fcntl.h> #ifndef WIN32 # include <sys/ioctl.h> diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index f37d1ad588..9097716f54 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -21,7 +21,6 @@ #include <config.h> -#include <sys/utsname.h> #include <fcntl.h> #include <unistd.h> -- 2.24.1

On Thu, Jan 23, 2020 at 11:43:01AM +0000, Daniel P. Berrangé wrote:
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virhostcpu.c | 1 - src/util/virhostmem.c | 1 - 2 files changed, 2 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

The virProcess code relies on windows.h and is getting it indirectly via some GNULIB header fixes. This dependancy needs to be made explicit. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virprocess.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index d5589daf6a..d8ee3142da 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -50,6 +50,11 @@ # include <sys/cpuset.h> #endif +#ifdef WIN32 +# define WIN32_LEAN_AND_MEAN +# include <windows.h> +#endif + #include "viratomic.h" #include "virprocess.h" #include "virerror.h" -- 2.24.1

On Thu, Jan 23, 2020 at 11:43:02AM +0000, Daniel P. Berrangé wrote:
The virProcess code relies on windows.h and is getting it indirectly via some GNULIB header fixes. This dependancy needs to be made explicit.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virprocess.c | 5 +++++ 1 file changed, 5 insertions(+)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

The gnulib stat-time.h header provides wrapper functions to hide the differences in 'struct stat' between various platforms. Linux and FreeBSD support the same names, except for birthtime which Linux only provides in the new 'statx()' syscall we're not using. macOS has completely different naming. Since we only rely on this code in one place we just use conditionals at time of need. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/storage/storage_util.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 987d937b04..7bbcfde064 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -71,7 +71,6 @@ #include "virfile.h" #include "virjson.h" #include "virqemu.h" -#include "stat-time.h" #include "virstring.h" #include "virxml.h" #include "virfdstream.h" @@ -1830,10 +1829,22 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target, if (!target->timestamps && VIR_ALLOC(target->timestamps) < 0) return -1; - target->timestamps->atime = get_stat_atime(sb); - target->timestamps->btime = get_stat_birthtime(sb); - target->timestamps->ctime = get_stat_ctime(sb); - target->timestamps->mtime = get_stat_mtime(sb); + +#ifdef __APPLE__ + target->timestamps->atime = sb->st_atimespec; + target->timestamps->btime = sb->st_birthtimespec; + target->timestamps->ctime = sb->st_ctimespec; + target->timestamps->mtime = sb->st_mtimespec; +#else /* ! __APPLE__ */ + target->timestamps->atime = sb->st_atim; +# ifdef __linux__ + target->timestamps->btime = (struct timespec){0, 0}; +# else /* ! __linux__ */ + target->timestamps->btime = sb->st_birthtim; +# endif /* ! __linux__ */ + target->timestamps->ctime = sb->st_ctim; + target->timestamps->mtime = sb->st_mtim; +#endif /* ! __APPLE__ */ target->type = VIR_STORAGE_TYPE_FILE; -- 2.24.1

On Thu, Jan 23, 2020 at 11:43:03AM +0000, Daniel P. Berrangé wrote:
The gnulib stat-time.h header provides wrapper functions to hide the differences in 'struct stat' between various platforms.
Linux and FreeBSD support the same names, except for birthtime which Linux only provides in the new 'statx()' syscall we're not using. macOS has completely different naming. Since we only rely on this code in one place we just use conditionals at time of need.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/storage/storage_util.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

This is a simplified variant of gnulib's passfd module without the portability code that we do not require. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/libvirt_private.syms | 5 ++ src/qemu/qemu_interface.c | 4 +- src/rpc/virnetsocket.c | 5 +- src/util/virfile.c | 5 +- src/util/virsocket.c | 142 +++++++++++++++++++++++++++++++++++++- src/util/virsocket.h | 3 + 6 files changed, 154 insertions(+), 10 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fa046051a3..4fe93e785c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3004,6 +3004,11 @@ virSecretLookupFormatSecret; virSecretLookupParseSecret; +# util/virsocket.h +virSocketRecvFD; +virSocketSendFD; + + # util/virsocketaddr.h virSocketAddrBroadcast; virSocketAddrBroadcastByPrefix; diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index bb62b53c04..48bb0043fe 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -25,7 +25,6 @@ #include "domain_audit.h" #include "domain_nwfilter.h" #include "qemu_interface.h" -#include "passfd.h" #include "viralloc.h" #include "virlog.h" #include "virstring.h" @@ -34,6 +33,7 @@ #include "virnetdevmacvlan.h" #include "virnetdevbridge.h" #include "virnetdevvportprofile.h" +#include "virsocket.h" #include <sys/stat.h> #include <fcntl.h> @@ -347,7 +347,7 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg, } do { - *tapfd = recvfd(pair[0], 0); + *tapfd = virSocketRecvFD(pair[0], 0); } while (*tapfd < 0 && errno == EINTR); if (*tapfd < 0) { diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 973827ebde..687099720f 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -56,7 +56,6 @@ #include "virprobe.h" #include "virprocess.h" #include "virstring.h" -#include "passfd.h" #if WITH_SSH2 # include "virnetsshsession.h" @@ -2045,7 +2044,7 @@ int virNetSocketSendFD(virNetSocketPtr sock, int fd) virObjectLock(sock); PROBE(RPC_SOCKET_SEND_FD, "sock=%p fd=%d", sock, fd); - if (sendfd(sock->fd, fd) < 0) { + if (virSocketSendFD(sock->fd, fd) < 0) { if (errno == EAGAIN) ret = 0; else @@ -2078,7 +2077,7 @@ int virNetSocketRecvFD(virNetSocketPtr sock, int *fd) } virObjectLock(sock); - if ((*fd = recvfd(sock->fd, O_CLOEXEC)) < 0) { + if ((*fd = virSocketRecvFD(sock->fd, O_CLOEXEC)) < 0) { if (errno == EAGAIN) ret = 0; else diff --git a/src/util/virfile.c b/src/util/virfile.c index b3a63fa2ea..51a0d40b50 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -25,7 +25,6 @@ #include <config.h> #include "internal.h" -#include <passfd.h> #include <fcntl.h> #ifndef WIN32 # include <termios.h> @@ -2268,7 +2267,7 @@ virFileOpenForked(const char *path, int openflags, mode_t mode, } do { - ret = sendfd(pair[1], fd); + ret = virSocketSendFD(pair[1], fd); } while (ret < 0 && errno == EINTR); if (ret < 0) { @@ -2302,7 +2301,7 @@ virFileOpenForked(const char *path, int openflags, mode_t mode, VIR_FORCE_CLOSE(pair[1]); do { - fd = recvfd(pair[0], 0); + fd = virSocketRecvFD(pair[0], 0); } while (fd < 0 && errno == EINTR); VIR_FORCE_CLOSE(pair[0]); /* NB: this preserves errno */ if (fd < 0) diff --git a/src/util/virsocket.c b/src/util/virsocket.c index 96b9ece2b7..0e3775ac44 100644 --- a/src/util/virsocket.c +++ b/src/util/virsocket.c @@ -19,10 +19,12 @@ #include <config.h> #include "virsocket.h" +#include "virutil.h" +#include "virfile.h" -#ifdef WIN32 +#include <fcntl.h> -# include <fcntl.h> +#ifdef WIN32 # define FD2SK(fd) _get_osfhandle(fd) # define SK2FD(sk) (_open_osfhandle((intptr_t) (sk), O_RDWR | O_BINARY)) @@ -365,3 +367,139 @@ vir_socket(int domain, int type, int protocol) } #endif /* WIN32 */ + +/* The code that uses CMSG_FIRSTHDR is enabled on + Linux, Mac OS X, FreeBSD, OpenBSD, NetBSD, AIX, OSF/1, Cygwin. + The code that uses HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS is enabled on + HP-UX, IRIX, Solaris. */ + +/* MSG_CMSG_CLOEXEC is defined only on Linux, as of 2011. */ +#ifndef MSG_CMSG_CLOEXEC +# define MSG_CMSG_CLOEXEC 0 +#endif + +#ifndef WIN32 +/* virSocketSendFD sends the file descriptor fd along the socket + to a process calling recvfd on the other end. + + Return 0 on success, or -1 with errno set in case of error. +*/ +int +virSocketSendFD(int sock, int fd) +{ + char byte = 0; + struct iovec iov; + struct msghdr msg; + struct cmsghdr *cmsg; + char buf[CMSG_SPACE(sizeof(fd))]; + + /* send at least one char */ + memset(&msg, 0, sizeof(msg)); + iov.iov_base = &byte; + iov.iov_len = 1; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_name = NULL; + msg.msg_namelen = 0; + + msg.msg_control = buf; + msg.msg_controllen = sizeof(buf); + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); + /* Initialize the payload: */ + memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd)); + msg.msg_controllen = cmsg->cmsg_len; + + if (sendmsg(sock, &msg, 0) != iov.iov_len) + return -1; + return 0; +} +#else +int +virSocketSendFD(int sock G_GNUC_UNUSED, int fd G_GNUC_UNUSED) +{ + errno = ENOSYS; + return -1; +} +#endif + + +#ifndef WIN32 +/* virSocketRecvFD receives a file descriptor through the socket. + The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>). + + Return the fd on success, or -1 with errno set in case of error. +*/ +int +virSocketRecvFD(int sock, int fdflags) +{ + char byte = 0; + struct iovec iov; + struct msghdr msg; + int fd = -1; + ssize_t len; + struct cmsghdr *cmsg; + char buf[CMSG_SPACE(sizeof(fd))]; + int fdflags_recvmsg = fdflags & O_CLOEXEC ? MSG_CMSG_CLOEXEC : 0; + + if ((fdflags & ~O_CLOEXEC) != 0) { + errno = EINVAL; + return -1; + } + + /* send at least one char */ + memset(&msg, 0, sizeof(msg)); + iov.iov_base = &byte; + iov.iov_len = 1; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_name = NULL; + msg.msg_namelen = 0; + + msg.msg_control = buf; + msg.msg_controllen = sizeof(buf); + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); + /* Initialize the payload: */ + memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd)); + msg.msg_controllen = cmsg->cmsg_len; + + len = recvmsg(sock, &msg, fdflags_recvmsg); + if (len < 0) + return -1; + + cmsg = CMSG_FIRSTHDR(&msg); + /* be paranoiac */ + if (len == 0 || cmsg == NULL || cmsg->cmsg_len != CMSG_LEN(sizeof(fd)) + || cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { + /* fake errno: at end the file is not available */ + errno = len ? EACCES : ENOTCONN; + return -1; + } + + memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd)); + + /* set close-on-exec flag */ + if (!MSG_CMSG_CLOEXEC && (fdflags & O_CLOEXEC)) { + if (virSetCloseExec(fd) < 0) { + int saved_errno = errno; + VIR_FORCE_CLOSE(fd); + errno = saved_errno; + return -1; + } + } + + return fd; +} +#else +int +virSocketRecvFD(int sock G_GNUC_UNUSED, int fdflags G_GNUC_UNUSED) +{ + errno = ENOSYS; + return -1; +} +#endif diff --git a/src/util/virsocket.h b/src/util/virsocket.h index 33f237886f..e1e7d08bb4 100644 --- a/src/util/virsocket.h +++ b/src/util/virsocket.h @@ -20,6 +20,9 @@ #include "internal.h" +int virSocketSendFD(int sock, int fd); +int virSocketRecvFD(int sock, int fdflags); + #ifdef WIN32 # define WIN32_LEAN_AND_MEAN -- 2.24.1

On Thu, Jan 23, 2020 at 11:43:04AM +0000, Daniel P. Berrangé wrote:
This is a simplified variant of gnulib's passfd module without the portability code that we do not require.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/libvirt_private.syms | 5 ++ src/qemu/qemu_interface.c | 4 +- src/rpc/virnetsocket.c | 5 +- src/util/virfile.c | 5 +- src/util/virsocket.c | 142 +++++++++++++++++++++++++++++++++++++- src/util/virsocket.h | 3 + 6 files changed, 154 insertions(+), 10 deletions(-)
[...]
diff --git a/src/util/virsocket.c b/src/util/virsocket.c index 96b9ece2b7..0e3775ac44 100644 --- a/src/util/virsocket.c +++ b/src/util/virsocket.c @@ -19,10 +19,12 @@ #include <config.h>
#include "virsocket.h" +#include "virutil.h" +#include "virfile.h"
-#ifdef WIN32 +#include <fcntl.h>
-# include <fcntl.h> +#ifdef WIN32
# define FD2SK(fd) _get_osfhandle(fd) # define SK2FD(sk) (_open_osfhandle((intptr_t) (sk), O_RDWR | O_BINARY)) @@ -365,3 +367,139 @@ vir_socket(int domain, int type, int protocol) }
#endif /* WIN32 */ + +/* The code that uses CMSG_FIRSTHDR is enabled on + Linux, Mac OS X, FreeBSD, OpenBSD, NetBSD, AIX, OSF/1, Cygwin. + The code that uses HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS is enabled on + HP-UX, IRIX, Solaris. */ + +/* MSG_CMSG_CLOEXEC is defined only on Linux, as of 2011. */ +#ifndef MSG_CMSG_CLOEXEC +# define MSG_CMSG_CLOEXEC 0 +#endif + +#ifndef WIN32 +/* virSocketSendFD sends the file descriptor fd along the socket + to a process calling recvfd on the other end.
s/recvfd/virSocketRecvFD/ Otherwise looks good compared to passfd GNULIB module. Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

The Windows platform does not have the signal handling support we need, so it must be disabled in several parts of the codebase. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/rpc/virnetclient.c | 33 ++++++++++++++++++++++-------- src/rpc/virnetdaemon.c | 35 +++++++++++++++++++++++++++++--- src/rpc/virnetdaemon.h | 4 ++++ tools/virsh-domain.c | 46 +++++++++++++++++++++++++++++++++++++----- tools/vsh.c | 12 ++++++++++- 5 files changed, 113 insertions(+), 17 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 50489b754c..eac02282e6 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -845,16 +845,19 @@ int virNetClientSetTLSSession(virNetClientPtr client, char buf[1]; int len; struct pollfd fds[1]; + +# ifndef WIN32 sigset_t oldmask, blockedsigs; sigemptyset(&blockedsigs); -# ifdef SIGWINCH +# ifdef SIGWINCH sigaddset(&blockedsigs, SIGWINCH); -# endif -# ifdef SIGCHLD +# endif +# ifdef SIGCHLD sigaddset(&blockedsigs, SIGCHLD); -# endif +# endif sigaddset(&blockedsigs, SIGPIPE); +# endif /* !WIN32 */ virObjectLock(client); @@ -880,19 +883,23 @@ int virNetClientSetTLSSession(virNetClientPtr client, else fds[0].events = POLLOUT; +# ifndef WIN32 /* Block SIGWINCH from interrupting poll in curses programs, * then restore the original signal mask again immediately * after the call (RHBZ#567931). Same for SIGCHLD and SIGPIPE * at the suggestion of Paolo Bonzini and Daniel Berrange. */ ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask)); +# endif /* !WIN32 */ repoll: ret = poll(fds, G_N_ELEMENTS(fds), -1); if (ret < 0 && (errno == EAGAIN || errno == EINTR)) goto repoll; +# ifndef WIN32 ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL)); +# endif /* !WIN32 */ } ret = virNetTLSContextCheckCertificate(tls, client->tls); @@ -908,15 +915,19 @@ int virNetClientSetTLSSession(virNetClientPtr client, fds[0].revents = 0; fds[0].events = POLLIN; +# ifndef WIN32 /* Block SIGWINCH from interrupting poll in curses programs */ ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask)); +# endif /* !WIN32 */ repoll2: ret = poll(fds, G_N_ELEMENTS(fds), -1); if (ret < 0 && (errno == EAGAIN || errno == EINTR)) goto repoll2; +# ifndef WIN32 ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL)); +# endif /* !WIN32 */ len = virNetTLSSessionRead(client->tls, buf, 1); if (len < 0 && errno != ENOMSG) { @@ -1574,7 +1585,9 @@ static int virNetClientIOEventLoop(virNetClientPtr client, for (;;) { char ignore; +#ifndef WIN32 sigset_t oldmask, blockedsigs; +#endif /* !WIN32 */ int timeout = -1; virNetMessagePtr msg = NULL; @@ -1615,27 +1628,31 @@ static int virNetClientIOEventLoop(virNetClientPtr client, * can stuff themselves on the queue */ virObjectUnlock(client); +#ifndef WIN32 /* Block SIGWINCH from interrupting poll in curses programs, * then restore the original signal mask again immediately * after the call (RHBZ#567931). Same for SIGCHLD and SIGPIPE * at the suggestion of Paolo Bonzini and Daniel Berrange. */ sigemptyset(&blockedsigs); -#ifdef SIGWINCH +# ifdef SIGWINCH sigaddset(&blockedsigs, SIGWINCH); -#endif -#ifdef SIGCHLD +# endif +# ifdef SIGCHLD sigaddset(&blockedsigs, SIGCHLD); -#endif +# endif sigaddset(&blockedsigs, SIGPIPE); ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask)); +#endif /* !WIN32 */ repoll: ret = poll(fds, G_N_ELEMENTS(fds), timeout); if (ret < 0 && (errno == EAGAIN || errno == EINTR)) goto repoll; +#ifndef WIN32 ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL)); +#endif /* !WIN32 */ virObjectLock(client); diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 570930436a..9634e93b52 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -45,6 +45,7 @@ VIR_LOG_INIT("rpc.netdaemon"); +#ifndef WIN32 typedef struct _virNetDaemonSignal virNetDaemonSignal; typedef virNetDaemonSignal *virNetDaemonSignalPtr; @@ -54,17 +55,20 @@ struct _virNetDaemonSignal { virNetDaemonSignalFunc func; void *opaque; }; +#endif /* !WIN32 */ struct _virNetDaemon { virObjectLockable parent; bool privileged; +#ifndef WIN32 size_t nsignals; virNetDaemonSignalPtr *signals; int sigread; int sigwrite; int sigwatch; +#endif /* !WIN32 */ virHashTablePtr servers; virJSONValuePtr srvObject; @@ -84,10 +88,9 @@ static void virNetDaemonDispose(void *obj) { virNetDaemonPtr dmn = obj; +#ifndef WIN32 size_t i; - VIR_FORCE_CLOSE(dmn->autoShutdownInhibitFd); - for (i = 0; i < dmn->nsignals; i++) { sigaction(dmn->signals[i]->signum, &dmn->signals[i]->oldaction, NULL); VIR_FREE(dmn->signals[i]); @@ -97,6 +100,9 @@ virNetDaemonDispose(void *obj) VIR_FORCE_CLOSE(dmn->sigwrite); if (dmn->sigwatch > 0) virEventRemoveHandle(dmn->sigwatch); +#endif /* !WIN32 */ + + VIR_FORCE_CLOSE(dmn->autoShutdownInhibitFd); virHashFree(dmn->servers); @@ -119,7 +125,9 @@ virNetDaemonPtr virNetDaemonNew(void) { virNetDaemonPtr dmn; +#ifndef WIN32 struct sigaction sig_action; +#endif /* !WIN32 */ if (virNetDaemonInitialize() < 0) return NULL; @@ -130,16 +138,21 @@ virNetDaemonNew(void) if (!(dmn->servers = virHashCreate(5, virObjectFreeHashData))) goto error; +#ifndef WIN32 dmn->sigwrite = dmn->sigread = -1; +#endif /* !WIN32 */ + dmn->privileged = geteuid() == 0; dmn->autoShutdownInhibitFd = -1; if (virEventRegisterDefaultImpl() < 0) goto error; +#ifndef WIN32 memset(&sig_action, 0, sizeof(sig_action)); sig_action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &sig_action, NULL); +#endif /* !WIN32 */ return dmn; @@ -587,7 +600,7 @@ virNetDaemonRemoveShutdownInhibition(virNetDaemonPtr dmn) } - +#ifndef WIN32 static sig_atomic_t sigErrors; static int sigLastErrno; static int sigWrite = -1; @@ -689,6 +702,7 @@ virNetDaemonSignalSetup(virNetDaemonPtr dmn) return -1; } + int virNetDaemonAddSignalHandler(virNetDaemonPtr dmn, int signum, @@ -731,6 +745,21 @@ virNetDaemonAddSignalHandler(virNetDaemonPtr dmn, return -1; } +#else /* WIN32 */ + +int +virNetDaemonAddSignalHandler(virNetDaemonPtr dmn G_GNUC_UNUSED, + int signum G_GNUC_UNUSED, + virNetDaemonSignalFunc func G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Signal handling not available on this platform")); + return -1; +} + +#endif /* WIN32 */ + static void virNetDaemonAutoShutdownTimer(int timerid G_GNUC_UNUSED, diff --git a/src/rpc/virnetdaemon.h b/src/rpc/virnetdaemon.h index 5a9842bee6..c2c7767037 100644 --- a/src/rpc/virnetdaemon.h +++ b/src/rpc/virnetdaemon.h @@ -55,6 +55,10 @@ void virNetDaemonAutoShutdown(virNetDaemonPtr dmn, void virNetDaemonAddShutdownInhibition(virNetDaemonPtr dmn); void virNetDaemonRemoveShutdownInhibition(virNetDaemonPtr dmn); +#ifdef WIN32 +# define siginfo_t void +#endif + typedef void (*virNetDaemonSignalFunc)(virNetDaemonPtr dmn, siginfo_t *info, void *opaque); int virNetDaemonAddSignalHandler(virNetDaemonPtr dmn, diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e64e08e5da..df4a03290f 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1697,12 +1697,14 @@ virshPrintJobProgress(const char *label, unsigned long long remaining, static volatile sig_atomic_t intCaught; +#ifndef WIN32 static void virshCatchInt(int sig G_GNUC_UNUSED, siginfo_t *siginfo G_GNUC_UNUSED, void *context G_GNUC_UNUSED) { intCaught = 1; } +#endif /* !WIN32 */ typedef struct _virshBlockJobWaitData virshBlockJobWaitData; @@ -1842,11 +1844,11 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) * the event to the given block job we will wait for the number of retries * before claiming that we entered synchronised phase */ unsigned int retries = 5; - +#ifndef WIN32 struct sigaction sig_action; struct sigaction old_sig_action; sigset_t sigmask, oldsigmask; - +#endif /* !WIN32 */ unsigned long long start = 0; unsigned long long curr = 0; @@ -1861,6 +1863,7 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) if (data->async_abort) abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; +#ifndef WIN32 sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); @@ -1869,6 +1872,7 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) sig_action.sa_flags = SA_SIGINFO; sigemptyset(&sig_action.sa_mask); sigaction(SIGINT, &sig_action, &old_sig_action); +#endif /* !WIN32 */ if (data->timeout && virTimeMillisNow(&start) < 0) { vshSaveLibvirtError(); @@ -1878,9 +1882,13 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) last.cur = last.end = 0; while (true) { +#ifndef WIN32 pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask); +#endif /* !WIN32 */ result = virDomainGetBlockJobInfo(data->dom, data->dev, &info, 0); +#ifndef WIN32 pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); +#endif /* !WIN32 */ if (result < 0) { vshError(data->ctl, _("failed to query job for disk %s"), data->dev); @@ -1944,7 +1952,9 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) virshPrintJobProgress(data->job_name, 0, 1); cleanup: +#ifndef WIN32 sigaction(SIGINT, &old_sig_action, NULL); +#endif /* !WIN32 */ return ret; } @@ -4226,12 +4236,14 @@ doSave(void *opaque) unsigned int flags = 0; const char *xmlfile = NULL; char *xml = NULL; +#ifndef WIN32 sigset_t sigmask, oldsigmask; sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0) goto out_sig; +#endif /* !WIN32 */ if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) goto out; @@ -4265,8 +4277,10 @@ doSave(void *opaque) ret = '0'; out: +#ifndef WIN32 pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: +#endif /* !WIN32 */ virshDomainFree(dom); VIR_FREE(xml); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); @@ -4285,8 +4299,11 @@ virshWatchJob(vshControl *ctl, void *opaque, const char *label) { +#ifndef WIN32 struct sigaction sig_action; struct sigaction old_sig_action; + sigset_t sigmask, oldsigmask; +#endif /* !WIN32 */ struct pollfd pollfd[2] = {{.fd = pipe_fd, .events = POLLIN, .revents = 0}, {.fd = STDIN_FILENO, .events = POLLIN, .revents = 0}}; unsigned long long start_us, curr_us; @@ -4294,10 +4311,10 @@ virshWatchJob(vshControl *ctl, int ret = -1; char retchar; bool functionReturn = false; - sigset_t sigmask, oldsigmask; bool jobStarted = false; nfds_t npollfd = 2; +#ifndef WIN32 sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); @@ -4306,6 +4323,7 @@ virshWatchJob(vshControl *ctl, sig_action.sa_flags = SA_SIGINFO; sigemptyset(&sig_action.sa_mask); sigaction(SIGINT, &sig_action, &old_sig_action); +#endif /* !WIN32 */ /* don't poll on STDIN if we are not using a terminal */ if (!vshTTYAvailable(ctl)) @@ -4355,9 +4373,13 @@ virshWatchJob(vshControl *ctl, } if (verbose || !jobStarted) { +#ifndef WIN32 pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask); +#endif /* !WIN32 */ ret = virDomainGetJobInfo(dom, &jobinfo); +#ifndef WIN32 pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); +#endif /* !WIN32 */ if (ret == 0) { if (verbose && jobinfo.dataTotal > 0) virshPrintJobProgress(label, jobinfo.dataRemaining, @@ -4378,7 +4400,9 @@ virshWatchJob(vshControl *ctl, functionReturn = true; cleanup: +#ifndef WIN32 sigaction(SIGINT, &old_sig_action, NULL); +#endif /* !WIN32 */ vshTTYRestore(ctl); return functionReturn; } @@ -4662,12 +4686,14 @@ doManagedsave(void *opaque) virDomainPtr dom = NULL; const char *name; unsigned int flags = 0; +#ifndef WIN32 sigset_t sigmask, oldsigmask; sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0) goto out_sig; +#endif /* !WIN32 */ if (vshCommandOptBool(cmd, "bypass-cache")) flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE; @@ -4686,8 +4712,10 @@ doManagedsave(void *opaque) ret = '0'; out: +#ifndef WIN32 pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: +#endif /* !WIN32 */ virshDomainFree(dom); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); } @@ -5340,17 +5368,19 @@ doDump(void *opaque) vshControl *ctl = data->ctl; const vshCmd *cmd = data->cmd; virDomainPtr dom = NULL; - sigset_t sigmask, oldsigmask; const char *name = NULL; const char *to = NULL; unsigned int flags = 0; const char *format = NULL; unsigned int dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_RAW; +#ifndef WIN32 + sigset_t sigmask, oldsigmask; sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0) goto out_sig; +#endif /* !WIN32 */ if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) goto out; @@ -5407,8 +5437,10 @@ doDump(void *opaque) ret = '0'; out: +#ifndef WIN32 pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: +#endif /* !WIN32 */ if (dom) virshDomainFree(dom); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); @@ -10601,7 +10633,6 @@ doMigrate(void *opaque) virshCtrlData *data = opaque; vshControl *ctl = data->ctl; const vshCmd *cmd = data->cmd; - sigset_t sigmask, oldsigmask; virTypedParameterPtr params = NULL; int nparams = 0; int maxparams = 0; @@ -10609,11 +10640,14 @@ doMigrate(void *opaque) unsigned long long ullOpt = 0; int rv; virConnectPtr dconn = data->dconn; +#ifndef WIN32 + sigset_t sigmask, oldsigmask; sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0) goto out_sig; +#endif /* !WIN32 */ if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) goto out; @@ -10881,8 +10915,10 @@ doMigrate(void *opaque) } out: +#ifndef WIN32 pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); out_sig: +#endif /* !WIN32 */ virTypedParamsFree(params, nparams); virshDomainFree(dom); ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); diff --git a/tools/vsh.c b/tools/vsh.c index 949c8dad7b..39bb75f192 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2013,6 +2013,7 @@ vshEventLoop(void *opaque) /* We want to use SIGINT to cancel a wait; but as signal handlers * don't have an opaque argument, we have to use static storage. */ +#ifndef WIN32 static int vshEventFd = -1; static struct sigaction vshEventOldAction; @@ -2027,6 +2028,7 @@ vshEventInt(int sig G_GNUC_UNUSED, if (vshEventFd >= 0) ignore_value(safewrite(vshEventFd, &reason, 1)); } +#endif /* !WIN32 */ /* Event loop handler used to limit length of waiting for any other event. */ @@ -2057,10 +2059,13 @@ vshEventTimeout(int timer G_GNUC_UNUSED, int vshEventStart(vshControl *ctl, int timeout_ms) { +#ifndef WIN32 struct sigaction action; + assert(vshEventFd == -1); +#endif /* !WIN32 */ assert(ctl->eventPipe[0] == -1 && ctl->eventPipe[1] == -1 && - vshEventFd == -1 && ctl->eventTimerId >= 0); + ctl->eventTimerId >= 0); if (pipe2(ctl->eventPipe, O_CLOEXEC) < 0) { char ebuf[1024]; @@ -2068,12 +2073,15 @@ vshEventStart(vshControl *ctl, int timeout_ms) virStrerror(errno, ebuf, sizeof(ebuf))); return -1; } + +#ifndef WIN32 vshEventFd = ctl->eventPipe[1]; action.sa_sigaction = vshEventInt; action.sa_flags = SA_SIGINFO; sigemptyset(&action.sa_mask); sigaction(SIGINT, &action, &vshEventOldAction); +#endif /* !WIN32 */ if (timeout_ms) virEventUpdateTimeout(ctl->eventTimerId, timeout_ms); @@ -2140,10 +2148,12 @@ vshEventWait(vshControl *ctl) void vshEventCleanup(vshControl *ctl) { +#ifndef WIN32 if (vshEventFd >= 0) { sigaction(SIGINT, &vshEventOldAction, NULL); vshEventFd = -1; } +#endif /* !WIN32 */ VIR_FORCE_CLOSE(ctl->eventPipe[0]); VIR_FORCE_CLOSE(ctl->eventPipe[1]); virEventUpdateTimeout(ctl->eventTimerId, -1); -- 2.24.1

The sys/uio.h header is only needed when building logging code with journald support enabled. Conditionally include it so that we avoid break on platforms which lack this header. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virlog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virlog.c b/src/util/virlog.c index ddc3ac1edb..8c17d666de 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -28,7 +28,6 @@ #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> -#include <sys/uio.h> #if HAVE_SYSLOG_H # include <syslog.h> #endif @@ -52,6 +51,7 @@ * htole64. */ #if HAVE_SYSLOG_H && defined(__linux__) && HAVE_DECL_HTOLE64 # define USE_JOURNALD 1 +# include <sys/uio.h> #endif #define VIR_FROM_THIS VIR_FROM_NONE -- 2.24.1

g_mkdir() provides portability to Windows platforms. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virfile.c | 2 +- tests/virlockspacetest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 51a0d40b50..d0e0062aa7 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3029,7 +3029,7 @@ virFileMakePathHelper(char *path, mode_t mode) *p = '/'; } - if (mkdir(path, mode) < 0 && errno != EEXIST) + if (g_mkdir(path, mode) < 0 && errno != EEXIST) return -1; return 0; diff --git a/tests/virlockspacetest.c b/tests/virlockspacetest.c index 57deb288a9..40395e8c72 100644 --- a/tests/virlockspacetest.c +++ b/tests/virlockspacetest.c @@ -300,7 +300,7 @@ static int testLockSpaceResourceLockPath(const void *args G_GNUC_UNUSED) if (!(lockspace = virLockSpaceNew(NULL))) goto cleanup; - if (mkdir(LOCKSPACE_DIR, 0700) < 0) + if (g_mkdir(LOCKSPACE_DIR, 0700) < 0) goto cleanup; if (virLockSpaceCreateResource(lockspace, LOCKSPACE_DIR "/foo") < 0) -- 2.24.1

polkit is only useful on Linux systems Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- m4/virt-polkit.m4 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/m4/virt-polkit.m4 b/m4/virt-polkit.m4 index 16889e1639..06da9e4ba6 100644 --- a/m4/virt-polkit.m4 +++ b/m4/virt-polkit.m4 @@ -25,6 +25,10 @@ AC_DEFUN([LIBVIRT_ARG_POLKIT], [ AC_DEFUN([LIBVIRT_CHECK_POLKIT], [ AC_REQUIRE([LIBVIRT_CHECK_DBUS]) + if test "x$with_win" = "xyes"; then + with_polkit=no + fi + if test "x$with_polkit" = "xcheck"; then dnl For --with-polkit=check, also require the pkcheck binary, even dnl though we talk to polkit directly over D-Bus. -- 2.24.1

A large part of the virCommand code is still built on WIN32, despite the fact that the core fork() & execve() functions are not available. So despite succesfully building most of the code, at runtime the APIs are none the less unusuable. With the elimination of GNULIB many of the APIs being used in this code no longer have portability wrappers/shims for Windows. Rather than try to add portability wrappers, or do tests for each individual function, it is clearer to conditionalize nearly all of the code using #ifdef WIN32. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/vircommand.c | 165 ++++++++++++++++++++++++++---------------- 1 file changed, 103 insertions(+), 62 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index dd37b0b8dc..26b3488d6b 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -21,11 +21,15 @@ #include <config.h> -#include <poll.h> +#ifndef WIN32 +# include <poll.h> +#endif #include <signal.h> #include <stdarg.h> #include <sys/stat.h> -#include <sys/wait.h> +#ifndef WIN32 +# include <sys/wait.h> +#endif #include <fcntl.h> #include <unistd.h> @@ -153,7 +157,9 @@ struct _virCommand { static virBufferPtr dryRunBuffer; static virCommandDryRunCallback dryRunCallback; static void *dryRunOpaque; +#ifndef WIN32 static int dryRunStatus; +#endif /* !WIN32 */ /* * virCommandFDIsSet: @@ -538,6 +544,7 @@ virCommandMassClose(virCommandPtr cmd, return 0; } + /* * virExec: * @cmd virCommandPtr containing all information about the program to @@ -805,6 +812,7 @@ virExec(virCommandPtr cmd) return -1; } + /** * virRun: * @argv NULL terminated argv to run @@ -842,18 +850,6 @@ virRun(const char *const *argv G_GNUC_UNUSED, return -1; } -static int -virExec(virCommandPtr cmd G_GNUC_UNUSED) -{ - /* XXX: Some day we can implement pieces of virCommand/virExec on - * top of _spawn() or CreateProcess(), but we can't implement - * everything, since mingw completely lacks fork(), so we cannot - * run our own code in the child process. */ - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("virExec is not implemented for WIN32")); - return -1; -} - pid_t virFork(void) { @@ -1682,6 +1678,7 @@ virCommandFreeSendBuffers(virCommandPtr cmd) } +#ifndef WIN32 /** * virCommandSetSendBuffer * @cmd: the command to modify @@ -1690,7 +1687,6 @@ virCommandFreeSendBuffers(virCommandPtr cmd) * given file descriptor. The buffer will be freed automatically * and the file descriptor closed. */ -#if defined(F_SETFL) int virCommandSetSendBuffer(virCommandPtr cmd, int fd, @@ -1724,23 +1720,6 @@ virCommandSetSendBuffer(virCommandPtr cmd, return 0; } -#else /* !defined(F_SETFL) */ - -int -virCommandSetSendBuffer(virCommandPtr cmd, - int fd G_GNUC_UNUSED, - unsigned char *buffer G_GNUC_UNUSED, - size_t buflen G_GNUC_UNUSED) -{ - if (!cmd || cmd->has_error) - return -1; - - cmd->has_error = ENOTSUP; - - return -1; -} - -#endif static int virCommandSendBuffersFillPollfd(virCommandPtr cmd, @@ -1797,6 +1776,9 @@ virCommandSendBuffersHandlePoll(virCommandPtr cmd, return 0; } +#endif /* !WIN32 */ + + /** * virCommandSetInputBuffer: * @cmd: the command to modify @@ -2105,6 +2087,7 @@ virCommandToString(virCommandPtr cmd, bool linebreaks) } +#ifndef WIN32 /* * Manage input and output to the child process. */ @@ -2276,7 +2259,6 @@ virCommandProcessIO(virCommandPtr cmd) * Returns -1 on any error executing the command. * Will not return on success. */ -#ifndef WIN32 int virCommandExec(virCommandPtr cmd, gid_t *groups, int ngroups) { if (!cmd ||cmd->has_error == ENOMEM) { @@ -2299,19 +2281,7 @@ int virCommandExec(virCommandPtr cmd, gid_t *groups, int ngroups) cmd->args[0]); return -1; } -#else -int virCommandExec(virCommandPtr cmd G_GNUC_UNUSED, gid_t *groups G_GNUC_UNUSED, - int ngroups G_GNUC_UNUSED) -{ - /* Mingw execve() has a broken signature. Disable this - * function until gnulib fixes the signature, since we - * don't really need this on Win32 anyway. - */ - virReportSystemError(ENOSYS, "%s", - _("Executing new processes is not supported on Win32 platform")); - return -1; -} -#endif + /** * virCommandRun: @@ -2516,7 +2486,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) } cmd->infd = infd[0]; cmd->inpipe = infd[1]; -#if defined (F_SETFL) + if (fcntl(cmd->inpipe, F_SETFL, O_NONBLOCK) < 0) { virReportSystemError(errno, "%s", _("fcntl failed to set O_NONBLOCK")); @@ -2524,11 +2494,6 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) ret = -1; goto cleanup; } -#else /* !defined(F_SETFL) */ - cmd->has_error = ENOTSUP; - ret = -1; - goto cleanup; -#endif } else if ((cmd->inbuf && cmd->infd == -1) || (cmd->outbuf && cmd->outfdptr != &cmd->outfd) || (cmd->errbuf && cmd->errfdptr != &cmd->errfd)) { @@ -2719,7 +2684,6 @@ virCommandWait(virCommandPtr cmd, int *exitstatus) } -#ifndef WIN32 /** * virCommandAbort: * @cmd: command to abort @@ -2738,15 +2702,6 @@ virCommandAbort(virCommandPtr cmd) cmd->pid = -1; cmd->reap = false; } -#else /* WIN32 */ -void -virCommandAbort(virCommandPtr cmd G_GNUC_UNUSED) -{ - /* Mingw lacks WNOHANG and kill(). But since we haven't ported - * virExec to mingw yet, there's no process to be killed, - * making this implementation trivially correct for now :) */ -} -#endif /** @@ -2891,6 +2846,92 @@ int virCommandHandshakeNotify(virCommandPtr cmd) VIR_FORCE_CLOSE(cmd->handshakeNotify[1]); return 0; } +#else /* WIN32 */ +int +virCommandSetSendBuffer(virCommandPtr cmd, + int fd G_GNUC_UNUSED, + unsigned char *buffer G_GNUC_UNUSED, + size_t buflen G_GNUC_UNUSED) +{ + if (!cmd || cmd->has_error) + return -1; + + cmd->has_error = ENOTSUP; + + return -1; +} + + +int +virCommandExec(virCommandPtr cmd G_GNUC_UNUSED, gid_t *groups G_GNUC_UNUSED, + int ngroups G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Win32 platform")); + return -1; +} + + +int +virCommandRun(virCommandPtr cmd G_GNUC_UNUSED, int *exitstatus G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Win32 platform")); + return -1; +} + + +int +virCommandRunAsync(virCommandPtr cmd G_GNUC_UNUSED, pid_t *pid G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Win32 platform")); + return -1; +} + + +int +virCommandWait(virCommandPtr cmd G_GNUC_UNUSED, int *exitstatus G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Win32 platform")); + return -1; +} + + +void +virCommandAbort(virCommandPtr cmd G_GNUC_UNUSED) +{ + /* Mingw lacks WNOHANG and kill(). But since we haven't ported + * virExec to mingw yet, there's no process to be killed, + * making this implementation trivially correct for now :) */ +} + + +void virCommandRequireHandshake(virCommandPtr cmd) +{ + if (!cmd || cmd->has_error) + return; + + cmd->has_error = ENOSYS; +} + + +int virCommandHandshakeWait(virCommandPtr cmd G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Win32 platform")); + return -1; +} + + +int virCommandHandshakeNotify(virCommandPtr cmd G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Executing new processes is not supported on Win32 platform")); + return -1; +} +#endif /* WIN32 */ /** -- 2.24.1

Cygwin is not a supported build platform for libvirt and has no testing coverage in our CI systems. Stop pretending the code is usable and remove it so there is less to port to Meson. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- configure.ac | 11 ++--------- m4/virt-compile-pie.m4 | 2 +- m4/virt-win-common.m4 | 8 +++----- m4/virt-win-cygwin.m4 | 32 -------------------------------- m4/virt-win-symbols.m4 | 4 ++-- m4/virt-win-windres.m4 | 4 ++-- m4/virt-xdr.m4 | 9 +++------ src/Makefile.am | 8 +++----- src/admin/Makefile.inc.am | 1 - src/locking/Makefile.inc.am | 1 - src/logging/Makefile.inc.am | 1 - src/rpc/Makefile.inc.am | 3 --- src/rpc/genprotocol.pl | 2 +- src/util/virsocketaddr.h | 10 ---------- src/util/virxdrdefs.h | 12 +----------- 15 files changed, 18 insertions(+), 90 deletions(-) delete mode 100644 m4/virt-win-cygwin.m4 diff --git a/configure.ac b/configure.ac index f0d79b95d4..855654c75d 100644 --- a/configure.ac +++ b/configure.ac @@ -181,8 +181,6 @@ case "$host" in # mingw's ld has the --version-script parameter, but it requires a .def file # instead to work properly, therefore clear --version-script here and use # -Wl, to pass the .def file to the linker - # cygwin's ld has the --version-script parameter too, but for some reason - # it's working there as expected VERSION_SCRIPT_FLAGS="-Wl," ;; * ) @@ -204,13 +202,12 @@ dnl are also linux specific. The "network" and storage_fs drivers are known dnl to not work on macOS presently, so we also make a note if compiling dnl for that -with_linux=no with_macos=no with_freebsd=no with_win=no with_cygwin=no +with_linux=no with_macos=no with_freebsd=no with_win=no case $host in *-*-linux*) with_linux=yes ;; *-*-darwin*) with_macos=yes ;; *-*-freebsd*) with_freebsd=yes ;; *-*-mingw* | *-*-msvc* ) with_win=yes ;; - *-*-cygwin*) with_cygwin=yes ;; esac if test $with_linux = no; then @@ -227,9 +224,6 @@ if test $with_freebsd = yes; then with_firewalld=no fi -if test $with_cygwin = yes; then - with_vbox=no -fi AM_CONDITIONAL([WITH_LINUX], [test "$with_linux" = "yes"]) AM_CONDITIONAL([WITH_FREEBSD], [test "$with_freebsd" = "yes"]) @@ -778,9 +772,8 @@ if test "$enable_test_coverage" = yes; then WARN_CFLAGS=$save_WARN_CFLAGS fi -dnl Cygwin, MinGW and MSVC checks +dnl MinGW checks LIBVIRT_WIN_CHECK_COMMON -LIBVIRT_WIN_CHECK_CYGWIN LIBVIRT_WIN_CHECK_MINGW LIBVIRT_WIN_CHECK_SYMBOLS LIBVIRT_WIN_CHECK_WINDRES diff --git a/m4/virt-compile-pie.m4 b/m4/virt-compile-pie.m4 index a2df38ea72..da5cdf57b7 100644 --- a/m4/virt-compile-pie.m4 +++ b/m4/virt-compile-pie.m4 @@ -22,7 +22,7 @@ AC_DEFUN([LIBVIRT_COMPILE_PIE],[ PIE_CFLAGS= PIE_LDFLAGS= case "$host" in - *-*-mingw* | *-*-msvc* | *-*-cygwin* ) + *-*-mingw* ) ;; dnl All code is position independent on Win32 target *) gl_COMPILER_OPTION_IF([-fPIE -DPIE -pie], [ diff --git a/m4/virt-win-common.m4 b/m4/virt-win-common.m4 index b639866e64..ebc9d0836e 100644 --- a/m4/virt-win-common.m4 +++ b/m4/virt-win-common.m4 @@ -1,4 +1,4 @@ -dnl The Cygwin, MinGW and MSVC common checks +dnl The MinGW common checks dnl dnl Copyright (C) 2016 Red Hat, Inc. dnl @@ -22,7 +22,7 @@ AC_DEFUN([LIBVIRT_WIN_CHECK_COMMON], [ WIN32_EXTRA_LIBS= case "$host" in - *-*-mingw* | *-*-cygwin* | *-*-msvc* ) + *-*-mingw* ) WIN32_EXTRA_LIBS="-lole32 -loleaut32" # If the host is Windows, and shared libraries are disabled, we # need to add -DLIBVIRT_STATIC to the CFLAGS for proper linking @@ -38,7 +38,5 @@ AC_DEFUN([LIBVIRT_WIN_CHECK_COMMON], [ AC_DEFUN([LIBVIRT_WIN_RESULT_COMMON], [ details="CFLAGS='$WIN32_EXTRA_CFLAGS' LIBS='$WIN32_EXTRA_LIBS'" - LIBVIRT_RESULT([Cygwin], [$with_cygwin], [$details]) - LIBVIRT_RESULT([MinGW], [$with_cygwin], [$details]) - LIBVIRT_RESULT([MSVC], [$with_cygwin], [$details]) + LIBVIRT_RESULT([MinGW], [$with_win], [$details]) ]) diff --git a/m4/virt-win-cygwin.m4 b/m4/virt-win-cygwin.m4 deleted file mode 100644 index 211b3c2b7b..0000000000 --- a/m4/virt-win-cygwin.m4 +++ /dev/null @@ -1,32 +0,0 @@ -dnl The Cygwin check -dnl -dnl Copyright (C) 2016 Red Hat, Inc. -dnl -dnl This library is free software; you can redistribute it and/or -dnl modify it under the terms of the GNU Lesser General Public -dnl License as published by the Free Software Foundation; either -dnl version 2.1 of the License, or (at your option) any later version. -dnl -dnl This library is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -dnl Lesser General Public License for more details. -dnl -dnl You should have received a copy of the GNU Lesser General Public -dnl License along with this library. If not, see -dnl <http://www.gnu.org/licenses/>. -dnl - -AC_DEFUN([LIBVIRT_WIN_CHECK_CYGWIN], [ - CYGWIN_EXTRA_LDFLAGS= - CYGWIN_EXTRA_LIBADD= - case "$host" in - *-*-cygwin*) - CYGWIN_EXTRA_LDFLAGS="-no-undefined" - CYGWIN_EXTRA_LIBADD="${INTLLIBS}" - ;; - esac - - AC_SUBST([CYGWIN_EXTRA_LDFLAGS]) - AC_SUBST([CYGWIN_EXTRA_LIBADD]) -]) diff --git a/m4/virt-win-symbols.m4 b/m4/virt-win-symbols.m4 index 66dd3b7b1c..eba5596e4b 100644 --- a/m4/virt-win-symbols.m4 +++ b/m4/virt-win-symbols.m4 @@ -1,4 +1,4 @@ -dnl The Cygwin, MinGW and MSVC symbols checks +dnl The MinGW symbols checks dnl dnl Copyright (C) 2016 Red Hat, Inc. dnl @@ -23,7 +23,7 @@ AC_DEFUN([LIBVIRT_WIN_CHECK_SYMBOLS], [ LIBVIRT_LXC_SYMBOL_FILE='$(srcdir)/libvirt_lxc.syms' LIBVIRT_QEMU_SYMBOL_FILE='$(srcdir)/libvirt_qemu.syms' case "$host" in - *-*-mingw* | *-*-msvc* ) + *-*-mingw* ) # Also set the symbol file to .def, so src/Makefile generates libvirt.def # from libvirt.syms and passes libvirt.def instead of libvirt.syms to the # linker diff --git a/m4/virt-win-windres.m4 b/m4/virt-win-windres.m4 index af27f231b4..e913eb48b8 100644 --- a/m4/virt-win-windres.m4 +++ b/m4/virt-win-windres.m4 @@ -1,4 +1,4 @@ -dnl The Cygwin, MinGW and MSVC windres checks +dnl The MinGW windres checks dnl dnl Copyright (C) 2016 Red Hat, Inc. dnl @@ -21,7 +21,7 @@ AC_DEFUN([LIBVIRT_WIN_CHECK_WINDRES], [ dnl Look for windres to build a Windows icon resource. with_windres=no case "$host" in - *-*-mingw* | *-*-cygwin* | *-*-msvc* ) + *-*-mingw* ) AC_CHECK_TOOL([WINDRES], [windres], []) if test "x$WINDRES" != "x"; then with_windres=yes diff --git a/m4/virt-xdr.m4 b/m4/virt-xdr.m4 index a65407d955..83754157d9 100644 --- a/m4/virt-xdr.m4 +++ b/m4/virt-xdr.m4 @@ -22,18 +22,15 @@ AC_DEFUN([LIBVIRT_CHECK_XDR], [ if test x"$with_remote" = x"yes" || test x"$with_libvirtd" = x"yes"; then dnl Where are the XDR functions? dnl If portablexdr is installed, prefer that. - dnl Otherwise try -lrpc (Cygwin) -lxdr (some MinGW), -lnsl (Solaris) + dnl Otherwise try -lxdr (some MinGW) dnl -ltirpc (glibc 2.13.90 or newer) or none (most Unix) AC_CHECK_LIB([portablexdr],[xdrmem_create],[],[ - AC_SEARCH_LIBS([xdrmem_create],[rpc xdr nsl tirpc],[], + AC_SEARCH_LIBS([xdrmem_create],[xdr tirpc],[], [AC_MSG_ERROR([Cannot find a XDR library])]) ]) with_xdr="yes" - dnl check for cygwin's variation in xdr function names - AC_CHECK_FUNCS([xdr_u_int64_t],[],[],[#include <rpc/xdr.h>]) - - dnl Cygwin/recent glibc requires -I/usr/include/tirpc for <rpc/rpc.h> + dnl Recent glibc requires -I/usr/include/tirpc for <rpc/rpc.h> old_CFLAGS=$CFLAGS AC_CACHE_CHECK([where to find <rpc/rpc.h>], [lv_cv_xdr_cflags], [ for add_CFLAGS in '' '-I/usr/include/tirpc' 'missing'; do diff --git a/src/Makefile.am b/src/Makefile.am index c9b5eeba47..a9b71131ce 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,7 +42,6 @@ AM_LDFLAGS = $(DRIVER_MODULES_LDFLAGS) \ $(COVERAGE_LDFLAGS) \ $(RELRO_LDFLAGS) \ $(NO_INDIRECT_LDFLAGS) \ - $(CYGWIN_EXTRA_LDFLAGS) \ $(MINGW_EXTRA_LDFLAGS) \ $(NULL) AM_LDFLAGS_MOD = \ @@ -449,8 +448,7 @@ endif WITH_MACOS libvirt_la_LDFLAGS += $(NULL) libvirt_la_BUILT_LIBADD += ../gnulib/lib/libgnu.la libvirt_la_LIBADD += \ - $(DRIVER_MODULES_LIBS) \ - $(CYGWIN_EXTRA_LIBADD) + $(DRIVER_MODULES_LIBS) libvirt_la_CFLAGS = -DIN_LIBVIRT $(AM_CFLAGS) # Because we specify libvirt_la_DEPENDENCIES for $(LIBVIRT_SYMBOL_FILE), we # lose automake's automatic dependencies on an appropriate subset of @@ -517,7 +515,7 @@ libvirt_qemu_la_LDFLAGS = \ $(AM_LDFLAGS) \ $(NULL) libvirt_qemu_la_CFLAGS = $(AM_CFLAGS) -libvirt_qemu_la_LIBADD = libvirt.la $(CYGWIN_EXTRA_LIBADD) +libvirt_qemu_la_LIBADD = libvirt.la libvirt_lxc_la_SOURCES = libvirt-lxc.c libvirt_lxc_la_LDFLAGS = \ @@ -527,7 +525,7 @@ libvirt_lxc_la_LDFLAGS = \ $(AM_LDFLAGS) \ $(NULL) libvirt_lxc_la_CFLAGS = $(AM_CFLAGS) -libvirt_lxc_la_LIBADD = libvirt.la $(CYGWIN_EXTRA_LIBADD) +libvirt_lxc_la_LIBADD = libvirt.la EXTRA_DIST += \ $(SYSCONF_FILES) \ diff --git a/src/admin/Makefile.inc.am b/src/admin/Makefile.inc.am index 7ceccafa8e..b4e2f1f2d3 100644 --- a/src/admin/Makefile.inc.am +++ b/src/admin/Makefile.inc.am @@ -73,7 +73,6 @@ libvirt_admin_la_LDFLAGS = \ libvirt_admin_la_LIBADD = \ libvirt.la \ - $(CYGWIN_EXTRA_LIBADD) \ $(CAPNG_LIBS) \ $(YAJL_LIBS) \ $(DEVMAPPER_LIBS) \ diff --git a/src/locking/Makefile.inc.am b/src/locking/Makefile.inc.am index 65b46ad5f3..d49383d9d7 100644 --- a/src/locking/Makefile.inc.am +++ b/src/locking/Makefile.inc.am @@ -162,7 +162,6 @@ virtlockd_LDADD = \ libvirt_driver_admin.la \ $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ - $(CYGWIN_EXTRA_LIBADD) \ $(NULL) if WITH_DTRACE_PROBES virtlockd_LDADD += libvirt_probes.lo diff --git a/src/logging/Makefile.inc.am b/src/logging/Makefile.inc.am index 0f7ffa73b3..e8240fa5c4 100644 --- a/src/logging/Makefile.inc.am +++ b/src/logging/Makefile.inc.am @@ -99,7 +99,6 @@ virtlogd_LDADD = \ libvirt.la \ $(GLIB_LIBS) \ ../gnulib/lib/libgnu.la \ - $(CYGWIN_EXTRA_LIBADD) \ $(NULL) if WITH_DTRACE_PROBES virtlogd_LDADD += libvirt_probes.lo diff --git a/src/rpc/Makefile.inc.am b/src/rpc/Makefile.inc.am index 11920b3270..0e154d9c69 100644 --- a/src/rpc/Makefile.inc.am +++ b/src/rpc/Makefile.inc.am @@ -97,7 +97,6 @@ libvirt_net_rpc_la_LDFLAGS = \ $(SECDRIVER_LIBS) \ $(AM_LDFLAGS) \ $(NULL) -libvirt_net_rpc_la_LIBADD = $(CYGWIN_EXTRA_LIBADD) libvirt_net_rpc_server_la_SOURCES = \ rpc/virnetserverprogram.h \ @@ -122,7 +121,6 @@ libvirt_net_rpc_server_la_LDFLAGS = \ $(AM_LDFLAGS) \ $(DBUS_LIBS) \ $(NULL) -libvirt_net_rpc_server_la_LIBADD = $(CYGWIN_EXTRA_LIBADD) libvirt_net_rpc_client_la_SOURCES = \ rpc/virnetclientprogram.h \ @@ -138,7 +136,6 @@ libvirt_net_rpc_client_la_CFLAGS = \ $(XDR_CFLAGS) \ $(NULL) libvirt_net_rpc_client_la_LDFLAGS = $(AM_LDFLAGS) -libvirt_net_rpc_client_la_LIBADD = $(CYGWIN_EXTRA_LIBADD) if WITH_SASL libvirt_net_rpc_client_la_CFLAGS += \ diff --git a/src/rpc/genprotocol.pl b/src/rpc/genprotocol.pl index 6baa4f22d5..f567260588 100755 --- a/src/rpc/genprotocol.pl +++ b/src/rpc/genprotocol.pl @@ -47,7 +47,7 @@ open RPCGEN, "-|", "$rpcgen $mode $xdrdef" open TARGET, ">$target" or die "cannot create $target: $!"; -my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd" || $^O eq "freebsd" || $^O eq "darwin"; +my $fixup = $^O eq "linux" || $^O eq "gnukfreebsd" || $^O eq "freebsd" || $^O eq "darwin"; if ($mode eq "-c") { print TARGET "#include <config.h>\n"; diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index 1180864f06..66aee2abcd 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -26,16 +26,6 @@ #include "internal.h" -/* On architectures which lack these limits, define them (ie. Cygwin). - * Note that the libvirt code should be robust enough to handle the - * case where actual value is longer than these limits (eg. by setting - * length correctly in second argument to gethostname and by always - * using strncpy instead of strcpy). - */ -#ifndef INET_ADDRSTRLEN -# define INET_ADDRSTRLEN 16 -#endif - #define VIR_LOOPBACK_IPV4_ADDR "127.0.0.1" typedef struct { diff --git a/src/util/virxdrdefs.h b/src/util/virxdrdefs.h index 264d02e7cd..b6f6ad5a4d 100644 --- a/src/util/virxdrdefs.h +++ b/src/util/virxdrdefs.h @@ -20,18 +20,8 @@ #pragma once -/* cygwin's xdr implementation defines xdr_u_int64_t instead of xdr_uint64_t - * and lacks IXDR_PUT_INT32 and IXDR_GET_INT32 +/* The portablexdr implementation lacks IXDR_PUT_U_INT32 and IXDR_GET_U_INT32 */ -#ifdef HAVE_XDR_U_INT64_T -# define xdr_uint64_t xdr_u_int64_t -#endif -#ifndef IXDR_PUT_INT32 -# define IXDR_PUT_INT32 IXDR_PUT_LONG -#endif -#ifndef IXDR_GET_INT32 -# define IXDR_GET_INT32 IXDR_GET_LONG -#endif #ifndef IXDR_PUT_U_INT32 # define IXDR_PUT_U_INT32 IXDR_PUT_U_LONG #endif -- 2.24.1

Many of the virProcess APIs are relying on GNULIB providing POSIX API stubs. Even with these stubs the APIs don't do anything useful once compiled. We can thus conditionalize the code so that we don't compile anything at all. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virprocess.c | 98 +++++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 22 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index d8ee3142da..60419538e2 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -24,7 +24,9 @@ #include <fcntl.h> #include <signal.h> -#include <sys/wait.h> +#ifndef WIN32 +# include <sys/wait.h> +#endif #include <unistd.h> #if HAVE_SYS_MOUNT_H # include <sys/mount.h> @@ -121,6 +123,8 @@ VIR_ENUM_IMPL(virProcessSchedPolicy, "rr", ); + +#ifndef WIN32 /** * virProcessTranslateStatus: * @status: child exit status to translate @@ -146,7 +150,6 @@ virProcessTranslateStatus(int status) } -#ifndef WIN32 /** * virProcessAbort: * @pid: child process to kill @@ -206,14 +209,6 @@ virProcessAbort(pid_t pid) cleanup: errno = saved_errno; } -#else -void -virProcessAbort(pid_t pid) -{ - /* Not yet ported to mingw. Any volunteers? */ - VIR_DEBUG("failed to reap child %lld, abandoning it", (long long)pid); -} -#endif /** @@ -282,6 +277,33 @@ virProcessWait(pid_t pid, int *exitstatus, bool raw) return -1; } +#else /* WIN32 */ + +char * +virProcessTranslateStatus(int status) +{ + return g_strdup_printf(_("invalid value %d"), status); +} + + +void +virProcessAbort(pid_t pid) +{ + /* Not yet ported to mingw. Any volunteers? */ + VIR_DEBUG("failed to reap child %lld, abandoning it", (long long)pid); +} + + +int +virProcessWait(pid_t pid, int *exitstatus G_GNUC_UNUSED, bool raw G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, _("unable to wait for process %lld"), + (long long) pid); + return -1; +} + +#endif /* WIN32 */ + /* send signal to a single process */ int virProcessKill(pid_t pid, int sig) @@ -1036,6 +1058,7 @@ int virProcessGetStartTime(pid_t pid, #endif +#ifdef __linux__ typedef struct _virProcessNamespaceHelperData virProcessNamespaceHelperData; struct _virProcessNamespaceHelperData { pid_t pid; @@ -1088,7 +1111,22 @@ virProcessRunInMountNamespace(pid_t pid, return virProcessRunInFork(virProcessNamespaceHelper, &data); } +#else /* ! __linux__ */ +int +virProcessRunInMountNamespace(pid_t pid G_GNUC_UNUSED, + virProcessNamespaceCallback cb G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Namespaces are not supported on this platform")); + return -1; +} + +#endif /* ! __linux__ */ + + +#ifndef WIN32 static int virProcessRunInForkHelper(int errfd, pid_t ppid, @@ -1174,8 +1212,21 @@ virProcessRunInFork(virProcessForkCallback cb, return ret; } +#else /* WIN32 */ + +int +virProcessRunInFork(virProcessForkCallback cb G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("Process spawning is not supported on this platform")); + return -1; +} + +#endif /* WIN32 */ -#if defined(HAVE_SYS_MOUNT_H) && defined(HAVE_UNSHARE) + +#if defined(__linux__) int virProcessSetupPrivateMountNS(void) { @@ -1194,24 +1245,14 @@ virProcessSetupPrivateMountNS(void) return 0; } -#else /* !defined(HAVE_SYS_MOUNT_H) || !defined(HAVE_UNSHARE) */ - -int -virProcessSetupPrivateMountNS(void) -{ - virReportSystemError(ENOSYS, "%s", - _("Namespaces are not supported on this platform.")); - return -1; -} -#endif /* !defined(HAVE_SYS_MOUNT_H) || !defined(HAVE_UNSHARE) */ -#if defined(__linux__) G_GNUC_NORETURN static int virProcessDummyChild(void *argv G_GNUC_UNUSED) { _exit(0); } + /** * virProcessNamespaceAvailable: * @ns: what namespaces to check (bitwise-OR of virProcessNamespaceFlags) @@ -1269,6 +1310,14 @@ virProcessNamespaceAvailable(unsigned int ns) #else /* !defined(__linux__) */ +int +virProcessSetupPrivateMountNS(void) +{ + virReportSystemError(ENOSYS, "%s", + _("Namespaces are not supported on this platform.")); + return -1; +} + int virProcessNamespaceAvailable(unsigned int ns G_GNUC_UNUSED) { @@ -1276,6 +1325,7 @@ virProcessNamespaceAvailable(unsigned int ns G_GNUC_UNUSED) _("Namespaces are not supported on this platform.")); return -1; } + #endif /* !defined(__linux__) */ /** @@ -1296,6 +1346,7 @@ virProcessExitWithStatus(int status) { int value = EXIT_CANNOT_INVOKE; +#ifndef WIN32 if (WIFEXITED(status)) { value = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { @@ -1312,6 +1363,9 @@ virProcessExitWithStatus(int status) raise(WTERMSIG(status)); value = 128 + WTERMSIG(status); } +#else /* WIN32 */ + (void)status; +#endif /* WIN32 */ exit(value); } -- 2.24.1

The net/if.h is not portable so we must check for its existance and avoid using it when missing. Some use of net/if.h was redundant and could be removed. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- build-aux/syntax-check.mk | 2 +- configure.ac | 1 + src/util/virnetdev.c | 1 - src/util/virnetdev.h | 4 +++- src/util/virnetdevbridge.c | 4 +++- src/util/virnetdevip.c | 4 +++- src/util/virnetdevtap.c | 4 +++- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index e5623606dd..7eb7d0beab 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -2338,4 +2338,4 @@ exclude_file_name_regexp--sc_prohibit_backslash_alignment = \ ^build-aux/syntax-check\.mk$$ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ - ^src/util/virfile\.c$$ + ^src/util/(virfile|virnetdev|virnetdevip)\.[c,h]|$$ diff --git a/configure.ac b/configure.ac index 855654c75d..75df326795 100644 --- a/configure.ac +++ b/configure.ac @@ -381,6 +381,7 @@ AC_CHECK_HEADERS([\ mntent.h \ net/ethernet.h \ netinet/tcp.h \ + net/if.h \ pty.h \ pwd.h \ stdarg.h \ diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index b896a7507e..094d1ac09b 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -34,7 +34,6 @@ #ifndef WIN32 # include <sys/ioctl.h> #endif -#include <net/if.h> #include <fcntl.h> #ifdef __linux__ diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 24b41498ed..78e1aa656a 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -18,7 +18,9 @@ #pragma once -#include <net/if.h> +#ifdef HAVE_NET_IF_H +# include <net/if.h> +#endif #include "virbitmap.h" #include "virsocketaddr.h" diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 5bb533f1f0..5a0fb5f42f 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -31,7 +31,9 @@ # include <sys/ioctl.h> #endif #include <sys/socket.h> -#include <net/if.h> +#ifdef HAVE_NET_IF +# include <net/if.h> +#endif #include <netinet/in.h> #ifdef __linux__ diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index 5897c4aa76..bfb93cf258 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -36,7 +36,9 @@ #ifndef WIN32 # include <sys/ioctl.h> #endif -#include <net/if.h> +#ifdef HAVE_NET_IF_H +# include <net/if.h> +#endif #include <fcntl.h> #ifdef __linux__ diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 8656e267cb..84d91428e7 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -36,7 +36,9 @@ #ifndef WIN32 # include <sys/ioctl.h> #endif -#include <net/if.h> +#ifdef HAVE_NET_IF +# include <net/if.h> +#endif #include <fcntl.h> #ifdef __linux__ # include <linux/if_tun.h> /* IFF_TUN, IFF_NO_PI */ -- 2.24.1

We currently get the sys/ioctl.h check indirectly via GNULIB, but this will soon stop happening. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 75df326795..2cd0e7dcee 100644 --- a/configure.ac +++ b/configure.ac @@ -386,6 +386,7 @@ AC_CHECK_HEADERS([\ pwd.h \ stdarg.h \ syslog.h \ + sys/ioctl.h \ sys/mount.h \ sys/syscall.h \ sys/sysctl.h \ -- 2.24.1

The S_ISSOCK macro is not available on Windows platforms. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/libvirt-domain.c | 2 ++ src/security/security_manager.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 4074397b30..ceda85c243 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -10584,12 +10584,14 @@ virDomainOpenGraphics(virDomainPtr dom, goto error; } +#ifndef WIN32 if (!S_ISSOCK(sb.st_mode)) { virReportInvalidArg(fd, _("fd %d must be a socket"), fd); goto error; } +#endif /* !WIN32 */ virCheckReadOnlyGoto(dom->conn->flags, error); diff --git a/src/security/security_manager.c b/src/security/security_manager.c index f229d94570..fe9def7fb9 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -1340,11 +1340,13 @@ virSecurityManagerMetadataLock(virSecurityManagerPtr mgr G_GNUC_UNUSED, } if ((fd = open(p, O_RDWR)) < 0) { +#ifndef WIN32 if (S_ISSOCK(sb.st_mode)) { /* Sockets can be opened only if there exists the * other side that listens. */ continue; } +#endif /* !WIN32 */ virReportSystemError(errno, _("unable to open %s"), -- 2.24.1

The AC_USE_SYSTEM_EXTENSIONS macro causes things like "USE_GNU" to be defined, which enables access to OS specific extensions to POSIX. We currently got this indirectly via GNULIB's 'extensions' module which is a dependancy of other GNULIB modules we use. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- configure.ac | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.ac b/configure.ac index 2cd0e7dcee..adfd950260 100644 --- a/configure.ac +++ b/configure.ac @@ -55,6 +55,8 @@ m4_ifndef([AM_SILENT_RULES], AC_CANONICAL_HOST +AC_USE_SYSTEM_EXTENSIONS + # First extract pieces from the version number string LIBVIRT_MAJOR_VERSION=`echo $VERSION | awk -F. '{print $1}'` LIBVIRT_MINOR_VERSION=`echo $VERSION | awk -F. '{print $2}'` -- 2.24.1

The O_DIRECTORY flag causes open() to return an error if the filename is a directory. There's no obvious reason why resctrl needs to use this, while the rest of libvirt code does not. Removing it avoids build issues on platforms where O_DIRECTORY is not defined, once we remove GNULIB. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virresctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 684d2ce398..e9bcdb44b1 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -455,7 +455,7 @@ VIR_ONCE_GLOBAL_INIT(virResctrl); static int virResctrlLockWrite(void) { - int fd = open(SYSFS_RESCTRL_PATH, O_DIRECTORY | O_CLOEXEC); + int fd = open(SYSFS_RESCTRL_PATH, O_RDWR | O_CLOEXEC); if (fd < 0) { virReportSystemError(errno, "%s", _("Cannot open resctrl")); -- 2.24.1

Windows uses _O_NOINHERIT as the name for its O_CLOEXEC equivalent. Define O_CLOEXEC to match this to fix portability when we remove GNULIB. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/internal.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/internal.h b/src/internal.h index 4a63984cec..8c9322ec1e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -89,6 +89,12 @@ #define NUL_TERMINATE(buf) do { (buf)[sizeof(buf)-1] = '\0'; } while (0) +#ifdef WIN32 +# ifndef O_CLOEXEC +# define O_CLOEXEC _O_NOINHERIT +# endif +#endif + /** * G_GNUC_NO_INLINE: * -- 2.24.1

The F_DUPFD_CLOEXEC functionality is not available on some platformms. We must thus explicitly call the virSetCloexec function once we remove GNULIB's equiv fix for this. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/rpc/virnetsocket.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 687099720f..906b5165eb 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1403,15 +1403,27 @@ int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec) { int fd; +#ifdef F_DUPFD_CLOEXEC if (cloexec) fd = fcntl(sock->fd, F_DUPFD_CLOEXEC, 0); else +#endif /* F_DUPFD_CLOEXEC */ fd = dup(sock->fd); if (fd < 0) { virReportSystemError(errno, "%s", _("Unable to copy socket file handle")); return -1; } +#ifndef F_DUPFD_CLOEXEC + if (cloexec && + virSetCloseExec(fd < 0)) { + int saveerr = errno; + closesocket(fd); + errno = saveerr; + return -1; + } +#endif /* F_DUPFD_CLOEXEC */ + return fd; } -- 2.24.1

The O_DIRECT flag is not available on platforms, so we must avoid it once we remove GNULIB. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virfile.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/virfile.c b/src/util/virfile.c index d0e0062aa7..617d5d7a48 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -178,7 +178,11 @@ virFileDirectFdFlag(void) { /* XXX For now, Linux posix_fadvise is not powerful enough to * avoid O_DIRECT. */ +#ifdef O_DIRECT return O_DIRECT ? O_DIRECT : -1; +#else + return -1; +#endif } /* Opaque type for managing a wrapper around a fd. For now, -- 2.24.1

On Thu, Jan 23, 2020 at 11:43:19AM +0000, Daniel P. Berrangé wrote:
The O_DIRECT flag is not available on platforms, so we must avoid it once we remove GNULIB.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virfile.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/src/util/virfile.c b/src/util/virfile.c index d0e0062aa7..617d5d7a48 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -178,7 +178,11 @@ virFileDirectFdFlag(void) { /* XXX For now, Linux posix_fadvise is not powerful enough to * avoid O_DIRECT. */ +#ifdef O_DIRECT return O_DIRECT ? O_DIRECT : -1; +#else + return -1; +#endif }
This patch is broken, as it misses iohelper. The real fix needs to be to follow what gnulib does diff --git a/src/util/iohelper.c b/src/util/iohelper.c index d864bbeaed..618bfb1d3d 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -39,6 +39,10 @@ #define VIR_FROM_THIS VIR_FROM_STORAGE +#ifndef O_DIRECT +# define O_DIRECT 0 +#endif + static int runIO(const char *path, int fd, int oflags) { diff --git a/src/util/virfile.c b/src/util/virfile.c index d0e0062aa7..efa59f2b13 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -95,6 +95,10 @@ VIR_LOG_INIT("util.file"); +#ifndef O_DIRECT +# define O_DIRECT 0 +#endif + int virFileClose(int *fdptr, virFileCloseFlags flags) { int saved_errno = 0; Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

The O_BINARY flag is not defined on all platforms so we must conditionalize its use once we remove GNULIB. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/util/virfdstream.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index a903107afb..58b77aa6fa 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -1243,7 +1243,10 @@ virFDStreamOpenFileInternal(virStreamPtr st, VIR_DEBUG("st=%p path=%s oflags=0x%x offset=%llu length=%llu mode=0%o", st, path, oflags, offset, length, mode); - oflags |= O_NOCTTY | O_BINARY; + oflags |= O_NOCTTY; +#ifdef O_BINARY + oflags |= O_BINARY; +#endif if (oflags & O_CREAT) fd = open(path, oflags, mode); -- 2.24.1

chown and some stat constants are not available on the Windows platform. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/security/security_dac.c | 4 ++++ src/storage/storage_util.c | 3 +++ src/util/virfile.c | 44 +++++++++++++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 2561ee440e..2aab227d71 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -710,7 +710,11 @@ virSecurityDACSetOwnershipInternal(const virSecurityDACData *priv, return 0; } +#ifdef WIN32 + rc = ENOSYS; +#else /* !WIN32 */ rc = chown(path, uid, gid); +#endif /* !WIN32 */ } if (rc < 0) { diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 7bbcfde064..b6ea0a2760 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -79,6 +79,9 @@ VIR_LOG_INIT("storage.storage_util"); +#ifndef S_IRWXUGO +# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) +#endif /* virStorageBackendNamespaceInit: * @poolType: virStoragePoolType diff --git a/src/util/virfile.c b/src/util/virfile.c index 617d5d7a48..d08eae5a1d 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -95,6 +95,17 @@ VIR_LOG_INIT("util.file"); +#ifndef S_ISUID +# define S_ISUID 04000 +#endif +#ifndef S_ISGID +# define S_ISGID 02000 +#endif +#ifndef S_ISVTX +# define S_ISVTX 01000 +#endif + + int virFileClose(int *fdptr, virFileCloseFlags flags) { int saved_errno = 0; @@ -314,7 +325,7 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned int flags) virFileWrapperFdFree(ret); return NULL; } -#else +#else /* WIN32 */ virFileWrapperFdPtr virFileWrapperFdNew(int *fd G_GNUC_UNUSED, const char *name G_GNUC_UNUSED, @@ -324,7 +335,7 @@ virFileWrapperFdNew(int *fd G_GNUC_UNUSED, _("virFileWrapperFd unsupported on this platform")); return NULL; } -#endif +#endif /* WIN32 */ /** * virFileWrapperFdClose: @@ -479,7 +490,7 @@ int virFileFlock(int fd, bool lock, bool shared) return flock(fd, LOCK_UN); } -#else +#else /* WIN32 */ int virFileLock(int fd G_GNUC_UNUSED, bool shared G_GNUC_UNUSED, @@ -507,7 +518,7 @@ int virFileFlock(int fd G_GNUC_UNUSED, return -1; } -#endif +#endif /* WIN32 */ int @@ -1581,10 +1592,12 @@ virFileResolveLinkHelper(const char *linkpath, if (g_lstat(linkpath, &st) < 0) return -1; +#ifndef WIN32 if (!S_ISLNK(st.st_mode)) { *resultpath = g_strdup(linkpath); return 0; } +#endif /* WIN32 */ } *resultpath = virFileCanonicalizePath(linkpath); @@ -1630,10 +1643,17 @@ virFileIsLink(const char *linkpath) { GStatBuf st; + /* Still do this on Windows so we report + * errors like ENOENT, etc + */ if (g_lstat(linkpath, &st) < 0) return -errno; +#ifndef WIN32 return S_ISLNK(st.st_mode) != 0; +#else /* WIN32 */ + return 0; +#endif /* WIN32 */ } /* @@ -2615,6 +2635,7 @@ virDirCreateNoFork(const char *path, virReportSystemError(errno, _("stat of '%s' failed"), path); goto error; } +# ifndef WIN32 if (((uid != (uid_t) -1 && st.st_uid != uid) || (gid != (gid_t) -1 && st.st_gid != gid)) && (chown(path, uid, gid) < 0)) { @@ -2623,6 +2644,7 @@ virDirCreateNoFork(const char *path, path, (unsigned int) uid, (unsigned int) gid); goto error; } +# endif if (mode != (mode_t) -1 && chmod(path, mode) < 0) { ret = -errno; virReportSystemError(errno, @@ -2959,6 +2981,7 @@ void virDirClose(DIR **dirp) * * Returns -1 on error, with error already reported, 0 on success. */ +#ifndef WIN32 int virFileChownFiles(const char *name, uid_t uid, gid_t gid) @@ -2999,6 +3022,19 @@ int virFileChownFiles(const char *name, return ret; } +#else + +int virFileChownFiles(const char *name, + uid_t uid, + gid_t gid) +{ + virReportSystemError(ENOSYS, + _("cannot chown '%s' to (%u, %u)"), + name, (unsigned int) uid, + (unsigned int) gid); + return -1; +} +#endif /* WIN32 */ static int virFileMakePathHelper(char *path, mode_t mode) -- 2.24.1

There are a large number of different header files that are related to the sockets APIs. The virsocket.h header includes all of the relevant headers for Windows and UNIX in one convenient place. If virsocketaddr.h is already included, then there's no need for virsocket.h Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- configure.ac | 8 +++++--- src/conf/network_conf.c | 2 -- src/esx/esx_util.c | 3 +-- src/esx/esx_util.h | 1 - src/libxl/libxl_conf.c | 2 -- src/lxc/lxc_controller.c | 4 +--- src/lxc/lxc_driver.c | 4 +--- src/nwfilter/nwfilter_dhcpsnoop.c | 3 --- src/nwfilter/nwfilter_learnipaddr.c | 4 +--- src/qemu/qemu_agent.c | 4 +--- src/qemu/qemu_conf.c | 3 +-- src/qemu/qemu_driver.c | 3 +-- src/qemu/qemu_migration.c | 3 +-- src/qemu/qemu_monitor.c | 3 +-- src/qemu/qemu_monitor_json.c | 4 +--- src/remote/qemu_protocol.x | 1 - src/remote/remote_protocol.x | 2 +- src/rpc/virnetprotocol.x | 2 +- src/rpc/virnetsocket.c | 14 ++++---------- src/util/virarptable.c | 1 - src/util/virfdstream.c | 8 ++------ src/util/virfile.c | 3 +-- src/util/virlog.c | 6 +----- src/util/virnetdevbridge.c | 6 +----- src/util/virnetdevmacvlan.c | 3 +-- src/util/virnetdevvportprofile.c | 3 +-- src/util/virnetlink.c | 3 +-- src/util/virsocket.h | 3 ++- src/util/virsocketaddr.c | 2 -- src/util/virsocketaddr.h | 10 ++-------- src/util/virsystemd.c | 9 ++------- src/util/virutil.c | 13 ------------- src/vbox/vbox_MSCOMGlue.c | 6 +----- tests/libxlmock.c | 2 +- tests/nsstest.c | 3 +-- tests/virnetsockettest.c | 1 - tests/virnettlscontexttest.c | 3 +-- tests/virnettlshelpers.c | 1 - tests/virnettlssessiontest.c | 3 +-- tests/virportallocatormock.c | 5 +---- tests/virtestmock.c | 9 ++------- 41 files changed, 43 insertions(+), 130 deletions(-) diff --git a/configure.ac b/configure.ac index adfd950260..b1f75fa751 100644 --- a/configure.ac +++ b/configure.ac @@ -231,9 +231,13 @@ AM_CONDITIONAL([WITH_LINUX], [test "$with_linux" = "yes"]) AM_CONDITIONAL([WITH_FREEBSD], [test "$with_freebsd" = "yes"]) AM_CONDITIONAL([WITH_MACOS], [test "$with_macos" = "yes"]) -# We don't support the daemon yet if test "$with_win" = "yes" ; then + # We don't support the daemon yet with_libvirtd=no + + # For AI_ADDRCONFIG + AC_DEFINE([_WIN32_WINNT], [0x0600], [Win Vista / Server 2008]) + AC_DEFINE([WINVER], [0x0600], [Win Vista / Server 2008]) fi # The daemon requires remote support. Likewise, if we are not using @@ -382,7 +386,6 @@ AC_CHECK_HEADERS([\ linux/magic.h \ mntent.h \ net/ethernet.h \ - netinet/tcp.h \ net/if.h \ pty.h \ pwd.h \ @@ -393,7 +396,6 @@ AC_CHECK_HEADERS([\ sys/syscall.h \ sys/sysctl.h \ sys/ucred.h \ - sys/un.h \ ]) dnl Check whether endian provides handy macros. AC_CHECK_DECLS([htole64], [], [], [[#include <endian.h>]]) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 27e83b7d85..1f14a964a2 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -22,8 +22,6 @@ #include <config.h> #include <unistd.h> -#include <arpa/inet.h> -#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index c265528056..89d136248f 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -23,8 +23,6 @@ #include <config.h> -#include <netdb.h> - #include "internal.h" #include "datatypes.h" #include "viralloc.h" @@ -34,6 +32,7 @@ #include "esx_private.h" #include "esx_util.h" #include "virstring.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_ESX diff --git a/src/esx/esx_util.h b/src/esx/esx_util.h index d80093dcb5..97b6d82a2b 100644 --- a/src/esx/esx_util.h +++ b/src/esx/esx_util.h @@ -21,7 +21,6 @@ #pragma once -#include <netdb.h> #include "internal.h" #include "viruri.h" diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index e41e84e3e2..b4462a6291 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -24,7 +24,6 @@ #include <libxl.h> #include <sys/types.h> -#include <sys/socket.h> #include "internal.h" #include "virlog.h" @@ -48,7 +47,6 @@ #include "virnetdevvportprofile.h" #include "virenum.h" - #define VIR_FROM_THIS VIR_FROM_LIBXL VIR_LOG_INIT("libxl.libxl_conf"); diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 42c631ed0b..558a964fca 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -23,7 +23,6 @@ #include <sys/epoll.h> #include <sys/wait.h> -#include <sys/socket.h> #ifdef MAJOR_IN_MKDEV # include <sys/mkdev.h> @@ -31,8 +30,6 @@ # include <sys/sysmacros.h> #endif -#include <sys/types.h> -#include <sys/un.h> #include <sys/personality.h> #include <unistd.h> #include <fcntl.h> @@ -69,6 +66,7 @@ #include "rpc/virnetdaemon.h" #include "virstring.h" #include "virgettext.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_LXC diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index bf1f8f8190..931730eabc 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -31,10 +31,7 @@ # include <sys/sysmacros.h> #endif -#include <sys/types.h> -#include <sys/socket.h> #include <sys/stat.h> -#include <sys/un.h> #include <sys/poll.h> #include <unistd.h> #include <wait.h> @@ -75,6 +72,7 @@ #include "viraccessapichecklxc.h" #include "virhostdev.h" #include "netdev_bandwidth_conf.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_LXC diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 629f974177..10567e9cd3 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -43,9 +43,6 @@ #include <fcntl.h> #include <poll.h> -#include <arpa/inet.h> -#include <netinet/ip.h> -#include <netinet/udp.h> #include <net/if.h> #include "viralloc.h" diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 5791724cf4..f2d5e60d43 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -31,10 +31,7 @@ #include <sys/ioctl.h> #include <poll.h> -#include <arpa/inet.h> #include <net/ethernet.h> -#include <netinet/ip.h> -#include <netinet/udp.h> #include <net/if_arp.h> #include "internal.h" @@ -53,6 +50,7 @@ #include "nwfilter_ipaddrmap.h" #include "nwfilter_learnipaddr.h" #include "virstring.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_NWFILTER diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index b6556ffbaf..4374235d34 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -21,9 +21,6 @@ #include <config.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> #include <poll.h> #include <unistd.h> #include <fcntl.h> @@ -41,6 +38,7 @@ #include "virobject.h" #include "virstring.h" #include "virenum.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_QEMU diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index b62dd1df52..8bc323345a 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -26,7 +26,6 @@ #include <unistd.h> #include <fcntl.h> #include <sys/wait.h> -#include <arpa/inet.h> #include "virerror.h" #include "qemu_conf.h" @@ -44,7 +43,7 @@ #include "cpu/cpu.h" #include "domain_nwfilter.h" #include "virfile.h" -#include "virsocketaddr.h" +#include "virsocket.h" #include "virstring.h" #include "viratomic.h" #include "storage_conf.h" diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2f66d7cd9a..d7b2528c80 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -32,8 +32,6 @@ #include <signal.h> #include <sys/wait.h> #include <sys/ioctl.h> -#include <sys/un.h> - #include "qemu_driver.h" #include "qemu_agent.h" @@ -104,6 +102,7 @@ #include "virdomainsnapshotobjlist.h" #include "virenum.h" #include "virdomaincheckpointobjlist.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_QEMU diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 29d228a8d9..5a7586fab9 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -21,8 +21,6 @@ #include <config.h> -#include <netdb.h> -#include <sys/socket.h> #include <sys/time.h> #include <fcntl.h> #include <poll.h> @@ -62,6 +60,7 @@ #include "virprocess.h" #include "nwfilter_conf.h" #include "virdomainsnapshotobjlist.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_QEMU diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index ccd20b3740..421dd9554f 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -22,8 +22,6 @@ #include <config.h> #include <poll.h> -#include <sys/socket.h> -#include <sys/un.h> #include <unistd.h> #include <fcntl.h> @@ -41,6 +39,7 @@ #include "virprobe.h" #include "virstring.h" #include "virtime.h" +#include "virsocket.h" #ifdef WITH_DTRACE_PROBES # include "libvirt_qemu_probes.h" diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e5164d218a..b74633441f 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -21,9 +21,6 @@ #include <config.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/un.h> #include <poll.h> #include <unistd.h> #include <sys/time.h> @@ -41,6 +38,7 @@ #include "virstring.h" #include "cpu/cpu_x86.h" #include "virenum.h" +#include "virsocket.h" #ifdef WITH_DTRACE_PROBES # include "libvirt_qemu_probes.h" diff --git a/src/remote/qemu_protocol.x b/src/remote/qemu_protocol.x index 423e8fadaf..8ff5dc8568 100644 --- a/src/remote/qemu_protocol.x +++ b/src/remote/qemu_protocol.x @@ -22,7 +22,6 @@ %#include "internal.h" %#include "remote_protocol.h" -%#include <arpa/inet.h> /*----- Protocol. -----*/ struct qemu_domain_monitor_command_args { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 79cdb13a90..1f7963510a 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -37,7 +37,7 @@ %#include <libvirt/libvirt.h> %#include "internal.h" %#include "virxdrdefs.h" -%#include <arpa/inet.h> +%#include "virsocket.h" /*----- Data types. -----*/ diff --git a/src/rpc/virnetprotocol.x b/src/rpc/virnetprotocol.x index 99f4f2e539..2d9b23ca18 100644 --- a/src/rpc/virnetprotocol.x +++ b/src/rpc/virnetprotocol.x @@ -20,7 +20,7 @@ %#include "internal.h" %#include "virxdrdefs.h" -%#include <arpa/inet.h> +%#include "virsocket.h" /*----- Data types. -----*/ diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 906b5165eb..8f3833e2ff 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -22,7 +22,6 @@ #include <config.h> #include <sys/stat.h> -#include <sys/socket.h> #include <unistd.h> #include <sys/wait.h> #include <signal.h> @@ -30,11 +29,6 @@ #ifdef HAVE_IFADDRS_H # include <ifaddrs.h> #endif -#include <netdb.h> - -#ifdef HAVE_NETINET_TCP_H -# include <netinet/tcp.h> -#endif #ifdef HAVE_SYS_UCRED_H # include <sys/ucred.h> @@ -461,7 +455,7 @@ int virNetSocketNewListenTCP(const char *nodename, } -#if HAVE_SYS_UN_H +#ifndef WIN32 int virNetSocketNewListenUNIX(const char *path, mode_t mask, uid_t user, @@ -647,7 +641,7 @@ int virNetSocketNewConnectTCP(const char *nodename, } -#ifdef HAVE_SYS_UN_H +#ifndef WIN32 int virNetSocketNewConnectUNIX(const char *path, bool spawnDaemon, const char *binary, @@ -1349,7 +1343,7 @@ void virNetSocketDispose(void *obj) sock->watch = -1; } -#ifdef HAVE_SYS_UN_H +#ifndef WIN32 /* If a server socket, then unlink UNIX path */ if (sock->unlinkUNIX && sock->localAddr.data.sa.sa_family == AF_UNIX && @@ -2289,7 +2283,7 @@ void virNetSocketClose(virNetSocketPtr sock) sock->fd = -1; } -#ifdef HAVE_SYS_UN_H +#ifndef WIN32 /* If a server socket, then unlink UNIX path */ if (sock->unlinkUNIX && sock->localAddr.data.sa.sa_family == AF_UNIX && diff --git a/src/util/virarptable.c b/src/util/virarptable.c index 265f60d645..c4b46604a9 100644 --- a/src/util/virarptable.c +++ b/src/util/virarptable.c @@ -20,7 +20,6 @@ #include <config.h> -#include <arpa/inet.h> #ifdef __linux__ # include <linux/rtnetlink.h> #endif diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 58b77aa6fa..c094876dee 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -25,12 +25,7 @@ #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> -#include <sys/socket.h> #include <sys/wait.h> -#if HAVE_SYS_UN_H -# include <sys/un.h> -#endif -#include <netinet/in.h> #ifndef WIN32 # include <termios.h> #endif @@ -46,6 +41,7 @@ #include "virstring.h" #include "virtime.h" #include "virprocess.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_STREAMS @@ -1163,7 +1159,7 @@ int virFDStreamOpen(virStreamPtr st, } -#if HAVE_SYS_UN_H +#ifndef WIN32 int virFDStreamConnectUNIX(virStreamPtr st, const char *path, bool abstract) diff --git a/src/util/virfile.c b/src/util/virfile.c index d08eae5a1d..0b51040638 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -42,8 +42,6 @@ # include <libutil.h> #endif /* !HAVE_LIBUTIL_H */ #include <sys/stat.h> -#include <sys/types.h> -#include <sys/socket.h> #include <sys/wait.h> #if defined(HAVE_SYS_MOUNT_H) # include <sys/mount.h> @@ -90,6 +88,7 @@ #include "virprocess.h" #include "virstring.h" #include "virutil.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_NONE diff --git a/src/util/virlog.c b/src/util/virlog.c index 8c17d666de..e4944d1258 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -24,17 +24,12 @@ #include <stdarg.h> #include <time.h> #include <sys/time.h> -#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #if HAVE_SYSLOG_H # include <syslog.h> #endif -#include <sys/socket.h> -#if HAVE_SYS_UN_H -# include <sys/un.h> -#endif #include "virerror.h" #include "virlog.h" @@ -46,6 +41,7 @@ #include "virtime.h" #include "virstring.h" #include "configmake.h" +#include "virsocket.h" /* Journald output is only supported on Linux new enough to expose * htole64. */ diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 5a0fb5f42f..769289ae0b 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -26,15 +26,11 @@ #include "viralloc.h" #include "virlog.h" #include "virstring.h" +#include "virsocket.h" -#ifndef WIN32 -# include <sys/ioctl.h> -#endif -#include <sys/socket.h> #ifdef HAVE_NET_IF # include <net/if.h> #endif -#include <netinet/in.h> #ifdef __linux__ # if defined(HAVE_LIBNL) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index 3ca568fb44..dcea93a5fe 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -42,8 +42,6 @@ VIR_ENUM_IMPL(virNetDevMacVLanMode, #if WITH_MACVTAP # include <fcntl.h> -# include <sys/socket.h> -# include <sys/ioctl.h> # include <net/if.h> # include <linux/if_tun.h> @@ -61,6 +59,7 @@ VIR_ENUM_IMPL(virNetDevMacVLanMode, # include "virnetdev.h" # include "virpidfile.h" # include "virbitmap.h" +# include "virsocket.h" VIR_LOG_INIT("util.netdevmacvlan"); diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c index 5ca96132c4..475a0d9cbc 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -49,8 +49,6 @@ VIR_ENUM_IMPL(virNetDevVPortProfileOp, #if WITH_VIRTUALPORT # include <fcntl.h> -# include <sys/socket.h> -# include <sys/ioctl.h> # include <net/if.h> # include <linux/if_tun.h> @@ -59,6 +57,7 @@ VIR_ENUM_IMPL(virNetDevVPortProfileOp, # include "virfile.h" # include "virlog.h" # include "virnetdev.h" +# include "virsocket.h" VIR_LOG_INIT("util.netdevvportprofile"); diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 710b4f5f51..2ce3d0fae9 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -24,8 +24,6 @@ #include <config.h> #include <unistd.h> -#include <sys/types.h> -#include <sys/socket.h> #include "virnetlink.h" #include "virnetdev.h" @@ -34,6 +32,7 @@ #include "virmacaddr.h" #include "virerror.h" #include "viralloc.h" +#include "virsocket.h" #define VIR_FROM_THIS VIR_FROM_NET diff --git a/src/util/virsocket.h b/src/util/virsocket.h index e1e7d08bb4..6d323e0a12 100644 --- a/src/util/virsocket.h +++ b/src/util/virsocket.h @@ -79,13 +79,14 @@ int vir_socket(int domain, int type, int protocol); #else # include <sys/socket.h> -# include <unistd.h> # include <sys/ioctl.h> # include <arpa/inet.h> +# include <netinet/ip.h> # include <netinet/in.h> # include <netinet/udp.h> # include <netinet/tcp.h> # include <sys/un.h> +# include <netdb.h> # define closesocket close # define ioctlsocket ioctl diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index f90022827e..4cad329d15 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -24,8 +24,6 @@ #include "virbuffer.h" #include "viralloc.h" -#include <netdb.h> - #define VIR_FROM_THIS VIR_FROM_NONE /* diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index 66aee2abcd..d06e751f73 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -18,13 +18,7 @@ #pragma once -#include <netinet/in.h> -#include <sys/socket.h> -#ifdef HAVE_SYS_UN_H -# include <sys/un.h> -#endif - -#include "internal.h" +#include "virsocket.h" #define VIR_LOOPBACK_IPV4_ADDR "127.0.0.1" @@ -34,7 +28,7 @@ typedef struct { struct sockaddr_storage stor; struct sockaddr_in inet4; struct sockaddr_in6 inet6; -#ifdef HAVE_SYS_UN_H +#ifndef WIN32 struct sockaddr_un un; #endif } data; diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 96d43e5440..a9ff782fb8 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -21,11 +21,6 @@ #include <config.h> -#include <sys/socket.h> -#ifdef HAVE_SYS_UN_H -# include <sys/un.h> -#endif - #define LIBVIRT_VIRSYSTEMDPRIV_H_ALLOW #include "virsystemdpriv.h" @@ -515,7 +510,7 @@ int virSystemdTerminateMachine(const char *name) void virSystemdNotifyStartup(void) { -#ifdef HAVE_SYS_UN_H +#ifndef WIN32 const char *path; const char *msg = "READY=1"; int fd; @@ -559,7 +554,7 @@ virSystemdNotifyStartup(void) VIR_WARN("Failed to notify systemd"); VIR_FORCE_CLOSE(fd); -#endif /* HAVE_SYS_UN_H */ +#endif /* !WIN32 */ } static int diff --git a/src/util/virutil.c b/src/util/virutil.c index 4bc0aef35f..ad05ef5fc1 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -44,7 +44,6 @@ # include <libdevmapper.h> #endif -#include <netdb.h> #ifdef HAVE_GETPWUID_R # include <pwd.h> # include <grp.h> @@ -54,18 +53,6 @@ # include <sys/prctl.h> #endif -#ifdef WIN32 -# ifdef HAVE_WINSOCK2_H -# include <winsock2.h> -# endif -# include <windows.h> -# include <shlobj.h> -#endif - -#ifdef HAVE_SYS_UN_H -# include <sys/un.h> -#endif - #include "virerror.h" #include "virlog.h" #include "virbuffer.h" diff --git a/src/vbox/vbox_MSCOMGlue.c b/src/vbox/vbox_MSCOMGlue.c index 5cc3f5c7c8..18dbb0ffe1 100644 --- a/src/vbox/vbox_MSCOMGlue.c +++ b/src/vbox/vbox_MSCOMGlue.c @@ -22,11 +22,6 @@ #include <config.h> -#ifdef HAVE_WINSOCK2_H -# include <winsock2.h> -#endif -#include <windows.h> - #define nsCID CLSID #include "internal.h" @@ -35,6 +30,7 @@ #include "virerror.h" #include "virstring.h" #include "virutil.h" +#include "virsocket.h" #include "vbox_MSCOMGlue.h" #define VIR_FROM_THIS VIR_FROM_VBOX diff --git a/tests/libxlmock.c b/tests/libxlmock.c index 38302b2ae8..b995b34cc5 100644 --- a/tests/libxlmock.c +++ b/tests/libxlmock.c @@ -27,9 +27,9 @@ # include <libxl.h> # include <xenstore.h> # include <xenctrl.h> -# include <sys/socket.h> # include "virfile.h" +# include "virsocket.h" VIR_MOCK_IMPL_RET_VOID(xs_daemon_open, struct xs_handle *) diff --git a/tests/nsstest.c b/tests/nsstest.c index d146100747..514b4f7195 100644 --- a/tests/nsstest.c +++ b/tests/nsstest.c @@ -22,9 +22,8 @@ #ifdef NSS -# include <arpa/inet.h> # include "libvirt_nss.h" -# include "virsocketaddr.h" +# include "virsocket.h" # define VIR_FROM_THIS VIR_FROM_NONE diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 42a3971d41..af11a0f6e8 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -22,7 +22,6 @@ #ifdef HAVE_IFADDRS_H # include <ifaddrs.h> #endif -#include <netdb.h> #include "testutils.h" #include "virutil.h" diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c index 8013f9eda8..328b1340d6 100644 --- a/tests/virnettlscontexttest.c +++ b/tests/virnettlscontexttest.c @@ -19,7 +19,6 @@ #include <config.h> #include <fcntl.h> -#include <sys/socket.h> #include "testutils.h" #include "virnettlshelpers.h" @@ -29,7 +28,7 @@ #include "virlog.h" #include "virfile.h" #include "vircommand.h" -#include "virsocketaddr.h" +#include "virsocket.h" #if !defined WIN32 && HAVE_LIBTASN1_H && LIBGNUTLS_VERSION_NUMBER >= 0x020600 diff --git a/tests/virnettlshelpers.c b/tests/virnettlshelpers.c index a6aacf4cc3..5aaf98e345 100644 --- a/tests/virnettlshelpers.c +++ b/tests/virnettlshelpers.c @@ -19,7 +19,6 @@ #include <config.h> #include <fcntl.h> -#include <sys/socket.h> #include "virnettlshelpers.h" #include "viralloc.h" diff --git a/tests/virnettlssessiontest.c b/tests/virnettlssessiontest.c index 4f1b2aa8d2..6807581d70 100644 --- a/tests/virnettlssessiontest.c +++ b/tests/virnettlssessiontest.c @@ -19,7 +19,6 @@ #include <config.h> #include <fcntl.h> -#include <sys/socket.h> #include "testutils.h" #include "virnettlshelpers.h" @@ -29,7 +28,7 @@ #include "virlog.h" #include "virfile.h" #include "vircommand.h" -#include "virsocketaddr.h" +#include "virsocket.h" #if !defined WIN32 && HAVE_LIBTASN1_H && LIBGNUTLS_VERSION_NUMBER >= 0x020600 diff --git a/tests/virportallocatormock.c b/tests/virportallocatormock.c index e715f34e04..28fe89200e 100644 --- a/tests/virportallocatormock.c +++ b/tests/virportallocatormock.c @@ -23,10 +23,7 @@ #endif #if defined(__linux__) && defined(RTLD_NEXT) -# include "internal.h" -# include <sys/socket.h> -# include <arpa/inet.h> -# include <netinet/in.h> +# include "virsocket.h" # include <unistd.h> static bool host_has_ipv6; diff --git a/tests/virtestmock.c b/tests/virtestmock.c index 046898dbe1..e5dccae2a8 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -20,16 +20,11 @@ #include "virmock.h" #include <unistd.h> -#include <sys/types.h> #include <fcntl.h> #include <sys/file.h> #include <sys/stat.h> -#include <sys/socket.h> -#ifdef HAVE_SYS_UN_H -# include <sys/un.h> -#endif -#include "internal.h" +#include "virsocket.h" #include "configmake.h" #include "virstring.h" #include "viralloc.h" @@ -202,7 +197,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { init_syms(); -#ifdef HAVE_SYS_UN_H +#ifndef WIN32 if (addrlen == sizeof(struct sockaddr_un)) { struct sockaddr_un *tmp = (struct sockaddr_un *) addr; if (tmp->sun_family == AF_UNIX) -- 2.24.1

SIGPIPE is not available on the Windows platform. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- tests/virauthconfigtest.c | 2 ++ tests/virkeyfiletest.c | 2 ++ tests/virlockspacetest.c | 2 ++ tests/virnetmessagetest.c | 2 ++ tests/virnetsockettest.c | 2 ++ tests/virtimetest.c | 2 ++ tests/viruritest.c | 2 ++ 7 files changed, 14 insertions(+) diff --git a/tests/virauthconfigtest.c b/tests/virauthconfigtest.c index e3bd927dcb..20855f004e 100644 --- a/tests/virauthconfigtest.c +++ b/tests/virauthconfigtest.c @@ -84,7 +84,9 @@ mymain(void) virAuthConfigPtr config; +#ifndef WIN32 signal(SIGPIPE, SIG_IGN); +#endif /* WIN32 */ #define TEST_LOOKUP(config, hostname, service, credname, expect) \ do { \ diff --git a/tests/virkeyfiletest.c b/tests/virkeyfiletest.c index b1236a47e1..abdf06c4a7 100644 --- a/tests/virkeyfiletest.c +++ b/tests/virkeyfiletest.c @@ -109,7 +109,9 @@ mymain(void) { int ret = 0; +#ifndef WIN32 signal(SIGPIPE, SIG_IGN); +#endif /* WIN32 */ if (virTestRun("Test parse", testParse, NULL) < 0) ret = -1; diff --git a/tests/virlockspacetest.c b/tests/virlockspacetest.c index 40395e8c72..3afedb4c46 100644 --- a/tests/virlockspacetest.c +++ b/tests/virlockspacetest.c @@ -342,7 +342,9 @@ mymain(void) { int ret = 0; +#ifndef WIN32 signal(SIGPIPE, SIG_IGN); +#endif /* WIN32 */ if (virTestRun("Lockspace creation", testLockSpaceCreate, NULL) < 0) ret = -1; diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c index b0a01e8b9d..a207f2d85f 100644 --- a/tests/virnetmessagetest.c +++ b/tests/virnetmessagetest.c @@ -525,7 +525,9 @@ mymain(void) { int ret = 0; +#ifndef WIN32 signal(SIGPIPE, SIG_IGN); +#endif /* WIN32 */ if (virTestRun("Message Header Encode", testMessageHeaderEncode, NULL) < 0) ret = -1; diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index af11a0f6e8..9dfc707c90 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -522,7 +522,9 @@ mymain(void) int freePort; #endif +#ifndef WIN32 signal(SIGPIPE, SIG_IGN); +#endif /* WIN32 */ virEventRegisterDefaultImpl(); diff --git a/tests/virtimetest.c b/tests/virtimetest.c index f9ac55192d..5736245722 100644 --- a/tests/virtimetest.c +++ b/tests/virtimetest.c @@ -115,7 +115,9 @@ mymain(void) { int ret = 0; +#ifndef WIN32 signal(SIGPIPE, SIG_IGN); +#endif /* WIN32 */ #define TEST_FIELDS(ts, year, mon, day, hour, min, sec) \ do { \ diff --git a/tests/viruritest.c b/tests/viruritest.c index 07cf7261d1..0edf3e5522 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -145,7 +145,9 @@ mymain(void) { int ret = 0; +#ifndef WIN32 signal(SIGPIPE, SIG_IGN); +#endif /* WIN32 */ #define TEST_FULL(uri, uri_out, scheme, server, port, path, query, \ fragment, user, params) \ -- 2.24.1

The EAI_ADDRFAMILY constant has been removed from FreeBSD headers, supposedly because it is deprecated by new RFC drafts. Previously GNULIB was providing a replacement because MinGW lacked it too. The replacement provided for MinGW was thus being used on FreeBSD too, but with a completely bogus integer value. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- src/rpc/virnetsocket.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 8f3833e2ff..f7d71dea9e 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -180,8 +180,10 @@ int virNetSocketCheckProtocols(bool *hasIPv4, hints.ai_socktype = SOCK_STREAM; if ((gaierr = getaddrinfo("::1", NULL, &hints, &ai)) != 0) { - if (gaierr == EAI_ADDRFAMILY || - gaierr == EAI_FAMILY || + if (gaierr == EAI_FAMILY || +#ifdef EAI_ADDRFAMILY + gaierr == EAI_ADDRFAMILY || +#endif gaierr == EAI_NONAME) { *hasIPv6 = false; } else { -- 2.24.1

* chown: use is conditionally compiled * configmake: functionality imported to Makefile.am * getaddrinfo: we have no portability problems with Windows impl * getpass: simplified impl is imported * mgetgroups: getgrouplist is used directly * net_if: header includes are conditionalized * netdb: header includes are conditionalized * passfd: simplified impl is imported * posix-shell: functionality was unused & removed * sigaction: usage is conditionalized * sigpipe: usage is conditionalized * stat-time: struct stat is used directly * strchrnul: usage is eliminated * strtok_r: usage is not a portability problem * sys_stat: usage is conditionalized * uname: rewritten to use native Win32 function to get host arch * waitpid: usage is conditionalized * wcwidth: rewritten using g_unichar APIs Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> --- bootstrap.conf | 36 ------------------------------------ po/POTFILES.in | 1 - src/rpc/virnetsocket.c | 5 +++++ 3 files changed, 5 insertions(+), 37 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 4159199d08..7e1412093f 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -24,56 +24,20 @@ # turning it into a FD, since closing an FD also closes # the original HANDLE. -# -> conditional build to avoid Win32 -gnulib_modules="$gnulib_modules chown" -# -> Meson -gnulib_modules="$gnulib_modules configmake" -# -> GSocket -gnulib_modules="$gnulib_modules getaddrinfo" -# -> copy gnuliub win32 impl -gnulib_modules="$gnulib_modules getpass" # -> Meson gnulib_modules="$gnulib_modules largefile" # -> custom configure check gnulib_modules="$gnulib_modules localeconv" -# -> painful copy gnulib -gnulib_modules="$gnulib_modules mgetgroups" -# -> GSocket -gnulib_modules="$gnulib_modules net_if" -# -> GSocket -gnulib_modules="$gnulib_modules netdb" -# -> GSocket -gnulib_modules="$gnulib_modules passfd" # -> open code / conditional comp gnulib_modules="$gnulib_modules pipe-posix" # -> open code / conditional comp gnulib_modules="$gnulib_modules pipe2" # -> GMainLoop gnulib_modules="$gnulib_modules poll" -# -> Meson -gnulib_modules="$gnulib_modules posix-shell" -# -> open code conditional logic -gnulib_modules="$gnulib_modules sigaction" -# -> open code conditional logic -gnulib_modules="$gnulib_modules sigpipe" -# -> open code conditional or use GIO GFileInfo -gnulib_modules="$gnulib_modules stat-time" # -> GThread gnulib_modules="$gnulib_modules threadlib" -# -> remove use or open-code it. possibly add to glib -gnulib_modules="$gnulib_modules strchrnul" -# -> g_strsplit -gnulib_modules="$gnulib_modules strtok_r" -# -> remove sys/stat.h include from any win32 code paths -gnulib_modules="$gnulib_modules sys_stat" # -> remove sys/wait.h include from any win32 code paths gnulib_modules="$gnulib_modules sys_wait" -# -> g_get_os_info in GLib 2.64 but can't use that yet -gnulib_modules="$gnulib_modules uname" -# -> remove from Win32 code paths -gnulib_modules="$gnulib_modules waitpid" -# -> open code impl -gnulib_modules="$gnulib_modules wcwidth" SKIP_PO=true diff --git a/po/POTFILES.in b/po/POTFILES.in index e266871907..c18e21615f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,7 +5,6 @@ @BUILDDIR@/src/admin/admin_server_dispatch_stubs.h @BUILDDIR@/src/remote/remote_client_bodies.h @BUILDDIR@/src/remote/remote_daemon_dispatch_stubs.h -@SRCDIR@/gnulib/lib/gai_strerror.c @SRCDIR@/src/access/viraccessdriverpolkit.c @SRCDIR@/src/access/viraccessmanager.c @SRCDIR@/src/admin/admin_server.c diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index f7d71dea9e..c77310d3f2 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1394,6 +1394,11 @@ int virNetSocketGetFD(virNetSocketPtr sock) return fd; } +/* Temp hack - we're still pulling in gnulib + * fcntl-h indirectly, but not fcntl */ +#ifdef WIN32 +# undef F_DUPFD_CLOEXEC +#endif int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec) { -- 2.24.1

On Thu, Jan 23, 2020 at 11:42:53AM +0000, Daniel P. Berrangé wrote:
We currently have 25 gnulib modules in bootstrap.conf and after this series we're down to 7. Except this is a lie, because we've been failing to count the indirect dependencies, so after this series, libvirt is actually pulling in 41 modules. Still, that's better than the 115 modules we indirectly use before this series :-)
I have actually eliminated the remaining modules too, but I'm having trouble with the event loop impl in the RPC client on Windows that I'm still debugging. I'll poist the remaining patches once I've figured out that problem.
FYI https://github.com/berrange/libvirt/tree/no-gnulib-reorder https://travis-ci.org/berrange/libvirt/ and also tested on FreeBSD 12, and validate RPC client on Windows. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (2)
-
Daniel P. Berrangé
-
Pavel Hrdina