Skip to content

Commit

Permalink
add fixes from 6.8, add new pkgconfig file
Browse files Browse the repository at this point in the history
update patch version to 6.8.2

Signed-off-by: Aisha Tammy <[email protected]>
  • Loading branch information
epsilon-0 committed Apr 22, 2021
1 parent b031158 commit ea0b380
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION ?= 6.8.0
VERSION ?= 6.8.2

STATICLIB ?= libimsg.a
SONAME ?= libimsg.so
Expand All @@ -16,34 +16,41 @@ OBJS = ${SRCS:.c=.o}
TESTSRCS = test/imsg_sendrcv.c
TESTOBJS = ${TESTSRCS:.c=.test}

all: ${LIBRARY} ${STATICLIB}
all: ${LIBRARY} ${STATICLIB} libimsg.pc

${LIBRARY}: ${OBJS}
${CC} -shared -o ${LIBRARY} ${OBJS} -Wl,--soname,${SONAME} ${LDFLAGS}

${STATICLIB}: ${OBJS}
${AR} rcs ${STATICLIB} ${OBJS}

libimsg.pc: libimsg.pc.in
sed -e "s|@VERSION@|${VERSION}|" \
-e "s|@PREFIX@|${PREFIX}|" \
-e "s|@LIBDIR@|${LIBDIR}|" \
libimsg.pc.in > libimsg.pc

.c.o:
${CC} -D_XOPEN_SOURCE -D_DEFAULT_SOURCE ${CFLAGS} -fPIC -c $< -o $@

install: all
mkdir -p ${DESTDIR}${MANDIR}/man3 ${DESTDIR}${INCLUDEDIR} ${DESTDIR}${LIBDIR}
mkdir -p ${DESTDIR}${MANDIR}/man3 ${DESTDIR}${INCLUDEDIR} ${DESTDIR}${LIBDIR}/pkgconfig
install -t ${DESTDIR}${MANDIR}/man3 man/imsg_init.3
install -t ${DESTDIR}${INCLUDEDIR} src/imsg.h
install -t ${DESTDIR}${LIBDIR} ${LIBRARY}
ln -sf ${LIBRARY} ${DESTDIR}${LIBDIR}/${SONAME}
install -t ${DESTDIR}${LIBDIR} ${STATICLIB}
install -t ${DESTDIR}${LIBDIR}/pkgconfig libimsg.pc

check: test

test: all ${TESTOBJS}

${TESTOBJS}: ${TESTSRCS}
${CC} ${CFLAGS} -Isrc -static $< -o $@ -L. -limsg
./$@
${CC} ${CFLAGS} -Isrc $< -o $@ -L. -limsg
env -i LD_LIBRARY_PATH=. ./$@

clean:
rm -f ${LIBRARY} ${STATICLIB} ${OBJS} ${TESTOBJS}
rm -f ${LIBRARY} ${STATICLIB} ${OBJS} ${TESTOBJS} libimsg.pc

.PHONY: all check clean install test
11 changes: 11 additions & 0 deletions libimsg.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@PREFIX@
libdir=${prefix}/@LIBDIR@
includedir=${prefix}/include

Name: IMSG
Version: 9999
Description: Unofficial OpenBSD imsg port
URL: https://github.com/bsd-ac/imsg-compat

Cflags: -I${includedir}
Libs: -L${libdir} -limsg
18 changes: 10 additions & 8 deletions src/imsg-buffer.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: imsg-buffer.c,v 1.12 2019/01/20 02:50:03 bcook Exp $ */
/* $OpenBSD: imsg-buffer.c,v 1.13 2021/03/31 17:42:24 eric Exp $ */

/*
* Copyright (c) 2003, 2004 Henning Brauer <[email protected]>
Expand Down Expand Up @@ -226,7 +226,7 @@ int
msgbuf_write(struct msgbuf *msgbuf)
{
struct iovec iov[IOV_MAX];
struct ibuf *buf;
struct ibuf *buf, *buf0 = NULL;
unsigned int i = 0;
ssize_t n;
struct msghdr msg;
Expand All @@ -242,24 +242,26 @@ msgbuf_write(struct msgbuf *msgbuf)
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
if (i >= IOV_MAX)
break;
if (i > 0 && buf->fd != -1)
break;
iov[i].iov_base = buf->buf + buf->rpos;
iov[i].iov_len = buf->wpos - buf->rpos;
i++;
if (buf->fd != -1)
break;
buf0 = buf;
}

msg.msg_iov = iov;
msg.msg_iovlen = i;

if (buf != NULL && buf->fd != -1) {
if (buf0 != NULL) {
msg.msg_control = (caddr_t)&cmsgbuf.buf;
msg.msg_controllen = sizeof(cmsgbuf.buf);
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) = buf->fd;
*(int *)CMSG_DATA(cmsg) = buf0->fd;
}

again:
Expand All @@ -280,9 +282,9 @@ msgbuf_write(struct msgbuf *msgbuf)
* assumption: fd got sent if sendmsg sent anything
* this works because fds are passed one at a time
*/
if (buf != NULL && buf->fd != -1) {
close(buf->fd);
buf->fd = -1;
if (buf0 != NULL) {
close(buf0->fd);
buf0->fd = -1;
}

msgbuf_drain(msgbuf, n);
Expand Down
3 changes: 2 additions & 1 deletion src/imsg.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: imsg.h,v 1.5 2019/01/20 02:50:03 bcook Exp $ */
/* $OpenBSD: imsg.h,v 1.6 2021/01/13 09:56:28 claudio Exp $ */

/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <[email protected]>
Expand Down Expand Up @@ -78,6 +78,7 @@ struct imsg {
void *data;
};

struct iovec;

/* buffer.c */
struct ibuf *ibuf_open(size_t);
Expand Down

0 comments on commit ea0b380

Please sign in to comment.