commit d7cad54ee75f65cb83dbfa63db242bf5eb503527 from: Thomas Adam date: Thu Jul 14 22:40:53 2022 UTC portable: gotwebd: first stab at compilation This is not yet "clean", but does compile. A few things to consider: * See comments beginning with "TA:" commit - 56324ebe810a1ac808ed970c5c9d8ecd5d64503b commit + d7cad54ee75f65cb83dbfa63db242bf5eb503527 blob - b61874a2364add0e17f44fe202b2f5f129a3b41f blob + fc6eb096a39e9f187ac3455284648c233358aaf0 --- Makefile.am +++ Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = compat libexec got tog gotadmin +SUBDIRS = compat libexec got tog gotadmin gotwebd include $(top_builddir)/Makefile.common blob - 45fdaf9ab0ae1e114a29a44dd2389d38cae2abb9 blob + 01a84b1cba6ca21ae4177de01aa706cc1a23c9cb --- configure.ac +++ configure.ac @@ -77,6 +77,9 @@ AC_TYPE_UINT32_T AC_TYPE_UINT64_T AC_TYPE_UINT8_T +# Check for ifgroupreq which is only available on BSD. +AC_CHECK_TYPES([struct ifgroupreq]) + # Look for library needed for flock. AC_SEARCH_LIBS(flock, bsd) @@ -224,6 +227,56 @@ if test "x$found_imsg_init" = xyes; then else AC_LIBOBJ(imsg) AC_LIBOBJ(imsg-buffer) +fi + +# libevent (for gotwebd). Lifted from tmux. +# Look for libevent. Try libevent_core or libevent with pkg-config first then +# look for the library. +PKG_CHECK_MODULES( + LIBEVENT_CORE, + [libevent_core >= 2], + [ + AM_CPPFLAGS="$LIBEVENT_CORE_CFLAGS $AM_CPPFLAGS" + CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS" + LIBS="$LIBEVENT_CORE_LIBS $LIBS" + found_libevent=yes + ], + found_libevent=no +) +if test x$found_libevent = xno; then + PKG_CHECK_MODULES( + LIBEVENT, + [libevent >= 2], + [ + AM_CPPFLAGS="$LIBEVENT_CFLAGS $AM_CPPFLAGS" + CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS" + LIBS="$LIBEVENT_LIBS $LIBS" + found_libevent=yes + ], + found_libevent=no + ) +fi +if test x$found_libevent = xno; then + AC_SEARCH_LIBS( + event_init, + [event_core event event-1.4], + found_libevent=yes, + found_libevent=no + ) +fi +AC_CHECK_HEADER( + event2/event.h, + AC_DEFINE(HAVE_EVENT2_EVENT_H), + [ + AC_CHECK_HEADER( + event.h, + AC_DEFINE(HAVE_EVENT_H), + found_libevent=no + ) + ] +) +if test "x$found_libevent" = xno; then + AC_MSG_ERROR("libevent not found") fi # libcrypto (via libssl for SHA information) @@ -497,6 +550,7 @@ AC_CONFIG_FILES([Makefile libexec/got-send-pack/Makefile got/Makefile gotadmin/Makefile + gotwebd/Makefile tog/Makefile Makefile.common:Makefile.common.in]) AC_OUTPUT blob - 4c0096efb52bb79e4a8f7e5f09c1b1d953009636 (mode 644) blob + /dev/null --- gotwebd/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -.PATH:${.CURDIR}/../lib - -SUBDIR = libexec - -.include "../got-version.mk" -.include "Makefile.inc" - -PROG = gotwebd -SRCS = config.c sockets.c log.c gotwebd.c parse.y proc.c \ - fcgi.c gotweb.c got_operations.c -SRCS += blame.c commit_graph.c delta.c diff.c \ - diffreg.c error.c fileindex.c object.c object_cache.c \ - object_idset.c object_parse.c opentemp.c path.c pack.c \ - privsep.c reference.c repository.c sha1.c worktree.c \ - utf8.c inflate.c buf.c rcsutil.c diff3.c \ - lockfile.c deflate.c object_create.c delta_cache.c \ - gotconfig.c diff_main.c diff_atomize_text.c diff_myers.c \ - diff_output.c diff_output_plain.c diff_output_unidiff.c \ - diff_output_edscript.c diff_patience.c bloom.c murmurhash2.c \ - worktree_open.c patch.c sigs.c date.c - -MAN = ${PROG}.conf.5 ${PROG}.8 - -CPPFLAGS += -I${.CURDIR}/../include -I${.CURDIR}/../lib -I${.CURDIR} -LDADD += -lz -levent -lutil -lm -YFLAGS = -DPADD = ${LIBEVENT} ${LIBUTIL} -#CFLAGS += -DGOT_NO_OBJ_CACHE - -.if ${GOT_RELEASE} != "Yes" -NOMAN = Yes -.endif - -.if defined(PROFILE) -CPPFLAGS += -DPROFILE -DEBUG = -O0 -pg -g -static -.else -DEBUG = -O0 -g -.endif - -realinstall: - if [ ! -d ${DESTDIR}${PUB_REPOS_DIR}/. ]; then \ - ${INSTALL} -d -o root -g daemon -m 755 ${DESTDIR}${PUB_REPOS_DIR}; \ - fi - ${INSTALL} -c -o root -g daemon -m 0755 ${PROG} ${BINDIR}/${PROG} - if [ ! -d ${DESTDIR}${HTTPD_DIR}/. ]; then \ - ${INSTALL} -d -o root -g daemon -m 755 ${DESTDIR}${HTTPD_DIR}; \ - fi - if [ ! -d ${DESTDIR}${PROG_DIR}/. ]; then \ - ${INSTALL} -d -o root -g daemon -m 755 ${DESTDIR}${PROG_DIR}; \ - fi - ${INSTALL} -c -o ${WWWUSR} -g ${WWWGRP} -m 0755 \ - ${.CURDIR}/files/htdocs/${PROG}/* ${DESTDIR}${PROG_DIR} - -.include blob - /dev/null blob + c01b6b26c3efb3e67767d7f6011240f5356eab38 (mode 644) --- /dev/null +++ gotwebd/Makefile.am @@ -0,0 +1,83 @@ +bin_PROGRAMS = gotwebd + +include $(top_builddir)/Makefile.common + +gotwebd_SOURCES = config.c \ + fcgi.c \ + got_operations.c \ + gotweb.c \ + gotwebd.c \ + log.c \ + proc.c \ + sockets.c \ + parse.y \ + $(top_srcdir)/lib/blame.c \ + $(top_srcdir)/lib/bloom.c \ + $(top_srcdir)/lib/buf.c \ + $(top_srcdir)/lib/commit_graph.c \ + $(top_srcdir)/lib/date.c \ + $(top_srcdir)/lib/deflate.c \ + $(top_srcdir)/lib/delta.c \ + $(top_srcdir)/lib/delta_cache.c \ + $(top_srcdir)/lib/diff.c \ + $(top_srcdir)/lib/diff3.c \ + $(top_srcdir)/lib/diff_atomize_text.c \ + $(top_srcdir)/lib/diff_main.c \ + $(top_srcdir)/lib/diff_myers.c \ + $(top_srcdir)/lib/diff_output.c \ + $(top_srcdir)/lib/diff_output_edscript.c \ + $(top_srcdir)/lib/diff_output_plain.c \ + $(top_srcdir)/lib/diff_output_unidiff.c \ + $(top_srcdir)/lib/diff_patience.c \ + $(top_srcdir)/lib/diffreg.c \ + $(top_srcdir)/lib/error.c \ + $(top_srcdir)/lib/fileindex.c \ + $(top_srcdir)/lib/gotconfig.c \ + $(top_srcdir)/lib/inflate.c \ + $(top_srcdir)/lib/lockfile.c \ + $(top_srcdir)/lib/murmurhash2.c \ + $(top_srcdir)/lib/object.c \ + $(top_srcdir)/lib/object_cache.c \ + $(top_srcdir)/lib/object_create.c \ + $(top_srcdir)/lib/object_idset.c \ + $(top_srcdir)/lib/object_parse.c \ + $(top_srcdir)/lib/opentemp.c \ + $(top_srcdir)/lib/pack.c \ + $(top_srcdir)/lib/patch.c \ + $(top_srcdir)/lib/path.c \ + $(top_srcdir)/lib/privsep.c \ + $(top_srcdir)/lib/rcsutil.c \ + $(top_srcdir)/lib/reference.c \ + $(top_srcdir)/lib/repository.c \ + $(top_srcdir)/lib/sha1.c \ + $(top_srcdir)/lib/sigs.c \ + $(top_srcdir)/lib/utf8.c \ + $(top_srcdir)/lib/worktree.c \ + $(top_srcdir)/lib/worktree_open.c + +gotwebd_DEPENDENCIES = $(top_builddir)/compat/libopenbsd-compat.a +EXTRA_DIST = gotwebd.8 gotwebd.conf.5 + +man5_MANS = gotwebd.conf.5 +man8_MANS = gotwebd.8 + +LDADD = -L$(top_builddir)/compat -lopenbsd-compat -lm +if HOST_FREEBSD +LDADD += -lmd +endif + +#realinstall: +# if [ ! -d ${DESTDIR}${PUB_REPOS_DIR}/. ]; then \ +# ${INSTALL} -d -o root -g daemon -m 755 ${DESTDIR}${PUB_REPOS_DIR}; \ +# fi +# ${INSTALL} -c -o root -g daemon -m 0755 ${PROG} ${BINDIR}/${PROG} +# if [ ! -d ${DESTDIR}${HTTPD_DIR}/. ]; then \ +# ${INSTALL} -d -o root -g daemon -m 755 ${DESTDIR}${HTTPD_DIR}; \ +# fi +# if [ ! -d ${DESTDIR}${PROG_DIR}/. ]; then \ +# ${INSTALL} -d -o root -g daemon -m 755 ${DESTDIR}${PROG_DIR}; \ +# fi +# ${INSTALL} -c -o ${WWWUSR} -g ${WWWGRP} -m 0755 \ +# ${.CURDIR}/files/htdocs/${PROG}/* ${DESTDIR}${PROG_DIR} +# +#.include blob - 4a8874a87e47d8824f253f466514c16f8ce8c881 blob + 5a76b94aca16e49a18882ea8ab6ac4d9dfcd7f48 --- gotwebd/config.c +++ gotwebd/config.c @@ -16,7 +16,6 @@ */ #include -#include #include #include #include @@ -32,12 +31,12 @@ #include #include #include -#include #include -#include #include "got_opentemp.h" +#include "got_compat.h" + #include "proc.h" #include "gotwebd.h" blob - 1581cf938674fc59b27476119bfcc54b5b4417b5 blob + 9e68f4027f2f8406d2668b558f5c35423ddd20de --- gotwebd/fcgi.c +++ gotwebd/fcgi.c @@ -17,13 +17,11 @@ */ #include -#include #include #include #include #include -#include #include #include #include @@ -31,6 +29,8 @@ #include #include "got_error.h" + +#include "got_compat.h" #include "proc.h" #include "gotwebd.h" blob - 6437bf550c8e246193623b0bed1c1356161f0b2e blob + 235daa3c0d9dae94b8f7e264cdc447e038b3bacd --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -19,8 +19,6 @@ #include #include -#include -#include #include #include #include @@ -36,6 +34,8 @@ #include "got_commit_graph.h" #include "got_blame.h" #include "got_privsep.h" + +#include "got_compat.h" #include "proc.h" #include "gotwebd.h" blob - 5de75e9906e8db76b4f47ea4e47f97bbff344227 blob + c7147685f051d09aa8e7135cf48c818204004e60 --- gotwebd/gotweb.c +++ gotwebd/gotweb.c @@ -25,8 +25,6 @@ #include #include #include -#include -#include #include #include #include @@ -46,6 +44,8 @@ #include "proc.h" #include "gotwebd.h" + +#include "got_compat.h" enum gotweb_ref_tm { TM_DIFF, @@ -2827,4 +2827,4 @@ gotweb_get_time_str(char **repo_age, time_t committer_ break; } return NULL; -} \ No newline at end of file +} blob - c6930e3119c2231e948970c004f3f21d33c34c16 blob + 56cc78f8ef8d5f658fc9176ef43485f72507a60b --- gotwebd/gotwebd.c +++ gotwebd/gotwebd.c @@ -16,7 +16,6 @@ */ #include -#include #include #include #include @@ -32,19 +31,19 @@ #include #include #include -#include #include #include #include #include #include -#include #include "got_opentemp.h" #include "proc.h" #include "gotwebd.h" +#include "got_compat.h" + __dead void usage(void); int main(int, char **); blob - 79d3d334581eddd8ffcc0f02f067e5c64d0be72e blob + 1504f3baa6e43159943e72833c450f5ebbbebf05 --- gotwebd/log.c +++ gotwebd/log.c @@ -22,6 +22,8 @@ #include #include +#include "got_compat.h" + static int debug; static int verbose; const char *log_procname; blob - c7b300955ba979db3cd4d8308802a8179f9d7ac4 blob + 60f3a7e3479292bfe3d5319dbb88e596a222da7b --- gotwebd/parse.y +++ gotwebd/parse.y @@ -23,7 +23,6 @@ %{ #include #include -#include #include #include @@ -37,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -50,6 +48,7 @@ #include "proc.h" #include "gotwebd.h" +#include "got_compat.h" TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files); static struct file { @@ -1047,7 +1046,10 @@ host_v4(const char *s) if ((h = calloc(1, sizeof(*h))) == NULL) fatal(__func__); sain = (struct sockaddr_in *)&h->ss; +/* TA: Iffy... */ +#ifndef __linux__ sain->sin_len = sizeof(struct sockaddr_in); +#endif sain->sin_family = AF_INET; sain->sin_addr.s_addr = ina.s_addr; if (sain->sin_addr.s_addr == INADDR_ANY) @@ -1072,7 +1074,10 @@ host_v6(const char *s) if ((h = calloc(1, sizeof(*h))) == NULL) fatal(__func__); sa_in6 = (struct sockaddr_in6 *)&h->ss; +/* TA: Iffy... */ +#ifndef __linux__ sa_in6->sin6_len = sizeof(struct sockaddr_in6); +#endif sa_in6->sin6_family = AF_INET6; memcpy(&sa_in6->sin6_addr, &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr, @@ -1142,12 +1147,18 @@ host_dns(const char *s, struct addresslist *al, int ma if (res->ai_family == AF_INET) { sain = (struct sockaddr_in *)&h->ss; +/* TA: Iffy... */ +#ifndef __linux__ sain->sin_len = sizeof(struct sockaddr_in); +#endif sain->sin_addr.s_addr = ((struct sockaddr_in *) res->ai_addr)->sin_addr.s_addr; } else { sin6 = (struct sockaddr_in6 *)&h->ss; +/* TA: Iffy... */ +#ifndef __linux__ sin6->sin6_len = sizeof(struct sockaddr_in6); +#endif memcpy(&sin6->sin6_addr, &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr, sizeof(struct in6_addr)); } @@ -1208,12 +1219,18 @@ host_if(const char *s, struct addresslist *al, int max if (af == AF_INET) { sain = (struct sockaddr_in *)&h->ss; +/* TA: Iffy... */ +#ifndef __linux__ sain->sin_len = sizeof(struct sockaddr_in); +#endif sain->sin_addr.s_addr = ((struct sockaddr_in *) p->ifa_addr)->sin_addr.s_addr; } else { sin6 = (struct sockaddr_in6 *)&h->ss; +/* TA: Iffy... */ +#ifndef __linux__ sin6->sin6_len = sizeof(struct sockaddr_in6); +#endif memcpy(&sin6->sin6_addr, &((struct sockaddr_in6 *) p->ifa_addr)->sin6_addr, sizeof(struct in6_addr)); sin6->sin6_scope_id = ((struct sockaddr_in6 *) @@ -1274,6 +1291,8 @@ host(const char *s, struct addresslist *al, int max, int is_if_in_group(const char *ifname, const char *groupname) { +/* TA: Check this... */ +#ifdef HAVE_STRUCT_IFGROUPREQ unsigned int len; struct ifgroupreq ifgr; struct ifg_req *ifg; @@ -1313,6 +1332,9 @@ is_if_in_group(const char *ifname, const char *groupna end: close(s); return (ret); +#else + return (0); +#endif } int blob - 037993ed0667b68af3bc09186201595197a814c9 blob + 9a66f6ba7ddb7546a29900c4fc95a185fe56f657 --- gotwebd/proc.c +++ gotwebd/proc.c @@ -16,10 +16,12 @@ */ #include -#include #include #include +/* TA: FIXME */ +#include + #include #include #include @@ -29,10 +31,11 @@ #include #include #include -#include #include "proc.h" +#include "got_compat.h" + void proc_exec(struct privsep *, struct privsep_proc *, unsigned int, int, char **); void proc_setup(struct privsep *, struct privsep_proc *, unsigned int); blob - 524112fcf4b0c72a25c6f5a4cb85c16bd33ef3a9 blob + 217c9e4be9fba252cfbaf0026bb6f2c271888bfc --- gotwebd/proc.h +++ gotwebd/proc.h @@ -14,6 +14,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "got_compat.h" + enum { IMSG_NONE, IMSG_CTL_OK, blob - f07a3be3b97818f5ddfc016d4f5b93952636de34 blob + d6c6ae4610fffa999ac7595ada5fb92eac62307c --- gotwebd/sockets.c +++ gotwebd/sockets.c @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -37,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -47,13 +45,14 @@ #include #include #include -#include #include "got_error.h" #include "got_opentemp.h" #include "proc.h" #include "gotwebd.h" + +#include "got_compat.h" #define SOCKS_BACKLOG 5 #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) @@ -296,13 +295,19 @@ sockets_socket_af(struct sockaddr_storage *ss, in_port switch (ss->ss_family) { case AF_INET: ((struct sockaddr_in *)ss)->sin_port = port; +/* TA: Iffy... */ +#ifndef __linux__ ((struct sockaddr_in *)ss)->sin_len = sizeof(struct sockaddr_in); +#endif break; case AF_INET6: ((struct sockaddr_in6 *)ss)->sin6_port = port; +/* TA: Iffy... */ +#ifndef __linux__ ((struct sockaddr_in6 *)ss)->sin6_len = sizeof(struct sockaddr_in6); +#endif break; default: return -1; @@ -579,7 +584,8 @@ sockets_create_socket(struct addresslist *al, in_port_ flags |= O_NONBLOCK; fcntl(fd, F_SETFL, flags); - if (bind(fd, (struct sockaddr *)&a->ss, a->ss.ss_len) == -1) { + /* TA: 'sizeof a' vs a->ss.len */ + if (bind(fd, (struct sockaddr *)&a->ss, sizeof a) == -1) { close(fd); log_info("%s: can't bind to port %d", __func__, ntohs(port)); @@ -721,4 +727,4 @@ sockets_rlimit(int maxfd) rl.rlim_cur = MAXIMUM(rl.rlim_max, (rlim_t)maxfd); if (setrlimit(RLIMIT_NOFILE, &rl) == -1) fatal("%s: failed to set resource limit", __func__); -} \ No newline at end of file +}