From e29469463b6b998eac2dffdf2f72c3eb8929c5d0 Mon Sep 17 00:00:00 2001 From: nia Date: Sat, 6 Aug 2022 10:48:21 +0200 Subject: [PATCH 1/7] NetBSD support: Initial build machinery. Make kqueue/libepoll-shim detection independent of FreeBSD. Signed-off-by: Nia Alarie --- meson.build | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index f469756f..e5d23d07 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,9 @@ cc_args = [] if host_machine.system() != 'freebsd' cc_args += ['-D_POSIX_C_SOURCE=200809L'] endif +if host_machine.system() == 'netbsd' + cc_args += ['-D_NETBSD_SOURCE'] +endif add_project_arguments(cc_args, language: 'c') compiler_flags = [ @@ -41,12 +44,16 @@ endforeach have_funcs = [ 'accept4', 'mkostemp', - 'posix_fallocate', 'prctl', 'memfd_create', 'mremap', 'strndup', ] +# NetBSD defines posix_fallocate(), but it's unimplemented for most file +# systems as of NetBSD 9. +if host_machine.system() != 'netbsd' + have_funcs += [ 'posix_fallocate' ] +endif foreach f: have_funcs config_h.set('HAVE_' + f.underscorify().to_upper(), cc.has_function(f)) endforeach @@ -69,8 +76,8 @@ endif config_h.set10('HAVE_BROKEN_MSG_CMSG_CLOEXEC', have_broken_msg_cmsg_cloexec) if get_option('libraries') - if host_machine.system() == 'freebsd' - # When building for FreeBSD, epoll(7) is provided by a userspace + if cc.has_function('kqueue', prefix: '#include ') + # When building for BSD, epoll(7) is provided by a userspace # wrapper around kqueue(2). epoll_dep = dependency('epoll-shim') else From e3521796e6b4bc6ba845b9e6ec9ed16dbb594a18 Mon Sep 17 00:00:00 2001 From: nia Date: Sat, 6 Aug 2022 10:48:54 +0200 Subject: [PATCH 2/7] NetBSD support: Eliminate ctype-related compiler warnings. The C standard says that the ctype functions must be used with unsigned char arguments, and NetBSD triggers -Wchar-subscript warnings. Signed-off-by: Nia Alarie --- src/scanner.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scanner.c b/src/scanner.c index da8adea4..ed99a392 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -294,7 +294,7 @@ uppercase_dup(const char *src) u = xstrdup(src); for (i = 0; u[i]; i++) - u[i] = toupper(u[i]); + u[i] = toupper((unsigned char) u[i]); u[i] = '\0'; return u; @@ -354,7 +354,7 @@ desc_dump(char *desc, const char *fmt, ...) for (i = 0; desc[i]; ) { k = i; newlines = 0; - while (desc[i] && isspace(desc[i])) { + while (desc[i] && isspace((unsigned char) desc[i])) { if (desc[i] == '\n') newlines++; i++; @@ -363,7 +363,7 @@ desc_dump(char *desc, const char *fmt, ...) break; j = i; - while (desc[i] && !isspace(desc[i])) + while (desc[i] && !isspace((unsigned char) desc[i])) i++; if (newlines > 1) From 6feba4cd81e076f8f3edd4195d4ffa040478fe74 Mon Sep 17 00:00:00 2001 From: nia Date: Sat, 6 Aug 2022 10:49:40 +0200 Subject: [PATCH 3/7] NetBSD support: Implement wl_os_socket_peercred Signed-off-by: Nia Alarie --- src/wayland-os.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/wayland-os.c b/src/wayland-os.c index a9066cae..c76b5090 100644 --- a/src/wayland-os.c +++ b/src/wayland-os.c @@ -100,7 +100,25 @@ wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid) #endif return 0; } -#elif defined(SO_PEERCRED) +#elif defined(LOCAL_CREDS) /* NetBSD */ +#ifndef SOL_LOCAL /* Before NetBSD 10.0, SOL_LOCAL isn't defined */ +#define SOL_LOCAL (0) +#endif +int +wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid) +{ + socklen_t len; + struct sockcred ucred; + + len = sizeof(ucred); + if (getsockopt(sockfd, SOL_LOCAL, LOCAL_CREDS, &ucred, &len) < 0) + return -1; + *uid = ucred.sc_uid; + *gid = ucred.sc_gid; + *pid = ucred.sc_pid; + return 0; +} +#elif defined(SO_PEERCRED) /* Linux */ int wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid) { From 01cbf0981bc4729ee80de5b5174d42faed655e37 Mon Sep 17 00:00:00 2001 From: nia Date: Mon, 8 Aug 2022 17:04:38 +0200 Subject: [PATCH 4/7] Remove workaround for posix_fallocate on NetBSD. posix_fallocate being unimplemented is now handled in the code. Signed-off-by: Nia Alarie --- meson.build | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/meson.build b/meson.build index e5d23d07..8221e89f 100644 --- a/meson.build +++ b/meson.build @@ -44,16 +44,12 @@ endforeach have_funcs = [ 'accept4', 'mkostemp', + 'posix_fallocate', 'prctl', 'memfd_create', 'mremap', 'strndup', ] -# NetBSD defines posix_fallocate(), but it's unimplemented for most file -# systems as of NetBSD 9. -if host_machine.system() != 'netbsd' - have_funcs += [ 'posix_fallocate' ] -endif foreach f: have_funcs config_h.set('HAVE_' + f.underscorify().to_upper(), cc.has_function(f)) endforeach From 5efad9cfeaaf294da1af601b63d7c55dfb85041d Mon Sep 17 00:00:00 2001 From: nia Date: Mon, 8 Aug 2022 17:09:14 +0200 Subject: [PATCH 5/7] tests: Fix building tests on NetBSD by providing is_debugger_attached Signed-off-by: Nia Alarie --- tests/test-runner.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test-runner.c b/tests/test-runner.c index d07dab15..1bfb0df4 100644 --- a/tests/test-runner.c +++ b/tests/test-runner.c @@ -308,6 +308,13 @@ is_debugger_attached(void) return rc; } +#else +static int +is_debugger_attached(void) +{ + /* 0=debugger can't be determined */ + return 0; +} #endif int main(int argc, char *argv[]) From 3466f4667c305a4658ffaf03d78e4d9f02543d46 Mon Sep 17 00:00:00 2001 From: nia Date: Mon, 8 Aug 2022 17:11:22 +0200 Subject: [PATCH 6/7] Avoid defining _POSIX_C_SOURCE on all BSD systems Removes the need to also define _NETBSD_SOURCE. Signed-off-by: Nia Alarie --- meson.build | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 8221e89f..c54c39ef 100644 --- a/meson.build +++ b/meson.build @@ -16,12 +16,9 @@ config_h.set_quoted('PACKAGE', meson.project_name()) config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) cc_args = [] -if host_machine.system() != 'freebsd' +if not host_machine.system().contains('bsd') cc_args += ['-D_POSIX_C_SOURCE=200809L'] endif -if host_machine.system() == 'netbsd' - cc_args += ['-D_NETBSD_SOURCE'] -endif add_project_arguments(cc_args, language: 'c') compiler_flags = [ From 725d5bbbee75e6dbf22efa7240955c87fb215f59 Mon Sep 17 00:00:00 2001 From: nia Date: Mon, 29 Aug 2022 13:02:02 +0200 Subject: [PATCH 7/7] meson.build: Only set -D_POSIX_C_SOURCE=200809L on Linux. Signed-off-by: Nia Alarie --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index c54c39ef..be45703e 100644 --- a/meson.build +++ b/meson.build @@ -16,7 +16,7 @@ config_h.set_quoted('PACKAGE', meson.project_name()) config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) cc_args = [] -if not host_machine.system().contains('bsd') +if host_machine.system() == 'linux' cc_args += ['-D_POSIX_C_SOURCE=200809L'] endif add_project_arguments(cc_args, language: 'c')