mirror of
https://github.com/dovecot/core.git
synced 2026-10-23 22:08:58 +03:00
meson: FD-passing
This commit is contained in:
committed by
timo.sirainen
parent
aef7e1db5f
commit
856ec50e4d
@@ -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 == ''
|
||||
|
||||
60
meson/fd/fd-passing.c
Normal file
60
meson/fd/fd-passing.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
18
meson/fd/meson.build
Normal file
18
meson/fd/meson.build
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user