Commit bb5b19e3e76cd78d622d174e0a2a718869a2c8fd

Stefan Sperling 2020-01-28T12:15:59

ensure that we always install static binaries to gotweb's chroot Compile static libexec binaries for gotweb, keeping them separate from the main build. Use the same source files but a separate set of Makefiles. Previously, 'make web-install' installed whichever libexec binaries had already been built, and if those happened to be dynamically linked they failed to run inside the chroot which resulted in "privsep peer process closed pipe" being rendered on the index page.

diff --git a/Makefile b/Makefile
index 50b44e8..39e9e02 100644
--- a/Makefile
+++ b/Makefile
@@ -30,9 +30,9 @@ dist: clean
 	rm got-dist.txt.new
 
 web:
-	${MAKE} -C gotweb MAKEWEB=Yes
+	${MAKE} -C gotweb
 
 web-install:
-	${MAKE} -C gotweb install MAKEWEB=Yes
+	${MAKE} -C gotweb install
 
 .include <bsd.subdir.mk>
diff --git a/Makefile.inc b/Makefile.inc
index c51458d..bb6ed69 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -27,22 +27,3 @@ DEBUG = -O0 -g
 .endif
 
 .endif
-
-.if "${MAKEWEB}" == "Yes"
-LDADD +=	-L${PREFIX}/lib -lz -lutil
-LDSTATIC =	${STATIC}
-PREFIX =	/usr/local
-CHROOT_DIR =	/var/www
-GOTWEB_DIR =	/cgi-bin/gotweb
-LIBEXECDIR =	${GOTWEB_DIR}/libexec
-LIBEXEC_DIR =	${CHROOT_DIR}${LIBEXECDIR}
-ETC_DIR =	${CHROOT_DIR}/etc
-HTTPD_DIR =	${CHROOT_DIR}/htdocs
-TMP_DIR =	${CHROOT_DIR}/tmp
-PROG_DIR =	${HTTPD_DIR}/${PROG}
-CGI_DIR =	${CHROOT_DIR}${GOTWEB_DIR}
-TMPL_DIR =	${CGI_DIR}/gw_tmpl
-PUB_REPOS_DIR =	${CHROOT_DIR}/got/public
-WWWUSR ?=	www
-WWWGRP ?=	www
-.endif
diff --git a/gotweb/Makefile b/gotweb/Makefile
index a738cb3..3a1ae06 100644
--- a/gotweb/Makefile
+++ b/gotweb/Makefile
@@ -1,8 +1,9 @@
 .PATH:${.CURDIR}/../lib
 
-SUBDIR = ../libexec
+SUBDIR = libexec
 
 .include "../got-version.mk"
+.include "Makefile.inc"
 
 PROG =		gotweb
 SRCS =		gotweb.c parse.y blame.c commit_graph.c delta.c diff.c \
@@ -14,9 +15,8 @@ SRCS =		gotweb.c parse.y blame.c commit_graph.c delta.c diff.c \
 MAN =		${PROG}.conf.5
 
 CPPFLAGS +=	-I${.CURDIR}/../include -I${.CURDIR}/../lib -I${.CURDIR} \
-		-I${PREFIX}/include
-
-LDADD =		-L${PREFIX}/lib -lkcgihtml -lkcgi -lz -lutil
+		-I${KCGIBASE}/include
+LDADD +=	-L${KCGIBASE}/lib -lkcgihtml -lkcgi
 LDSTATIC =	${STATIC}
 
 .if ${GOT_RELEASE} != "Yes"
