mirror of https://github.com/omar-polo/gmid.git
test imsg
This commit is contained in:
parent
7c83689428
commit
6cd611c58c
37
.cirrus.yml
37
.cirrus.yml
|
@ -1,38 +1,11 @@
|
|||
# gcc' -Werror=use-after-free gets tripped by vis.c: it sees a use
|
||||
# after free where it's not possible and breaks the CI.
|
||||
|
||||
linux_amd64_task:
|
||||
container:
|
||||
image: alpine:latest
|
||||
ventura_task:
|
||||
macos_instance:
|
||||
image: ghcr.io/cirruslabs/macos-ventura-xcode:latest
|
||||
test_script:
|
||||
- apk add alpine-sdk linux-headers bison libretls-dev libevent-dev
|
||||
- ./configure CFLAGS='-O2 -pipe -Wno-deprecated-declarations -Wno-use-after-free' -Werror
|
||||
- make
|
||||
- make regress REGRESS_HOST="*"
|
||||
|
||||
linux_arm_task:
|
||||
arm_container:
|
||||
image: alpine:latest
|
||||
test_script:
|
||||
- apk add alpine-sdk linux-headers bison libretls-dev libevent-dev
|
||||
- ./configure CFLAGS='-O2 -pipe -Wno-deprecated-declarations -Wno-use-after-free' -Werror
|
||||
- make
|
||||
- make regress REGRESS_HOST="*"
|
||||
|
||||
freebsd_14_task:
|
||||
freebsd_instance:
|
||||
image_family: freebsd-14-0
|
||||
install_script: pkg install -y libevent libressl pkgconf
|
||||
script:
|
||||
- ./configure CFLAGS='-O2 -pipe -Wno-deprecated-declarations' -Werror
|
||||
- make
|
||||
- make regress
|
||||
|
||||
mac_task:
|
||||
sonoma_task:
|
||||
macos_instance:
|
||||
image: ghcr.io/cirruslabs/macos-sonoma-xcode:latest
|
||||
test_script:
|
||||
- brew install libevent openssl libretls
|
||||
- PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig" ./configure CFLAGS='-O2 -pipe -Wno-deprecated-declarations' -Werror
|
||||
- make
|
||||
- SKIP_RUNTIME_TESTS=1 make regress
|
||||
- make regress
|
||||
|
|
195
Makefile
195
Makefile
|
@ -1,190 +1,7 @@
|
|||
# Copyright (c) 2022 Omar Polo <op@omarpolo.com>
|
||||
# Copyright (c) 2011, 2013-2022 Ingo Schwarze <schwarze@openbsd.org>
|
||||
# Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
all: test
|
||||
test: test.c
|
||||
${CC} -o test test.c
|
||||
|
||||
# tests to run as a port of the regression suite. Leave empty to run
|
||||
# all.
|
||||
TESTS=
|
||||
|
||||
# host to bind to during regress
|
||||
REGRESS_HOST = localhost
|
||||
|
||||
# -- build-related variables --
|
||||
|
||||
COBJS = ${COMPATS:.c=.o}
|
||||
|
||||
GMID_SRCS = gmid.c config.c crypto.c dirs.c fcgi.c iri.c log.c \
|
||||
logger.c mime.c proc.c proxy.c puny.c sandbox.c \
|
||||
server.c utf8.c utils.c y.tab.c
|
||||
|
||||
GMID_OBJS = ${GMID_SRCS:.c=.o} ${COBJS}
|
||||
|
||||
GEMEXP_SRCS = ge.c config.c crypto.c dirs.c fcgi.c iri.c log.c mime.c \
|
||||
proc.c proxy.c puny.c sandbox.c server.c utf8.c utils.c
|
||||
|
||||
GEMEXP_OBJS = ${GEMEXP_SRCS:.c=.o} ${COBJS}
|
||||
|
||||
GG_SRCS = gg.c iri.c log.c utf8.c
|
||||
|
||||
GG_OBJS = ${GG_SRCS:.c=.o} ${COBJS}
|
||||
|
||||
TITAN_SRCS = titan.c iri.c log.c utf8.c
|
||||
TITAN_OBJS = ${TITAN_SRCS:.c=.o} ${COBJS}
|
||||
|
||||
SRCS = gmid.h iri.h log.h parse.y proc.h \
|
||||
${GMID_SRCS} ${GEMEXP_SRCS} ${GG_SRCS} ${TITAN_SRCS}
|
||||
|
||||
DISTNAME = gmid-${VERSION}
|
||||
|
||||
# -- public targets --
|
||||
|
||||
all: config.mk gmid gemexp gg titan
|
||||
.PHONY: all tags clean cleanall test regress install
|
||||
|
||||
config.mk config.h: configure
|
||||
@echo "$@ is out of date; please run ./configure"
|
||||
@exit 1
|
||||
|
||||
include config.mk
|
||||
|
||||
clean:
|
||||
rm -f gmid gemexp gg
|
||||
rm -f *.[do] compat/*.[do] compat/libtls/*.[do]
|
||||
rm -f y.tab.c y.tab.h y.output
|
||||
rm -f compile_flags.txt
|
||||
${MAKE} -C regress clean
|
||||
|
||||
distclean: clean
|
||||
rm -f config.h config.h.old config.log config.log.old config.mk
|
||||
|
||||
test: regress
|
||||
regress: all
|
||||
${MAKE} 'TESTS=${TESTS}' -C regress all
|
||||
|
||||
install: gmid gg gemexp
|
||||
mkdir -p ${DESTDIR}${BINDIR}
|
||||
mkdir -p ${DESTDIR}${MANDIR}/man1
|
||||
mkdir -p ${DESTDIR}${MANDIR}/man5
|
||||
mkdir -p ${DESTDIR}${MANDIR}/man8
|
||||
${INSTALL_PROGRAM} gemexp ${DESTDIR}${BINDIR}
|
||||
${INSTALL_PROGRAM} gg ${DESTDIR}${BINDIR}
|
||||
${INSTALL_PROGRAM} gmid ${DESTDIR}${BINDIR}
|
||||
${INSTALL_PROGRAM} titan ${DESTDIR}${BINDIR}
|
||||
${INSTALL_MAN} gemexp.1 ${DESTDIR}${MANDIR}/man1
|
||||
${INSTALL_MAN} gg.1 ${DESTDIR}${MANDIR}/man1
|
||||
${INSTALL_MAN} titan.1 ${DESTDIR}${MANDIR}/man1
|
||||
${INSTALL_MAN} gmid.conf.5 ${DESTDIR}${MANDIR}/man5
|
||||
${INSTALL_MAN} gmid.8 ${DESTDIR}${MANDIR}/man8
|
||||
|
||||
uninstall:
|
||||
rm ${DESTDIR}${BINDIR}/gemexp
|
||||
rm ${DESTDIR}${BINDIR}/gg
|
||||
rm ${DESTDIR}${BINDIR}/gmid
|
||||
rm ${DESTDIR}${BINDIR}/titan
|
||||
rm ${DESTDIR}${MANDIR}/man1/gemexp.1
|
||||
rm ${DESTDIR}${MANDIR}/man1/gg.1
|
||||
rm ${DESTDIR}${MANDIR}/man1/titan.1
|
||||
rm ${DESTDIR}${MANDIR}/man5/gmid.conf.5
|
||||
rm ${DESTDIR}${MANDIR}/man8/gmid.8
|
||||
|
||||
tags:
|
||||
ctags ${SRCS}
|
||||
|
||||
# --internal build targets --
|
||||
|
||||
gmid: ${GMID_OBJS}
|
||||
${CC} ${GMID_OBJS} -o $@ ${LDFLAGS} ${LIBS}
|
||||
|
||||
gemexp: ${GEMEXP_OBJS}
|
||||
${CC} ${GEMEXP_OBJS} -o $@ ${LDFLAGS} ${LIBS}
|
||||
|
||||
gg: ${GG_OBJS}
|
||||
${CC} ${GG_OBJS} -o $@ ${LDFLAGS} ${LIBS}
|
||||
|
||||
titan: ${TITAN_OBJS}
|
||||
${CC} ${TITAN_OBJS} -o $@ ${LDFLAGS} ${LIBS}
|
||||
|
||||
y.tab.c: parse.y
|
||||
${YACC} -b y parse.y
|
||||
|
||||
# make sure we pass -o to ${CC}. OpenBSD default suffix rule doesn't
|
||||
.SUFFIXES: .c .o
|
||||
.c.o:
|
||||
${CC} ${CFLAGS} -c $< -o $@
|
||||
|
||||
# -- maintainer targets --
|
||||
|
||||
.PHONY: lint release dist
|
||||
|
||||
lint:
|
||||
man -Tlint -Wstyle -l gmid.8 gmid.conf.5 gemexp.1 gg.1 titan.1
|
||||
|
||||
PUBKEY = keys/gmid-2.0.pub
|
||||
PRIVKEY = set-PRIVKEY
|
||||
DISTFILES = .cirrus.yml .dockerignore .gitignore ChangeLog LICENSE \
|
||||
Makefile README.md config.c configure crypto.c dirs.c fcgi.c \
|
||||
ge.c gemexp.1 gg.1 gg.c gmid.8 gmid.c gmid.conf.5 gmid.h \
|
||||
iri.c iri.h log.c log.h logger.c mime.c parse.y proc.c \
|
||||
proc.h proxy.c puny.c sandbox.c server.c titan.1 titan.c \
|
||||
utf8.c utils.c y.tab.c
|
||||
|
||||
release:
|
||||
sed -i -e '/^RELEASE=/s/no/yes/' configure
|
||||
${MAKE} dist
|
||||
sed -i -e '/^RELEASE=/s/yes/no/' configure
|
||||
signify -S -e -m ${DISTNAME}.sha256 -s ${PRIVKEY}
|
||||
|
||||
verify-release:
|
||||
signify -C -p ${PUBKEY} -x ${DISTNAME}.sha256.sig
|
||||
|
||||
dist: ${DISTNAME}.sha256
|
||||
|
||||
${DISTNAME}.sha256: ${DISTNAME}.tar.gz
|
||||
sha256 ${DISTNAME}.tar.gz > $@
|
||||
|
||||
${DISTNAME}.tar.gz: ${DISTFILES}
|
||||
mkdir -p .dist/${DISTNAME}/
|
||||
${INSTALL} -m 0644 ${DISTFILES} .dist/${DISTNAME}/
|
||||
cd .dist/${DISTNAME} && chmod 755 configure
|
||||
${MAKE} -C compat DESTDIR=${PWD}/.dist/${DISTNAME}/compat dist
|
||||
${MAKE} -C contrib DESTDIR=${PWD}/.dist/${DISTNAME}/contrib dist
|
||||
${MAKE} -C have DESTDIR=${PWD}/.dist/${DISTNAME}/have dist
|
||||
${MAKE} -C keys DESTDIR=${PWD}/.dist/${DISTNAME}/keys dist
|
||||
${MAKE} -C regress DESTDIR=${PWD}/.dist/${DISTNAME}/regress dist
|
||||
cd .dist/ && tar zcf ../$@ ${DISTNAME}
|
||||
rm -rf .dist/
|
||||
|
||||
# -- dependencies --
|
||||
|
||||
-include config.d
|
||||
-include crypto.d
|
||||
-include dirs.d
|
||||
-include fcgi.d
|
||||
-include ge.d
|
||||
-include gg.d
|
||||
-include gmid.d
|
||||
-include iri.d
|
||||
-include log.d
|
||||
-include logger.d
|
||||
-include mime.d
|
||||
-include proc.d
|
||||
-include proxy.d
|
||||
-include puny.d
|
||||
-include sandbox.d
|
||||
-include server.d
|
||||
-include titan.d
|
||||
-include utf8.d
|
||||
-include utils.d
|
||||
-include y.tab.d
|
||||
.PHONY: regress
|
||||
regress: test
|
||||
./test
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
#include <sys/queue.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <imsg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
parent(int sock)
|
||||
{
|
||||
int fd;
|
||||
char data = 'X';
|
||||
struct msghdr msg;
|
||||
struct cmsghdr *cmsg;
|
||||
union {
|
||||
struct cmsghdr hdr;
|
||||
unsigned char buf[CMSG_SPACE(sizeof(int))];
|
||||
} cmsgbuf;
|
||||
struct iovec iov[1];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 1000000; ++i) {
|
||||
if ((fd = open("/dev/null", O_RDONLY)) == -1)
|
||||
err(1, "parent: open /dev/null");
|
||||
|
||||
iov[0].iov_base = &data;
|
||||
iov[0].iov_len = 1;
|
||||
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.msg_control = &cmsgbuf.buf;
|
||||
msg.msg_controllen = sizeof(cmsgbuf.buf);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
cmsg = CMSG_FIRSTHDR(&msg);
|
||||
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
cmsg->cmsg_level = SOL_SOCKET;
|
||||
cmsg->cmsg_type = SCM_RIGHTS;
|
||||
*(int *)CMSG_DATA(cmsg) = fd;
|
||||
|
||||
fprintf(stderr, "parent: sending %d\n", fd);
|
||||
if (sendmsg(sock, &msg, 0) == -1)
|
||||
err(1, "parent:sendmsg");
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
child(int sock)
|
||||
{
|
||||
int fd;
|
||||
char data;
|
||||
struct msghdr msg;
|
||||
struct cmsghdr *cmsg;
|
||||
union {
|
||||
struct cmsghdr hdr;
|
||||
unsigned char buf[CMSG_SPACE(sizeof(int))];
|
||||
} cmsgbuf;
|
||||
struct iovec iov[1];
|
||||
ssize_t n;
|
||||
|
||||
for (;;) {
|
||||
iov[0].iov_base = &data;
|
||||
iov[0].iov_len = 1;
|
||||
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
msg.msg_control = &cmsgbuf.buf;
|
||||
msg.msg_controllen = sizeof(cmsgbuf.buf);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
if ((n = recvmsg(sock, &msg, 0)) == -1)
|
||||
err(1, "child: recvmsg");
|
||||
if (n == 0)
|
||||
errx(0, "child: done!");
|
||||
if ((msg.msg_flags & MSG_TRUNC) ||
|
||||
(msg.msg_flags & MSG_CTRUNC))
|
||||
errx(1, "child: control message truncated");
|
||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg;
|
||||
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||
if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) &&
|
||||
cmsg->cmsg_level == SOL_SOCKET &&
|
||||
cmsg->cmsg_type == SCM_RIGHTS) {
|
||||
fd = *(int *)CMSG_DATA(cmsg);
|
||||
fprintf(stderr, "child: recv fd %d\n",
|
||||
fd);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int p[2];
|
||||
pid_t pid;
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, p) == -1)
|
||||
err(1, "socketpair");
|
||||
|
||||
if ((pid = fork()) == -1)
|
||||
err(1, "fork");
|
||||
if (pid == 0) {
|
||||
close(p[0]);
|
||||
return child(p[1]);
|
||||
}
|
||||
|
||||
close(p[1]);
|
||||
return parent(p[0]);
|
||||
}
|
Loading…
Reference in New Issue