diff --git a/meson.build b/meson.build index b3d0c145c3..0927f0cf22 100644 --- a/meson.build +++ b/meson.build @@ -123,6 +123,7 @@ subdir('meson' / 'libbsd') subdir('meson' / 'libc') subdir('meson' / 'random') subdir('meson' / 'ioloop') +subdir('meson' / 'fd') dovecot_moduledir = get_option('moduledir') if dovecot_moduledir == '' diff --git a/meson/fd/fd-passing.c b/meson/fd/fd-passing.c new file mode 100644 index 0000000000..91cae29640 --- /dev/null +++ b/meson/fd/fd-passing.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include "fdpass.h" + +static int nopen(void) { + int i, n; + struct stat sb; + for (i = n = 0; i < 256; i++) { + if (fstat(i, &sb) == 0) n++; + } + return n; +} + +int main(void) { + int fd[2], send_fd, recv_fd, status, n1, n2; + struct stat st, st2; + char data; + + send_fd = creat("conftest.fdpass", 0600); + if (send_fd == -1) { + return 2; + } + + unlink("conftest.fdpass"); + + if (fstat(send_fd, &st) < 0) { + return 2; + } + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) { + return 2; + } + + n1 = nopen(); + + switch (fork()) { + case -1: + return 2; + case 0: + alarm(1); + if (fd_send(fd[0], send_fd, &data, 1) != 1) return 2; + return 0; + default: + alarm(2); + if (wait(&status) == -1) + return 2; + if (status != 0) + return status; + if (fd_read(fd[1], &data, 1, &recv_fd) != 1) return 1; + if (fstat(recv_fd, &st2) < 0) return 2; + /* nopen check is for making sure that only a single fd + was received */ + n2 = nopen(); + return st.st_ino == st2.st_ino && n2 == n1 + 1 ? 0 : 1; + } +} diff --git a/meson/fd/meson.build b/meson/fd/meson.build new file mode 100644 index 0000000000..01ebe5d148 --- /dev/null +++ b/meson/fd/meson.build @@ -0,0 +1,18 @@ +fs = import('fs') + +fdpass_c_file = meson.global_source_root() / 'src' / 'lib' / 'fdpass.c' +fdpass_include = meson.global_source_root() / 'src' / 'lib' + +fd_pass_check = fs.read('fd-passing.c') +args = [f'-I@fdpass_include@', fdpass_c_file] + +if cc.run(fd_pass_check, args: args, name: 'fd passing').returncode() != 0 + args += '-DBUGGY_CMSG_MACROS' + if cc.run(fd_pass_check, args: args, name: 'fd passing').returncode() == 0 + conf.set10('BUGGY_CMSG_MACROS', true) + endif +endif + +if system == 'darwin' + conf.set10('BUGGY_CMSG_MACROS', true) +endif