diff --git a/gotweb/Makefile.inc b/gotweb/Makefile.inc
new file mode 100644
index 0000000..f7c4df6
--- /dev/null
+++ b/gotweb/Makefile.inc
@@ -0,0 +1,16 @@
+KCGIBASE ?=	/usr/local
+LDADD +=	-lz -lutil
+LDSTATIC =	${STATIC}
+CHROOT_DIR =	/var/www
+GOTWEB_DIR =	/cgi-bin/gotweb
+LIBEXECDIR =	${GOTWEB_DIR}/libexec
+LIBEXEC_DIR =	${CHROOT_DIR}${LIBEXECDIR}
+ETC_DIR =	${CHROOT_DIR}/etc
+HTTPD_DIR =	${CHROOT_DIR}/htdocs
+TMP_DIR =	${CHROOT_DIR}/tmp
+PROG_DIR =	${HTTPD_DIR}/${PROG}
+CGI_DIR =	${CHROOT_DIR}${GOTWEB_DIR}
+TMPL_DIR =	${CGI_DIR}/gw_tmpl
+PUB_REPOS_DIR =	${CHROOT_DIR}/got/public
+WWWUSR ?=	www
+WWWGRP ?=	www
diff --git a/gotweb/libexec/Makefile b/gotweb/libexec/Makefile
new file mode 100644
index 0000000..a4c900b
--- /dev/null
+++ b/gotweb/libexec/Makefile
@@ -0,0 +1,4 @@
+SUBDIR = got-read-blob got-read-commit got-read-object got-read-tree \
+	got-read-tag got-read-pack got-read-gitconfig
+
+.include <bsd.subdir.mk>
diff --git a/gotweb/libexec/Makefile.inc b/gotweb/libexec/Makefile.inc
new file mode 100644
index 0000000..ea1131a
--- /dev/null
+++ b/gotweb/libexec/Makefile.inc
@@ -0,0 +1,11 @@
+.include "../Makefile.inc"
+
+realinstall:
+	if [ ! -d ${CHROOT_DIR}${LIBEXECDIR}/. ]; then \
+		${INSTALL} -d -o root -g daemon -m 755 \
+		    ${CHROOT_DIR}${LIBEXECDIR}; \
+	fi
+	${INSTALL} ${INSTALL_COPY} -o root -g daemon -m 755 ${PROG} \
+	    ${CHROOT_DIR}${LIBEXECDIR}/${PROG}
+
+NOMAN = Yes
diff --git a/gotweb/libexec/got-read-blob/Makefile b/gotweb/libexec/got-read-blob/Makefile
new file mode 100644
index 0000000..fb9095d
--- /dev/null
+++ b/gotweb/libexec/got-read-blob/Makefile
@@ -0,0 +1,15 @@
+
+.include "../../../got-version.mk"
+
+PROG=		got-read-blob
+SRCS=		got-read-blob.c error.c inflate.c object_parse.c \
+		path.c privsep.c sha1.c
+
+CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
+LDADD = -lutil -lz
+DPADD = ${LIBZ} ${LIBUTIL}
+LDSTATIC = ${STATIC}
+
+.PATH:	${.CURDIR}/../../../lib ${.CURDIR}/../../../libexec/got-read-blob
+
+.include <bsd.prog.mk>
diff --git a/gotweb/libexec/got-read-commit/Makefile b/gotweb/libexec/got-read-commit/Makefile
new file mode 100644
index 0000000..1e78a9b
--- /dev/null
+++ b/gotweb/libexec/got-read-commit/Makefile
@@ -0,0 +1,15 @@
+
+.include "../../../got-version.mk"
+
+PROG=		got-read-commit
+SRCS=		got-read-commit.c error.c inflate.c object_parse.c \
+		path.c privsep.c sha1.c
+
+CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
+LDADD = -lutil -lz
+DPADD = ${LIBZ} ${LIBUTIL}
+LDSTATIC = ${STATIC}
+
+.PATH:	${.CURDIR}/../../../lib ${.CURDIR}/../../../libexec/got-read-commit
+
+.include <bsd.prog.mk>
diff --git a/gotweb/libexec/got-read-gitconfig/Makefile b/gotweb/libexec/got-read-gitconfig/Makefile
new file mode 100644
index 0000000..76cd8d7
--- /dev/null
+++ b/gotweb/libexec/got-read-gitconfig/Makefile
@@ -0,0 +1,15 @@
+
+.include "../../../got-version.mk"
+
+PROG=		got-read-gitconfig
+SRCS=		got-read-gitconfig.c error.c inflate.c object_parse.c \
+		path.c privsep.c sha1.c gitconfig.c
+
+CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
+LDADD = -lutil -lz
+DPADD = ${LIBZ} ${LIBUTIL}
+LDSTATIC = ${STATIC}
+
+.PATH:	${.CURDIR}/../../../lib ${.CURDIR}/../../../libexec/got-read-gitconfig
+
+.include <bsd.prog.mk>
diff --git a/gotweb/libexec/got-read-object/Makefile b/gotweb/libexec/got-read-object/Makefile
new file mode 100644
index 0000000..22604cc
--- /dev/null
+++ b/gotweb/libexec/got-read-object/Makefile
@@ -0,0 +1,15 @@
+
+.include "../../../got-version.mk"
+
+PROG=		got-read-object
+SRCS=		got-read-object.c error.c inflate.c object_parse.c \
+		path.c privsep.c sha1.c
+
+CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
+LDADD = -lutil -lz
+DPADD = ${LIBZ} ${LIBUTIL}
+LDSTATIC = ${STATIC}
+
+.PATH:	${.CURDIR}/../../../lib ${.CURDIR}/../../../libexec/got-read-object
+
+.include <bsd.prog.mk>
diff --git a/gotweb/libexec/got-read-pack/Makefile b/gotweb/libexec/got-read-pack/Makefile
new file mode 100644
index 0000000..eae7dbb
--- /dev/null
+++ b/gotweb/libexec/got-read-pack/Makefile
@@ -0,0 +1,16 @@
+
+.include "../../../got-version.mk"
+
+PROG=		got-read-pack
+SRCS=		got-read-pack.c delta.c error.c inflate.c object_cache.c \
+		object_idset.c object_parse.c opentemp.c pack.c path.c \
+		privsep.c sha1.c delta_cache.c
+
+CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
+LDADD = -lutil -lz
+DPADD = ${LIBZ} ${LIBUTIL}
+LDSTATIC = ${STATIC}
+
+.PATH:	${.CURDIR}/../../../lib ${.CURDIR}/../../../libexec/got-read-pack
+
+.include <bsd.prog.mk>
diff --git a/gotweb/libexec/got-read-tag/Makefile b/gotweb/libexec/got-read-tag/Makefile
new file mode 100644
index 0000000..375212d
--- /dev/null
+++ b/gotweb/libexec/got-read-tag/Makefile
@@ -0,0 +1,15 @@
+
+.include "../../../got-version.mk"
+
+PROG=		got-read-tag
+SRCS=		got-read-tag.c error.c inflate.c object_parse.c \
+		path.c privsep.c sha1.c
+
+CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
+LDADD = -lutil -lz
+DPADD = ${LIBZ} ${LIBUTIL}
+LDSTATIC = ${STATIC}
+
+.PATH:	${.CURDIR}/../../../lib ${.CURDIR}/../../../libexec/got-read-tag
+
+.include <bsd.prog.mk>
diff --git a/gotweb/libexec/got-read-tree/Makefile b/gotweb/libexec/got-read-tree/Makefile
new file mode 100644
index 0000000..b601aea
--- /dev/null
+++ b/gotweb/libexec/got-read-tree/Makefile
@@ -0,0 +1,15 @@
+
+.include "../../../got-version.mk"
+
+PROG=		got-read-tree
+SRCS=		got-read-tree.c error.c inflate.c object_parse.c \
+		path.c privsep.c sha1.c
+
+CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib
+LDADD = -lutil -lz
+DPADD = ${LIBZ} ${LIBUTIL}
+LDSTATIC = ${STATIC}
+
+.PATH:	${.CURDIR}/../../../lib ${.CURDIR}/../../../libexec/got-read-tree
+
+.include <bsd.prog.mk>